mirror of https://gitee.com/bigwinds/arangodb
more tests for indexes to overcome getIndexes() mysteries (related to issue #366)
This commit is contained in:
parent
346e364767
commit
92abde4932
|
@ -386,6 +386,7 @@ static TRI_json_t* JsonPrimary (TRI_index_t* idx, TRI_primary_collection_t const
|
|||
TRI_PushBack3ListJson(TRI_UNKNOWN_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_UNKNOWN_MEM_ZONE, "_id"));
|
||||
|
||||
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "id", TRI_CreateNumberJson(TRI_UNKNOWN_MEM_ZONE, 0));
|
||||
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "unique", TRI_CreateBooleanJson(TRI_UNKNOWN_MEM_ZONE, true));
|
||||
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "type", TRI_CreateStringCopyJson(TRI_UNKNOWN_MEM_ZONE, "primary"));
|
||||
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "fields", fields);
|
||||
|
||||
|
@ -648,6 +649,7 @@ static TRI_json_t* JsonEdge (TRI_index_t* idx, TRI_primary_collection_t const* c
|
|||
TRI_PushBack3ListJson(TRI_UNKNOWN_MEM_ZONE, fields, TRI_CreateStringCopyJson(TRI_UNKNOWN_MEM_ZONE, "_to"));
|
||||
|
||||
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "id", TRI_CreateNumberJson(TRI_UNKNOWN_MEM_ZONE, 0));
|
||||
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "unique", TRI_CreateBooleanJson(TRI_UNKNOWN_MEM_ZONE, false));
|
||||
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "type", TRI_CreateStringCopyJson(TRI_UNKNOWN_MEM_ZONE, "edge"));
|
||||
TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "fields", fields);
|
||||
|
||||
|
|
|
@ -137,6 +137,349 @@ function indexSuite() {
|
|||
};
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- getIndexes
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test suite: return value of getIndexes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function getIndexesSuite() {
|
||||
var cn = "UnitTestsCollectionIdx";
|
||||
var collection = null;
|
||||
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set up
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
setUp : function () {
|
||||
internal.db._drop(cn);
|
||||
collection = internal.db._create(cn, { waitForSync : false });
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tear down
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
tearDown : function () {
|
||||
collection.drop();
|
||||
collection = null;
|
||||
internal.wait(0.0);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get primary
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetPrimary : function () {
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(1, res.length);
|
||||
var idx = res[0];
|
||||
|
||||
assertEqual("primary", idx.type);
|
||||
assertEqual(true, idx.unique);
|
||||
assertEqual([ "_id" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get unique hash index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetHashUnique1 : function () {
|
||||
collection.ensureUniqueConstraint("value");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("hash", idx.type);
|
||||
assertEqual(true, idx.unique);
|
||||
assertEqual([ "value" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get unique hash index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetHashUnique2 : function () {
|
||||
collection.ensureUniqueConstraint("value1", "value2");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("hash", idx.type);
|
||||
assertEqual(true, idx.unique);
|
||||
assertEqual([ "value1", "value2" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get non-unique hash index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetHashNonUnique1 : function () {
|
||||
collection.ensureHashIndex("value");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("hash", idx.type);
|
||||
assertEqual(false, idx.unique);
|
||||
assertEqual([ "value" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get non-unique hash index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetHashNonUnique2 : function () {
|
||||
collection.ensureHashIndex("value1", "value2");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("hash", idx.type);
|
||||
assertEqual(false, idx.unique);
|
||||
assertEqual([ "value1", "value2" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get unique skiplist index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetSkiplistUnique1 : function () {
|
||||
collection.ensureUniqueSkiplist("value");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("skiplist", idx.type);
|
||||
assertEqual(true, idx.unique);
|
||||
assertEqual([ "value" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get unique skiplist index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetSkiplistUnique2 : function () {
|
||||
collection.ensureUniqueSkiplist("value1", "value2");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("skiplist", idx.type);
|
||||
assertEqual(true, idx.unique);
|
||||
assertEqual([ "value1", "value2" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get non-unique skiplist index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetSkiplistNonUnique1 : function () {
|
||||
collection.ensureSkiplist("value");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("skiplist", idx.type);
|
||||
assertEqual(false, idx.unique);
|
||||
assertEqual([ "value" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get non-unique skiplist index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetSkiplistNonUnique2 : function () {
|
||||
collection.ensureSkiplist("value1", "value2");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("skiplist", idx.type);
|
||||
assertEqual(false, idx.unique);
|
||||
assertEqual([ "value1", "value2" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get bitarray index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetBitarray: function () {
|
||||
collection.ensureBitarray("value", [ "one", "two", "three" ]);
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("bitarray", idx.type);
|
||||
assertEqual(false, idx.unique);
|
||||
assertEqual(false, idx["undefined"]);
|
||||
assertEqual([ [ "value", [ "one", "two", "three" ] ] ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get fulltext index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetFulltext: function () {
|
||||
collection.ensureFulltextIndex("value");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("fulltext", idx.type);
|
||||
assertEqual(false, idx.unique);
|
||||
assertEqual([ "value" ], idx.fields);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- getIndexes for edges
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test suite: return value of getIndexes for an edge collection
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function getIndexesEdgesSuite() {
|
||||
var cn = "UnitTestsCollectionIdx";
|
||||
var collection = null;
|
||||
|
||||
return {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief set up
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
setUp : function () {
|
||||
internal.db._drop(cn);
|
||||
collection = internal.db._createEdgeCollection(cn, { waitForSync : false });
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief tear down
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
tearDown : function () {
|
||||
collection.drop();
|
||||
collection = null;
|
||||
internal.wait(0.0);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get primary
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetPrimary : function () {
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[0];
|
||||
|
||||
assertEqual("primary", idx.type);
|
||||
assertEqual(true, idx.unique);
|
||||
assertEqual([ "_id" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get edge
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetEdge : function () {
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(2, res.length);
|
||||
var idx = res[1];
|
||||
|
||||
assertEqual("edge", idx.type);
|
||||
assertEqual(false, idx.unique);
|
||||
assertEqual([ "_from", "_to" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get unique hash index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetHashUnique1 : function () {
|
||||
collection.ensureUniqueConstraint("value");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(3, res.length);
|
||||
var idx = res[2];
|
||||
|
||||
assertEqual("hash", idx.type);
|
||||
assertEqual(true, idx.unique);
|
||||
assertEqual([ "value" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get unique skiplist index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetSkiplistUnique1 : function () {
|
||||
collection.ensureUniqueSkiplist("value");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(3, res.length);
|
||||
var idx = res[2];
|
||||
|
||||
assertEqual("skiplist", idx.type);
|
||||
assertEqual(true, idx.unique);
|
||||
assertEqual([ "value" ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get bitarray index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetBitarray: function () {
|
||||
collection.ensureBitarray("value", [ "one", "two", "three" ]);
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(3, res.length);
|
||||
var idx = res[2];
|
||||
|
||||
assertEqual("bitarray", idx.type);
|
||||
assertEqual(false, idx.unique);
|
||||
assertEqual(false, idx["undefined"]);
|
||||
assertEqual([ [ "value", [ "one", "two", "three" ] ] ], idx.fields);
|
||||
},
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief test: get fulltext index
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
testGetFulltext: function () {
|
||||
collection.ensureFulltextIndex("value");
|
||||
var res = collection.getIndexes();
|
||||
|
||||
assertEqual(3, res.length);
|
||||
var idx = res[2];
|
||||
|
||||
assertEqual("fulltext", idx.type);
|
||||
assertEqual(false, idx.unique);
|
||||
assertEqual([ "value" ], idx.fields);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- main
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -146,6 +489,8 @@ function indexSuite() {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
jsunity.run(indexSuite);
|
||||
jsunity.run(getIndexesSuite);
|
||||
jsunity.run(getIndexesEdgesSuite);
|
||||
|
||||
return jsunity.done();
|
||||
|
||||
|
|
Loading…
Reference in New Issue