summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-04-26 11:07:19 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-04-26 15:34:25 -0400
commit6dfaea7ca3e29e421a86420de20fa11cdae690b6 (patch)
tree8070e77deb30e706ebc1f8afa60f07ec0cada2bf /jstests
parent19d3e69975d32bf8f358aafe4067d578a4bf4440 (diff)
downloadmongo-6dfaea7ca3e29e421a86420de20fa11cdae690b6.tar.gz
SERVER-23930 Ensure new shard is available in the ShardRegistry after addShard
Diffstat (limited to 'jstests')
-rw-r--r--jstests/sharding/move_chunk_basic.js40
1 files changed, 18 insertions, 22 deletions
diff --git a/jstests/sharding/move_chunk_basic.js b/jstests/sharding/move_chunk_basic.js
index 354a222da10..69bdf4d8c90 100644
--- a/jstests/sharding/move_chunk_basic.js
+++ b/jstests/sharding/move_chunk_basic.js
@@ -6,24 +6,35 @@
'use strict';
var st = new ShardingTest({mongos: 1, shards: 2});
+ var kDbName = 'db';
var mongos = st.s0;
+ var shard0 = st.shard0.shardName;
+ var shard1 = st.shard1.shardName;
- var kDbName = 'db';
+ assert.commandWorked(mongos.adminCommand({enableSharding: kDbName}));
+ st.ensurePrimaryShard(kDbName, shard0);
- var shards = mongos.getCollection('config.shards').find().toArray();
+ // Fail if invalid namespace.
+ assert.commandFailed(mongos.adminCommand({moveChunk: '', find: {_id: 1}, to: shard1}));
+
+ // Fail if database does not exist.
+ assert.commandFailed(mongos.adminCommand({moveChunk: 'a.b', find: {_id: 1}, to: shard1}));
- var shard0 = shards[0]._id;
- var shard1 = shards[1]._id;
+ // Fail if collection is unsharded.
+ assert.commandFailed(
+ mongos.adminCommand({moveChunk: kDbName + '.xxx', find: {_id: 1}, to: shard1}));
function testHashed() {
var ns = kDbName + '.fooHashed';
-
- // Errors if either bounds is not a valid shard key
assert.commandWorked(mongos.adminCommand({shardCollection: ns, key: {_id: 'hashed'}}));
var aChunk = mongos.getDB('config').chunks.findOne({_id: RegExp(ns), shard: shard0});
assert(aChunk);
+
+ // Error if either of the bounds is not a valid shard key (BSON object - 1 yields a NaN)
+ assert.commandFailed(mongos.adminCommand(
+ {moveChunk: ns, bounds: [aChunk.min - 1, aChunk.max], to: shard1}));
assert.commandFailed(mongos.adminCommand(
{moveChunk: ns, bounds: [aChunk.min, aChunk.max - 1], to: shard1}));
@@ -40,6 +51,7 @@
assert.commandWorked(
mongos.adminCommand({moveChunk: ns, bounds: [aChunk.min, aChunk.max], to: shard1}));
+
assert.eq(0, mongos.getDB('config').chunks.count({_id: aChunk._id, shard: shard0}));
assert.eq(1, mongos.getDB('config').chunks.count({_id: aChunk._id, shard: shard1}));
@@ -70,22 +82,6 @@
mongos.getDB(kDbName).foo.drop();
}
- assert.commandWorked(mongos.adminCommand({enableSharding: kDbName}));
-
- st.ensurePrimaryShard(kDbName, shard0);
-
- // Fail if invalid namespace.
- var res =
- assert.commandFailed(mongos.adminCommand({moveChunk: '', find: {_id: 1}, to: shard1}));
- assert.eq(res.info);
-
- // Fail if database does not exist.
- assert.commandFailed(mongos.adminCommand({moveChunk: 'a.b', find: {_id: 1}, to: shard1}));
-
- // Fail if collection is unsharded.
- assert.commandFailed(
- mongos.adminCommand({moveChunk: kDbName + '.xxx', find: {_id: 1}, to: shard1}));
-
testHashed();
testNotHashed({a: 1});