diff options
author | Randolph Tan <randolph@10gen.com> | 2014-03-04 17:41:56 -0500 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2014-04-21 16:53:25 -0400 |
commit | 7acafe85d9bdd63122c19ba1cca86a7f55174941 (patch) | |
tree | 234effd8e5a5b6c63d8b12c74de2d9acb78a7509 /jstests/sharding/mongos_rs_shard_failure_tolerance.js | |
parent | e87b42c4f13e48078f5c4aefba3caf18dcfba072 (diff) | |
download | mongo-7acafe85d9bdd63122c19ba1cca86a7f55174941.tar.gz |
SERVER-13425 migrate sharding jstest suite to use write commands api
Diffstat (limited to 'jstests/sharding/mongos_rs_shard_failure_tolerance.js')
-rw-r--r-- | jstests/sharding/mongos_rs_shard_failure_tolerance.js | 142 |
1 files changed, 41 insertions, 101 deletions
diff --git a/jstests/sharding/mongos_rs_shard_failure_tolerance.js b/jstests/sharding/mongos_rs_shard_failure_tolerance.js index 23ae95e857f..730860c2bf7 100644 --- a/jstests/sharding/mongos_rs_shard_failure_tolerance.js +++ b/jstests/sharding/mongos_rs_shard_failure_tolerance.js @@ -28,10 +28,8 @@ var collSharded = mongos.getCollection( "fooSharded.barSharded" ); var collUnsharded = mongos.getCollection( "fooUnsharded.barUnsharded" ); // Create the unsharded database -collUnsharded.insert({ some : "doc" }); -assert.eq( null, collUnsharded.getDB().getLastError() ); -collUnsharded.remove({}); -assert.eq( null, collUnsharded.getDB().getLastError() ); +assert.writeOK(collUnsharded.insert({ some : "doc" })); +assert.writeOK(collUnsharded.remove({})); printjson( admin.runCommand({ movePrimary : collUnsharded.getDB().toString(), to : shards[0]._id }) ); @@ -47,21 +45,6 @@ assert.commandWorked( admin.runCommand({ moveChunk : collSharded.toString(), st.printShardingStatus(); -// Needed b/c the GLE command itself can fail if the shard is down ("write result unknown") - we -// don't care if this happens in this test, we only care that we did not get "write succeeded". -// Depending on the connection pool state, we could get either. -function gleErrorOrThrow(database, msg) { - var gle; - try { - gle = database.getLastErrorObj(); - } - catch (ex) { - return; - } - if (!gle.err) doassert("getLastError is null: " + tojson(gle) + " :" + msg); - return; -}; - // // Setup is complete // @@ -72,12 +55,9 @@ var mongosConnActive = new Mongo( mongos.host ); var mongosConnIdle = null; var mongosConnNew = null; -mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -1 }); -mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 1 }); -assert.eq(null, mongosConnActive.getCollection( collSharded.toString() ).getDB().getLastError()); - -mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 1 }); -assert.eq(null, mongosConnActive.getCollection( collUnsharded.toString() ).getDB().getLastError()); +assert.writeOK(mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -1 })); +assert.writeOK(mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 1 })); +assert.writeOK(mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 1 })); jsTest.log("Stopping primary of third shard..."); @@ -91,21 +71,15 @@ assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOn assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 })); assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 })); -mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -2 }); -assert.gleSuccess(mongosConnActive.getCollection( collSharded.toString() ).getDB()); -mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 2 }); -assert.gleSuccess(mongosConnActive.getCollection( collSharded.toString() ).getDB()); -mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 2 }); -assert.gleSuccess(mongosConnActive.getCollection( collUnsharded.toString() ).getDB()); +assert.writeOK(mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -2 })); +assert.writeOK(mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 2 })); +assert.writeOK(mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 2 })); jsTest.log("Testing idle connection with third primary down..."); -mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -3 }); -assert.gleSuccess(mongosConnIdle.getCollection( collSharded.toString() ).getDB()); -mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 3 }); -assert.gleSuccess(mongosConnIdle.getCollection( collSharded.toString() ).getDB()); -mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 3 }); -assert.gleSuccess(mongosConnIdle.getCollection( collUnsharded.toString() ).getDB()); +assert.writeOK(mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -3 })); +assert.writeOK(mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 3 })); +assert.writeOK(mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 3 })); assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }) ); assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : 1 }) ); @@ -121,14 +95,11 @@ mongosConnNew = new Mongo( mongos.host ); assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) ); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -4 }); -assert.gleSuccess(mongosConnNew.getCollection( collSharded.toString() ).getDB()); +assert.writeOK(mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -4 })); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 4 }); -assert.gleSuccess(mongosConnNew.getCollection( collSharded.toString() ).getDB()); +assert.writeOK(mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 4 })); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 4 }); -assert.gleSuccess(mongosConnNew.getCollection( collUnsharded.toString() ).getDB()); +assert.writeOK(mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 4 })); gc(); // Clean up new connections @@ -188,22 +159,16 @@ assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOn assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 })); // Writes -mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -5 }); -assert.gleSuccess(mongosConnActive.getCollection( collSharded.toString() ).getDB()); -mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 5 }); -gleErrorOrThrow(mongosConnActive.getCollection( collSharded.toString() ).getDB()); -mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 5 }); -assert.gleSuccess(mongosConnActive.getCollection( collUnsharded.toString() ).getDB()); +assert.writeOK(mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -5 })); +assert.writeError(mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 5 })); +assert.writeOK(mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 5 })); jsTest.log("Testing idle connection with second primary down..."); // Writes -mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -6 }); -assert.gleSuccess(mongosConnIdle.getCollection( collSharded.toString() ).getDB()); -mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 6 }); -gleErrorOrThrow(mongosConnIdle.getCollection( collSharded.toString() ).getDB()); -mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 6 }); -assert.gleSuccess(mongosConnIdle.getCollection( collUnsharded.toString() ).getDB()); +assert.writeOK(mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -6 })); +assert.writeError(mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 6 })); +assert.writeOK(mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 6 })); // Reads with read prefs mongosConnIdle.setSlaveOk(); @@ -332,14 +297,11 @@ assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne // Writes mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -7 }); -assert.gleSuccess(mongosConnNew.getCollection( collSharded.toString() ).getDB()); +assert.writeOK(mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -7 })); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 7 }); -gleErrorOrThrow(mongosConnNew.getCollection( collSharded.toString() ).getDB()); +assert.writeError(mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 7 })); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 7 }); -assert.gleSuccess(mongosConnNew.getCollection( collUnsharded.toString() ).getDB()); +assert.writeOK(mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 7 })); gc(); // Clean up new connections @@ -356,21 +318,15 @@ assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOn assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : 1 })); assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 })); -mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -8 }); -gleErrorOrThrow(mongosConnActive.getCollection( collSharded.toString() ).getDB()); -mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 8 }); -gleErrorOrThrow(mongosConnActive.getCollection( collSharded.toString() ).getDB()); -mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 8 }); -gleErrorOrThrow(mongosConnActive.getCollection( collUnsharded.toString() ).getDB()); +assert.writeError(mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -8 })); +assert.writeError(mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 8 })); +assert.writeError(mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 8 })); jsTest.log("Testing idle connection with first primary down..."); -mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -9 }); -gleErrorOrThrow(mongosConnIdle.getCollection( collSharded.toString() ).getDB()); -mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 9 }); -gleErrorOrThrow(mongosConnIdle.getCollection( collSharded.toString() ).getDB()); -mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 9 }); -gleErrorOrThrow(mongosConnIdle.getCollection( collUnsharded.toString() ).getDB()); +assert.writeError(mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -9 })); +assert.writeError(mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 9 })); +assert.writeError(mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 9 })); mongosConnIdle.setSlaveOk(); assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }) ); @@ -390,14 +346,11 @@ mongosConnNew.setSlaveOk(); assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) ); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -10 }); -gleErrorOrThrow(mongosConnNew.getCollection( collSharded.toString() ).getDB()); +assert.writeError(mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -10 })); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 10 }); -gleErrorOrThrow(mongosConnNew.getCollection( collSharded.toString() ).getDB()); +assert.writeError(mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 10 })); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 10 }); -gleErrorOrThrow(mongosConnNew.getCollection( collUnsharded.toString() ).getDB()); +assert.writeError(mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 10 })); gc(); // Clean up new connections @@ -413,21 +366,15 @@ mongosConnActive.setSlaveOk(); assert.neq(null, mongosConnActive.getCollection( collSharded.toString() ).findOne({ _id : -1 })); assert.neq(null, mongosConnActive.getCollection( collUnsharded.toString() ).findOne({ _id : 1 })); -mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -11 }); -gleErrorOrThrow(mongosConnActive.getCollection( collSharded.toString() ).getDB()); -mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 11 }); -gleErrorOrThrow(mongosConnActive.getCollection( collSharded.toString() ).getDB()); -mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 11 }); -gleErrorOrThrow(mongosConnActive.getCollection( collUnsharded.toString() ).getDB()); +assert.writeError(mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : -11 })); +assert.writeError(mongosConnActive.getCollection( collSharded.toString() ).insert({ _id : 11 })); +assert.writeError(mongosConnActive.getCollection( collUnsharded.toString() ).insert({ _id : 11 })); jsTest.log("Testing idle connection with second shard down..."); -mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -12 }); -gleErrorOrThrow(mongosConnIdle.getCollection( collSharded.toString() ).getDB()); -mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 12 }); -gleErrorOrThrow(mongosConnIdle.getCollection( collSharded.toString() ).getDB()); -mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 12 }); -gleErrorOrThrow(mongosConnIdle.getCollection( collUnsharded.toString() ).getDB()); +assert.writeError(mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : -12 })); +assert.writeError(mongosConnIdle.getCollection( collSharded.toString() ).insert({ _id : 12 })); +assert.writeError(mongosConnIdle.getCollection( collUnsharded.toString() ).insert({ _id : 12 })); mongosConnIdle.setSlaveOk(); assert.neq(null, mongosConnIdle.getCollection( collSharded.toString() ).findOne({ _id : -1 }) ); @@ -443,21 +390,14 @@ mongosConnNew.setSlaveOk(); assert.neq(null, mongosConnNew.getCollection( collUnsharded.toString() ).findOne({ _id : 1 }) ); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -13 }); -gleErrorOrThrow(mongosConnNew.getCollection( collSharded.toString() ).getDB()); +assert.writeError(mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : -13 })); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 13 }); -gleErrorOrThrow(mongosConnNew.getCollection( collSharded.toString() ).getDB()); +assert.writeError(mongosConnNew.getCollection( collSharded.toString() ).insert({ _id : 13 })); mongosConnNew = new Mongo( mongos.host ); -mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 13 }); -gleErrorOrThrow(mongosConnNew.getCollection( collUnsharded.toString() ).getDB()); +assert.writeError(mongosConnNew.getCollection( collUnsharded.toString() ).insert({ _id : 13 })); gc(); // Clean up new connections jsTest.log("DONE!"); st.stop(); - - - - |