summaryrefslogtreecommitdiff
path: root/jstests/sharding/config_rs_no_primary.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/sharding/config_rs_no_primary.js')
-rw-r--r--jstests/sharding/config_rs_no_primary.js94
1 files changed, 50 insertions, 44 deletions
diff --git a/jstests/sharding/config_rs_no_primary.js b/jstests/sharding/config_rs_no_primary.js
index 9fce3421474..11d9a8e41aa 100644
--- a/jstests/sharding/config_rs_no_primary.js
+++ b/jstests/sharding/config_rs_no_primary.js
@@ -1,48 +1,54 @@
// Tests operation of the cluster when the config servers have no primary and thus the cluster
// metadata is in read-only mode.
(function() {
-"use strict";
-
-var st = new ShardingTest({shards: 1,
- other: {c0: {}, // Make sure 1st config server is primary
- c1: {rsConfig: {priority: 0}},
- c2: {rsConfig: {priority: 0}}}});
-
-assert.eq(st.config0, st.configRS.getPrimary());
-
-// Create the "test" database while the cluster metadata is still writeable.
-st.s.getDB('test').foo.insert({a:1});
-
-// Take down two of the config servers so the remaining one goes into SECONDARY state.
-st.configRS.stop(1);
-st.configRS.stop(2);
-st.configRS.awaitNoPrimary();
-
-jsTestLog("Starting a new mongos when the config servers have no primary which should work");
-var mongos2 = MongoRunner.runMongos({configdb: st.configRS.getURL()});
-assert.neq(null, mongos2);
-
-var testOps = function(mongos) {
- jsTestLog("Doing ops that don't require metadata writes and thus should succeed against: " +
- mongos);
- var initialCount = mongos.getDB('test').foo.count();
- assert.writeOK(mongos.getDB('test').foo.insert({a:1}));
- assert.eq(initialCount + 1, mongos.getDB('test').foo.count());
-
- assert.throws(function() {mongos.getDB('config').shards.findOne();});
- mongos.setSlaveOk(true);
- var shardDoc = mongos.getDB('config').shards.findOne();
- mongos.setSlaveOk(false);
- assert.neq(null, shardDoc);
-
- jsTestLog("Doing ops that require metadata writes and thus should fail against: " + mongos);
- assert.writeError(mongos.getDB("newDB").foo.insert({a:1}));
- assert.commandFailed(mongos.getDB('admin').runCommand({shardCollection: "test.foo",
- key: {a:1}}));
-};
-
-testOps(mongos2);
-testOps(st.s);
-
-st.stop();
+ "use strict";
+
+ var st = new ShardingTest({
+ shards: 1,
+ other: {
+ c0: {}, // Make sure 1st config server is primary
+ c1: {rsConfig: {priority: 0}},
+ c2: {rsConfig: {priority: 0}}
+ }
+ });
+
+ assert.eq(st.config0, st.configRS.getPrimary());
+
+ // Create the "test" database while the cluster metadata is still writeable.
+ st.s.getDB('test').foo.insert({a: 1});
+
+ // Take down two of the config servers so the remaining one goes into SECONDARY state.
+ st.configRS.stop(1);
+ st.configRS.stop(2);
+ st.configRS.awaitNoPrimary();
+
+ jsTestLog("Starting a new mongos when the config servers have no primary which should work");
+ var mongos2 = MongoRunner.runMongos({configdb: st.configRS.getURL()});
+ assert.neq(null, mongos2);
+
+ var testOps = function(mongos) {
+ jsTestLog("Doing ops that don't require metadata writes and thus should succeed against: " +
+ mongos);
+ var initialCount = mongos.getDB('test').foo.count();
+ assert.writeOK(mongos.getDB('test').foo.insert({a: 1}));
+ assert.eq(initialCount + 1, mongos.getDB('test').foo.count());
+
+ assert.throws(function() {
+ mongos.getDB('config').shards.findOne();
+ });
+ mongos.setSlaveOk(true);
+ var shardDoc = mongos.getDB('config').shards.findOne();
+ mongos.setSlaveOk(false);
+ assert.neq(null, shardDoc);
+
+ jsTestLog("Doing ops that require metadata writes and thus should fail against: " + mongos);
+ assert.writeError(mongos.getDB("newDB").foo.insert({a: 1}));
+ assert.commandFailed(
+ mongos.getDB('admin').runCommand({shardCollection: "test.foo", key: {a: 1}}));
+ };
+
+ testOps(mongos2);
+ testOps(st.s);
+
+ st.stop();
}()); \ No newline at end of file