diff options
author | Randolph Tan <randolph@10gen.com> | 2014-04-25 14:04:36 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2014-05-06 16:32:44 -0400 |
commit | 87dc3ae516e1d12a632dc604710661e38ed7b3dd (patch) | |
tree | 3a483a3d0c38ce00a7f4d7dba0e9cba7f7eba5f3 /jstests/repl | |
parent | 6b945ec15c61f6bd4bfbaf382624d886ec8441d2 (diff) | |
download | mongo-87dc3ae516e1d12a632dc604710661e38ed7b3dd.tar.gz |
SERVER-13741 Migrate remaining tests to use write commands
Diffstat (limited to 'jstests/repl')
-rw-r--r-- | jstests/repl/basic1.js | 43 | ||||
-rw-r--r-- | jstests/repl/block1.js | 3 | ||||
-rw-r--r-- | jstests/repl/block2.js | 25 | ||||
-rw-r--r-- | jstests/repl/drop_dups.js | 24 | ||||
-rw-r--r-- | jstests/repl/master1.js | 4 | ||||
-rw-r--r-- | jstests/repl/mastermaster1.js | 55 | ||||
-rw-r--r-- | jstests/repl/mod_move.js | 37 | ||||
-rw-r--r-- | jstests/repl/repl12.js | 1 | ||||
-rw-r--r-- | jstests/repl/repl13.js | 13 | ||||
-rw-r--r-- | jstests/repl/repl17.js | 1 | ||||
-rw-r--r-- | jstests/repl/repl19.js | 3 | ||||
-rw-r--r-- | jstests/repl/repl20.js | 3 | ||||
-rw-r--r-- | jstests/repl/repl21.js | 11 | ||||
-rw-r--r-- | jstests/repl/repl5.js | 4 |
14 files changed, 61 insertions, 166 deletions
diff --git a/jstests/repl/basic1.js b/jstests/repl/basic1.js index ccde8874fbd..a2ec3ceb52f 100644 --- a/jstests/repl/basic1.js +++ b/jstests/repl/basic1.js @@ -25,7 +25,7 @@ function check( note ){ sleep( 200 ); } lastOpLogEntry = m.getDB("local").oplog.$main.find({op:{$ne:"n"}}).sort({$natural:-1}).limit(-1).next(); - note = note + tojson(am.a.find().toArray()) + " != " + tojson(as.a.find().toArray()) + note = note + tojson(am.a.find().toArray()) + " != " + tojson(as.a.find().toArray()) + "last oplog:" + tojson(lastOpLogEntry); assert.eq( x.md5 , y.md5 , note ); } @@ -44,9 +44,8 @@ check( "C" ); // ----- check features ------- // map/reduce -am.mr.insert( { tags : [ "a" ] } ) -am.mr.insert( { tags : [ "a" , "b" ] } ) -am.getLastError(); +assert.writeOK(am.mr.insert({ tags: [ "a" ]})); +assert.writeOK(am.mr.insert({ tags: [ "a", "b" ]})); check( "mr setup" ); m = function(){ @@ -87,22 +86,19 @@ block(); checkNumCollections( "MR4" ); - -t = am.rpos; -t.insert( { _id : 1 , a : [ { n : "a" , c : 1 } , { n : "b" , c : 1 } , { n : "c" , c : 1 } ] , b : [ 1 , 2 , 3 ] } ) -block(); +var t = am.rpos; +var writeOption = { writeConcern: { w: 2, wtimeout: 3000 }}; +t.insert({ _id: 1, a: [{ n: "a", c: 1 }, { n: "b", c: 1 }, { n: "c", c: 1 }], b: [ 1, 2, 3 ]}, + writeOption); check( "after pos 1 " ); -t.update( { "a.n" : "b" } , { $inc : { "a.$.c" : 1 } } ) -block(); +t.update({ "a.n": "b" }, { $inc: { "a.$.c": 1 }}, writeOption); check( "after pos 2 " ); -t.update( { "b" : 2 } , { $inc : { "b.$" : 1 } } ) -block(); +t.update({ b: 2 }, { $inc: { "b.$": 1 }}, writeOption); check( "after pos 3 " ); -t.update( { "b" : 3} , { $set : { "b.$" : 17 } } ) -block(); +t.update({ b: 3 }, { $set: { "b.$": 17 }}, writeOption); check( "after pos 4 " ); @@ -112,23 +108,17 @@ printjson( as.rpos.findOne() ) //am.getSisterDB( "local" ).getCollection( "oplog.$main" ).find().limit(10).sort( { $natural : -1 } ).forEach( printjson ) t = am.b; -t.update( { "_id" : "fun"}, { $inc : {"a.b.c.x" : 6743} } , true, false) -block() +var updateOption = { upsert: true, multi: false, writeConcern: { w: 2, wtimeout: 3000 }}; +t.update({ _id: "fun" }, { $inc: { "a.b.c.x": 6743 }}, updateOption); check( "b 1" ); -t.update( { "_id" : "fun"}, { $inc : {"a.b.c.x" : 5} } , true, false) -block() +t.update({ _id: "fun" }, { $inc: { "a.b.c.x": 5 }}, updateOption); check( "b 2" ); -t.update( { "_id" : "fun"}, { $inc : {"a.b.c.x" : 100, "a.b.c.y" : 911} } , true, false) -block() +t.update({ _id: "fun" }, { $inc: { "a.b.c.x": 100, "a.b.c.y": 911 }}, updateOption); assert.eq( { _id : "fun" , a : { b : { c : { x : 6848 , y : 911 } } } } , as.b.findOne() , "b 3" ); -//printjson( t.findOne() ) -//printjson( as.b.findOne() ) -//am.getSisterDB( "local" ).getCollection( "oplog.$main" ).find().sort( { $natural : -1 } ).limit(3).forEach( printjson ) check( "b 4" ); - // lots of indexes am.lotOfIndexes.insert( { x : 1 } ) @@ -136,10 +126,8 @@ for ( i=0; i<200; i++ ){ var idx = {} idx["x"+i] = 1; am.lotOfIndexes.ensureIndex( idx ); - am.getLastError() } - assert.soon( function(){ return am.lotOfIndexes.getIndexes().length == as.lotOfIndexes.getIndexes().length; } , "lots of indexes a" ) assert.eq( am.lotOfIndexes.getIndexes().length , as.lotOfIndexes.getIndexes().length , "lots of indexes b" ) @@ -154,9 +142,8 @@ assert.soon( function(){ z = as.mu1.findOne(); printjson( z ); return friendlyEq // profiling - this sould be last am.setProfilingLevel( 2 ) -am.foo.insert( { x : 1 } ) +am.foo.insert({ x: 1 }, writeOption); am.foo.findOne() -block(); assert.eq( 2 , am.system.profile.count() , "P1" ) assert.eq( 0 , as.system.profile.count() , "P2" ) diff --git a/jstests/repl/block1.js b/jstests/repl/block1.js index e358ba39705..ef36c3efb34 100644 --- a/jstests/repl/block1.js +++ b/jstests/repl/block1.js @@ -11,8 +11,7 @@ tm = dbm.bar; ts = dbs.bar; for ( var i=0; i<1000; i++ ){ - tm.insert( { _id : i } ); - dbm.runCommand( { getlasterror : 1 , w : 2 } ) + tm.insert({ _id: i }, { writeConcern: { w: 2 }}); assert.eq( i + 1 , ts.count() , "A" + i ); assert.eq( i + 1 , tm.count() , "B" + i ); } diff --git a/jstests/repl/block2.js b/jstests/repl/block2.js index 64e52b8a94f..fc35b2774c4 100644 --- a/jstests/repl/block2.js +++ b/jstests/repl/block2.js @@ -18,33 +18,14 @@ function check( msg ){ assert.eq( tm.count() , ts.count() , "check: " + msg ); } -function worked( w , wtimeout ){ - var gle = dbm.getLastError( w , wtimeout ); - if (gle != null) { - printjson(gle); - } - return gle == null; -} - check( "A" ); -tm.save( { x : 1 } ); -assert( worked( 2 ) , "B" ); - -tm.save( { x : 2 } ); -assert( worked( 2 , 3000 ) , "C" ) +assert.writeOK(tm.insert({ x: 1 }, { writeConcern: { w: 2 }})); +assert.writeOK(tm.insert({ x: 2 }, { writeConcern: { w: 2, wtimeout: 3000 }})); rt.stop( false ); -tm.save( { x : 3 } ) +assert.writeError(tm.insert({ x: 3 }, { writeConcern: { w: 2, wtimeout: 3000 }})); assert.eq( 3 , tm.count() , "D1" ); -assert( ! worked( 2 , 3000 ) , "D2" ) - -s = rt.start( false ) -setup(); -assert( worked( 2 , 30000 ) , "E" ) rt.stop(); - - - diff --git a/jstests/repl/drop_dups.js b/jstests/repl/drop_dups.js index 1b151cfb71f..bd3d2820108 100644 --- a/jstests/repl/drop_dups.js +++ b/jstests/repl/drop_dups.js @@ -4,9 +4,7 @@ var rt = new ReplTest( "drop_dups" ); m = rt.start( true ); s = rt.start( false ); -function block(){ - am.runCommand( { getlasterror : 1 , w : 2 , wtimeout : 3000 } ) -} +var writeOption = { writeConcern: { w: 2, wtimeout: 3000 }}; am = m.getDB( "foo" ); as = s.getDB( "foo" ); @@ -16,20 +14,18 @@ function run( createInBackground ) { collName = "foo" + ( createInBackground ? "B" : "F" ); am[collName].drop(); - am.blah.insert( { x : 1 } ) + am.blah.insert({ x: 1 }, writeOption); assert.soon( function(){ - block(); return as.blah.findOne(); } ); - - - for ( i=0; i<10; i++ ) { - am[collName].insert( { _id : i , x : Math.floor( i / 2 ) } ) + + var bulk = am[collName].initializeUnorderedBulkOp(); + for (var i = 0; i < 10; i++) { + bulk.insert({ _id: i, x: Math.floor( i / 2 ) }); } - - block(); - + assert.writeOK(bulk.execute({ w: 2, wtimeout: 3000 })); + am.runCommand( { "godinsert" : collName , obj : { _id : 100 , x : 20 } } ); am.runCommand( { "godinsert" : collName , obj : { _id : 101 , x : 20 } } ); @@ -43,8 +39,8 @@ function run( createInBackground ) { } am[collName].ensureIndex( { x : 1 } , { unique : true , dropDups : true , background : createInBackground } ); - am.blah.insert( { x : 1 } ) - block(); + am.blah.insert({ x: 1 }, writeOption); + assert.eq( 2 , am[collName].getIndexKeys().length , "A1 : " + createInBackground ) if (!createInBackground) { assert.eq( 2 , as[collName].getIndexKeys().length , "A2 : " + createInBackground ) diff --git a/jstests/repl/master1.js b/jstests/repl/master1.js index 93bfaf7862c..49b3416d202 100644 --- a/jstests/repl/master1.js +++ b/jstests/repl/master1.js @@ -43,11 +43,9 @@ m.getDB( "local" ).runCommand( {godinsert:"oplog.$main", obj:op} ); rt.stop( true ); m = rt.start( true, null, true ); assert.eq( op.ts.i, lastop().ts.i ); -am().save( {} ); -// The above write should cause the server to terminate assert.throws(function() { - am().findOne(); + am().save( {} ); // triggers fassert because ofclock skew }); assert.neq(0, rt.stop( true )); // fasserted diff --git a/jstests/repl/mastermaster1.js b/jstests/repl/mastermaster1.js deleted file mode 100644 index 97fdc149b56..00000000000 --- a/jstests/repl/mastermaster1.js +++ /dev/null @@ -1,55 +0,0 @@ -// basic testing of master/master - - -ports = allocatePorts( 2 ) - -left = startMongodTest( ports[0] , "mastermaster1left" , false , { master : "" , slave : "" , source : "127.0.0.1:" + ports[1] } ) - -x = left.getDB( "admin" ).runCommand( "ismaster" ) -assert( x.ismaster , "left: " + tojson( x ) ) - -right = startMongodTest( ports[1] , "mastermaster1right" , false , { master : "" , slave : "" , source : "127.0.0.1:" + ports[0] } ) - -x = right.getDB( "admin" ).runCommand( "ismaster" ) -assert( x.ismaster , "right: " + tojson( x ) ) - -print( "check 1" ) - - -ldb = left.getDB( "test" ) -rdb = right.getDB( "test" ) - -print( "check 2" ) - -ldb.foo.insert( { _id : 1 , x : "eliot" } ) -result = ldb.runCommand( { getlasterror : 1 , w : 2 , wtimeout : 40000 } ); -printjson(result); -rdb.foo.insert( { _id : 2 , x : "sara" } ) -result = rdb.runCommand( { getlasterror : 1 , w : 2 , wtimeout : 40000 } ) -printjson(result); - -print( "check 3" ) - -print( "left" ) -ldb.foo.find().forEach( printjsononeline ) -print( "right" ) -rdb.foo.find().forEach( printjsononeline ) - -print( "oplog" ) - -rdb.getSisterDB( "local" ).getCollection( "oplog.$main" ).find().forEach( printjsononeline ) - -/* -assert.eq( 2 , ldb.foo.count() , "B1" ) -assert.eq( 2 , rdb.foo.count() , "B2" ) -*/ - -print( "going to stop everything" ) - -for ( var i=0; i<ports.length; i++ ){ - stopMongod( ports[i] ); -} - -print( "yay" ) - - diff --git a/jstests/repl/mod_move.js b/jstests/repl/mod_move.js index d39e747b833..66cc00b39e5 100644 --- a/jstests/repl/mod_move.js +++ b/jstests/repl/mod_move.js @@ -6,10 +6,6 @@ var rt = new ReplTest( "mod_move" ); m = rt.start( true , { oplogSize : 50 } ); -function block(){ - am.runCommand( { getlasterror : 1 , w : 2 , wtimeout : 3000 } ) -} - am = m.getDB( "foo" ); function check( note ){ @@ -31,39 +27,30 @@ function check( note ){ BIG = 100000; N = BIG * 2; -s : "asdasdasdasdasdasdasdadasdadasdadasdasdas" - -for ( i=0; i<BIG; i++ ) { - am.a.insert( { _id : i , s : 1 , x : 1 } ) +var bulk = am.a.initializeUnorderedBulkOp(); +for (var i = 0; i < BIG; i++) { + bulk.insert({ _id: i, s: 1, x: 1 }); } -for ( ; i<N; i++ ) { - am.a.insert( { _id : i , s : 1 } ) +for (; i < N; i++) { + bulk.insert({ _id: i, s: 1 }); } -for ( i=0; i<BIG; i++ ) { - am.a.remove( { _id : i } ) +for (i = 0; i < BIG; i++) { + bulk.find({ _id: i }).remove(); } -am.getLastError(); +assert.writeOK(bulk.execute()); assert.eq( BIG , am.a.count() ) assert.eq( 1 , am.a.stats().paddingFactor , "A2" ) - // start slave s = rt.start( false ); as = s.getDB( "foo" ); -for ( i=N-1; i>=BIG; i-- ) { - am.a.update( { _id : i } , { $set : { x : 1 } } ) - if ( i == N ) { - am.getLastError() - assert.lt( as.a.count() , BIG , "B1" ) - print( "NOW : " + as.a.count() ) - } +bulk = am.a.initializeUnorderedBulkOp(); +for (i = N - 1; i >= BIG; i--) { + bulk.find({ _id: i }).update({ $set: { x: 1 }}); } +assert.writeOK(bulk.execute()); check( "B" ) rt.stop(); - - - - diff --git a/jstests/repl/repl12.js b/jstests/repl/repl12.js index 8db4b75e7a9..4bfaf17d5d7 100644 --- a/jstests/repl/repl12.js +++ b/jstests/repl/repl12.js @@ -17,7 +17,6 @@ for( i = 0; i < 3; ++i ) { m.getDB( a ).c.save( {} ); a += "a"; } -m.getDB(a).getLastError(); //print("\n\n\n DB NAMES MASTER:"); //printjson(m.getDBNames()); diff --git a/jstests/repl/repl13.js b/jstests/repl/repl13.js index e8a80966dab..78daae24c32 100644 --- a/jstests/repl/repl13.js +++ b/jstests/repl/repl13.js @@ -12,10 +12,11 @@ m = rt.start( true ); mc = m.getDB( 'd' )[ 'c' ]; // Insert some documents with a:{} fields. -for( i = 0; i < 100000; ++i ) { - mc.save( {_id:i,a:{}} ); +var bulk = mc.initializeUnorderedBulkOp(); +for(var i = 0; i < 100000; ++i) { + bulk.insert({ _id: i, a: {}}); } -m.getDB( 'd' ).getLastError(); +assert.writeOK(bulk.execute()); s = rt.start( false ); sc = s.getDB( 'd' )[ 'c' ]; @@ -26,11 +27,13 @@ assert.soon( function() { debug( sc.count() ); return sc.count() > 0; } ); // Update documents that will be cloned last with the intent that an updated version will be cloned. // This may cause an assertion when an update that was successfully applied to the original version // of a document is replayed against an updated version of the same document. +bulk = mc.initializeUnorderedBulkOp(); for( i = 99999; i >= 90000; --i ) { // If the document is cloned as {a:1}, the {$set:{'a.b':1}} modifier will uassert. - mc.update( {_id:i}, {$set:{'a.b':1}} ); - mc.update( {_id:i}, {$set:{a:1}} ); + bulk.find({ _id: i }).update({ $set: { 'a.b': 1 }}); + bulk.find({ _id: i }).update({ $set: { a: 1 }}); } +assert.writeOK(bulk.execute()); // The initial sync completes and subsequent writes succeed, in spite of any assertions that occur // when the update operations above are replicated. diff --git a/jstests/repl/repl17.js b/jstests/repl/repl17.js index 8011d974328..c7a7be35ffc 100644 --- a/jstests/repl/repl17.js +++ b/jstests/repl/repl17.js @@ -11,7 +11,6 @@ md = master.getDB( 'd' ); for( i = 0; i < 1000; ++i ) { md[ ''+i ].save( {} ); } -md.getLastError(); slave = rt.start( false ); sd = slave.getDB( 'd' ); diff --git a/jstests/repl/repl19.js b/jstests/repl/repl19.js index 71d4335014a..a655d522bae 100644 --- a/jstests/repl/repl19.js +++ b/jstests/repl/repl19.js @@ -13,8 +13,7 @@ for( i = 0; i < 100000; ++i ) { } targetId = 1000*1000; -mc.insert( { _id:targetId, val:[ 1, 2, 3 ] } ); -master.getDB( 'd' ).getLastError(); +assert.writeOK(mc.insert({ _id: targetId, val: [ 1, 2, 3 ] })); slave = rt.start( false ); sc = slave.getDB( 'd' )[ 'c' ]; diff --git a/jstests/repl/repl20.js b/jstests/repl/repl20.js index 02e50f58f1f..c30ef8d6f3c 100644 --- a/jstests/repl/repl20.js +++ b/jstests/repl/repl20.js @@ -13,8 +13,7 @@ for( i = 0; i < 100000; ++i ) { } targetId = 1000*1000; -mc.insert( { _id:targetId, val:[ 1 ] } ); -master.getDB( 'd' ).getLastError(); +assert.writeOK(mc.insert({ _id: targetId, val: [ 1 ] })); slave = rt.start( false ); sc = slave.getDB( 'd' )[ 'c' ]; diff --git a/jstests/repl/repl21.js b/jstests/repl/repl21.js index a94a4b5b779..87c0c7fdd02 100644 --- a/jstests/repl/repl21.js +++ b/jstests/repl/repl21.js @@ -8,13 +8,14 @@ rt = new ReplTest( "repl21tests" ); master = rt.start( true ); mc = master.getDB( 'd' )[ 'c' ]; -for( i = 0; i < 100000; ++i ) { - mc.insert( { _id:i, z:i } ); +var bulk = mc.initializeUnorderedBulkOp(); +for(var i = 0; i < 100000; ++i) { + bulk.insert({ _id: i, z: i }); } targetId = 1000*1000; -mc.insert( { _id:targetId, val:[ 1 ] } ); -master.getDB( 'd' ).getLastError(); +bulk.insert({ _id: targetId, val: [ 1 ] }); +assert.writeOK(bulk.execute()); slave = rt.start( false ); sc = slave.getDB( 'd' )[ 'c' ]; @@ -36,4 +37,4 @@ assert.soon( function() { return sc.count( { _id:'sentinel' } ) > 0; } ); assert.eq( [ 1, 3 ], mc.findOne( { _id:targetId } ).val ); assert.eq( [ 1, 3 ], sc.findOne( { _id:targetId } ).val ); -}
\ No newline at end of file +} diff --git a/jstests/repl/repl5.js b/jstests/repl/repl5.js index eda48496656..aeba7eb1095 100644 --- a/jstests/repl/repl5.js +++ b/jstests/repl/repl5.js @@ -14,8 +14,10 @@ doTest = function(signal, extraOpts) { m = rt.start( true ); ma = m.getDB( "a" ).a; + var bulk = ma.initializeUnorderedBulkOp(); for( i = 0; i < 10000; ++i ) - ma.save( { i:i } ); + bulk.insert({ i: i }); + assert.writeOK(bulk.execute()); s = rt.start(false, extraOpts); soonCountAtLeast( "a", "a", 1 ); |