summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/moveprimary-replset.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthroughWithMongod/moveprimary-replset.js')
-rw-r--r--[-rwxr-xr-x]jstests/noPassthroughWithMongod/moveprimary-replset.js105
1 files changed, 55 insertions, 50 deletions
diff --git a/jstests/noPassthroughWithMongod/moveprimary-replset.js b/jstests/noPassthroughWithMongod/moveprimary-replset.js
index 2725585a08e..0f956f638ea 100755..100644
--- a/jstests/noPassthroughWithMongod/moveprimary-replset.js
+++ b/jstests/noPassthroughWithMongod/moveprimary-replset.js
@@ -5,67 +5,72 @@
(function() {
"use strict";
-var numDocs = 10000;
-var baseName = "moveprimary-replset";
-var testDBName = baseName;
-var testCollName = 'coll';
+ var numDocs = 10000;
+ var baseName = "moveprimary-replset";
+ var testDBName = baseName;
+ var testCollName = 'coll';
-jsTest.log("Spinning up a sharded cluster, but not adding the shards");
-var shardingTestConfig = {
- name : baseName,
- mongos : 1,
- shards : 2,
- config : 3,
- rs : { nodes : 3 },
- other : { manualAddShard : true }
-};
-var shardingTest = new ShardingTest(shardingTestConfig);
+ jsTest.log("Spinning up a sharded cluster, but not adding the shards");
+ var shardingTestConfig = {
+ name: baseName,
+ mongos: 1,
+ shards: 2,
+ config: 3,
+ rs: {nodes: 3},
+ other: {manualAddShard: true}
+ };
+ var shardingTest = new ShardingTest(shardingTestConfig);
-jsTest.log("Geting connections to the individual shards");
-var replSet1 = shardingTest.rs0;
-var replSet2 = shardingTest.rs1;
+ jsTest.log("Geting connections to the individual shards");
+ var replSet1 = shardingTest.rs0;
+ var replSet2 = shardingTest.rs1;
-jsTest.log("Adding data to our first replica set");
-var repset1DB = replSet1.getPrimary().getDB(testDBName);
-for (var i = 1; i <= numDocs; i++) {
- repset1DB[testCollName].insert({ x : i });
-}
-replSet1.awaitReplication();
+ jsTest.log("Adding data to our first replica set");
+ var repset1DB = replSet1.getPrimary().getDB(testDBName);
+ for (var i = 1; i <= numDocs; i++) {
+ repset1DB[testCollName].insert({x: i});
+ }
+ replSet1.awaitReplication();
-jsTest.log("Geting connection to mongos for the cluster");
-var mongosConn = shardingTest.s;
-var testDB = mongosConn.getDB(testDBName);
+ jsTest.log("Geting connection to mongos for the cluster");
+ var mongosConn = shardingTest.s;
+ var testDB = mongosConn.getDB(testDBName);
-jsTest.log("Adding replSet1 as only shard");
-mongosConn.adminCommand({ addshard : replSet1.getURL() });
+ jsTest.log("Adding replSet1 as only shard");
+ mongosConn.adminCommand({addshard: replSet1.getURL()});
-jsTest.log("Updating the data via mongos and making sure all documents are updated and present");
-testDB[testCollName].update({}, { $set : { y : 'hello' } }, false/*upsert*/, true/*multi*/);
-assert.eq(testDB[testCollName].count({ y : 'hello' }), numDocs,
- 'updating and counting docs via mongos failed');
+ jsTest.log(
+ "Updating the data via mongos and making sure all documents are updated and present");
+ testDB[testCollName].update({}, {$set: {y: 'hello'}}, false /*upsert*/, true /*multi*/);
+ assert.eq(testDB[testCollName].count({y: 'hello'}),
+ numDocs,
+ 'updating and counting docs via mongos failed');
-jsTest.log("Adding replSet2 as second shard");
-mongosConn.adminCommand({ addshard : replSet2.getURL() });
+ jsTest.log("Adding replSet2 as second shard");
+ mongosConn.adminCommand({addshard: replSet2.getURL()});
-mongosConn.getDB('admin').printShardingStatus();
-printjson(replSet2.getPrimary().getDBs());
+ mongosConn.getDB('admin').printShardingStatus();
+ printjson(replSet2.getPrimary().getDBs());
-jsTest.log("Moving test db from replSet1 to replSet2");
-assert.commandWorked(mongosConn.getDB('admin').runCommand({ moveprimary: testDBName,
- to: replSet2.getURL() }));
-mongosConn.getDB('admin').printShardingStatus();
-printjson(replSet2.getPrimary().getDBs());
-assert.eq(testDB.getSiblingDB("config").databases.findOne({ "_id" : testDBName }).primary,
- replSet2.name, "Failed to change primary shard for unsharded database.");
+ jsTest.log("Moving test db from replSet1 to replSet2");
+ assert.commandWorked(
+ mongosConn.getDB('admin').runCommand({moveprimary: testDBName, to: replSet2.getURL()}));
+ mongosConn.getDB('admin').printShardingStatus();
+ printjson(replSet2.getPrimary().getDBs());
+ assert.eq(testDB.getSiblingDB("config").databases.findOne({"_id": testDBName}).primary,
+ replSet2.name,
+ "Failed to change primary shard for unsharded database.");
-jsTest.log("Updating the data via mongos and making sure all documents are updated and present");
-testDB[testCollName].update({}, { $set : { z : 'world' } }, false/*upsert*/, true/*multi*/);
-assert.eq(testDB[testCollName].count({ z : 'world' }), numDocs,
- 'updating and counting docs via mongos failed');
+ jsTest.log(
+ "Updating the data via mongos and making sure all documents are updated and present");
+ testDB[testCollName].update({}, {$set: {z: 'world'}}, false /*upsert*/, true /*multi*/);
+ assert.eq(testDB[testCollName].count({z: 'world'}),
+ numDocs,
+ 'updating and counting docs via mongos failed');
-jsTest.log("Shutting down cluster");
-shardingTest.stop();
+ jsTest.log("Shutting down cluster");
+ shardingTest.stop();
-print('moveprimary-replset.js SUCCESS');
+ print('moveprimary-replset.js SUCCESS');
})();