1
0
Fork 0

More tests

This commit is contained in:
Andreas Streichardt 2017-01-20 12:03:12 +01:00
parent dd7c14a3e9
commit b594257677
2 changed files with 246 additions and 72 deletions

View File

@ -610,9 +610,6 @@ function executePlanForCollections(plannedCollections) {
db._useDatabase('_system');
let localDatabases = getLocalDatabases();
let database;
let i;
// Create shards in Plan that are not there locally:
Object.keys(plannedCollections).forEach(database => {
if (localDatabases.hasOwnProperty(database)) {
@ -628,7 +625,6 @@ function executePlanForCollections(plannedCollections) {
Object.keys(collections).forEach(function (collection) {
let collInfo = collections[collection];
let shards = collInfo.shards;
let shard;
collInfo.planId = collInfo.id;
Object.keys(shards).forEach(shard => {
@ -651,7 +647,7 @@ function executePlanForCollections(plannedCollections) {
let save = {id: collInfo.id, name: collInfo.name};
delete collInfo.id; // must not
delete collInfo.name;
delete collInfo.name;
try {
if (collInfo.type === ArangoCollection.TYPE_EDGE) {
db._createEdgeCollection(shard, collInfo);
@ -687,23 +683,23 @@ function executePlanForCollections(plannedCollections) {
if (!shouldBeLeader && localCollections[shard].isLeader) {
db._collection(shard).leaderResign();
} else if (shouldBeLeader &&
!localCollections[shard].isLeader) {
!localCollections[shard].isLeader()) {
db._collection(shard).assumeLeadership();
}
collectionStatus = localCollections[shard].status;
// collection exists, now compare collection properties
let properties = { };
let cmp = [ 'journalSize', 'waitForSync', 'doCompact',
'indexBuckets' ];
for (i = 0; i < cmp.length; ++i) {
let p = cmp[i];
if (localCollections[shard][p] !== collInfo[p]) {
let properties = cmp.reduce((obj, key) => {
if (localCollections[shard][key] !== collInfo[key]) {
// property change
properties[p] = collInfo[p];
obj[key] = collInfo[key];
}
}
return obj;
}, {});
if (Object.keys(properties).length > 0) {
console.info("updating properties for local shard '%s/%s'",
@ -747,7 +743,7 @@ function executePlanForCollections(plannedCollections) {
let index;
if (collInfo.hasOwnProperty('indexes')) {
for (i = 0; i < collInfo.indexes.length; ++i) {
for (let i = 0; i < collInfo.indexes.length; ++i) {
index = collInfo.indexes[i];
if (index.type !== 'primary' && index.type !== 'edge' &&
@ -776,7 +772,7 @@ function executePlanForCollections(plannedCollections) {
if (indexes[idx].type !== 'primary' && indexes[idx].type !== 'edge') {
let found = false;
for (i = 0; i < collInfo.indexes.length; ++i) {
for (let i = 0; i < collInfo.indexes.length; ++i) {
if (collInfo.indexes[i].id === idx) {
found = true;
break;
@ -811,7 +807,6 @@ function executePlanForCollections(plannedCollections) {
}
}
});
// Drop local shards that do no longer exist in Plan:
let shardMap = getShardMap(plannedCollections);
@ -821,7 +816,6 @@ function executePlanForCollections(plannedCollections) {
// switch into other database
db._useDatabase(database);
try {
// iterate over collections of database
let collections = getLocalCollections();
@ -832,6 +826,7 @@ function executePlanForCollections(plannedCollections) {
if (removeAll ||
!shardMap.hasOwnProperty(collection) ||
shardMap[collection].indexOf(ourselves) === -1) {
// May be we have been the leader and are asked to withdraw: ***
if (shardMap.hasOwnProperty(collection) &&
shardMap[collection][0] === '_' + ourselves) {

View File

@ -208,56 +208,53 @@ describe('Cluster sync', function() {
expect(collections.map(collection => collection.name())).to.contain('s100001');
expect(db._collection('s100001').status()).to.equal(ArangoCollection.STATUS_UNLOADED);
});
it('should unload a collection', function() {
it('should unload an existing collection', function() {
db._create('s100001');
expect(db._collection('s100001').status()).to.equal(ArangoCollection.STATUS_LOADED);
let plan = {
Collections: {
test: {
"100001": {
"deleted": false,
"doCompact": true,
"id": "100001",
"indexBuckets": 8,
"indexes": [
{
"fields": [
"_key"
],
"id": "0",
"sparse": false,
"type": "primary",
"unique": true
}
],
"isSystem": false,
"isVolatile": false,
"journalSize": 1048576,
"keyOptions": {
"allowUserKeys": true,
"type": "traditional"
},
"name": "test",
"numberOfShards": 1,
"replicationFactor": 2,
"shardKeys": [
"_key"
],
"shards": {
"s100001": [
"",
]
},
"status": 2,
"type": 2,
"waitForSync": false
}
test: {
"100001": {
"deleted": false,
"doCompact": true,
"id": "100001",
"indexBuckets": 8,
"indexes": [
{
"fields": [
"_key"
],
"id": "0",
"sparse": false,
"type": "primary",
"unique": true
}
],
"isSystem": false,
"isVolatile": false,
"journalSize": 1048576,
"keyOptions": {
"allowUserKeys": true,
"type": "traditional"
},
"name": "test",
"numberOfShards": 1,
"replicationFactor": 2,
"shardKeys": [
"_key"
],
"shards": {
"s100001": [
"",
]
},
"status": 2,
"type": 2,
"waitForSync": false
}
}
};
cluster.executePlanForCollections(plan.Collections);
cluster.executePlanForCollections(plan);
db._useDatabase('test');
let collections = db._collections();
expect(db._collection('s100001').status()).to.equal(ArangoCollection.STATUS_UNLOADED);
});
it('should delete a stale collection', function() {
@ -311,7 +308,7 @@ describe('Cluster sync', function() {
"swag",
]
},
"status": 2,
"status": 3,
"type": 2,
"waitForSync": false
}
@ -326,12 +323,6 @@ describe('Cluster sync', function() {
it('should delete a collection for which it lost responsibility', function() {
db._create('s100001');
let plan = {
Databases: {
"test": {
"id": 1,
"name": "test"
}
},
Collections: {
test: {
"100001": {
@ -383,12 +374,6 @@ describe('Cluster sync', function() {
it('should create an additional index if instructed to do so', function() {
db._create('s100001');
let plan = {
Databases: {
"test": {
"id": 1,
"name": "test"
}
},
Collections: {
test: {
"100001": {
@ -560,6 +545,200 @@ describe('Cluster sync', function() {
expect(errors).to.be.an('object');
expect(errors).to.have.property('Möter');
});
it('should be leading a collection when ordered to be leader', function() {
let plan = {
test: {
"100001": {
"deleted": false,
"doCompact": true,
"id": "100001",
"indexBuckets": 8,
"indexes": [
{
"fields": [
"_key"
],
"id": "0",
"sparse": false,
"type": "primary",
"unique": true
}
],
"isSystem": false,
"isVolatile": false,
"journalSize": 1048576,
"keyOptions": {
"allowUserKeys": true,
"type": "traditional"
},
"name": "test",
"numberOfShards": 1,
"replicationFactor": 2,
"shardKeys": [
"_key"
],
"shards": {
"s100001": [
"",
]
},
"status": 3,
"type": 2,
"waitForSync": false
}
}
};
let errors = cluster.executePlanForCollections(plan);
db._useDatabase('test');
expect(db._collection('s100001').isLeader()).to.equal(true);
});
it('should be following a leader when ordered to be follower', function() {
let plan = {
test: {
"100001": {
"deleted": false,
"doCompact": true,
"id": "100001",
"indexBuckets": 8,
"indexes": [
{
"fields": [
"_key"
],
"id": "0",
"sparse": false,
"type": "primary",
"unique": true
}
],
"isSystem": false,
"isVolatile": false,
"journalSize": 1048576,
"keyOptions": {
"allowUserKeys": true,
"type": "traditional"
},
"name": "test",
"numberOfShards": 1,
"replicationFactor": 2,
"shardKeys": [
"_key"
],
"shards": {
"s100001": [
"the leader-leader",
"",
]
},
"status": 2,
"type": 2,
"waitForSync": false
}
}
};
let errors = cluster.executePlanForCollections(plan);
db._useDatabase('test');
expect(db._collection('s100001').isLeader()).to.equal(false);
});
it('should be able to switch from leader to follower', function() {
let plan = {
test: {
"100001": {
"deleted": false,
"doCompact": true,
"id": "100001",
"indexBuckets": 8,
"indexes": [
{
"fields": [
"_key"
],
"id": "0",
"sparse": false,
"type": "primary",
"unique": true
}
],
"isSystem": false,
"isVolatile": false,
"journalSize": 1048576,
"keyOptions": {
"allowUserKeys": true,
"type": "traditional"
},
"name": "test",
"numberOfShards": 1,
"replicationFactor": 2,
"shardKeys": [
"_key"
],
"shards": {
"s100001": [
"",
]
},
"status": 2,
"type": 2,
"waitForSync": false
}
}
};
let errors = cluster.executePlanForCollections(plan);
plan.test['100001'].shards['s100001'].unshift('der-hund');
cluster.executePlanForCollections(plan);
db._useDatabase('test');
expect(db._collection('s100001').isLeader()).to.equal(false);
});
it('should be able to switch from follower to leader', function() {
let plan = {
test: {
"100001": {
"deleted": false,
"doCompact": true,
"id": "100001",
"indexBuckets": 8,
"indexes": [
{
"fields": [
"_key"
],
"id": "0",
"sparse": false,
"type": "primary",
"unique": true
}
],
"isSystem": false,
"isVolatile": false,
"journalSize": 1048576,
"keyOptions": {
"allowUserKeys": true,
"type": "traditional"
},
"name": "test",
"numberOfShards": 1,
"replicationFactor": 2,
"shardKeys": [
"_key"
],
"shards": {
"s100001": [
"old-leader",
"",
]
},
"status": 2,
"type": 2,
"waitForSync": false
}
}
};
let errors = cluster.executePlanForCollections(plan);
plan.test['100001'].shards['s100001'] = [""];
cluster.executePlanForCollections(plan);
db._useDatabase('test');
expect(db._collection('s100001').isLeader()).to.equal(false);
});
});
describe('Update current', function() {
beforeEach(function() {