From f8476ce0b0d89d1ae7fa471126522f4df623f68c Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 13 Feb 2014 18:14:53 +0100 Subject: [PATCH] fixed tests --- Documentation/ImplementorManual/HttpSimple.md | 20 + .../ImplementorManual/HttpSimpleTOC.md | 5 + UnitTests/Makefile.unittests | 3 +- arangod/V8Server/v8-query.cpp | 37 +- js/actions/api-index.js | 7 +- js/actions/api-simple.js | 333 +++++++++- .../modules/org/arangodb/arango-collection.js | 26 +- .../modules/org/arangodb/arango-collection.js | 26 +- js/common/tests/shell-index.js | 516 ---------------- js/server/modules/org/arangodb/actions.js | 6 +- js/server/tests/shell-index-ensure.js | 570 ++++++++++++++++++ lib/BasicsC/errors.dat | 2 +- lib/BasicsC/voc-errors.h | 4 +- 13 files changed, 1006 insertions(+), 549 deletions(-) create mode 100644 js/server/tests/shell-index-ensure.js diff --git a/Documentation/ImplementorManual/HttpSimple.md b/Documentation/ImplementorManual/HttpSimple.md index 0a47c61ddc..be3af93382 100644 --- a/Documentation/ImplementorManual/HttpSimple.md +++ b/Documentation/ImplementorManual/HttpSimple.md @@ -42,6 +42,26 @@ dispose the server-side cursor afterwards. @anchor HttpSimpleFirstExample @copydetails JSA_put_api_simple_first_example +@CLEARPAGE +@anchor HttpSimpleByExampleHash +@copydetails JSA_put_api_simple_by_example_hash + +@CLEARPAGE +@anchor HttpSimpleByExampleSkiplist +@copydetails JSA_put_api_simple_by_example_skiplist + +@CLEARPAGE +@anchor HttpSimpleByExampleBitarray +@copydetails JSA_put_api_simple_by_example_bitarray + +@CLEARPAGE +@anchor HttpSimpleByConditionSkiplist +@copydetails JSA_put_api_simple_by_condition_skiplist + +@CLEARPAGE +@anchor HttpSimpleByConditionBitarray +@copydetails JSA_put_api_simple_by_condition_bitarray + @CLEARPAGE @anchor HttpSimpleAny @copydetails JSA_put_api_simple_any diff --git a/Documentation/ImplementorManual/HttpSimpleTOC.md b/Documentation/ImplementorManual/HttpSimpleTOC.md index 0972da2847..14c484fb82 100644 --- a/Documentation/ImplementorManual/HttpSimpleTOC.md +++ b/Documentation/ImplementorManual/HttpSimpleTOC.md @@ -7,6 +7,11 @@ TOC {#HttpSimpleTOC} - @ref HttpSimpleAll "PUT /_api/simple/all" - @ref HttpSimpleByExample "PUT /_api/simple/by-example" - @ref HttpSimpleFirstExample "PUT /_api/simple/first-example" + - @ref HttpSimpleByExampleHash "PUT /_api/simple/by-example-hash" + - @ref HttpSimpleByExampleSkiplist "PUT /_api/simple/by-example-skiplist" + - @ref HttpSimpleByExampleBitarray "PUT /_api/simple/by-example-bitarray" + - @ref HttpSimpleByConditionSkiplist "PUT /_api/simple/by-condition-skiplist" + - @ref HttpSimpleByConditionBitarray "PUT /_api/simple/by-condition-bitarray" - @ref HttpSimpleAny "PUT /_api/simple/any" - @ref HttpSimpleRange "PUT /_api/simple/range" - @ref HttpSimpleNear "PUT /_api/simple/near" diff --git a/UnitTests/Makefile.unittests b/UnitTests/Makefile.unittests index c768bd4a02..0c9bc9f1aa 100755 --- a/UnitTests/Makefile.unittests +++ b/UnitTests/Makefile.unittests @@ -322,7 +322,7 @@ unittests-single: @rm -rf "$(VOCDIR)" @mkdir -p "$(VOCDIR)/databases" - $(VALGRIND) @builddir@/bin/arangod "$(VOCDIR)" $(SERVER_OPT) --javascript.unit-test $(TEST) || test "x$(FORCE)" == "x1" + $(VALGRIND) @builddir@/bin/arangod "$(VOCDIR)" $(SERVER_OPT) --server.endpoint "tcp://$(VOCHOST):$(VOCPORT)" --javascript.unit-tests $(TEST) || test "x$(FORCE)" == "x1" @rm -rf "$(VOCDIR)" @@ -399,6 +399,7 @@ SHELL_SERVER_ONLY = \ @top_srcdir@/js/server/tests/shell-foxx-template-middleware.js \ @top_srcdir@/js/server/tests/shell-foxx-format-middleware.js \ @top_srcdir@/js/server/tests/shell-foxx-preprocessor.js \ + @top_srcdir@/js/server/tests/shell-index-ensure.js \ @top_srcdir@/js/server/tests/shell-skiplist-index.js \ @top_srcdir@/js/server/tests/shell-skiplist-rm-performance.js \ @top_srcdir@/js/server/tests/shell-skiplist-correctness.js diff --git a/arangod/V8Server/v8-query.cpp b/arangod/V8Server/v8-query.cpp index 630cfb6bc8..bd08b84d63 100644 --- a/arangod/V8Server/v8-query.cpp +++ b/arangod/V8Server/v8-query.cpp @@ -134,11 +134,11 @@ static void ExtractSkipAndLimit (v8::Arguments const& argv, skip = TRI_QRY_NO_SKIP; limit = TRI_QRY_NO_LIMIT; - if (pos < (size_t) argv.Length() && ! argv[pos]->IsNull()) { + if (pos < (size_t) argv.Length() && ! argv[pos]->IsNull() && ! argv[pos]->IsUndefined()) { skip = (TRI_voc_size_t) TRI_ObjectToDouble(argv[pos]); } - if (pos + 1 < (size_t) argv.Length() && ! argv[pos + 1]->IsNull()) { + if (pos + 1 < (size_t) argv.Length() && ! argv[pos + 1]->IsNull() && ! argv[pos + 1]->IsUndefined()) { limit = (TRI_voc_ssize_t) TRI_ObjectToDouble(argv[pos + 1]); } } @@ -280,10 +280,11 @@ static TRI_index_operator_t* SetupConditionsSkiplist (TRI_index_t* idx, TRI_shaper_t* shaper, v8::Handle conditions) { TRI_index_operator_t* lastOperator = 0; - TRI_json_t* parameters = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE); size_t numEq = 0; size_t lastNonEq = 0; + TRI_json_t* parameters = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE); + if (parameters == 0) { return 0; } @@ -1056,7 +1057,7 @@ static v8::Handle ExecuteSkiplistQuery (v8::Arguments const& argv, } if (idx->_type != TRI_IDX_TYPE_SKIPLIST_INDEX) { - TRI_V8_TYPE_ERROR(scope, "index must be a skiplist index"); + TRI_V8_EXCEPTION(scope, TRI_ERROR_ARANGO_NO_INDEX); } TRI_index_operator_t* skiplistOperator; @@ -1070,7 +1071,7 @@ static v8::Handle ExecuteSkiplistQuery (v8::Arguments const& argv, } if (skiplistOperator == 0) { - TRI_V8_EXCEPTION_PARAMETER(scope, "setting up skiplist operator failed"); + TRI_V8_EXCEPTION(scope, TRI_ERROR_BAD_PARAMETER); } TRI_skiplist_iterator_t* skiplistIterator = TRI_LookupSkiplistIndex(idx, skiplistOperator); @@ -1258,7 +1259,7 @@ static v8::Handle ExecuteBitarrayQuery (v8::Arguments const& argv, } if (idx->_type != TRI_IDX_TYPE_BITARRAY_INDEX) { - TRI_V8_TYPE_ERROR(scope, "index must be a skiplist index"); + TRI_V8_EXCEPTION(scope, TRI_ERROR_ARANGO_NO_INDEX); } @@ -1272,7 +1273,7 @@ static v8::Handle ExecuteBitarrayQuery (v8::Arguments const& argv, } if (indexOperator == 0) { // something wrong - TRI_V8_EXCEPTION_PARAMETER(scope, "setting up bitarray index operator failed"); + TRI_V8_EXCEPTION(scope, TRI_ERROR_BAD_PARAMETER); } // ............................................................................. @@ -2088,7 +2089,7 @@ static v8::Handle ByExampleHashIndexQuery (ReadTransactionType& trx, } if (idx->_type != TRI_IDX_TYPE_HASH_INDEX) { - TRI_V8_TYPE_ERROR(scope, "index must be a hash index"); + TRI_V8_EXCEPTION(scope, TRI_ERROR_ARANGO_NO_INDEX); } TRI_hash_index_t* hashIndex = (TRI_hash_index_t*) idx; @@ -2204,7 +2205,7 @@ static v8::Handle JS_ByExampleHashIndex (v8::Arguments const& argv) { //////////////////////////////////////////////////////////////////////////////// static v8::Handle JS_ByConditionSkiplist (v8::Arguments const& argv) { - std::string signature("BY_CONDITION_SKIPLIST(, , , )"); + std::string const signature("BY_CONDITION_SKIPLIST(, , , )"); return ExecuteSkiplistQuery(argv, signature, QUERY_CONDITION); } @@ -2214,7 +2215,7 @@ static v8::Handle JS_ByConditionSkiplist (v8::Arguments const& argv) //////////////////////////////////////////////////////////////////////////////// static v8::Handle JS_ByExampleSkiplist (v8::Arguments const& argv) { - std::string signature("BY_EXAMPLE_SKIPLIST(, , , )"); + std::string const signature("BY_EXAMPLE_SKIPLIST(, , , )"); return ExecuteSkiplistQuery(argv, signature, QUERY_EXAMPLE); } @@ -2224,7 +2225,7 @@ static v8::Handle JS_ByExampleSkiplist (v8::Arguments const& argv) { //////////////////////////////////////////////////////////////////////////////// static v8::Handle JS_ByExampleBitarray (v8::Arguments const& argv) { - std::string signature("BY_EXAMPLE_BITARRAY(, , , )"); + std::string const signature("BY_EXAMPLE_BITARRAY(, , , )"); return ExecuteBitarrayQuery(argv, signature, QUERY_EXAMPLE); } @@ -2234,7 +2235,7 @@ static v8::Handle JS_ByExampleBitarray (v8::Arguments const& argv) { //////////////////////////////////////////////////////////////////////////////// static v8::Handle JS_ByConditionBitarray (v8::Arguments const& argv) { - std::string signature("BY_CONDITION_BITARRAY(, , , )"); + std::string const signature("BY_CONDITION_BITARRAY(, , , )"); return ExecuteBitarrayQuery(argv, signature, QUERY_CONDITION); } @@ -2570,7 +2571,7 @@ static v8::Handle FulltextQuery (ReadTransactionType& trx, } if (idx->_type != TRI_IDX_TYPE_FULLTEXT_INDEX) { - TRI_V8_TYPE_ERROR(scope, "index must be a fulltext index"); + TRI_V8_EXCEPTION(scope, TRI_ERROR_ARANGO_NO_INDEX); } const string queryString = TRI_ObjectToString(argv[1]); @@ -2828,8 +2829,9 @@ static v8::Handle NearQuery (ReadTransactionType& trx, return scope.Close(v8::ThrowException(*err)); } - if (idx->_type != TRI_IDX_TYPE_GEO1_INDEX && idx->_type != TRI_IDX_TYPE_GEO2_INDEX) { - TRI_V8_TYPE_ERROR(scope, "index must be a geo-index"); + if (idx->_type != TRI_IDX_TYPE_GEO1_INDEX && + idx->_type != TRI_IDX_TYPE_GEO2_INDEX) { + TRI_V8_EXCEPTION(scope, TRI_ERROR_ARANGO_NO_INDEX); } // extract latitude and longitude @@ -2951,8 +2953,9 @@ static v8::Handle WithinQuery (ReadTransactionType& trx, return scope.Close(v8::ThrowException(*err)); } - if (idx->_type != TRI_IDX_TYPE_GEO1_INDEX && idx->_type != TRI_IDX_TYPE_GEO2_INDEX) { - TRI_V8_TYPE_ERROR(scope, "index must be a geo-index"); + if (idx->_type != TRI_IDX_TYPE_GEO1_INDEX && + idx->_type != TRI_IDX_TYPE_GEO2_INDEX) { + TRI_V8_EXCEPTION(scope, TRI_ERROR_ARANGO_NO_INDEX); } // extract latitude and longitude diff --git a/js/actions/api-index.js b/js/actions/api-index.js index 707d061865..069faa3f5c 100644 --- a/js/actions/api-index.js +++ b/js/actions/api-index.js @@ -837,7 +837,12 @@ function post_api_index_bitarray (req, res, collection, body) { var index; - index = collection.ensureBitarray.apply(collection, fields); + if (body["undefined"]) { + index = collection.ensureUndefBitarray.apply(collection, fields); + } + else { + index = collection.ensureBitarray.apply(collection, fields); + } if (index.isNewlyCreated) { actions.resultOk(req, res, actions.HTTP_CREATED, index); diff --git a/js/actions/api-simple.js b/js/actions/api-simple.js index 94643374d9..6eb0ed1f14 100644 --- a/js/actions/api-simple.js +++ b/js/actions/api-simple.js @@ -1,4 +1,4 @@ -/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true, stupid: true */ +/*jslint indent: 2, nomen: true, maxlen: 120, sloppy: true, vars: true, white: true, plusplus: true, stupid: true */ /*global require, CREATE_CURSOR */ //////////////////////////////////////////////////////////////////////////////// @@ -34,15 +34,338 @@ var ERRORS = require("internal").errors; var API = "_api/simple/"; -// ----------------------------------------------------------------------------- -// --SECTION-- public functions -// ----------------------------------------------------------------------------- - //////////////////////////////////////////////////////////////////////////////// /// @addtogroup ArangoAPI /// @{ //////////////////////////////////////////////////////////////////////////////// +// ----------------------------------------------------------------------------- +// --SECTION-- private functions +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @fn JSA_put_api_simple_by_example_hash +/// @brief returns all documents of a collection matching a given example, +/// using a specific hash index +/// +/// @RESTHEADER{PUT /_api/simple/by-example-hash,executes query by-example using a hash index} +/// +/// @RESTBODYPARAM{query,string,required} +/// Contains the query specification. +/// +/// @RESTDESCRIPTION +/// +/// This will find all documents matching a given example, using the specified +/// hash index. +/// +/// The call expects a JSON object as body with the following attributes: +/// +/// - `collection`: The name of the collection to query. +/// +/// - `index`: The id of the index to be used for the query. The index must exist +/// and must be of type `hash`. +/// +/// - `example`: an example document. The example must contain a value for each +/// attribute in the index. +/// +/// - `skip`: The number of documents to skip in the query. (optional) +/// +/// - `limit`: The maximal number of documents to return. (optional) +/// +/// Returns a cursor containing the result, see @ref HttpCursor for details. +/// +/// @RESTRETURNCODES +/// +/// @RESTRETURNCODE{201} +/// is returned if the query was executed successfully. +/// +/// @RESTRETURNCODE{400} +/// is returned if the body does not contain a valid JSON representation of a +/// query. The response body contains an error document in this case. +/// +/// @RESTRETURNCODE{404} +/// is returned if the collection specified by `collection` is unknown. The +/// response body contains an error document in this case. +/// The same error code is also returned if an invalid index id or type is used. +/// +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @fn JSA_put_api_simple_by_example_skiplist +/// @brief returns all documents of a collection matching a given example, +/// using a specific skiplist index +/// +/// @RESTHEADER{PUT /_api/simple/by-example-skiplist,executes query by-example using a skiplist index} +/// +/// @RESTBODYPARAM{query,string,required} +/// Contains the query specification. +/// +/// @RESTDESCRIPTION +/// +/// This will find all documents matching a given example, using the specified +/// skiplist index. +/// +/// The call expects a JSON object as body with the following attributes: +/// +/// - `collection`: The name of the collection to query. +/// +/// - `index`: The id of the index to be used for the query. The index must +/// exist and must be of type `skiplist`. +/// +/// - `example`: an example document. The example must contain a value for each +/// attribute in the index. +/// +/// - `skip`: The number of documents to skip in the query. (optional) +/// +/// - `limit`: The maximal number of documents to return. (optional) +/// +/// Returns a cursor containing the result, see @ref HttpCursor for details. +/// +/// @RESTRETURNCODES +/// +/// @RESTRETURNCODE{201} +/// is returned if the query was executed successfully. +/// +/// @RESTRETURNCODE{400} +/// is returned if the body does not contain a valid JSON representation of a +/// query. The response body contains an error document in this case. +/// +/// @RESTRETURNCODE{404} +/// is returned if the collection specified by `collection` is unknown. The +/// response body contains an error document in this case. +/// The same error code is also returned if an invalid index id or type is used. +/// +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @fn JSA_put_api_simple_by_example_bitarray +/// @brief returns all documents of a collection matching a given example, +/// using a specific bitarray index +/// +/// @RESTHEADER{PUT /_api/simple/by-example-bitarray,executes query by-example using a bitarray index} +/// +/// @RESTBODYPARAM{query,string,required} +/// Contains the query specification. +/// +/// @RESTDESCRIPTION +/// +/// This will find all documents matching a given example, using the specified +/// skiplist index. +/// +/// The call expects a JSON object as body with the following attributes: +/// +/// - `collection`: The name of the collection to query. +/// +/// - `index`: The id of the index to be used for the query. The index must +/// exist and must be of type `bitarray`. +/// +/// - `example`: an example document. The example must contain a value for each +/// attribute in the index. +/// +/// - `skip`: The number of documents to skip in the query. (optional) +/// +/// - `limit`: The maximal number of documents to return. (optional) +/// +/// Returns a cursor containing the result, see @ref HttpCursor for details. +/// +/// @RESTRETURNCODES +/// +/// @RESTRETURNCODE{201} +/// is returned if the query was executed successfully. +/// +/// @RESTRETURNCODE{400} +/// is returned if the body does not contain a valid JSON representation of a +/// query. The response body contains an error document in this case. +/// +/// @RESTRETURNCODE{404} +/// is returned if the collection specified by `collection` is unknown. The +/// response body contains an error document in this case. +/// The same error code is also returned if an invalid index id or type is used. +/// +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @fn JSA_put_api_simple_by_condition_skiplist +/// @brief returns all documents of a collection matching a given condition, +/// using a specific skiplist index +/// +/// @RESTHEADER{PUT /_api/simple/by-condition-skiplist,executes query by-condition using a skiplist index} +/// +/// @RESTBODYPARAM{query,string,required} +/// Contains the query specification. +/// +/// @RESTDESCRIPTION +/// +/// This will find all documents matching a given condition, using the specified +/// skiplist index. +/// +/// The call expects a JSON object as body with the following attributes: +/// +/// - `collection`: The name of the collection to query. +/// +/// - `index`: The id of the index to be used for the query. The index must +/// exist and must be of type `skiplist`. +/// +/// - `condition`: the condition which all returned documents shall satisfy. +/// Conditions must be specified for all indexed attributes. +/// +/// - `skip`: The number of documents to skip in the query. (optional) +/// +/// - `limit`: The maximal number of documents to return. (optional) +/// +/// Returns a cursor containing the result, see @ref HttpCursor for details. +/// +/// @RESTRETURNCODES +/// +/// @RESTRETURNCODE{201} +/// is returned if the query was executed successfully. +/// +/// @RESTRETURNCODE{400} +/// is returned if the body does not contain a valid JSON representation of a +/// query. The response body contains an error document in this case. +/// +/// @RESTRETURNCODE{404} +/// is returned if the collection specified by `collection` is unknown. The +/// response body contains an error document in this case. +/// The same error code is also returned if an invalid index id or type is used. +/// +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @fn JSA_put_api_simple_by_condition_bitarray +/// @brief returns all documents of a collection matching a given condition, +/// using a specific bitarray index +/// +/// @RESTHEADER{PUT /_api/simple/by-condition-bitarray,executes query by-condition using a bitarray index} +/// +/// @RESTBODYPARAM{query,string,required} +/// Contains the query specification. +/// +/// @RESTDESCRIPTION +/// +/// This will find all documents matching a given condition, using the specified +/// skiplist index. +/// +/// The call expects a JSON object as body with the following attributes: +/// +/// - `collection`: The name of the collection to query. +/// +/// - `index`: The id of the index to be used for the query. The index must +/// exist and must be of type `bitarray`. +/// +/// - `condition`: the condition which all returned documents shall satisfy. +/// Conditions must be specified for all indexed attributes. +/// +/// - `skip`: The number of documents to skip in the query. (optional) +/// +/// - `limit`: The maximal number of documents to return. (optional) +/// +/// Returns a cursor containing the result, see @ref HttpCursor for details. +/// +/// @RESTRETURNCODES +/// +/// @RESTRETURNCODE{201} +/// is returned if the query was executed successfully. +/// +/// @RESTRETURNCODE{400} +/// is returned if the body does not contain a valid JSON representation of a +/// query. The response body contains an error document in this case. +/// +/// @RESTRETURNCODE{404} +/// is returned if the collection specified by `collection` is unknown. The +/// response body contains an error document in this case. +/// The same error code is also returned if an invalid index id or type is used. +/// +//////////////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////////////// +/// @brief setup an index query +//////////////////////////////////////////////////////////////////////////////// + +function setupIndexQuery (name, func, isExampleQuery) { + actions.defineHttp({ + url : API + name, + context : "api", + + callback : function (req, res) { + try { + var body = actions.getJsonBody(req, res); + + if (body === undefined) { + return; + } + + if (req.requestType !== actions.PUT) { + actions.resultUnsupported(req, res); + } + else { + var limit = body.limit; + var skip = body.skip || 0; + var name = body.collection; + var index = body.index; + var collection = db._collection(name); + + if (collection === null) { + actions.collectionNotFound(req, res, name); + return; + } + + var result; + + if (isExampleQuery) { + if (typeof body.example !== "object" || Array.isArray(body.example)) { + actions.badParameter(req, res, "example"); + return; + } + + result = collection[func](index, body.example, skip, limit); + } + else { + if (typeof body.condition !== "object" || Array.isArray(body.condition)) { + actions.badParameter(req, res, "condition"); + return; + } + + result = collection[func](index, body.condition, skip, limit); + } + + actions.resultCursor(req, res, CREATE_CURSOR(result.documents, true, body.batchSize)); + } + } + catch (err) { + actions.resultException(req, res, err, undefined, false); + } + } + }); +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief register all these functions +//////////////////////////////////////////////////////////////////////////////// + +function setupIndexQueries () { + var map = { + "by-example-hash" : [ "BY_EXAMPLE_HASH", true ], + "by-example-skiplist" : [ "BY_EXAMPLE_SKIPLIST", true ], + "by-example-bitarray" : [ "BY_EXAMPLE_BITARRAY", true ], + "by-condition-skiplist" : [ "BY_CONDITION_SKIPLIST", false ], + "by-condition-bitarray" : [ "BY_CONDITION_BITARRAY", false ] + }; + + var m; + for (m in map) { + if (map.hasOwnProperty(m)) { + setupIndexQuery(m, map[m][0], map[m][1]); + } + } +} + +setupIndexQueries(); + +// ----------------------------------------------------------------------------- +// --SECTION-- public functions +// ----------------------------------------------------------------------------- + //////////////////////////////////////////////////////////////////////////////// /// @fn JSA_put_api_simple_all /// @brief returns all documents of a collection diff --git a/js/apps/system/aardvark/frontend/js/modules/org/arangodb/arango-collection.js b/js/apps/system/aardvark/frontend/js/modules/org/arangodb/arango-collection.js index 0a1c25bae0..ab91b3ac9c 100644 --- a/js/apps/system/aardvark/frontend/js/modules/org/arangodb/arango-collection.js +++ b/js/apps/system/aardvark/frontend/js/modules/org/arangodb/arango-collection.js @@ -596,7 +596,7 @@ ArangoCollection.prototype.index = function (id) { }; //////////////////////////////////////////////////////////////////////////////// -/// @brief deletes one index +/// @brief deletes an index //////////////////////////////////////////////////////////////////////////////// ArangoCollection.prototype.dropIndex = function (id) { @@ -619,7 +619,7 @@ ArangoCollection.prototype.dropIndex = function (id) { }; //////////////////////////////////////////////////////////////////////////////// -/// @brief adds a bitarray index +/// @brief ensures a bitarray index //////////////////////////////////////////////////////////////////////////////// ArangoCollection.prototype.ensureBitarray = function () { @@ -640,6 +640,28 @@ ArangoCollection.prototype.ensureBitarray = function () { return requestResult; }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief ensures a bitarray index +//////////////////////////////////////////////////////////////////////////////// + +ArangoCollection.prototype.ensureUndefBitarray = function () { + var i; + var body; + var fields = []; + + for (i = 0; i < arguments.length; ++i) { + fields.push(arguments[i]); + } + + body = { type : "bitarray", unique : false, fields : fields, "undefined" : true }; + + var requestResult = this._database._connection.POST(this._indexurl(), JSON.stringify(body)); + + arangosh.checkRequestResult(requestResult); + + return requestResult; +}; + //////////////////////////////////////////////////////////////////////////////// /// @brief adds a cap constraint //////////////////////////////////////////////////////////////////////////////// diff --git a/js/client/modules/org/arangodb/arango-collection.js b/js/client/modules/org/arangodb/arango-collection.js index e7aded02b6..9ff4f46792 100644 --- a/js/client/modules/org/arangodb/arango-collection.js +++ b/js/client/modules/org/arangodb/arango-collection.js @@ -595,7 +595,7 @@ ArangoCollection.prototype.index = function (id) { }; //////////////////////////////////////////////////////////////////////////////// -/// @brief deletes one index +/// @brief deletes an index //////////////////////////////////////////////////////////////////////////////// ArangoCollection.prototype.dropIndex = function (id) { @@ -618,7 +618,7 @@ ArangoCollection.prototype.dropIndex = function (id) { }; //////////////////////////////////////////////////////////////////////////////// -/// @brief adds a bitarray index +/// @brief ensures a bitarray index //////////////////////////////////////////////////////////////////////////////// ArangoCollection.prototype.ensureBitarray = function () { @@ -639,6 +639,28 @@ ArangoCollection.prototype.ensureBitarray = function () { return requestResult; }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief ensures a bitarray index +//////////////////////////////////////////////////////////////////////////////// + +ArangoCollection.prototype.ensureUndefBitarray = function () { + var i; + var body; + var fields = []; + + for (i = 0; i < arguments.length; ++i) { + fields.push(arguments[i]); + } + + body = { type : "bitarray", unique : false, fields : fields, "undefined" : true }; + + var requestResult = this._database._connection.POST(this._indexurl(), JSON.stringify(body)); + + arangosh.checkRequestResult(requestResult); + + return requestResult; +}; + //////////////////////////////////////////////////////////////////////////////// /// @brief adds a cap constraint //////////////////////////////////////////////////////////////////////////////// diff --git a/js/common/tests/shell-index.js b/js/common/tests/shell-index.js index 04cb6a437b..8ffdc2459c 100644 --- a/js/common/tests/shell-index.js +++ b/js/common/tests/shell-index.js @@ -227,521 +227,6 @@ function indexSuite() { }; } -// ----------------------------------------------------------------------------- -// --SECTION-- ensure index -// ----------------------------------------------------------------------------- - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test suite: ensureIndex -//////////////////////////////////////////////////////////////////////////////// - -function ensureIndexSuite() { - var cn = "UnitTestsCollectionIdx"; - var collection = null; - - return { - -//////////////////////////////////////////////////////////////////////////////// -/// @brief set up -//////////////////////////////////////////////////////////////////////////////// - - setUp : function () { - internal.db._drop(cn); - collection = internal.db._create(cn); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief tear down -//////////////////////////////////////////////////////////////////////////////// - - tearDown : function () { - // we need try...catch here because at least one test drops the collection itself! - try { - collection.drop(); - } - catch (err) { - } - collection = null; - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ids -//////////////////////////////////////////////////////////////////////////////// - - testEnsureId1 : function () { - var id = "273475235"; - var idx = collection.ensureIndex({ type: "hash", fields: [ "a" ], id: id }); - assertEqual("hash", idx.type); - assertFalse(idx.unique); - assertEqual([ "a" ], idx.fields); - assertEqual(collection.name() + "/" + id, idx.id); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("hash", res.type); - assertFalse(res.unique); - assertEqual([ "a" ], res.fields); - assertEqual(collection.name() + "/" + id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ids -//////////////////////////////////////////////////////////////////////////////// - - testEnsureId2 : function () { - var id = "2734752388"; - var idx = collection.ensureIndex({ type: "skiplist", fields: [ "b", "d" ], id: id }); - assertEqual("skiplist", idx.type); - assertFalse(idx.unique); - assertEqual([ "b", "d" ], idx.fields); - assertEqual(collection.name() + "/" + id, idx.id); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("skiplist", res.type); - assertFalse(res.unique); - assertEqual([ "b", "d" ], res.fields); - assertEqual(collection.name() + "/" + id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure invalid type -//////////////////////////////////////////////////////////////////////////////// - - testEnsureTypeFail1 : function () { - try { - // invalid type given - collection.ensureIndex({ type: "foo" }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure invalid type -//////////////////////////////////////////////////////////////////////////////// - - testEnsureTypeFail2 : function () { - try { - // no type given - collection.ensureIndex({ something: "foo" }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure invalid type -//////////////////////////////////////////////////////////////////////////////// - - testEnsureTypeForbidden1 : function () { - try { - // no type given - collection.ensureIndex({ type: "primary" }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_FORBIDDEN.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure invalid type -//////////////////////////////////////////////////////////////////////////////// - - testEnsureTypeForbidden2 : function () { - try { - // no type given - collection.ensureIndex({ type: "edge" }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_FORBIDDEN.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ hash -//////////////////////////////////////////////////////////////////////////////// - - testEnsureHash : function () { - var res = collection.getIndexes(); - - assertEqual(1, res.length); - - var idx = collection.ensureIndex({ type: "hash", fields: [ "a" ] }); - assertEqual("hash", idx.type); - assertFalse(idx.unique); - assertEqual([ "a" ], idx.fields); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("hash", res.type); - assertFalse(res.unique); - assertEqual([ "a" ], res.fields); - - assertEqual(idx.id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ hash -//////////////////////////////////////////////////////////////////////////////// - - testEnsureUniqueConstraint : function () { - var res = collection.getIndexes(); - - assertEqual(1, res.length); - - var idx = collection.ensureIndex({ type: "hash", unique: true, fields: [ "b", "c" ] }); - assertEqual("hash", idx.type); - assertTrue(idx.unique); - assertEqual([ "b", "c" ], idx.fields); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("hash", res.type); - assertTrue(res.unique); - assertEqual([ "b", "c" ], res.fields); - - assertEqual(idx.id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ hash -//////////////////////////////////////////////////////////////////////////////// - - testEnsureHashFail : function () { - try { - collection.ensureIndex({ type: "hash" }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ skiplist -//////////////////////////////////////////////////////////////////////////////// - - testEnsureSkiplist : function () { - var res = collection.getIndexes(); - - assertEqual(1, res.length); - - var idx = collection.ensureIndex({ type: "skiplist", fields: [ "a" ] }); - assertEqual("skiplist", idx.type); - assertFalse(idx.unique); - assertEqual([ "a" ], idx.fields); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("skiplist", res.type); - assertFalse(res.unique); - assertEqual([ "a" ], res.fields); - - assertEqual(idx.id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ skiplist -//////////////////////////////////////////////////////////////////////////////// - - testEnsureUniqueSkiplist : function () { - var res = collection.getIndexes(); - - assertEqual(1, res.length); - - var idx = collection.ensureIndex({ type: "skiplist", unique: true, fields: [ "b", "c" ] }); - assertEqual("skiplist", idx.type); - assertTrue(idx.unique); - assertEqual([ "b", "c" ], idx.fields); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("skiplist", res.type); - assertTrue(res.unique); - assertEqual([ "b", "c" ], res.fields); - - assertEqual(idx.id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ skiplist -//////////////////////////////////////////////////////////////////////////////// - - testEnsureSkiplistFail : function () { - try { - collection.ensureIndex({ type: "skiplist" }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ fulltext -//////////////////////////////////////////////////////////////////////////////// - - testEnsureFulltext : function () { - var res = collection.getIndexes(); - - assertEqual(1, res.length); - - var idx = collection.ensureIndex({ type: "fulltext", fields: [ "a" ] }); - assertEqual("fulltext", idx.type); - assertFalse(idx.unique); - assertEqual([ "a" ], idx.fields); - assertEqual(2, idx.minLength); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("fulltext", res.type); - assertFalse(res.unique); - assertEqual([ "a" ], res.fields); - assertEqual(2, res.minLength); - - assertEqual(idx.id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ fulltext -//////////////////////////////////////////////////////////////////////////////// - - testEnsureFulltextFail : function () { - try { - collection.ensureIndex({ type: "fulltext", fields: [ "a", "b" ] }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ geo -//////////////////////////////////////////////////////////////////////////////// - - testEnsureGeo : function () { - var res = collection.getIndexes(); - - assertEqual(1, res.length); - - var idx = collection.ensureIndex({ type: "geo1", fields: [ "a" ] }); - assertEqual("geo1", idx.type); - assertFalse(idx.unique); - assertEqual([ "a" ], idx.fields); - assertFalse(idx.ignoreNull); - assertFalse(idx.geoJson); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("geo1", res.type); - assertFalse(res.unique); - assertEqual([ "a" ], res.fields); - assertFalse(res.ignoreNull); - assertFalse(res.geoJson); - - assertEqual(idx.id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ geo -//////////////////////////////////////////////////////////////////////////////// - - testEnsureGeoConstraint : function () { - var res = collection.getIndexes(); - - assertEqual(1, res.length); - - var idx = collection.ensureIndex({ type: "geo2", fields: [ "a", "b" ], unique: true }); - assertEqual("geo2", idx.type); - assertTrue(idx.unique); - assertEqual([ "a", "b" ], idx.fields); - assertFalse(idx.ignoreNull); - assertFalse(idx.geoJson); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("geo2", res.type); - assertTrue(res.unique); - assertEqual([ "a", "b" ], res.fields); - assertFalse(res.ignoreNull); - assertFalse(res.geoJson); - - assertEqual(idx.id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ geo -//////////////////////////////////////////////////////////////////////////////// - - testEnsureGeoFail1 : function () { - try { - collection.ensureIndex({ type: "geo1", fields: [ "a", "b" ] }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ geo -//////////////////////////////////////////////////////////////////////////////// - - testEnsureGeoFail2 : function () { - try { - collection.ensureIndex({ type: "geo1", fields: [ ] }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ geo -//////////////////////////////////////////////////////////////////////////////// - - testEnsureGeoFail3 : function () { - try { - collection.ensureIndex({ type: "geo2", fields: [ "a" ] }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ geo -//////////////////////////////////////////////////////////////////////////////// - - testEnsureGeoFail4 : function () { - try { - collection.ensureIndex({ type: "geo2", fields: [ "a", "b", "c" ] }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ bitarray -//////////////////////////////////////////////////////////////////////////////// - - testEnsureBitarray : function () { - var res = collection.getIndexes(); - - assertEqual(1, res.length); - - var idx = collection.ensureIndex({ type: "bitarray", fields: [ [ "a", [ 1, 2 ] ], [ "b", [ 3, 4 ] ] ] }); - assertEqual("bitarray", idx.type); - assertFalse(idx.unique); - assertFalse(idx["undefined"]); - assertEqual([ [ "a", [ 1, 2 ] ], [ "b", [ 3, 4 ] ] ], idx.fields); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("bitarray", res.type); - assertFalse(res.unique); - assertFalse(res["undefined"]); - assertEqual([ [ "a", [ 1, 2 ] ], [ "b", [ 3, 4 ] ] ], res.fields); - - assertEqual(idx.id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ bitarray -//////////////////////////////////////////////////////////////////////////////// - - testEnsureUndefBitarray : function () { - var res = collection.getIndexes(); - - assertEqual(1, res.length); - - var idx = collection.ensureIndex({ type: "bitarray", fields: [ [ "a", [ 1, 2 ] ] ], "undefined" : true }); - assertEqual("bitarray", idx.type); - assertFalse(idx.unique); - assertTrue(idx["undefined"]); - assertEqual([ [ "a", [ 1, 2 ] ] ], idx.fields); - - res = collection.getIndexes()[collection.getIndexes().length - 1]; - - assertEqual("bitarray", res.type); - assertFalse(res.unique); - assertTrue(res["undefined"]); - assertEqual([ [ "a", [ 1, 2 ] ] ], res.fields); - - assertEqual(idx.id, res.id); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ bitarray -//////////////////////////////////////////////////////////////////////////////// - - testEnsureBitarrayFail1 : function () { - try { - collection.ensureIndex({ type: "bitarray", fields: [ "a" ] }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ bitarray -//////////////////////////////////////////////////////////////////////////////// - - testEnsureBitarrayFail2 : function () { - try { - collection.ensureIndex({ type: "bitarray", fields: [ "a", "b" ] }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ bitarray -//////////////////////////////////////////////////////////////////////////////// - - testEnsureBitarrayFail3 : function () { - try { - collection.ensureIndex({ type: "bitarray", fields: [ [ "a", "b" ] ] }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: ensure w/ bitarray -//////////////////////////////////////////////////////////////////////////////// - - testEnsureBitarrayFail4 : function () { - try { - collection.ensureIndex({ type: "bitarray", fields: [ [ "a" ] ] }); - fail(); - } - catch (err) { - assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); - } - } - - }; -} - // ----------------------------------------------------------------------------- // --SECTION-- getIndexes // ----------------------------------------------------------------------------- @@ -1271,7 +756,6 @@ function getIndexesEdgesSuite() { //////////////////////////////////////////////////////////////////////////////// jsunity.run(indexSuite); -jsunity.run(ensureIndexSuite); jsunity.run(getIndexesSuite); jsunity.run(getIndexesEdgesSuite); diff --git a/js/server/modules/org/arangodb/actions.js b/js/server/modules/org/arangodb/actions.js index c23285c663..f0e51f95ae 100644 --- a/js/server/modules/org/arangodb/actions.js +++ b/js/server/modules/org/arangodb/actions.js @@ -1661,9 +1661,9 @@ function collectionNotFound (req, res, collection, headers) { } //////////////////////////////////////////////////////////////////////////////// -/// @brief generates an error for unknown index +/// @brief generates an error for an unknown index /// -/// @FUN{actions.collectionNotFound(@FA{req}, @FA{res}, @FA{collection}, @FA{index}, @FA{headers})} +/// @FUN{actions.indexNotFound(@FA{req}, @FA{res}, @FA{collection}, @FA{index}, @FA{headers})} /// /// The function generates an error response. //////////////////////////////////////////////////////////////////////////////// @@ -1742,6 +1742,8 @@ function resultException (req, res, err, headers, verbose) { case arangodb.ERROR_ARANGO_DOCUMENT_NOT_FOUND: case arangodb.ERROR_ARANGO_DATABASE_NOT_FOUND: case arangodb.ERROR_ARANGO_ENDPOINT_NOT_FOUND: + case arangodb.ERROR_ARANGO_NO_INDEX: + case arangodb.ERROR_ARANGO_INDEX_NOT_FOUND: case arangodb.ERROR_CURSOR_NOT_FOUND: case arangodb.ERROR_USER_NOT_FOUND: code = exports.HTTP_NOT_FOUND; diff --git a/js/server/tests/shell-index-ensure.js b/js/server/tests/shell-index-ensure.js new file mode 100644 index 0000000000..158cc0dcdf --- /dev/null +++ b/js/server/tests/shell-index-ensure.js @@ -0,0 +1,570 @@ +/*jslint indent: 2, + nomen: true, + maxlen: 80 */ +/*global require, + db, + assertEqual, assertTrue, + ArangoCollection */ + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test the index +/// +/// @file +/// +/// DISCLAIMER +/// +/// Copyright 2010-2012 triagens GmbH, Cologne, Germany +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// +/// Copyright holder is triAGENS GmbH, Cologne, Germany +/// +/// @author Dr. Frank Celler, Lucas Dohmen +/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +var jsunity = require("jsunity"); +var internal = require("internal"); +var errors = internal.errors; + +// ----------------------------------------------------------------------------- +// --SECTION-- ensure index +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test suite: ensureIndex +//////////////////////////////////////////////////////////////////////////////// + +function ensureIndexSuite() { + var cn = "UnitTestsCollectionIdx"; + var collection = null; + + return { + +//////////////////////////////////////////////////////////////////////////////// +/// @brief set up +//////////////////////////////////////////////////////////////////////////////// + + setUp : function () { + internal.db._drop(cn); + collection = internal.db._create(cn); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief tear down +//////////////////////////////////////////////////////////////////////////////// + + tearDown : function () { + // we need try...catch here because at least one test drops the collection itself! + try { + collection.drop(); + } + catch (err) { + } + collection = null; + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ids +//////////////////////////////////////////////////////////////////////////////// + + testEnsureId1 : function () { + var id = "273475235"; + var idx = collection.ensureIndex({ type: "hash", fields: [ "a" ], id: id }); + assertEqual("hash", idx.type); + assertFalse(idx.unique); + assertEqual([ "a" ], idx.fields); + assertEqual(collection.name() + "/" + id, idx.id); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("hash", res.type); + assertFalse(res.unique); + assertEqual([ "a" ], res.fields); + assertEqual(collection.name() + "/" + id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ids +//////////////////////////////////////////////////////////////////////////////// + + testEnsureId2 : function () { + var id = "2734752388"; + var idx = collection.ensureIndex({ type: "skiplist", fields: [ "b", "d" ], id: id }); + assertEqual("skiplist", idx.type); + assertFalse(idx.unique); + assertEqual([ "b", "d" ], idx.fields); + assertEqual(collection.name() + "/" + id, idx.id); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("skiplist", res.type); + assertFalse(res.unique); + assertEqual([ "b", "d" ], res.fields); + assertEqual(collection.name() + "/" + id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure invalid type +//////////////////////////////////////////////////////////////////////////////// + + testEnsureTypeFail1 : function () { + try { + // invalid type given + collection.ensureIndex({ type: "foo" }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure invalid type +//////////////////////////////////////////////////////////////////////////////// + + testEnsureTypeFail2 : function () { + try { + // no type given + collection.ensureIndex({ something: "foo" }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure invalid type +//////////////////////////////////////////////////////////////////////////////// + + testEnsureTypeForbidden1 : function () { + try { + // no type given + collection.ensureIndex({ type: "primary" }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_FORBIDDEN.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure invalid type +//////////////////////////////////////////////////////////////////////////////// + + testEnsureTypeForbidden2 : function () { + try { + // no type given + collection.ensureIndex({ type: "edge" }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_FORBIDDEN.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ hash +//////////////////////////////////////////////////////////////////////////////// + + testEnsureHash : function () { + var res = collection.getIndexes(); + + assertEqual(1, res.length); + + var idx = collection.ensureIndex({ type: "hash", fields: [ "a" ] }); + assertEqual("hash", idx.type); + assertFalse(idx.unique); + assertEqual([ "a" ], idx.fields); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("hash", res.type); + assertFalse(res.unique); + assertEqual([ "a" ], res.fields); + + assertEqual(idx.id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ hash +//////////////////////////////////////////////////////////////////////////////// + + testEnsureUniqueConstraint : function () { + var res = collection.getIndexes(); + + assertEqual(1, res.length); + + var idx = collection.ensureIndex({ type: "hash", unique: true, fields: [ "b", "c" ] }); + assertEqual("hash", idx.type); + assertTrue(idx.unique); + assertEqual([ "b", "c" ], idx.fields); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("hash", res.type); + assertTrue(res.unique); + assertEqual([ "b", "c" ], res.fields); + + assertEqual(idx.id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ hash +//////////////////////////////////////////////////////////////////////////////// + + testEnsureHashFail : function () { + try { + collection.ensureIndex({ type: "hash" }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ skiplist +//////////////////////////////////////////////////////////////////////////////// + + testEnsureSkiplist : function () { + var res = collection.getIndexes(); + + assertEqual(1, res.length); + + var idx = collection.ensureIndex({ type: "skiplist", fields: [ "a" ] }); + assertEqual("skiplist", idx.type); + assertFalse(idx.unique); + assertEqual([ "a" ], idx.fields); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("skiplist", res.type); + assertFalse(res.unique); + assertEqual([ "a" ], res.fields); + + assertEqual(idx.id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ skiplist +//////////////////////////////////////////////////////////////////////////////// + + testEnsureUniqueSkiplist : function () { + var res = collection.getIndexes(); + + assertEqual(1, res.length); + + var idx = collection.ensureIndex({ type: "skiplist", unique: true, fields: [ "b", "c" ] }); + assertEqual("skiplist", idx.type); + assertTrue(idx.unique); + assertEqual([ "b", "c" ], idx.fields); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("skiplist", res.type); + assertTrue(res.unique); + assertEqual([ "b", "c" ], res.fields); + + assertEqual(idx.id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ skiplist +//////////////////////////////////////////////////////////////////////////////// + + testEnsureSkiplistFail : function () { + try { + collection.ensureIndex({ type: "skiplist" }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ fulltext +//////////////////////////////////////////////////////////////////////////////// + + testEnsureFulltext : function () { + var res = collection.getIndexes(); + + assertEqual(1, res.length); + + var idx = collection.ensureIndex({ type: "fulltext", fields: [ "a" ] }); + assertEqual("fulltext", idx.type); + assertFalse(idx.unique); + assertEqual([ "a" ], idx.fields); + assertEqual(2, idx.minLength); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("fulltext", res.type); + assertFalse(res.unique); + assertEqual([ "a" ], res.fields); + assertEqual(2, res.minLength); + + assertEqual(idx.id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ fulltext +//////////////////////////////////////////////////////////////////////////////// + + testEnsureFulltextFail : function () { + try { + collection.ensureIndex({ type: "fulltext", fields: [ "a", "b" ] }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ geo +//////////////////////////////////////////////////////////////////////////////// + + testEnsureGeo : function () { + var res = collection.getIndexes(); + + assertEqual(1, res.length); + + var idx = collection.ensureIndex({ type: "geo1", fields: [ "a" ] }); + assertEqual("geo1", idx.type); + assertFalse(idx.unique); + assertEqual([ "a" ], idx.fields); + assertFalse(idx.ignoreNull); + assertFalse(idx.geoJson); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("geo1", res.type); + assertFalse(res.unique); + assertEqual([ "a" ], res.fields); + assertFalse(res.ignoreNull); + assertFalse(res.geoJson); + + assertEqual(idx.id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ geo +//////////////////////////////////////////////////////////////////////////////// + + testEnsureGeoConstraint : function () { + var res = collection.getIndexes(); + + assertEqual(1, res.length); + + var idx = collection.ensureIndex({ type: "geo2", fields: [ "a", "b" ], unique: true }); + assertEqual("geo2", idx.type); + assertTrue(idx.unique); + assertEqual([ "a", "b" ], idx.fields); + assertFalse(idx.ignoreNull); + assertFalse(idx.geoJson); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("geo2", res.type); + assertTrue(res.unique); + assertEqual([ "a", "b" ], res.fields); + assertFalse(res.ignoreNull); + assertFalse(res.geoJson); + + assertEqual(idx.id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ geo +//////////////////////////////////////////////////////////////////////////////// + + testEnsureGeoFail1 : function () { + try { + collection.ensureIndex({ type: "geo1", fields: [ "a", "b" ] }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ geo +//////////////////////////////////////////////////////////////////////////////// + + testEnsureGeoFail2 : function () { + try { + collection.ensureIndex({ type: "geo1", fields: [ ] }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ geo +//////////////////////////////////////////////////////////////////////////////// + + testEnsureGeoFail3 : function () { + try { + collection.ensureIndex({ type: "geo2", fields: [ "a" ] }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ geo +//////////////////////////////////////////////////////////////////////////////// + + testEnsureGeoFail4 : function () { + try { + collection.ensureIndex({ type: "geo2", fields: [ "a", "b", "c" ] }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ bitarray +//////////////////////////////////////////////////////////////////////////////// + + testEnsureBitarray : function () { + var res = collection.getIndexes(); + + assertEqual(1, res.length); + + var idx = collection.ensureIndex({ type: "bitarray", fields: [ [ "a", [ 1, 2 ] ], [ "b", [ 3, 4 ] ] ] }); + assertEqual("bitarray", idx.type); + assertFalse(idx.unique); + assertFalse(idx["undefined"]); + assertEqual([ [ "a", [ 1, 2 ] ], [ "b", [ 3, 4 ] ] ], idx.fields); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("bitarray", res.type); + assertFalse(res.unique); + assertFalse(res["undefined"]); + assertEqual([ [ "a", [ 1, 2 ] ], [ "b", [ 3, 4 ] ] ], res.fields); + + assertEqual(idx.id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ bitarray +//////////////////////////////////////////////////////////////////////////////// + + testEnsureUndefBitarray : function () { + var res = collection.getIndexes(); + + assertEqual(1, res.length); + + var idx = collection.ensureIndex({ type: "bitarray", fields: [ [ "a", [ 1, 2 ] ] ], "undefined" : true }); + assertEqual("bitarray", idx.type); + assertFalse(idx.unique); + assertTrue(idx["undefined"]); + assertEqual([ [ "a", [ 1, 2 ] ] ], idx.fields); + + res = collection.getIndexes()[collection.getIndexes().length - 1]; + + assertEqual("bitarray", res.type); + assertFalse(res.unique); + assertTrue(res["undefined"]); + assertEqual([ [ "a", [ 1, 2 ] ] ], res.fields); + + assertEqual(idx.id, res.id); + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ bitarray +//////////////////////////////////////////////////////////////////////////////// + + testEnsureBitarrayFail1 : function () { + try { + collection.ensureIndex({ type: "bitarray", fields: [ "a" ] }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ bitarray +//////////////////////////////////////////////////////////////////////////////// + + testEnsureBitarrayFail2 : function () { + try { + collection.ensureIndex({ type: "bitarray", fields: [ "a", "b" ] }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ bitarray +//////////////////////////////////////////////////////////////////////////////// + + testEnsureBitarrayFail3 : function () { + try { + collection.ensureIndex({ type: "bitarray", fields: [ [ "a", "b" ] ] }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + }, + +//////////////////////////////////////////////////////////////////////////////// +/// @brief test: ensure w/ bitarray +//////////////////////////////////////////////////////////////////////////////// + + testEnsureBitarrayFail4 : function () { + try { + collection.ensureIndex({ type: "bitarray", fields: [ [ "a" ] ] }); + fail(); + } + catch (err) { + assertEqual(errors.ERROR_BAD_PARAMETER.code, err.errorNum); + } + } + + }; +} + +// ----------------------------------------------------------------------------- +// --SECTION-- main +// ----------------------------------------------------------------------------- + +//////////////////////////////////////////////////////////////////////////////// +/// @brief executes the test suites +//////////////////////////////////////////////////////////////////////////////// + +jsunity.run(ensureIndexSuite); + +return jsunity.done(); + +// Local Variables: +// mode: outline-minor +// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)" +// End: diff --git a/lib/BasicsC/errors.dat b/lib/BasicsC/errors.dat index ef75bdd3a3..ffae3a7e80 100755 --- a/lib/BasicsC/errors.dat +++ b/lib/BasicsC/errors.dat @@ -90,7 +90,7 @@ ERROR_ARANGO_DUPLICATE_NAME,1207,"duplicate name","Will be raised when a name du ERROR_ARANGO_ILLEGAL_NAME,1208,"illegal name","Will be raised when an illegal name is detected." ERROR_ARANGO_NO_INDEX,1209,"no suitable index known","Will be raised when no suitable index for the query is known." ERROR_ARANGO_UNIQUE_CONSTRAINT_VIOLATED,1210,"unique constraint violated","Will be raised when there is a unique constraint violation." -ERROR_ARANGO_GEO_INDEX_VIOLATED,1211,"geo index violated","Will be raised when a illegale coordinate is used." +ERROR_ARANGO_GEO_INDEX_VIOLATED,1211,"geo index violated","Will be raised when an illegal coordinate is used." ERROR_ARANGO_INDEX_NOT_FOUND,1212,"index not found","Will be raised when an index with a given identifier is unknown." ERROR_ARANGO_CROSS_COLLECTION_REQUEST,1213,"cross collection request not allowed","Will be raised when a cross-collection is requested." ERROR_ARANGO_INDEX_HANDLE_BAD,1214,"illegal index handle","Will be raised when a index handle is corrupt." diff --git a/lib/BasicsC/voc-errors.h b/lib/BasicsC/voc-errors.h index d6e9f264e5..d745f9b538 100644 --- a/lib/BasicsC/voc-errors.h +++ b/lib/BasicsC/voc-errors.h @@ -139,7 +139,7 @@ extern "C" { /// - 1210: @LIT{unique constraint violated} /// Will be raised when there is a unique constraint violation. /// - 1211: @LIT{geo index violated} -/// Will be raised when a illegale coordinate is used. +/// Will be raised when an illegal coordinate is used. /// - 1212: @LIT{index not found} /// Will be raised when an index with a given identifier is unknown. /// - 1213: @LIT{cross collection request not allowed} @@ -1083,7 +1083,7 @@ void TRI_InitialiseErrorMessages (void); /// /// geo index violated /// -/// Will be raised when a illegale coordinate is used. +/// Will be raised when an illegal coordinate is used. //////////////////////////////////////////////////////////////////////////////// #define TRI_ERROR_ARANGO_GEO_INDEX_VIOLATED (1211)