From 41f8185553386488a4371abf1e547cae6c57d6cf Mon Sep 17 00:00:00 2001 From: Andreas Streichardt Date: Mon, 15 May 2017 16:46:47 +0200 Subject: [PATCH] Add test for rolling back indexes --- arangod/Cluster/ClusterInfo.cpp | 1 + .../tests/shell/shell-index-cluster-spec.js | 80 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 js/server/tests/shell/shell-index-cluster-spec.js diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 1ba9382686..c374bb2517 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -1654,6 +1654,7 @@ int ClusterInfo::ensureIndexCoordinator( AgencyCommResult eraseResult = _agency.sendTransactionWithFailover(trx, 0.0); if (eraseResult.successful()) { + loadPlan(); return errorCode; } std::chrono::duration waitTime(10); diff --git a/js/server/tests/shell/shell-index-cluster-spec.js b/js/server/tests/shell/shell-index-cluster-spec.js new file mode 100644 index 0000000000..c91136feff --- /dev/null +++ b/js/server/tests/shell/shell-index-cluster-spec.js @@ -0,0 +1,80 @@ +/*global describe, it, ArangoAgency, afterEach */ + +//////////////////////////////////////////////////////////////////////////////// +/// @brief cluster collection creation tests +/// +/// @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 Andreas Streichardt +/// @author Copyright 2017, ArangoDB GmbH, Cologne, Germany +//////////////////////////////////////////////////////////////////////////////// + +'use strict'; + +const expect = require('chai').expect; + +var internal = require("internal"); +var db = require("org/arangodb").db; + +describe('Cluster collection creation options', function() { + afterEach(function() { + db._drop('testi'); + }); + it('should always throw an error when creating a faulty index', function() { + db._create("testi", {numberOfShards: 1}); + db.testi.save({"test": 1}); + db.testi.save({"test": 1}); + + expect(function() { + db.testi.ensureIndex({ type: "hash", fields: [ "test" ], unique: true }); + }).to.throw(); + // before fixing it the second call would return the faulty index + expect(function() { + db.testi.ensureIndex({ type: "hash", fields: [ "test" ], unique: true }); + }).to.throw(); + }); + it('should cleanup current after creating a faulty index', function() { + db._create("testi", {numberOfShards: 1}); + let current = ArangoAgency.get('Current/Collections/_system'); + let plan = ArangoAgency.get('Plan/Collections/_system'); + let collectionId = Object.values(plan.arango.Plan.Collections['_system']).reduce((result, collectionDef) => { + if (result) { + return result; + } + + if (collectionDef.name === 'testi') { + return collectionDef.id; + } + }, undefined); + db.testi.save({"test": 1}); + db.testi.save({"test": 1}); + + expect(function() { + db.testi.ensureIndex({ type: "hash", fields: [ "test" ], unique: true }); + }).to.throw(); + // wait for the schmutz + internal.wait(1.0); + current = ArangoAgency.get('Current/Collections/_system/' + collectionId); + Object.values(current.arango.Current.Collections['_system'][collectionId]).forEach(entry => { + expect(entry.indexes).to.have.lengthOf(1); + }); + }); +}); \ No newline at end of file