From 80413739d1f21c2b8174ee40edb4eee782e4ab8c Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 22 Mar 2016 14:34:18 +0100 Subject: [PATCH 1/8] fixed test --- arangod/Aql/CalculationBlock.cpp | 1 + arangod/Aql/ExecutionBlock.cpp | 29 - arangod/Aql/ExecutionBlock.h | 9 +- arangod/Aql/Functions.cpp | 45 +- arangod/Utils/Transaction.cpp | 30 +- arangod/Utils/Transaction.h | 1 + js/common/tests/shell/shell-attributes.js | 28 +- js/common/tests/shell/shell-cap-constraint.js | 664 ------------------ 8 files changed, 57 insertions(+), 750 deletions(-) delete mode 100644 js/common/tests/shell/shell-cap-constraint.js diff --git a/arangod/Aql/CalculationBlock.cpp b/arangod/Aql/CalculationBlock.cpp index 2b6c4ee85f..1fa850baa0 100644 --- a/arangod/Aql/CalculationBlock.cpp +++ b/arangod/Aql/CalculationBlock.cpp @@ -113,6 +113,7 @@ void CalculationBlock::executeExpression(AqlItemBlock* result) { DEBUG_BEGIN_BLOCK(); bool const hasCondition = (static_cast(_exeNode) ->_conditionVariable != nullptr); + TRI_ASSERT(!hasCondition); // currently not implemented size_t const n = result->size(); diff --git a/arangod/Aql/ExecutionBlock.cpp b/arangod/Aql/ExecutionBlock.cpp index 9512f1e3ab..ebea98ea4c 100644 --- a/arangod/Aql/ExecutionBlock.cpp +++ b/arangod/Aql/ExecutionBlock.cpp @@ -185,35 +185,6 @@ void ExecutionBlock::returnBlock(AqlItemBlock*& block) { _engine->_itemBlockManager.returnBlock(block); } -//////////////////////////////////////////////////////////////////////////////// -/// @brief resolve a collection name and return success or failure -/// this is used for parsing _from, _to and _id values -//////////////////////////////////////////////////////////////////////////////// - -int ExecutionBlock::resolve(std::string const& input) const { - DEBUG_BEGIN_BLOCK(); - char const* handle = input.c_str(); - char const* p = strchr(handle, TRI_DOCUMENT_HANDLE_SEPARATOR_CHR); - if (p == nullptr || *p == '\0') { - return TRI_ERROR_ARANGO_DOCUMENT_HANDLE_BAD; - } - - TRI_voc_cid_t cid = 0; - if (*handle >= '0' && *handle <= '9') { - cid = arangodb::basics::StringUtils::uint64(handle, p - handle); - } else { - std::string const name(handle, p - handle); - cid = _trx->resolver()->getCollectionIdCluster(name); - } - - if (cid == 0) { - return TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND; - } - - return TRI_ERROR_NO_ERROR; - DEBUG_END_BLOCK(); -} - //////////////////////////////////////////////////////////////////////////////// /// @brief copy register data from one block (src) into another (dst) /// register values are cloned diff --git a/arangod/Aql/ExecutionBlock.h b/arangod/Aql/ExecutionBlock.h index 8ffd4fdf24..6c3f120126 100644 --- a/arangod/Aql/ExecutionBlock.h +++ b/arangod/Aql/ExecutionBlock.h @@ -32,7 +32,7 @@ #if 0 #define DEBUG_BEGIN_BLOCK() try { // -#define DEBUG_END_BLOCK() } catch (...) { LOG(WARN) << "exception caught in " << __FILE__ << ":" << __LINE__; throw; } // +#define DEBUG_END_BLOCK() } catch (arangodb::basics::Exception const& ex) { LOG(WARN) << "arango exception caught in " << __FILE__ << ":" << __LINE__ << ":" << ex.what(); throw; } catch (std::exception const& ex) { LOG(WARN) << "std exception caught in " << __FILE__ << ":" << __LINE__ << ": " << ex.what(); throw; } catch (...) { LOG(WARN) << "exception caught in " << __FILE__ << ":" << __LINE__; throw; } // #else @@ -181,13 +181,6 @@ class ExecutionBlock { void returnBlock(AqlItemBlock*&); - ////////////////////////////////////////////////////////////////////////////// - /// @brief resolve a collection name and return success or failure - /// this is used for parsing _from, _to and _id values - ////////////////////////////////////////////////////////////////////////////// - - int resolve(std::string const&) const; - ////////////////////////////////////////////////////////////////////////////// /// @brief copy register data from one block (src) into another (dst) /// register values are cloned diff --git a/arangod/Aql/Functions.cpp b/arangod/Aql/Functions.cpp index bf9e6b2b8d..6dedb303b1 100644 --- a/arangod/Aql/Functions.cpp +++ b/arangod/Aql/Functions.cpp @@ -850,13 +850,14 @@ static AqlValue VertexIdsToAqlValueVPack(arangodb::aql::Query* query, static arangodb::Index* getGeoIndex(arangodb::AqlTransaction* trx, TRI_voc_cid_t const& cid, - std::string const& colName) { - trx->addCollectionAtRuntime(cid, colName); + std::string const& collectionName) { + trx->addCollectionAtRuntime(cid, collectionName); auto document = trx->documentCollection(cid); if (document == nullptr) { - THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, + "'%s'", collectionName.c_str()); } arangodb::Index* index = nullptr; @@ -871,7 +872,7 @@ static arangodb::Index* getGeoIndex(arangodb::AqlTransaction* trx, if (index == nullptr) { THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_GEO_INDEX_MISSING, - colName.c_str()); + collectionName.c_str()); } trx->orderDitch(cid); @@ -2318,7 +2319,7 @@ AqlValue Functions::Near(arangodb::aql::Query* query, TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "NEAR"); } - std::string const colName(collectionValue.slice().copyString()); + std::string const collectionName(collectionValue.slice().copyString()); AqlValue latitude = ExtractFunctionParameterValue(trx, parameters, 1); AqlValue longitude = ExtractFunctionParameterValue(trx, parameters, 2); @@ -2357,8 +2358,8 @@ AqlValue Functions::Near(arangodb::aql::Query* query, } } - TRI_voc_cid_t cid = trx->resolver()->getCollectionIdLocal(colName); - arangodb::Index* index = getGeoIndex(trx, cid, colName); + TRI_voc_cid_t cid = trx->resolver()->getCollectionIdLocal(collectionName); + arangodb::Index* index = getGeoIndex(trx, cid, collectionName); TRI_ASSERT(index != nullptr); @@ -2384,7 +2385,7 @@ AqlValue Functions::Within(arangodb::aql::Query* query, TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "WITHIN"); } - std::string const colName(collectionValue.slice().copyString()); + std::string const collectionName(collectionValue.slice().copyString()); AqlValue latitudeValue = ExtractFunctionParameterValue(trx, parameters, 1); AqlValue longitudeValue = ExtractFunctionParameterValue(trx, parameters, 2); @@ -2410,8 +2411,8 @@ AqlValue Functions::Within(arangodb::aql::Query* query, } } - TRI_voc_cid_t cid = trx->resolver()->getCollectionIdLocal(colName); - arangodb::Index* index = getGeoIndex(trx, cid, colName); + TRI_voc_cid_t cid = trx->resolver()->getCollectionIdLocal(collectionName); + arangodb::Index* index = getGeoIndex(trx, cid, collectionName); TRI_ASSERT(index != nullptr); @@ -3407,15 +3408,16 @@ AqlValue Functions::CollectionCount( TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "COLLECTION_COUNT"); } - std::string const colName(element.slice().copyString()); + std::string const collectionName(element.slice().copyString()); auto resolver = trx->resolver(); - TRI_voc_cid_t cid = resolver->getCollectionIdLocal(colName); - trx->addCollectionAtRuntime(cid, colName); + TRI_voc_cid_t cid = resolver->getCollectionIdLocal(collectionName); + trx->addCollectionAtRuntime(cid, collectionName); auto document = trx->documentCollection(cid); if (document == nullptr) { - THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, + "'%s'", collectionName.c_str()); } TransactionBuilderLeaser builder(trx); @@ -3815,7 +3817,7 @@ AqlValue Functions::Fulltext(arangodb::aql::Query* query, TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "FULLTEXT"); } - std::string const colName(collection.slice().copyString()); + std::string const collectionName(collection.slice().copyString()); AqlValue attribute = ExtractFunctionParameterValue(trx, parameters, 1); @@ -3851,13 +3853,14 @@ AqlValue Functions::Fulltext(arangodb::aql::Query* query, } auto resolver = trx->resolver(); - TRI_voc_cid_t cid = resolver->getCollectionIdLocal(colName); - trx->addCollectionAtRuntime(cid, colName); + TRI_voc_cid_t cid = resolver->getCollectionIdLocal(collectionName); + trx->addCollectionAtRuntime(cid, collectionName); auto document = trx->documentCollection(cid); if (document == nullptr) { - THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, + "'%s'", collectionName.c_str()); } arangodb::Index* index = nullptr; @@ -3879,7 +3882,7 @@ AqlValue Functions::Fulltext(arangodb::aql::Query* query, if (index == nullptr) { THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FULLTEXT_INDEX_MISSING, - colName.c_str()); + collectionName.c_str()); } trx->orderDitch(cid); @@ -3943,7 +3946,7 @@ AqlValue Functions::IsSameCollection( TRI_ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, "IS_SAME_COLLECTION"); } - std::string const colName(first.slice().copyString()); + std::string const collectionName(first.slice().copyString()); AqlValue value = ExtractFunctionParameterValue(trx, parameters, 1); std::string identifier; @@ -3964,7 +3967,7 @@ AqlValue Functions::IsSameCollection( size_t pos = identifier.find('/'); if (pos != std::string::npos) { - bool const isSame = (colName == identifier.substr(0, pos)); + bool const isSame = (collectionName == identifier.substr(0, pos)); return AqlValue(isSame); } diff --git a/arangod/Utils/Transaction.cpp b/arangod/Utils/Transaction.cpp index 482fb2cf3e..a566d76232 100644 --- a/arangod/Utils/Transaction.cpp +++ b/arangod/Utils/Transaction.cpp @@ -775,7 +775,8 @@ OperationResult Transaction::anyLocal(std::string const& collectionName, TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName); if (cid == 0) { - return OperationResult(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, "'%s'", + collectionName.c_str()); } orderDitch(cid); // will throw when it fails @@ -901,7 +902,8 @@ void Transaction::invokeOnAllElements(std::string const& collectionName, TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName); if (cid == 0) { - THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, "'%s'", + collectionName.c_str()); } TRI_transaction_collection_t* trxCol = trxCollection(cid); @@ -1010,7 +1012,8 @@ OperationResult Transaction::documentLocal(std::string const& collectionName, TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName); if (cid == 0) { - return OperationResult(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, "'%s'", + collectionName.c_str()); } // TODO: clean this up @@ -1588,7 +1591,8 @@ OperationResult Transaction::removeLocal(std::string const& collectionName, TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName); if (cid == 0) { - return OperationResult(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, "'%s'", + collectionName.c_str()); } // TODO: clean this up @@ -1711,7 +1715,8 @@ OperationResult Transaction::allKeysLocal(std::string const& collectionName, TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName); if (cid == 0) { - return OperationResult(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, "'%s'", + collectionName.c_str()); } orderDitch(cid); // will throw when it fails @@ -1801,7 +1806,8 @@ OperationResult Transaction::allLocal(std::string const& collectionName, TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName); if (cid == 0) { - return OperationResult(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, "'%s'", + collectionName.c_str()); } orderDitch(cid); // will throw when it fails @@ -1885,7 +1891,8 @@ OperationResult Transaction::truncateLocal(std::string const& collectionName, TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName); if (cid == 0) { - return OperationResult(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, "'%s'", + collectionName.c_str()); } orderDitch(cid); // will throw when it fails @@ -1973,7 +1980,8 @@ OperationResult Transaction::countLocal(std::string const& collectionName) { TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName); if (cid == 0) { - return OperationResult(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, "'%s'", + collectionName.c_str()); } int res = lock(trxCollection(cid), TRI_TRANSACTION_READ); @@ -2202,7 +2210,8 @@ arangodb::Index* Transaction::getIndexByIdentifier( TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName); if (cid == 0) { - THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, "'%s'", + collectionName.c_str()); } TRI_document_collection_t* document = documentCollection(trxCollection(cid)); @@ -2485,7 +2494,8 @@ std::vector Transaction::indexesForCollection( TRI_voc_cid_t cid = resolver()->getCollectionIdLocal(collectionName); if (cid == 0) { - THROW_ARANGO_EXCEPTION(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND); + THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, "'%s'", + collectionName.c_str()); } TRI_document_collection_t* document = documentCollection(trxCollection(cid)); diff --git a/arangod/Utils/Transaction.h b/arangod/Utils/Transaction.h index 452c8847d8..32c4e7debf 100644 --- a/arangod/Utils/Transaction.h +++ b/arangod/Utils/Transaction.h @@ -288,6 +288,7 @@ class Transaction { collectionName.c_str()); } } + TRI_ASSERT(collection != nullptr); } ////////////////////////////////////////////////////////////////////////////// diff --git a/js/common/tests/shell/shell-attributes.js b/js/common/tests/shell/shell-attributes.js index 7540cf7535..24bc578750 100644 --- a/js/common/tests/shell/shell-attributes.js +++ b/js/common/tests/shell/shell-attributes.js @@ -91,16 +91,11 @@ function AttributesSuite () { var d1 = c.save(doc); var d2 = c.document(d1._id); - delete d1.error; - var i; - for (i in d2) { - if (d2.hasOwnProperty(i)) { - assertTrue(i !== ""); - } - } - - assertEqual(d1, d2); + assertTrue(d2.hasOwnProperty("")); + assertEqual(d1._key, d2._key); + assertEqual(d1._rev, d2._rev); + assertEqual(d1._id, d2._id); }, //////////////////////////////////////////////////////////////////////////////// @@ -114,13 +109,7 @@ function AttributesSuite () { var docs = c.toArray(); assertEqual(1, docs.length); var d = docs[0]; - - var i; - for (i in d) { - if (d.hasOwnProperty(i)) { - assertTrue(i !== ""); - } - } + assertTrue(d.hasOwnProperty("")); }, //////////////////////////////////////////////////////////////////////////////// @@ -197,11 +186,14 @@ function AttributesSuite () { assertEqual(d1._rev, d2._rev); assertFalse(d2._test); assertEqual("bang", d2._boom); - assertFalse(d2.hasOwnProperty("_from")); - assertFalse(d2.hasOwnProperty("_to")); // user specified _rev value must have been ignored assertTrue(d1._rev !== "99"); + + assertTrue(d2.hasOwnProperty("_from")); + assertEqual("33", d2._from); + assertTrue(d2.hasOwnProperty("_to")); + assertEqual("99", d2._to); }, //////////////////////////////////////////////////////////////////////////////// diff --git a/js/common/tests/shell/shell-cap-constraint.js b/js/common/tests/shell/shell-cap-constraint.js deleted file mode 100644 index 17040e43e4..0000000000 --- a/js/common/tests/shell/shell-cap-constraint.js +++ /dev/null @@ -1,664 +0,0 @@ -/*jshint globalstrict:false, strict:false */ -/*global fail, assertEqual, assertTrue, assertNotEqual */ - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test the cap constraint -/// -/// @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 testHelper = require("@arangodb/test-helper").Helper; - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test suite: Creation -//////////////////////////////////////////////////////////////////////////////// - -function CapConstraintSuite() { - 'use strict'; - var ERRORS = internal.errors; - var cn = "UnitTestsCollectionCap"; - var collection = null; - - var nsort = function (l, r) { - if (l !== r) { - return (l < r) ? -1 : 1; - } - return 0; - }; - - var assertBadParameter = function (err) { - assertTrue(err.errorNum === ERRORS.ERROR_BAD_PARAMETER.code || - err.errorNum === ERRORS.ERROR_HTTP_BAD_PARAMETER.code); - }; - - return { - -//////////////////////////////////////////////////////////////////////////////// -/// @brief set up -//////////////////////////////////////////////////////////////////////////////// - - setUp : function () { - internal.db._drop(cn); - collection = internal.db._create(cn); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief tear down -//////////////////////////////////////////////////////////////////////////////// - - tearDown : function () { - if (collection !== null) { - internal.wait(0); - collection.unload(); - collection.drop(); - collection = null; - } - internal.wait(0.0); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: cap with invalid count -//////////////////////////////////////////////////////////////////////////////// - - testInvalidCount1 : function () { - try { - collection.ensureCapConstraint(0); - fail(); - } - catch (err) { - assertBadParameter(err); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: cap with invalid count -//////////////////////////////////////////////////////////////////////////////// - - testInvalidCount2 : function () { - try { - collection.ensureCapConstraint(-10); - fail(); - } - catch (err) { - assertBadParameter(err); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: cap with invalid byteSize -//////////////////////////////////////////////////////////////////////////////// - - testInvalidBytesize1 : function () { - try { - collection.ensureCapConstraint(0, -1024); - fail(); - } - catch (err) { - assertBadParameter(err); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: cap with invalid byteSize -//////////////////////////////////////////////////////////////////////////////// - - testInvalidBytesize2 : function () { - try { - collection.ensureCapConstraint(0, 1024); - fail(); - } - catch (err) { - assertBadParameter(err); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: cap with invalid count -//////////////////////////////////////////////////////////////////////////////// - - testInvalidCombination : function () { - try { - collection.ensureCapConstraint(0, 0); - fail(); - } - catch (err) { - assertBadParameter(err); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: cap creation -//////////////////////////////////////////////////////////////////////////////// - - testCreationCap : function () { - var idx = collection.ensureCapConstraint(10); - var id = idx.id; - - assertNotEqual(0, id); - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(10, idx.size); - assertEqual(0, idx.byteSize); - - idx = collection.ensureCapConstraint(10); - - assertEqual(id, idx.id); - assertEqual("cap", idx.type); - assertEqual(false, idx.isNewlyCreated); - assertEqual(10, idx.size); - assertEqual(0, idx.byteSize); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: index creation error handling -//////////////////////////////////////////////////////////////////////////////// - - testCreationTwoCap : function () { - var idx = collection.ensureCapConstraint(10); - var id = idx.id; - - assertNotEqual(0, id); - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(10, idx.size); - assertEqual(0, idx.byteSize); - - try { - idx = collection.ensureCapConstraint(20); - fail(); - } - catch (err) { - assertEqual(ERRORS.ERROR_ARANGO_CAP_CONSTRAINT_ALREADY_DEFINED.code, err.errorNum); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: number of documents -//////////////////////////////////////////////////////////////////////////////// - - testNumberDocuments : function () { - var idx = collection.ensureCapConstraint(10); - var fun = function(d) { return d.n; }; - - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(10, idx.size); - assertEqual(0, idx.byteSize); - - assertEqual(0, collection.count()); - - for (var i = 0; i < 10; ++i) { - collection.save({ n : i }); - } - - assertEqual(10, collection.count()); - assertEqual([0,1,2,3,4,5,6,7,8,9], collection.toArray().map(fun).sort(nsort)); - - collection.save({ n : 10 }); - var a = collection.save({ n : 11 }); - - for (i = 12; i < 20; ++i) { - collection.save({ n : i }); - } - - assertEqual(10, collection.count()); - assertEqual([10,11,12,13,14,15,16,17,18,19], collection.toArray().map(fun).sort(nsort)); - - collection.replace(a._id, { n : 11, a : 1 }); - - for (i = 20; i < 29; ++i) { - collection.save({ n : i }); - } - - assertEqual(10, collection.count()); - assertEqual([11,20,21,22,23,24,25,26,27,28], collection.toArray().map(fun).sort(nsort)); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: deletes -//////////////////////////////////////////////////////////////////////////////// - - testDeletes : function () { - var idx = collection.ensureCapConstraint(5); - var fun = function(d) { return d.n; }; - - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(5, idx.size); - assertEqual(0, idx.byteSize); - - assertEqual(0, collection.count()); - - for (var i = 0; i < 5; ++i) { - try { - collection.remove("foo"); - } - catch (err) { - } - } - - assertEqual(0, collection.count()); - assertEqual([ ], collection.toArray()); - - var d = collection.save({ n : 1 }); - assertEqual(1, collection.count()); - assertEqual([ 1 ], collection.toArray().map(fun).sort(nsort)); - - collection.remove(d); - assertEqual(0, collection.count()); - assertEqual([ ], collection.toArray()); - - for (i = 0; i < 10; ++i) { - collection.save({ n : i }); - } - - assertEqual(5, collection.count()); - assertEqual([ 5, 6, 7, 8, 9 ], collection.toArray().map(fun).sort(nsort)); - - collection.truncate(); - assertEqual(0, collection.count()); - assertEqual([ ], collection.toArray()); - - for (i = 25; i < 35; ++i) { - collection.save({ n : i }); - } - - assertEqual(5, collection.count()); - assertEqual([ 30, 31, 32, 33, 34 ], collection.toArray().map(fun).sort(nsort)); - - collection.truncate(); - assertEqual(0, collection.count()); - - testHelper.waitUnload(collection, true); - - assertEqual(0, collection.count()); - assertEqual([ ], collection.toArray()); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: updates -//////////////////////////////////////////////////////////////////////////////// - - testUpdates1 : function () { - var idx = collection.ensureCapConstraint(5); - var fun = function(d) { return d.n; }; - - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(5, idx.size); - assertEqual(0, idx.byteSize); - - assertEqual(0, collection.count()); - - var docs = [ ]; - for (var i = 0; i < 6; ++i) { - docs[i] = collection.save({ n : i }); - } - - assertEqual(5, collection.count()); - assertEqual([1, 2, 3, 4, 5], collection.toArray().map(fun).sort(nsort)); - - collection.replace(docs[1], { n: 100 }); - assertEqual(5, collection.count()); - assertEqual([2, 3, 4, 5, 100], collection.toArray().map(fun).sort(nsort)); - - collection.save({ n: 99 }); - assertEqual(5, collection.count()); - assertEqual([3, 4, 5, 99, 100], collection.toArray().map(fun).sort(nsort)); - - collection.remove(docs[3]); - assertEqual(4, collection.count()); - assertEqual([4, 5, 99, 100], collection.toArray().map(fun).sort(nsort)); - - collection.save({ n: 98 }); - assertEqual(5, collection.count()); - assertEqual([4, 5, 98, 99, 100], collection.toArray().map(fun).sort(nsort)); - - collection.save({ n: 97 }); - assertEqual(5, collection.count()); - assertEqual([5, 97, 98, 99, 100], collection.toArray().map(fun).sort(nsort)); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: updates -//////////////////////////////////////////////////////////////////////////////// - - testUpdates2 : function () { - var idx = collection.ensureCapConstraint(3); - var fun = function(d) { return d._key; }; - - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(3, idx.size); - assertEqual(0, idx.byteSize); - - collection.save({ _key: "foo" }); - collection.save({ _key: "bar" }); - collection.save({ _key: "baz" }); - - assertEqual(3, collection.count()); - assertEqual([ "bar", "baz", "foo" ], collection.toArray().map(fun).sort()); - - collection.replace("foo", { a : 1 }); // bar, baz, foo - assertEqual(3, collection.count()); - assertEqual([ "bar", "baz", "foo" ], collection.toArray().map(fun).sort()); - - collection.save({ _key: "bad" }); // baz, foo, bad - assertEqual(3, collection.count()); - assertEqual([ "bad", "baz", "foo" ], collection.toArray().map(fun).sort()); - - collection.replace("baz", { a : 1 }); // foo, bad, baz - assertEqual(3, collection.count()); - assertEqual([ "bad", "baz", "foo" ], collection.toArray().map(fun).sort()); - - collection.save({ _key: "bam" }); // bad, baz, bam - assertEqual(3, collection.count()); - assertEqual([ "bad", "bam", "baz" ], collection.toArray().map(fun).sort()); - - collection.save({ _key: "abc" }); // baz, bam, abc - assertEqual(3, collection.count()); - assertEqual([ "abc", "bam", "baz" ], collection.toArray().map(fun).sort()); - - testHelper.waitUnload(collection, true); - - assertEqual(3, collection.count()); - assertEqual([ "abc", "bam", "baz" ], collection.toArray().map(fun).sort()); - - collection.save({ _key: "def" }); // bam, abc, def - assertEqual(3, collection.count()); - assertEqual([ "abc", "bam", "def" ], collection.toArray().map(fun).sort()); - - collection.save({ _key: "ghi" }); // abc, def, ghi - assertEqual(3, collection.count()); - assertEqual([ "abc", "def", "ghi" ], collection.toArray().map(fun).sort()); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: cap with byteSize -//////////////////////////////////////////////////////////////////////////////// - - testBytesize : function () { - var idx = collection.ensureCapConstraint(0, 16384); - var id = idx.id; - - assertNotEqual(0, id); - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(0, idx.size); - assertEqual(16384, idx.byteSize); - - idx = collection.ensureCapConstraint(0, 16384); - - assertEqual(id, idx.id); - assertEqual("cap", idx.type); - assertEqual(false, idx.isNewlyCreated); - assertEqual(0, idx.size); - assertEqual(16384, idx.byteSize); - - for (var i = 0; i < 1000; ++i) { - collection.save({ "test" : "this is a test" }); - } - - assertTrue(collection.count() < 1000); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: cap with count and byteSize -//////////////////////////////////////////////////////////////////////////////// - - testCombo1 : function () { - var idx = collection.ensureCapConstraint(50, 16384); - var id = idx.id; - - assertNotEqual(0, id); - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(50, idx.size); - assertEqual(16384, idx.byteSize); - - idx = collection.ensureCapConstraint(50, 16384); - - assertEqual(id, idx.id); - assertEqual("cap", idx.type); - assertEqual(false, idx.isNewlyCreated); - assertEqual(50, idx.size); - assertEqual(16384, idx.byteSize); - - for (var i = 0; i < 1000; ++i) { - collection.save({ "test" : "this is a test" }); - } - - assertEqual(50, collection.count()); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: cap with count and byteSize -//////////////////////////////////////////////////////////////////////////////// - - testCombo2 : function () { - var idx = collection.ensureCapConstraint(1000, 16384); - var id = idx.id; - - assertNotEqual(0, id); - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(1000, idx.size); - assertEqual(16384, idx.byteSize); - - idx = collection.ensureCapConstraint(1000, 16384); - - assertEqual(id, idx.id); - assertEqual("cap", idx.type); - assertEqual(false, idx.isNewlyCreated); - assertEqual(1000, idx.size); - assertEqual(16384, idx.byteSize); - - for (var i = 0; i < 1000; ++i) { - collection.save({ "test" : "this is a test" }); - } - - assertTrue(collection.count() < 1000); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: too large document -//////////////////////////////////////////////////////////////////////////////// - - testDocumentTooLarge1 : function () { - collection.ensureCapConstraint(1, 16384); - var doc = { }; - - for (var i = 0; i < 1000; ++i) { - doc["test" + i] = "this is a test for the too large document"; - } - - try { - collection.save(doc); - fail(); - } - catch (err) { - assertTrue(err.errorNum === ERRORS.ERROR_ARANGO_DOCUMENT_TOO_LARGE.code || - err.errorNum === ERRORS.ERROR_INTERNAL.code); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: too large document -//////////////////////////////////////////////////////////////////////////////// - - testDocumentTooLarge2 : function () { - collection.ensureCapConstraint(1000, 16384); - var doc = { }; - - for (var i = 0; i < 1000; ++i) { - doc["test" + i] = "this is a test for the too large document"; - } - - try { - collection.save(doc); - fail(); - } - catch (err) { - assertTrue(err.errorNum === ERRORS.ERROR_ARANGO_DOCUMENT_TOO_LARGE.code || - err.errorNum === ERRORS.ERROR_INTERNAL.code); - } - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: modification of collection size via updates -//////////////////////////////////////////////////////////////////////////////// - - testSizeModificationSimple : function () { - collection.ensureCapConstraint(1000, 16384); - - var doc = collection.save({ a : 1 }); - - // cap should not be triggered here, but we want to see whether assertions fail - doc = collection.replace(doc, { a : 2, b : 2 }); - assertEqual(1, collection.count()); - collection.truncate(); - assertEqual(0, collection.count()); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: modification of collection size via updates -//////////////////////////////////////////////////////////////////////////////// - - testSizeModificationsMulti : function () { - collection.ensureCapConstraint(1000, 16384); - - var doc = collection.save({ }); - var data = { }; - - for (var i = 0; i < 100; ++i) { - data["a" + i] = i; - - // cap should not be triggered here, but we want to see whether assertions fail - doc = collection.replace(doc, data); - } - - assertEqual(1, collection.count()); - - collection.truncate(); - doc = null; - testHelper.waitUnload(collection); - - assertEqual(0, collection.count()); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: modification of collection size via updates -//////////////////////////////////////////////////////////////////////////////// - - testSizeModifications : function () { - collection.ensureCapConstraint(2, 16384); - - var doc = collection.save({ _key: "test", a: 1 }); - var rev = doc._rev; - collection.save({ a : 2 }); - - var data = { }; - for (var i = 0; i < 1000; ++i) { - data["b" + i] = "this document will really get too big..."; - } - - try { - collection.update(doc, data); - fail(); - } - catch (err) { - assertTrue(err.errorNum === ERRORS.ERROR_ARANGO_DOCUMENT_TOO_LARGE.code || - err.errorNum === ERRORS.ERROR_INTERNAL.code); - } - - doc = null; - testHelper.waitUnload(collection); - - assertEqual(2, collection.count()); - assertEqual(1, collection.document("test").a); - assertEqual(rev, collection.document("test")._rev); - - collection.truncate(); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: modification of collection size via updates -//////////////////////////////////////////////////////////////////////////////// - - testSizeModificationsViolations : function () { - collection.ensureCapConstraint(1, 16384); - - var doc = collection.save({ }); - var data = { }; - - for (var i = 0; i < 10; ++i) { - data["a" + i] = i; - - doc = collection.replace(doc, data); - } - - assertEqual(1, collection.count()); - assertEqual(collection.toArray()[0].a9, 9); - - for (i = 0; i < 1000; ++i) { - data["b" + i] = "this document will really get too big..."; - } - - try { - collection.save(data); - fail(); - } - catch (err) { - assertTrue(err.errorNum === ERRORS.ERROR_ARANGO_DOCUMENT_TOO_LARGE.code || - err.errorNum === ERRORS.ERROR_INTERNAL.code); - } - - assertEqual(collection.toArray()[0].a9, 9); - assertEqual(1, collection.count()); - - doc = null; - testHelper.waitUnload(collection); - - assertEqual(collection.toArray()[0].a9, 9); - assertEqual(1, collection.count()); - - collection.truncate(); - assertEqual(0, collection.count()); - } - - }; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes the test suites -//////////////////////////////////////////////////////////////////////////////// - -jsunity.run(CapConstraintSuite); - -return jsunity.done(); - From d226175e913fb15864ea9da78749f8cb6dc2f164 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 22 Mar 2016 15:15:43 +0100 Subject: [PATCH 2/8] test fixes --- arangod/V8Server/v8-query.cpp | 10 +++- .../modules/@arangodb/arango-collection.js | 9 ++-- .../shell/shell-collection-noncluster.js | 46 +++++++++---------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/arangod/V8Server/v8-query.cpp b/arangod/V8Server/v8-query.cpp index cf37a1c7a1..5f7cfad72e 100644 --- a/arangod/V8Server/v8-query.cpp +++ b/arangod/V8Server/v8-query.cpp @@ -382,7 +382,15 @@ static void JS_ChecksumCollection( if (withData) { // with data - localHash += slice.hash(); + for (auto const& it : VPackObjectIterator(slice)) { + // loop over all attributes, but exclude _rev, _id and _key + // _id is different for each collection anyway, _rev is covered by withRevisions, and _key + // was already handled before + std::string key(it.key.copyString()); + if (key != TRI_VOC_ATTRIBUTE_ID && key != TRI_VOC_ATTRIBUTE_KEY && key != TRI_VOC_ATTRIBUTE_REV) { + localHash ^= it.value.hash(); + } + } } hash ^= localHash; diff --git a/js/client/modules/@arangodb/arango-collection.js b/js/client/modules/@arangodb/arango-collection.js index 3cb3fcea60..b2443e775c 100644 --- a/js/client/modules/@arangodb/arango-collection.js +++ b/js/client/modules/@arangodb/arango-collection.js @@ -280,7 +280,6 @@ ArangoCollection.prototype._help = function () { internal.print(helpArangoCollection); }; - //////////////////////////////////////////////////////////////////////////////// /// @brief gets the name of a collection //////////////////////////////////////////////////////////////////////////////// @@ -978,7 +977,7 @@ ArangoCollection.prototype.insert = function (from, to, data, options) { data._from = from; data._to = to; - url = "/_api/collection/" + encodeURIComponent(this.name()); + url = "/_api/document/" + encodeURIComponent(this.name()); } if (options === undefined) { @@ -1212,6 +1211,8 @@ ArangoCollection.prototype.replace = function (id, data, overwrite, waitForSync) id = id._key; } url = this._documenturl(id); + } else { + url = this._documenturl(id); } url = this._appendSyncParameter(url, waitForSync); @@ -1286,7 +1287,6 @@ ArangoCollection.prototype.update = function (id, data, overwrite, keepNull, wai } } else { - // set default value for keepNull var keepNullValue = ((typeof keepNull === "undefined") ? true : keepNull); params = "?keepNull=" + (keepNullValue ? "true" : "false"); @@ -1296,7 +1296,6 @@ ArangoCollection.prototype.update = function (id, data, overwrite, keepNull, wai } options = {}; - } var url; @@ -1321,6 +1320,8 @@ ArangoCollection.prototype.update = function (id, data, overwrite, keepNull, wai id = id._key; } url = this._documenturl(id) + params; + } else { + url = this._documenturl(id) + params; } url = this._appendSyncParameter(url, waitForSync); diff --git a/js/common/tests/shell/shell-collection-noncluster.js b/js/common/tests/shell/shell-collection-noncluster.js index e708df2fd7..65f01069ed 100644 --- a/js/common/tests/shell/shell-collection-noncluster.js +++ b/js/common/tests/shell/shell-collection-noncluster.js @@ -209,8 +209,8 @@ function CollectionSuite () { assertTypeOf("string", r1.revision); assertTrue(r1.revision !== ""); assertTrue(r1.revision.match(/^[0-9]+$/)); - assertTypeOf("number", r1.checksum); - assertEqual(0, r1.checksum); + assertTypeOf("string", r1.checksum); + assertEqual("0", r1.checksum); // inserting a doc, checksum should change c1.save({ a : 1 }); @@ -219,8 +219,8 @@ function CollectionSuite () { assertTypeOf("string", r2.revision); assertTrue(r2.revision !== ""); assertTrue(r2.revision.match(/^[0-9]+$/)); - assertTypeOf("number", r2.checksum); - assertNotEqual(0, r2.checksum); + assertTypeOf("string", r2.checksum); + assertNotEqual("0", r2.checksum); // inserting another doc, checksum should change c1.save({ a : 2 }); @@ -230,8 +230,8 @@ function CollectionSuite () { assertTypeOf("string", r3.revision); assertTrue(r3.revision !== ""); assertTrue(r3.revision.match(/^[0-9]+$/)); - assertTypeOf("number", r3.checksum); - assertNotEqual(0, r3.checksum); + assertTypeOf("string", r3.checksum); + assertNotEqual("0", r3.checksum); assertNotEqual(r2.checksum, r3.checksum); // test after unloading @@ -239,16 +239,16 @@ function CollectionSuite () { var r4 = c1.checksum(true); assertTypeOf("string", r4.revision); assertEqual(r3.revision, r4.revision); - assertTypeOf("number", r4.checksum); - assertNotEqual(0, r4.checksum); + assertTypeOf("string", r4.checksum); + assertNotEqual("0", r4.checksum); assertEqual(r3.checksum, r4.checksum); // test withData var r5 = c1.checksum(true, true); assertTypeOf("string", r5.revision); assertEqual(r4.revision, r5.revision); - assertTypeOf("number", r5.checksum); - assertNotEqual(0, r5.checksum); + assertTypeOf("string", r5.checksum); + assertNotEqual("0", r5.checksum); assertNotEqual(r4.checksum, r5.checksum); // test after truncation @@ -257,8 +257,8 @@ function CollectionSuite () { assertTypeOf("string", r6.revision); assertNotEqual(r4.revision, r6.revision); assertNotEqual(r5.revision, r6.revision); - assertTypeOf("number", r6.checksum); - assertEqual(0, r6.checksum); + assertTypeOf("string", r6.checksum); + assertEqual("0", r6.checksum); db._drop(cn); }, @@ -280,8 +280,8 @@ function CollectionSuite () { assertTypeOf("string", r1.revision); assertTrue(r1.revision !== ""); assertTrue(r1.revision.match(/^[0-9]+$/)); - assertTypeOf("number", r1.checksum); - assertEqual(0, r1.checksum); + assertTypeOf("string", r1.checksum); + assertEqual("0", r1.checksum); c1.save(vn + "/1", vn + "/2", { a : 1 }); var r2 = c1.checksum(true); @@ -289,8 +289,8 @@ function CollectionSuite () { assertTypeOf("string", r2.revision); assertTrue(r2.revision !== ""); assertTrue(r2.revision.match(/^[0-9]+$/)); - assertTypeOf("number", r2.checksum); - assertNotEqual(0, r2.checksum); + assertTypeOf("string", r2.checksum); + assertNotEqual("0", r2.checksum); c1.save(vn + "/1", vn + "/2", { a : 2 }); var r3 = c1.checksum(true); @@ -299,23 +299,23 @@ function CollectionSuite () { assertTypeOf("string", r3.revision); assertTrue(r3.revision !== ""); assertTrue(r3.revision.match(/^[0-9]+$/)); - assertTypeOf("number", r3.checksum); - assertNotEqual(0, r3.checksum); + assertTypeOf("string", r3.checksum); + assertNotEqual("0", r3.checksum); assertNotEqual(r2.checksum, r3.checksum); c1.unload(); var r4 = c1.checksum(true); assertTypeOf("string", r4.revision); assertEqual(r3.revision, r4.revision); - assertTypeOf("number", r4.checksum); + assertTypeOf("string", r4.checksum); assertEqual(r3.checksum, r4.checksum); // test withData var r5 = c1.checksum(true, true); assertTypeOf("string", r5.revision); assertEqual(r4.revision, r5.revision); - assertTypeOf("number", r5.checksum); - assertNotEqual(0, r5.checksum); + assertTypeOf("string", r5.checksum); + assertNotEqual("0", r5.checksum); assertNotEqual(r4.checksum, r5.checksum); // test after truncation @@ -324,8 +324,8 @@ function CollectionSuite () { assertTypeOf("string", r6.revision); assertNotEqual(r4.revision, r6.revision); assertNotEqual(r5.revision, r6.revision); - assertTypeOf("number", r6.checksum); - assertEqual(0, r6.checksum); + assertTypeOf("string", r6.checksum); + assertEqual("0", r6.checksum); db._drop(cn); db._drop(vn); From 04b436f0b5352f1ce68bdc629745a4012cd1dbf4 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 22 Mar 2016 15:18:34 +0100 Subject: [PATCH 3/8] fixed test --- js/common/tests/shell/shell-collection.js | 183 ---------------------- 1 file changed, 183 deletions(-) diff --git a/js/common/tests/shell/shell-collection.js b/js/common/tests/shell/shell-collection.js index 63858f06ed..fd43b2a755 100644 --- a/js/common/tests/shell/shell-collection.js +++ b/js/common/tests/shell/shell-collection.js @@ -905,189 +905,6 @@ function CollectionSuite () { db._drop(cn); }, -//////////////////////////////////////////////////////////////////////////////// -/// @brief test first -//////////////////////////////////////////////////////////////////////////////// - - testFirst : function () { - var cn = "example"; - - db._drop(cn); - var c1 = db._create(cn); - - assertNull(c1.first()); - - c1.save({ "a": 1, "_key" : "one" }); - assertEqual(1, c1.first().a); - - c1.save({ "a": 2, "_key" : "two" }); - assertEqual(1, c1.first().a); - - c1.remove("one"); - assertEqual(2, c1.first().a); - - c1.remove("two"); - assertNull(c1.first()); - - c1.truncate(); - for (var i = 0; i < 1000; ++i) { - c1.save({ "a" : i, "_key" : "test" + i }); - } - - var actual = c1.first(1); - assertEqual(1, actual.length); - assertEqual(0, actual[0].a); - assertEqual("test0", actual[0]._key); - - actual = c1.first(2); - assertEqual(2, actual.length); - assertEqual(0, actual[0].a); - assertEqual(1, actual[1].a); - assertEqual("test0", actual[0]._key); - assertEqual("test1", actual[1]._key); - - actual = c1.first(10); - assertEqual(10, actual.length); - assertEqual(0, actual[0].a); - assertEqual(1, actual[1].a); - assertEqual(9, actual[9].a); - assertEqual("test0", actual[0]._key); - assertEqual("test1", actual[1]._key); - assertEqual("test9", actual[9]._key); - - c1.remove("test0"); - c1.remove("test3"); - - actual = c1.first(10); - assertEqual(10, actual.length); - assertEqual(1, actual[0].a); - assertEqual(2, actual[1].a); - assertEqual(4, actual[2].a); - assertEqual(11, actual[9].a); - assertEqual("test1", actual[0]._key); - assertEqual("test2", actual[1]._key); - assertEqual("test4", actual[2]._key); - assertEqual("test11", actual[9]._key); - - c1.truncate(); - - actual = c1.first(10); - assertEqual(0, actual.length); - - db._drop(cn); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test last -//////////////////////////////////////////////////////////////////////////////// - - testLast : function () { - var cn = "example"; - - db._drop(cn); - var c1 = db._create(cn); - - assertNull(c1.last()); - - c1.save({ "a": 1, "_key" : "one" }); - assertEqual(1, c1.last().a); - - c1.save({ "a": 2, "_key" : "two" }); - assertEqual(2, c1.last().a); - - c1.remove("two"); - assertEqual(1, c1.last().a); - - c1.remove("one"); - assertNull(c1.last()); - - c1.truncate(); - for (var i = 0; i < 1000; ++i) { - c1.save({ "a" : i, "_key" : "test" + i }); - } - - var actual = c1.last(1); - assertEqual(1, actual.length); - assertEqual(999, actual[0].a); - assertEqual("test999", actual[0]._key); - - actual = c1.last(2); - assertEqual(2, actual.length); - assertEqual(999, actual[0].a); - assertEqual(998, actual[1].a); - assertEqual("test999", actual[0]._key); - assertEqual("test998", actual[1]._key); - - actual = c1.last(10); - assertEqual(10, actual.length); - assertEqual(999, actual[0].a); - assertEqual(998, actual[1].a); - assertEqual(990, actual[9].a); - assertEqual("test999", actual[0]._key); - assertEqual("test998", actual[1]._key); - assertEqual("test990", actual[9]._key); - - c1.remove("test999"); - c1.remove("test996"); - - actual = c1.last(10); - assertEqual(10, actual.length); - assertEqual(998, actual[0].a); - assertEqual(997, actual[1].a); - assertEqual(995, actual[2].a); - assertEqual(988, actual[9].a); - assertEqual("test998", actual[0]._key); - assertEqual("test997", actual[1]._key); - assertEqual("test995", actual[2]._key); - assertEqual("test988", actual[9]._key); - - db._drop(cn); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test first / last after reload -//////////////////////////////////////////////////////////////////////////////// - - testFirstLastAfterReload : function () { - var cn = "example"; - - db._drop(cn); - var c1 = db._create(cn); - - for (var i = 0; i < 1000; ++i) { - c1.save({ _key : "test" + i, "value" : i }); - } - - testHelper.waitUnload(c1); - c1 = null; - - c1 = db._collection(cn); - - for (i = 1000; i < 2000; ++i) { - c1.save({ _key : "test" + i, "value" : i }); - } - - var actual = c1.first(10); - assertEqual(10, actual.length); - assertEqual(0, actual[0].value); - assertEqual(1, actual[1].value); - assertEqual(9, actual[9].value); - assertEqual("test0", actual[0]._key); - assertEqual("test1", actual[1]._key); - assertEqual("test9", actual[9]._key); - - actual = c1.last(10); - assertEqual(10, actual.length); - assertEqual(1999, actual[0].value); - assertEqual(1998, actual[1].value); - assertEqual(1990, actual[9].value); - assertEqual("test1999", actual[0]._key); - assertEqual("test1998", actual[1]._key); - assertEqual("test1990", actual[9]._key); - - db._drop(cn); - }, - //////////////////////////////////////////////////////////////////////////////// /// @brief test system collection dropping / renaming / unloading //////////////////////////////////////////////////////////////////////////////// From 7f9583350550edb12d1af6f426d5572797017403 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 22 Mar 2016 16:14:52 +0100 Subject: [PATCH 4/8] fixed tests --- js/client/modules/@arangodb/arango-collection.js | 7 +++++++ js/client/modules/@arangodb/arango-database.js | 5 +---- js/common/tests/shell/shell-document.js | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/js/client/modules/@arangodb/arango-collection.js b/js/client/modules/@arangodb/arango-collection.js index b2443e775c..b44a047e3f 100644 --- a/js/client/modules/@arangodb/arango-collection.js +++ b/js/client/modules/@arangodb/arango-collection.js @@ -966,6 +966,13 @@ ArangoCollection.prototype.insert = function (from, to, data, options) { errorMessage : internal.errors.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.message }); } + if (data === undefined || data === null || typeof data !== 'object') { + throw new ArangoError({ + errorNum : internal.errors.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.code, + errorMessage : internal.errors.ERROR_ARANGO_DOCUMENT_TYPE_INVALID.message + }); + } + if (typeof from === 'object' && from.hasOwnProperty("_id")) { from = from._id; } diff --git a/js/client/modules/@arangodb/arango-database.js b/js/client/modules/@arangodb/arango-database.js index 3ea8a4e6d1..16820590c2 100644 --- a/js/client/modules/@arangodb/arango-database.js +++ b/js/client/modules/@arangodb/arango-database.js @@ -31,8 +31,6 @@ var internal = require("internal"); var arangosh = require("@arangodb/arangosh"); - - //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// @@ -57,7 +55,6 @@ ArangoCollection = require("@arangodb/arango-collection").ArangoCollection; var ArangoError = require("@arangodb").ArangoError; var ArangoStatement = require("@arangodb/arango-statement").ArangoStatement; - //////////////////////////////////////////////////////////////////////////////// /// @brief index id regex //////////////////////////////////////////////////////////////////////////////// @@ -666,7 +663,7 @@ ArangoDatabase.prototype._remove = function (id, overwrite, waitForSync) { var url = this._documenturl(id) + params; url = this._appendSyncParameter(url, waitForSync); - url = this._appendBoolParameter(url, "ignoreRevs", true); + url = this._appendBoolParameter(url, "ignoreRevs", ignoreRevs); url = this._appendBoolParameter(url, "returnOld", options.returnOld); if (rev === null || ignoreRevs) { diff --git a/js/common/tests/shell/shell-document.js b/js/common/tests/shell/shell-document.js index 0838ab40d4..3c9e4f1c42 100644 --- a/js/common/tests/shell/shell-document.js +++ b/js/common/tests/shell/shell-document.js @@ -1949,6 +1949,7 @@ function DatabaseDocumentSuite () { var a2 = db._replace(a1, { a : 2 }); assertEqual(a1._id, a2._id); + assertEqual(a1._key, a2._key); assertNotEqual(a1._rev, a2._rev); try { From 2ab44cef037274066dcd8a10f3107d322ee312a1 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 22 Mar 2016 16:17:05 +0100 Subject: [PATCH 5/8] fixed tests --- .../tests/shell/shell-figures-noncluster.js | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/js/common/tests/shell/shell-figures-noncluster.js b/js/common/tests/shell/shell-figures-noncluster.js index aa2e2ba306..277809d8b5 100644 --- a/js/common/tests/shell/shell-figures-noncluster.js +++ b/js/common/tests/shell/shell-figures-noncluster.js @@ -59,8 +59,6 @@ function FiguresSuite () { var f = c1.figures(); assertEqual(0, f.datafiles.count); assertEqual(0, f.compactors.count); - assertEqual(0, f.shapefiles.count); - assertEqual(0, f.shapefiles.fileSize); assertEqual(0, f.alive.count); assertEqual(0, f.alive.size); assertEqual(0, f.dead.count); @@ -85,8 +83,6 @@ function FiguresSuite () { assertEqual(1, f.journals.count); assertTrue(f.journals.fileSize > 0); assertEqual(0, f.compactors.count); - assertEqual(0, f.shapefiles.count); - assertEqual(0, f.shapefiles.fileSize); assertEqual(1, f.alive.count); assertNotEqual(0, f.alive.size); assertEqual(0, f.dead.count); @@ -160,24 +156,6 @@ function FiguresSuite () { assertNotEqual(0, f.dead.size); assertEqual(2, f.dead.deletion); - var attributes = f.attributes.count; - var shapes = f.shapes.count; - - c1.save({ b0rk : "abc" }); - - internal.wal.flush(true, true); - tries = 0; - while (++tries < 20) { - f = c1.figures(); - if (f.shapes.count === shapes + 1) { - break; - } - internal.wait(1, false); - } - - assertEqual(attributes + 1, f.attributes.count); - assertEqual(shapes + 1, f.shapes.count); - db._drop(collection); }, From d763c102d6a1cf4888e34253968401d928966748 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 22 Mar 2016 18:34:40 +0100 Subject: [PATCH 6/8] fulltext fixes --- arangod/Aql/Functions.cpp | 3 ++- arangod/FulltextIndex/fulltext-index.cpp | 13 +++++-------- arangod/Indexes/FulltextIndex.cpp | 17 +++++++++-------- .../modules/@arangodb/simple-query-common.js | 4 +++- js/server/modules/@arangodb/simple-query.js | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/arangod/Aql/Functions.cpp b/arangod/Aql/Functions.cpp index 6dedb303b1..4c05ca817a 100644 --- a/arangod/Aql/Functions.cpp +++ b/arangod/Aql/Functions.cpp @@ -3860,7 +3860,7 @@ AqlValue Functions::Fulltext(arangodb::aql::Query* query, if (document == nullptr) { THROW_ARANGO_EXCEPTION_FORMAT(TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND, - "'%s'", collectionName.c_str()); + "", collectionName.c_str()); } arangodb::Index* index = nullptr; @@ -3881,6 +3881,7 @@ AqlValue Functions::Fulltext(arangodb::aql::Query* query, } if (index == nullptr) { + // fiddle collection name into error message THROW_ARANGO_EXCEPTION_PARAMS(TRI_ERROR_QUERY_FULLTEXT_INDEX_MISSING, collectionName.c_str()); } diff --git a/arangod/FulltextIndex/fulltext-index.cpp b/arangod/FulltextIndex/fulltext-index.cpp index e01ba62c49..f60cccb6fc 100644 --- a/arangod/FulltextIndex/fulltext-index.cpp +++ b/arangod/FulltextIndex/fulltext-index.cpp @@ -1195,14 +1195,11 @@ TRI_fulltext_result_t* FindDocuments (index__t* const idx, static inline size_t CommonPrefixLength(std::string const& left, std::string const& right) { - const char* lhs = left.c_str(); - const char* rhs = right.c_str(); - char* p1; - char* p2; + char const* lhs = left.c_str(); + char const* rhs = right.c_str(); size_t length = 0; - for (p1 = (char*)lhs, p2 = (char*)rhs; *p1 && *p2 && *p1 == *p2; - ++p1, ++p2, ++length) + for (; *lhs && *rhs && *lhs == *rhs; ++lhs, ++rhs, ++length) ; return length; @@ -1332,7 +1329,7 @@ bool TRI_InsertWordsFulltextIndex(TRI_fts_index_t* const ftx, paths[MAX_WORD_BYTES] = nullptr; // the words must be sorted so we can avoid duplicate words and use an - // optimisation + // optimization // for words with common prefixes (which will be adjacent in the sorted list // of words) // The default comparator (<) is exactly what we need here @@ -1383,7 +1380,7 @@ bool TRI_InsertWordsFulltextIndex(TRI_fts_index_t* const ftx, // insert the // same word multiple times for the same document if (start > 0 && start == lastLength && - start == tmp.length()) { + start == tmp.size()) { // duplicate word, skip it and continue with next word w++; continue; diff --git a/arangod/Indexes/FulltextIndex.cpp b/arangod/Indexes/FulltextIndex.cpp index a1ce5b6d89..2a8c3261bb 100644 --- a/arangod/Indexes/FulltextIndex.cpp +++ b/arangod/Indexes/FulltextIndex.cpp @@ -40,7 +40,8 @@ using namespace arangodb; static void ExtractWords(std::vector& words, VPackSlice const value, - size_t minWordLength) { + size_t minWordLength, + int level) { if (value.isString()) { // extract the string value for the indexed attribute std::string text = value.copyString(); @@ -50,13 +51,13 @@ static void ExtractWords(std::vector& words, words, text, minWordLength, TRI_FULLTEXT_MAX_WORD_LENGTH, true); // We don't care for the result. If the result is false, words stays // unchanged and is not indexed - } else if (value.isArray()) { + } else if (value.isArray() && level == 0) { for (auto const& v : VPackArrayIterator(value)) { - ExtractWords(words, v, minWordLength); + ExtractWords(words, v, minWordLength, level + 1); } - } else if (value.isObject()) { + } else if (value.isObject() && level == 0) { for (auto const& v : VPackObjectIterator(value)) { - ExtractWords(words, v.value, minWordLength); + ExtractWords(words, v.value, minWordLength, level + 1); } } } @@ -109,7 +110,7 @@ int FulltextIndex::insert(arangodb::Transaction*, TRI_doc_mptr_t const* doc, int res = TRI_ERROR_NO_ERROR; std::vector words = wordlist(doc); - + if (words.empty()) { // TODO: distinguish the cases "empty wordlist" and "out of memory" // LOG(WARN) << "could not build wordlist"; @@ -158,12 +159,12 @@ std::vector FulltextIndex::wordlist( VPackSlice const slice(document->vpack()); VPackSlice const value = slice.get(_attr); - if (!value.isString() || value.isArray()) { + if (!value.isString() && !value.isArray() && !value.isObject()) { // Invalid Input return words; } - ExtractWords(words, value, _minWordLength); + ExtractWords(words, value, _minWordLength, 0); } catch (...) { // Backwards compatibility // The pre-vpack impl. did just ignore all errors and returned nulltpr diff --git a/js/common/modules/@arangodb/simple-query-common.js b/js/common/modules/@arangodb/simple-query-common.js index 90d2aa50d1..3a1fb6377a 100644 --- a/js/common/modules/@arangodb/simple-query-common.js +++ b/js/common/modules/@arangodb/simple-query-common.js @@ -1047,7 +1047,9 @@ function SimpleQueryFulltext (collection, attribute, query, iid) { if (this._index === null) { var err = new ArangoError(); err.errorNum = arangodb.ERROR_QUERY_FULLTEXT_INDEX_MISSING; - err.errorMessage = arangodb.errors.ERROR_QUERY_FULLTEXT_INDEX_MISSING.message; + err.errorMessage = require("internal").sprintf( + arangodb.errors.ERROR_QUERY_FULLTEXT_INDEX_MISSING.message, + collection.name()); throw err; } } diff --git a/js/server/modules/@arangodb/simple-query.js b/js/server/modules/@arangodb/simple-query.js index aa6fe3a549..22ee702b79 100644 --- a/js/server/modules/@arangodb/simple-query.js +++ b/js/server/modules/@arangodb/simple-query.js @@ -313,7 +313,7 @@ SimpleQueryFulltext.prototype.execute = function () { "@collection": this._collection.name(), attribute: this._attribute, query: this._query, - limit: limit + limit: parseInt(this._limit + this._skip, 10) }; var query = "FOR doc IN FULLTEXT(@@collection, @attribute, @query, @limit) " + From 1a2fdb64ee7bbddeea732598397db9ddaae1b234 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 22 Mar 2016 18:52:49 +0100 Subject: [PATCH 7/8] removed unused test --- .../shell-cap-constraint-timecritical.js | 178 ------------------ 1 file changed, 178 deletions(-) delete mode 100644 js/common/tests/shell/shell-cap-constraint-timecritical.js diff --git a/js/common/tests/shell/shell-cap-constraint-timecritical.js b/js/common/tests/shell/shell-cap-constraint-timecritical.js deleted file mode 100644 index 0c80a63865..0000000000 --- a/js/common/tests/shell/shell-cap-constraint-timecritical.js +++ /dev/null @@ -1,178 +0,0 @@ -/*jshint globalstrict:false, strict:false */ -/*global assertEqual */ - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test the cap constraint -/// -/// @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 testHelper = require("@arangodb/test-helper").Helper; - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test suite: Creation -/// these tests seem to fail when run in cluster or with valgrind from arangosh -/// (while they succeed when run on the frontend) -/// test-helper.js:Helper.waitUnload expects timely behavior -//////////////////////////////////////////////////////////////////////////////// - -function CapConstraintTimecriticalSuite() { - 'use strict'; - var cn = "UnitTestsCollectionCap"; - var collection = null; - - var nsort = function (l, r) { - if (l !== r) { - return (l < r) ? -1 : 1; - } - return 0; - }; - - return { - -//////////////////////////////////////////////////////////////////////////////// -/// @brief set up -//////////////////////////////////////////////////////////////////////////////// - - setUp : function () { - internal.db._drop(cn); - collection = internal.db._create(cn); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief tear down -//////////////////////////////////////////////////////////////////////////////// - - tearDown : function () { - if (collection !== null) { - internal.wait(0); - collection.unload(); - collection.drop(); - collection = null; - } - internal.wait(0.0); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: reload -//////////////////////////////////////////////////////////////////////////////// - - testReload : function () { - var idx = collection.ensureCapConstraint(5); - var fun = function(d) { return d.n; }; - - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(5, idx.size); - assertEqual(0, idx.byteSize); - - assertEqual(0, collection.count()); - - for (var i = 0; i < 10; ++i) { - collection.save({ n : i }); - } - - assertEqual(5, collection.count()); - assertEqual([5, 6, 7, 8, 9], collection.toArray().map(fun).sort(nsort)); - - testHelper.waitUnload(collection, true); - - assertEqual(5, collection.count()); - assertEqual([5, 6, 7, 8, 9], collection.toArray().map(fun).sort(nsort)); - - collection.save({ n : 10 }); - assertEqual(5, collection.count()); - assertEqual([6, 7, 8, 9, 10], collection.toArray().map(fun).sort(nsort)); - - collection.save({ n : 11 }); - assertEqual(5, collection.count()); - assertEqual([7, 8, 9, 10, 11], collection.toArray().map(fun).sort(nsort)); - - testHelper.waitUnload(collection, true); - - assertEqual(5, collection.count()); - assertEqual([7, 8, 9, 10, 11], collection.toArray().map(fun).sort(nsort)); - - for (i = 15; i < 20; ++i) { - collection.save({ n : i }); - } - - assertEqual(5, collection.count()); - assertEqual([15, 16, 17, 18, 19], collection.toArray().map(fun).sort(nsort)); - }, - -//////////////////////////////////////////////////////////////////////////////// -/// @brief test: reload -//////////////////////////////////////////////////////////////////////////////// - - testReloadMulti : function () { - var idx = collection.ensureCapConstraint(5); - var fun = function(d) { return d.n; }; - - assertEqual("cap", idx.type); - assertEqual(true, idx.isNewlyCreated); - assertEqual(5, idx.size); - assertEqual(0, idx.byteSize); - - assertEqual(0, collection.count()); - - testHelper.waitUnload(collection, true); - - assertEqual(0, collection.count()); - - for (var i = 0; i < 10; ++i) { - collection.save({ n : i }); - } - - testHelper.waitUnload(collection, true); - - assertEqual(5, collection.count()); - assertEqual([5, 6, 7, 8, 9], collection.toArray().map(fun).sort(nsort)); - - collection.save({ n : 10 }); - - testHelper.waitUnload(collection, true); - - assertEqual(5, collection.count()); - assertEqual([6, 7, 8, 9, 10], collection.toArray().map(fun).sort(nsort)); - - collection.save({ n: 0 }); - assertEqual([0, 7, 8, 9, 10], collection.toArray().map(fun).sort(nsort)); - } - - }; -} - - -//////////////////////////////////////////////////////////////////////////////// -/// @brief executes the test suites -//////////////////////////////////////////////////////////////////////////////// - -jsunity.run(CapConstraintTimecriticalSuite); - -return jsunity.done(); - From e8c09f3cc18194970b53d4b08185ac645ba45ae3 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 22 Mar 2016 18:58:08 +0100 Subject: [PATCH 8/8] added missing reset functionality for nested traversals --- CHANGELOG | 7 +++++++ arangod/Aql/TraversalBlock.cpp | 4 ++++ arangod/V8Server/V8Traverser.cpp | 2 ++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 9b082fd211..963804563c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -136,6 +136,13 @@ the sort parameter. v2.8.6 (2016-03-XX) ------------------- +* added missing reset of traversal state for nested traversals. + The state of nested traversals (a traversal in an AQL query that was + located in a repeatedly executed subquery or inside another FOR loop) + was not reset properly, so that multiple invocations of the same nested + traversal with different start vertices led to the nested traversal + always using the start vertex provided on the first invocation. + * fixed issue #1781: ArangoDB startup time increased tremendously * fixed issue #1783: SIGHUP should rotate the log diff --git a/arangod/Aql/TraversalBlock.cpp b/arangod/Aql/TraversalBlock.cpp index b83763620b..1e9e73e624 100644 --- a/arangod/Aql/TraversalBlock.cpp +++ b/arangod/Aql/TraversalBlock.cpp @@ -246,6 +246,10 @@ void TraversalBlock::executeFilterExpressions() { } int TraversalBlock::initializeCursor(AqlItemBlock* items, size_t pos) { + _pos = 0; + _posInPaths = 0; + _usedConstant = false; + freeCaches(); return ExecutionBlock::initializeCursor(items, pos); } diff --git a/arangod/V8Server/V8Traverser.cpp b/arangod/V8Server/V8Traverser.cpp index 52f700ed8b..4b5d5891ab 100644 --- a/arangod/V8Server/V8Traverser.cpp +++ b/arangod/V8Server/V8Traverser.cpp @@ -894,6 +894,8 @@ void DepthFirstTraverser::_defInternalFunctions() { void DepthFirstTraverser::setStartVertex( arangodb::traverser::VertexId const& v) { + _pruneNext = false; + TRI_ASSERT(_expressions != nullptr); auto it = _expressions->find(0);