summaryrefslogtreecommitdiff
path: root/jstests/sharding/move_primary_basic.js
diff options
context:
space:
mode:
authorMisha Tyulenev <misha@mongodb.com>2015-12-10 14:54:04 -0500
committerMisha Tyulenev <misha@mongodb.com>2015-12-10 16:21:58 -0500
commita6e09d623cbb58135c4c3777c09879a0ae2fbe73 (patch)
treea7d801b87a034a6114cd4b8f9cf9315efb01396b /jstests/sharding/move_primary_basic.js
parentea6764dbe4a5131a9ad7694781d15a2d49af9b3e (diff)
downloadmongo-a6e09d623cbb58135c4c3777c09879a0ae2fbe73.tar.gz
SERVER-21137 add basic tests for movePrimary command
Diffstat (limited to 'jstests/sharding/move_primary_basic.js')
-rw-r--r--jstests/sharding/move_primary_basic.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/jstests/sharding/move_primary_basic.js b/jstests/sharding/move_primary_basic.js
new file mode 100644
index 00000000000..17b5b694ffb
--- /dev/null
+++ b/jstests/sharding/move_primary_basic.js
@@ -0,0 +1,58 @@
+//
+// Basic tests for movePrimary.
+//
+
+(function() {
+'use strict';
+
+var st = new ShardingTest({mongos:1, shards:2});
+
+var mongos = st.s0;
+
+var kDbName = 'db';
+
+var shards = mongos.getCollection('config.shards').find().toArray();
+
+var shard0 = shards[0]._id;
+var shard1 = shards[1]._id;
+
+assert.commandWorked(mongos.adminCommand({enableSharding : kDbName}));
+
+// Can run only on mongos.
+assert.commandFailedWithCode(st.d0.getDB('admin').runCommand({movePrimary : kDbName, to: shard0}),
+ ErrorCodes.CommandNotFound);
+
+// Can run only against the admin database.
+assert.commandFailedWithCode(mongos.getDB('test').runCommand({movePrimary : kDbName, to: shard0}),
+ ErrorCodes.Unauthorized);
+
+// Can't movePrimary for 'config' database.
+assert.commandFailed(mongos.adminCommand({movePrimary : 'config', to: shard0}));
+
+// Can't movePrimary for 'local' database.
+assert.commandFailed(mongos.adminCommand({movePrimary : 'local', to: shard0}));
+
+// Can't movePrimary for 'admin' database.
+assert.commandFailed(mongos.adminCommand({movePrimary : 'admin', to: shard0}));
+
+// Can't movePrimary for invalid db name.
+assert.commandFailed(mongos.adminCommand({movePrimary : 'a.b', to: shard0}));
+assert.commandFailed(mongos.adminCommand({movePrimary : '', to: shard0}));
+
+// Fail if shard does not exist or empty.
+assert.commandFailed(mongos.adminCommand({movePrimary : kDbName, to: 'Unknown'}));
+assert.commandFailed(mongos.adminCommand({movePrimary : kDbName, to: ''}));
+assert.commandFailed(mongos.adminCommand({movePrimary : kDbName}));
+
+// Fail if moveShard to already primary and verify metadata changes.
+assert.eq(shard0, mongos.getDB('config').databases.findOne({_id: kDbName}).primary);
+
+assert.commandWorked(mongos.adminCommand({movePrimary : kDbName, to: shard1}));
+assert.eq(shard1, mongos.getDB('config').databases.findOne({_id: kDbName}).primary);
+
+assert.commandFailed(mongos.adminCommand({movePrimary : kDbName, to: shard1}));
+assert.eq(shard1, mongos.getDB('config').databases.findOne({_id: kDbName}).primary);
+
+st.stop();
+
+})()