0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/repl/pair2.js

43 lines
1.7 KiB
JavaScript
Raw Normal View History

2009-02-02 15:54:00 +01:00
// Pairing resync
var baseName = "jstests_pair2test";
ismaster = function( n ) {
im = n.getDB( "admin" ).runCommand( { "ismaster" : 1 } );
assert( im );
return im.ismaster;
}
// spec small oplog for fast startup on 64bit machines
a = startMongod( "--port", "27018", "--dbpath", "/data/db/" + baseName + "-arbiter" );
l = startMongod( "--port", "27019", "--dbpath", "/data/db/" + baseName + "-left", "--pairwith", "127.0.0.1:27020", "127.0.0.1:27018", "--oplogSize", "1" );
r = startMongod( "--port", "27020", "--dbpath", "/data/db/" + baseName + "-right", "--pairwith", "127.0.0.1:27019", "127.0.0.1:27018", "--oplogSize", "1" );
l.setSlaveOk();
assert.soon( function() { return ( ismaster( l ) == 0 && ismaster( r ) == 1 ); } );
lz = l.getDB( baseName ).z
rz = r.getDB( baseName ).z
rz.save( { _id: new ObjectId() } );
2009-02-04 23:24:15 +01:00
assert.soon( function() { return lz.find().count() == 1; } );
2009-02-02 15:54:00 +01:00
assert.eq( 0, l.getDB( "admin" ).runCommand( { "resync" : 1 } ).ok );
stopMongod( 27019 );
big = new Array( 2000 ).toString();
for( i = 0; i < 1000; ++i )
rz.save( { _id: new ObjectId(), i: i, b: big } );
2009-02-14 15:15:05 +01:00
l = startMongoProgram( "mongod", "--port", "27019", "--dbpath", "/data/db/" + baseName + "-left", "--pairwith", "127.0.0.1:27020", "127.0.0.1:27018", "--oplogSize", "1" );
2009-02-02 15:54:00 +01:00
l.setSlaveOk();
assert.soon( function() { return 1 == l.getDB( "admin" ).runCommand( { "resync" : 1 } ).ok; } );
assert.soon( function() { return l.getDBNames().indexOf( baseName ) != -1; } );
lz = l.getDB( baseName ).z
2009-02-04 23:24:15 +01:00
assert.soon( function() { return 1001 == lz.find().count(); } );
assert.eq( 1, lz.find( { i: 0 } ).count() );
assert.eq( 1, lz.find( { i: 999 } ).count() );
2009-02-02 15:54:00 +01:00
assert.eq( 0, l.getDB( "admin" ).runCommand( { "resync" : 1 } ).ok );