diff options
author | gregs <greg@10gen.com> | 2011-07-12 18:24:03 -0400 |
---|---|---|
committer | gregs <greg@10gen.com> | 2011-07-27 15:59:26 -0400 |
commit | 0a3a147ffb9e726dec50bf121ba82e9b650f6e2b (patch) | |
tree | 58a06f54d8d6c1e362660b78571840c74d87afdc /jstests/sharding/group_slaveok.js | |
parent | 9551880b41944ef200d244f616b46466b906691c (diff) | |
download | mongo-0a3a147ffb9e726dec50bf121ba82e9b650f6e2b.tar.gz |
test and group slaveok fix for SERVER-3405
Diffstat (limited to 'jstests/sharding/group_slaveok.js')
-rw-r--r-- | jstests/sharding/group_slaveok.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/jstests/sharding/group_slaveok.js b/jstests/sharding/group_slaveok.js new file mode 100644 index 00000000000..930ea095351 --- /dev/null +++ b/jstests/sharding/group_slaveok.js @@ -0,0 +1,62 @@ +// Tests group using slaveOk + +var st = new ShardingTest( testName = "groupSlaveOk", + numShards = 1, + verboseLevel = 0, + numMongos = 1, + { rs : true, + rs0 : { nodes : 2 } + }) + +var rst = st._rs[0].test + +// Insert data into replica set +var conn = new Mongo( st.s.host ) +conn.setLogLevel( 3 ) + +var coll = conn.getCollection( "test.groupSlaveOk" ) +coll.drop() + +for( var i = 0; i < 300; i++ ){ + coll.insert( { i : i % 10 } ) +} + +// Make sure the writes get through, otherwise we can continue to error these one-at-a-time +coll.getDB().getLastError() + +st.printShardingStatus() + +// Wait for client to update itself and replication to finish +rst.awaitReplication() + +// Data now inserted... stop the master, since only two in set, other will still be secondary +rst.stop( rst.getMaster(), undefined, true ) +printjson( rst.status() ) + +// Need to check slaveOk=true first, since slaveOk=false will destroy conn in pool when +// master is down +conn.setSlaveOk() + +// Should throw exception, since not slaveOk'd +assert.eq( 10, coll.group({ key : { i : true } , + reduce : function( obj, ctx ){ ctx.count += 1 } , + initial : { count : 0 } }).length ) + +try { + + conn.setSlaveOk( false ) + coll.group({ key : { i : true } , + reduce : function( obj, ctx ){ ctx.count += 1 } , + initial : { count : 0 } }) + + print( "Should not reach here!" ) + printjson( coll.getDB().getLastError() ) + assert( false ) + +} +catch( e ){ + print( "Non-slaveOk'd connection failed." ) +} + +// Finish +st.stop() |