diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-08-12 13:53:11 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-08-14 15:27:45 -0400 |
commit | 2176ab64295b23e8c67f7799d1310791f14db147 (patch) | |
tree | 512fedafb883ebade66ed5dfb5523920ca5729b3 | |
parent | 1517ce9cd06ca1fe1f19c544f799e60f74732608 (diff) | |
download | mongo-2176ab64295b23e8c67f7799d1310791f14db147.tar.gz |
SERVER-30614 Add writeOK checks to JS test writes in missing_key.js
-rw-r--r-- | jstests/core/views/views_all_commands.js | 2 | ||||
-rw-r--r-- | jstests/sharding/missing_key.js | 77 | ||||
-rw-r--r-- | jstests/sharding/multi_mongos2.js | 87 | ||||
-rw-r--r-- | jstests/sharding/multi_mongos2a.js | 39 |
4 files changed, 98 insertions, 107 deletions
diff --git a/jstests/core/views/views_all_commands.js b/jstests/core/views/views_all_commands.js index 41a90144fc6..ea4f5efe2f9 100644 --- a/jstests/core/views/views_all_commands.js +++ b/jstests/core/views/views_all_commands.js @@ -459,7 +459,7 @@ max: {x: 0}, keyPattern: {x: 1}, splitKeys: [{x: -2}, {x: -1}], - shardVersion: [1, 2] + shardVersion: [ObjectId(), 2] }, skipSharded: true, expectFailure: true, diff --git a/jstests/sharding/missing_key.js b/jstests/sharding/missing_key.js index 588d85e1a95..304d77fc839 100644 --- a/jstests/sharding/missing_key.js +++ b/jstests/sharding/missing_key.js @@ -1,39 +1,42 @@ // Test that the shardCollection command fails when a preexisting document lacks a shard key field. // SERVER-8772 - -var st = new ShardingTest({shards: 1}); -st.stopBalancer(); - -var db = st.s.getDB('testDb'); -var coll = db.testColl; - -coll.insert({x: 1, z: 1}); -coll.insert({y: 1, z: 1}); -db.adminCommand({enableSharding: 'testDb'}); - -/** - * Assert that the shardCollection command fails, with a preexisting index on the provided - * 'shardKey'. - */ -function assertInvalidShardKey(shardKey) { - // Manually create a shard key index. - coll.dropIndexes(); - coll.ensureIndex(shardKey); - - // Ensure that the shard key index identifies 'x' as present in one document and absent in the - // other. - assert.eq(1, coll.find({x: 1}).hint(shardKey).itcount()); - assert.eq(1, coll.find({x: {$exists: false}}).hint(shardKey).itcount()); - - // Assert that the shardCollection command fails with the provided 'shardKey'. - assert.commandFailed(db.adminCommand({shardCollection: 'testDb.testColl', key: shardKey}), - 'shardCollection should have failed on key ' + tojson(shardKey)); -} - -// Test single, compound, and hashed shard keys. -assertInvalidShardKey({x: 1}); -assertInvalidShardKey({x: 1, y: 1}); -assertInvalidShardKey({y: 1, x: 1}); -assertInvalidShardKey({x: 'hashed'}); - -st.stop(); +(function() { + 'use strict'; + + var st = new ShardingTest({shards: 1}); + + var db = st.s.getDB('testDb'); + var coll = db.testColl; + + assert.writeOK(coll.insert({x: 1, z: 1})); + assert.writeOK(coll.insert({y: 1, z: 1})); + + assert.commandWorked(db.adminCommand({enableSharding: 'testDb'})); + + /** + * Assert that the shardCollection command fails, with a preexisting index on the provided + * 'shardKey'. + */ + function assertInvalidShardKey(shardKey) { + // Manually create a shard key index. + coll.dropIndexes(); + coll.ensureIndex(shardKey); + + // Ensure that the shard key index identifies 'x' as present in one document and absent in + // the other. + assert.eq(1, coll.find({x: 1}).hint(shardKey).itcount()); + assert.eq(1, coll.find({x: {$exists: false}}).hint(shardKey).itcount()); + + // Assert that the shardCollection command fails with the provided 'shardKey'. + assert.commandFailed(db.adminCommand({shardCollection: 'testDb.testColl', key: shardKey}), + 'shardCollection should have failed on key ' + tojson(shardKey)); + } + + // Test single, compound, and hashed shard keys. + assertInvalidShardKey({x: 1}); + assertInvalidShardKey({x: 1, y: 1}); + assertInvalidShardKey({y: 1, x: 1}); + assertInvalidShardKey({x: 'hashed'}); + + st.stop(); +})(); diff --git a/jstests/sharding/multi_mongos2.js b/jstests/sharding/multi_mongos2.js index dcbd5a66655..360bb629471 100644 --- a/jstests/sharding/multi_mongos2.js +++ b/jstests/sharding/multi_mongos2.js @@ -1,70 +1,63 @@ // This tests sharding an existing collection that both shards are aware of (SERVER-2828) (function() { + 'use strict'; - var s1 = new ShardingTest({name: "multi_mongos1", shards: 2, mongos: 2}); - s2 = s1._mongos[1]; + var st = new ShardingTest({shards: 2, mongos: 2}); - s1.adminCommand({enablesharding: "test"}); - s1.ensurePrimaryShard('test', 'shard0001'); - s1.adminCommand({shardcollection: "test.foo", key: {num: 1}}); + assert.commandWorked(st.s0.adminCommand({enablesharding: "test"})); + st.ensurePrimaryShard('test', 'shard0001'); + assert.commandWorked(st.s0.adminCommand({shardcollection: "test.foo", key: {num: 1}})); - s1.config.databases.find().forEach(printjson); + // Test queries + assert.writeOK(st.s0.getDB('test').existing.insert({_id: 1})); + assert.eq(1, st.s0.getDB('test').existing.count({_id: 1})); + assert.eq(1, st.s1.getDB('test').existing.count({_id: 1})); - // test queries + assert.commandWorked(st.s1.adminCommand({shardcollection: "test.existing", key: {_id: 1}})); + assert.commandWorked(st.s1.adminCommand({split: "test.existing", middle: {_id: 5}})); - s1.getDB('test').existing.insert({_id: 1}); - assert.eq(1, s1.getDB('test').existing.count({_id: 1})); - assert.eq(1, s2.getDB('test').existing.count({_id: 1})); - - s2.adminCommand({shardcollection: "test.existing", key: {_id: 1}}); - assert.commandWorked(s2.adminCommand({split: "test.existing", middle: {_id: 5}})); - - res = s2.getDB("admin").runCommand({ + assert.commandWorked(st.s1.adminCommand({ moveChunk: "test.existing", find: {_id: 1}, - to: s1.getOther(s1.getPrimaryShard("test")).name - }); - - assert.eq(1, res.ok, tojson(res)); + to: st.getOther(st.getPrimaryShard("test")).name + })); - printjson(s2.adminCommand({"getShardVersion": "test.existing"})); - printjson(new Mongo(s1.getPrimaryShard("test").name).getDB("admin").adminCommand({ + printjson(st.s1.adminCommand({"getShardVersion": "test.existing"})); + printjson(new Mongo(st.getPrimaryShard("test").name).getDB("admin").adminCommand({ "getShardVersion": "test.existing" })); - assert.eq(1, s1.getDB('test').existing.count({_id: 1})); // SERVER-2828 - assert.eq(1, s2.getDB('test').existing.count({_id: 1})); + assert.eq(1, st.s0.getDB('test').existing.count({_id: 1})); // SERVER-2828 + assert.eq(1, st.s1.getDB('test').existing.count({_id: 1})); - // test stats + // Test stats + assert.writeOK(st.s0.getDB('test').existing2.insert({_id: 1})); + assert.eq(1, st.s0.getDB('test').existing2.count({_id: 1})); + assert.eq(1, st.s1.getDB('test').existing2.count({_id: 1})); - s1.getDB('test').existing2.insert({_id: 1}); - assert.eq(1, s1.getDB('test').existing2.count({_id: 1})); - assert.eq(1, s2.getDB('test').existing2.count({_id: 1})); + assert.commandWorked(st.s1.adminCommand({shardcollection: "test.existing2", key: {_id: 1}})); + assert.eq(true, st.s1.getDB('test').existing2.stats().sharded); - s2.adminCommand({shardcollection: "test.existing2", key: {_id: 1}}); - assert.commandWorked(s2.adminCommand({split: "test.existing2", middle: {_id: 5}})); + assert.commandWorked(st.s1.adminCommand({split: "test.existing2", middle: {_id: 5}})); + { + var res = st.s0.getDB('test').existing2.stats(); + printjson(res); + assert.eq(true, res.sharded); // SERVER-2828 + } - var res = s1.getDB('test').existing2.stats(); - printjson(res); - assert.eq(true, res.sharded); // SERVER-2828 - assert.eq(true, s2.getDB('test').existing2.stats().sharded); + // Test admin commands + assert.writeOK(st.s0.getDB('test').existing3.insert({_id: 1})); + assert.eq(1, st.s0.getDB('test').existing3.count({_id: 1})); + assert.eq(1, st.s1.getDB('test').existing3.count({_id: 1})); - // test admin commands + assert.writeOK(st.s1.adminCommand({shardcollection: "test.existing3", key: {_id: 1}})); + assert.commandWorked(st.s1.adminCommand({split: "test.existing3", middle: {_id: 5}})); - s1.getDB('test').existing3.insert({_id: 1}); - assert.eq(1, s1.getDB('test').existing3.count({_id: 1})); - assert.eq(1, s2.getDB('test').existing3.count({_id: 1})); - - s2.adminCommand({shardcollection: "test.existing3", key: {_id: 1}}); - assert.commandWorked(s2.adminCommand({split: "test.existing3", middle: {_id: 5}})); - - res = s1.getDB("admin").runCommand({ + assert.commandWorked(st.s0.adminCommand({ moveChunk: "test.existing3", find: {_id: 1}, - to: s1.getOther(s1.getPrimaryShard("test")).name - }); - assert.eq(1, res.ok, tojson(res)); - - s1.stop(); + to: st.getOther(st.getPrimaryShard("test")).name + })); + st.stop(); })(); diff --git a/jstests/sharding/multi_mongos2a.js b/jstests/sharding/multi_mongos2a.js index 829ce0de194..e76dd547e85 100644 --- a/jstests/sharding/multi_mongos2a.js +++ b/jstests/sharding/multi_mongos2a.js @@ -1,35 +1,30 @@ // This tests sharding an existing collection that both shards are aware of (SERVER-2828) (function() { + 'use strict'; - var s1 = new ShardingTest({name: "multi_mongos2a", shards: 2, mongos: 2}); - s2 = s1._mongos[1]; + var st = new ShardingTest({shards: 2, mongos: 2}); - s1.adminCommand({enablesharding: "test"}); - s1.ensurePrimaryShard('test', 'shard0001'); - s1.adminCommand({shardcollection: "test.foo", key: {num: 1}}); + assert.commandWorked(st.s0.adminCommand({enablesharding: "test"})); + st.ensurePrimaryShard('test', 'shard0001'); + assert.commandWorked(st.s0.adminCommand({shardcollection: "test.foo", key: {num: 1}})); - s1.config.databases.find().forEach(printjson); + assert.writeOK(st.s0.getDB('test').existing.insert({_id: 1})); + assert.eq(1, st.s0.getDB('test').existing.count({_id: 1})); + assert.eq(1, st.s1.getDB('test').existing.count({_id: 1})); - s1.getDB('test').existing.insert({_id: 1}); - assert.eq(1, s1.getDB('test').existing.count({_id: 1})); - assert.eq(1, s2.getDB('test').existing.count({_id: 1})); + assert.commandWorked(st.s1.adminCommand({shardcollection: "test.existing", key: {_id: 1}})); + assert.eq(true, st.s1.getDB('test').existing.stats().sharded); - s2.adminCommand({shardcollection: "test.existing", key: {_id: 1}}); - assert.eq(true, s2.getDB('test').existing.stats().sharded); - - res = s2.getDB("admin").runCommand({ + assert.commandWorked(st.s1.getDB("admin").runCommand({ moveChunk: "test.existing", find: {_id: 1}, - to: s1.getOther(s1.getPrimaryShard("test")).name - }); - - assert.eq(1, res.ok, tojson(res)); - - s1.adminCommand({flushRouterConfig: 1}); + to: st.getOther(st.getPrimaryShard("test")).name + })); - assert.eq(1, s1.getDB('test').existing.count({_id: 1})); // SERVER-2828 - assert.eq(1, s2.getDB('test').existing.count({_id: 1})); + assert.commandWorked(st.s0.adminCommand({flushRouterConfig: 1})); - s1.stop(); + assert.eq(1, st.s0.getDB('test').existing.count({_id: 1})); // SERVER-2828 + assert.eq(1, st.s1.getDB('test').existing.count({_id: 1})); + st.stop(); })(); |