diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-07-15 15:27:03 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-07-16 15:02:01 -0400 |
commit | 5ebc97a8dd5905faa12db77f8e55434fd04cb297 (patch) | |
tree | 832155dfbbdb01a11e3c6ba5d0ba83bfba953272 /jstests/sharding | |
parent | 0ff7d59131c1710c85718e2dd54c0c1f1bd35194 (diff) | |
download | mongo-5ebc97a8dd5905faa12db77f8e55434fd04cb297.tar.gz |
SERVER-17955 Add cross-mongos collection rename test
Diffstat (limited to 'jstests/sharding')
-rw-r--r-- | jstests/sharding/rename.js | 39 | ||||
-rw-r--r-- | jstests/sharding/rename_across_mongos.js | 23 |
2 files changed, 49 insertions, 13 deletions
diff --git a/jstests/sharding/rename.js b/jstests/sharding/rename.js index 2ce41887a05..85bb3bffd37 100644 --- a/jstests/sharding/rename.js +++ b/jstests/sharding/rename.js @@ -1,39 +1,49 @@ -var rsOpt = { oplogSize: 10 }; -var s = new ShardingTest( { name:"rename", shards:2, verbose:1, mongos:1, rs:rsOpt } ); -var db = s.getDB( "test" ); +(function() { + +'use strict'; + +var s = new ShardingTest({ name: "rename", + shards: 2, + verbose: 1, + mongos: 1, + rs: { oplogSize: 10 } }); + +var db = s.getDB("test"); var replTest = s.rs0; -db.foo.insert({_id:1}); +db.foo.insert({ _id: 1 }); db.foo.renameCollection('bar'); assert.isnull(db.getLastError(), '1.0'); -assert.eq(db.bar.findOne(), {_id:1}, '1.1'); +assert.eq(db.bar.findOne(), { _id: 1 }, '1.1'); assert.eq(db.bar.count(), 1, '1.2'); assert.eq(db.foo.count(), 0, '1.3'); -db.foo.insert({_id:2}); +db.foo.insert({ _id: 2 }); db.foo.renameCollection('bar', true); assert.isnull(db.getLastError(), '2.0'); -assert.eq(db.bar.findOne(), {_id:2}, '2.1'); +assert.eq(db.bar.findOne(), { _id: 2 }, '2.1'); assert.eq(db.bar.count(), 1, '2.2'); assert.eq(db.foo.count(), 0, '2.3'); -s.adminCommand( { enablesharding : "test" } ); +s.adminCommand({ enablesharding: "test" }); s.getDB('admin').runCommand({ movePrimary: 'test', to: 'rename-rs0' }); jsTest.log("Testing write concern (1)"); -db.foo.insert({_id:3}); +db.foo.insert({ _id: 3 }); db.foo.renameCollection('bar', true); -var ans = db.runCommand({getLastError:1, w:3}); + +var ans = db.runCommand({ getLastError: 1, w: 3 }); printjson(ans); assert.isnull(ans.err, '3.0'); -assert.eq(db.bar.findOne(), {_id:3}, '3.1'); +assert.eq(db.bar.findOne(), { _id: 3 }, '3.1'); assert.eq(db.bar.count(), 1, '3.2'); assert.eq(db.foo.count(), 0, '3.3'); -// Ensure write concern works by shutting down 1 node in a replica set shard. +// Ensure write concern works by shutting down 1 node in a replica set shard jsTest.log("Testing write concern (2)"); + // Kill any node. Don't care if it's a primary or secondary. replTest.stop(0); @@ -45,7 +55,10 @@ ReplSetTest.awaitRSClientHosts(s.s, assert.writeOK(db.foo.insert({ _id: 4 })); assert.commandWorked(db.foo.renameCollection('bar', true)); -ans = db.runCommand({getLastError:1, w:3, wtimeout:5000}); + +ans = db.runCommand({ getLastError: 1, w: 3, wtimeout: 5000 }); assert.eq(ans.err, "timeout", 'gle: ' + tojson(ans)); s.stop(); + +})(); diff --git a/jstests/sharding/rename_across_mongos.js b/jstests/sharding/rename_across_mongos.js new file mode 100644 index 00000000000..71ab514e3d0 --- /dev/null +++ b/jstests/sharding/rename_across_mongos.js @@ -0,0 +1,23 @@ +(function() {
+
+'use strict';
+
+var st = new ShardingTest({ name: 'rename_across_mongos', shards: 1, mongos: 2 });
+var dbName = 'RenameDB';
+
+st.s0.getDB(dbName).dropDatabase();
+st.s1.getDB(dbName).dropDatabase();
+
+// Create collection on first mongos and insert a document
+assert.commandWorked(st.s0.getDB(dbName).runCommand({ create: 'CollNameBeforeRename' }));
+assert.writeOK(st.s0.getDB(dbName).CollNameBeforeRename.insert({ Key: 1, Value: 1 }));
+
+// Rename collection on second mongos and ensure the document is found
+assert.commandWorked(
+ st.s1.getDB(dbName).CollNameBeforeRename.renameCollection('CollNameAfterRename'));
+assert.eq([{ Key: 1, Value: 1 }],
+ st.s1.getDB(dbName).CollNameAfterRename.find({}, { _id: false }).toArray());
+
+st.stop();
+
+})();
|