mirror of https://gitee.com/bigwinds/arangodb
Added failure tests for new implementation of HashIndex. And fixed a memleak there.
This commit is contained in:
parent
9cbbd7dd0f
commit
fdde6a69c6
|
@ -140,6 +140,7 @@ HashIndex::UniqueArray::~UniqueArray () {
|
||||||
|
|
||||||
delete _hashArray;
|
delete _hashArray;
|
||||||
delete _hashElement;
|
delete _hashElement;
|
||||||
|
delete _isEqualElElByKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -98,6 +98,10 @@ int PathBasedIndex::fillElement (std::vector<TRI_index_element_t*>& elements,
|
||||||
return TRI_ERROR_INTERNAL;
|
return TRI_ERROR_INTERNAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRI_IF_FAILURE("FillElementIllegalShape") {
|
||||||
|
return TRI_ERROR_INTERNAL;
|
||||||
|
}
|
||||||
|
|
||||||
size_t const n = _paths.size();
|
size_t const n = _paths.size();
|
||||||
std::vector<TRI_shaped_json_t> shapes;
|
std::vector<TRI_shaped_json_t> shapes;
|
||||||
|
|
||||||
|
@ -115,6 +119,9 @@ int PathBasedIndex::fillElement (std::vector<TRI_index_element_t*>& elements,
|
||||||
if (element == nullptr) {
|
if (element == nullptr) {
|
||||||
return TRI_ERROR_OUT_OF_MEMORY;
|
return TRI_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
TRI_IF_FAILURE("FillElementOOM") {
|
||||||
|
return TRI_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
element->document(const_cast<TRI_doc_mptr_t*>(document));
|
element->document(const_cast<TRI_doc_mptr_t*>(document));
|
||||||
TRI_shaped_sub_t* subObjects = element->subObjects();
|
TRI_shaped_sub_t* subObjects = element->subObjects();
|
||||||
|
@ -144,6 +151,9 @@ int PathBasedIndex::fillElement (std::vector<TRI_index_element_t*>& elements,
|
||||||
if (element == nullptr) {
|
if (element == nullptr) {
|
||||||
return TRI_ERROR_OUT_OF_MEMORY;
|
return TRI_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
TRI_IF_FAILURE("FillElementOOM") {
|
||||||
|
return TRI_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
element->document(const_cast<TRI_doc_mptr_t*>(document));
|
element->document(const_cast<TRI_doc_mptr_t*>(document));
|
||||||
TRI_shaped_sub_t* subObjects = element->subObjects();
|
TRI_shaped_sub_t* subObjects = element->subObjects();
|
||||||
|
|
|
@ -0,0 +1,184 @@
|
||||||
|
/*jshint globalstrict:false, strict:false */
|
||||||
|
/*global fail, assertEqual, assertTrue, assertNotEqual */
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief tests failure cases in HashIndex
|
||||||
|
///
|
||||||
|
/// @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 ArangoDB GmbH, Cologne, Germany
|
||||||
|
///
|
||||||
|
/// @author Michael Hackstein
|
||||||
|
/// @author Copyright 2015, ArangoDB GmbH, Cologne, Germany
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var jsunity = require("jsunity");
|
||||||
|
var internal = require("internal");
|
||||||
|
var errors = internal.errors;
|
||||||
|
var testHelper = require("org/arangodb/test-helper").Helper;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// --SECTION-- basic methods
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test suite: Unique Hash Index
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function UniqueHashIndexFailuresSuite () {
|
||||||
|
'use strict';
|
||||||
|
var cn = "UnitTestsCollectionHash";
|
||||||
|
var collection = null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief set up
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
setUp : function () {
|
||||||
|
internal.db._drop(cn);
|
||||||
|
collection = internal.db._create(cn);
|
||||||
|
collection.ensureUniqueConstraint("a");
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief tear down
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
tearDrop : function () {
|
||||||
|
internal.db._drop(cn);
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test: unique hash index insert Illegal Shape
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testInsertIllegalShape : function () {
|
||||||
|
internal.debugSetFailAt("FillElementIllegalShape");
|
||||||
|
try {
|
||||||
|
collection.save({a: 1});
|
||||||
|
fail();
|
||||||
|
} catch (e) {
|
||||||
|
assertEqual(internal.errors.ERROR_INTERNAL.code, e.errorNum);
|
||||||
|
}
|
||||||
|
assertEqual(collection.count(), 0);
|
||||||
|
assertEqual(collection.firstExample({a: 1}), null);
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test: unique hash index fill element oom
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testCreateIndexElementOOM : function () {
|
||||||
|
internal.debugSetFailAt("FillElementOOM");
|
||||||
|
try {
|
||||||
|
collection.save({a: 1});
|
||||||
|
fail();
|
||||||
|
} catch (e) {
|
||||||
|
assertEqual(internal.errors.ERROR_INTERNAL.code, e.errorNum);
|
||||||
|
}
|
||||||
|
assertEqual(collection.count(), 0);
|
||||||
|
assertEqual(collection.firstExample({a: 1}), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test suite: Hash Index Multi
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
function HashIndexMultiFailuresSuite () {
|
||||||
|
'use strict';
|
||||||
|
var cn = "UnitTestsCollectionHash";
|
||||||
|
var collection = null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief set up
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
setUp : function () {
|
||||||
|
internal.db._drop(cn);
|
||||||
|
collection = internal.db._create(cn);
|
||||||
|
collection.ensureHashIndex("a");
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief tear down
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
tearDrop : function () {
|
||||||
|
internal.db._drop(cn);
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test: hash index multi insert Illegal Shape
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testInsertIllegalShape : function () {
|
||||||
|
internal.debugSetFailAt("FillElementIllegalShape");
|
||||||
|
try {
|
||||||
|
collection.save({a: 1});
|
||||||
|
fail();
|
||||||
|
} catch (e) {
|
||||||
|
assertEqual(internal.errors.ERROR_INTERNAL.code, e.errorNum);
|
||||||
|
}
|
||||||
|
assertEqual(collection.count(), 0);
|
||||||
|
assertEqual(collection.firstExample({a: 1}), null);
|
||||||
|
},
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief test: hash index multi fill element oom
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
testCreateIndexElementOOM : function () {
|
||||||
|
collection.ensureUniqueConstraint("a");
|
||||||
|
internal.debugSetFailAt("FillElementOOM");
|
||||||
|
try {
|
||||||
|
collection.save({a: 1});
|
||||||
|
fail();
|
||||||
|
} catch (e) {
|
||||||
|
assertEqual(internal.errors.ERROR_INTERNAL.code, e.errorNum);
|
||||||
|
}
|
||||||
|
assertEqual(collection.count(), 0);
|
||||||
|
assertEqual(collection.firstExample({a: 1}), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// @brief executes the test suites
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
if (internal.debugCanUseFailAt()) {
|
||||||
|
jsunity.run(UniqueHashIndexFailuresSuite);
|
||||||
|
jsunity.run(HashIndexMultiFailuresSuite);
|
||||||
|
}
|
||||||
|
|
||||||
|
return jsunity.done();
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// mode: outline-minor
|
||||||
|
// outline-regexp: "^\\(/// @brief\\|/// @addtogroup\\|// --SECTION--\\|/// @page\\|/// @}\\)"
|
||||||
|
// End:
|
||||||
|
|
Loading…
Reference in New Issue