summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/sharding_multiple_ns_rs.js
blob: 9c4d73d5a2ce7d783b953c951cf0cd9845d08b03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

s = new ShardingTest( "blah" , 1 /* numShards */, 1 /* verboseLevel */, 1 /* numMongos */, { rs : true , chunksize : 1 } )

s.adminCommand( { enablesharding : "test" } );
s.adminCommand( { shardcollection : "test.foo" , key : { _id : 1 } } );

db = s.getDB( "test" );

for ( i=0; i<100; i++ )  {
    db.foo.insert( { _id : i , x : i } )
    db.bar.insert( { _id : i , x : i } )
}

db.getLastError();

sh.splitAt( "test.foo" , { _id : 50 } )

other = new Mongo( s.s.name );
dbother = other.getDB( "test" );

assert.eq( 5 , db.foo.findOne( { _id : 5 } ).x );
assert.eq( 5 , dbother.foo.findOne( { _id : 5 } ).x );

assert.eq( 5 , db.bar.findOne( { _id : 5 } ).x );
assert.eq( 5 , dbother.bar.findOne( { _id : 5 } ).x );


s._rs[0].test.awaitReplication();

s._rs[0].test.stopMaster( 15 , true )

// Wait for the primary to come back online...
var primary = s._rs[0].test.getPrimary();

// Wait for the mongos to recognize the new primary...
ReplSetTest.awaitRSClientHosts( db.getMongo(), primary, { ismaster : true } );

assert.eq( 5 , db.foo.findOne( { _id : 5 } ).x );
assert.eq( 5 , db.bar.findOne( { _id : 5 } ).x );

s.adminCommand( { shardcollection : "test.bar" , key : { _id : 1 } } );
sh.splitAt( "test.bar" , { _id : 50 } )

yetagain = new Mongo( s.s.name )
assert.eq( 5 , yetagain.getDB( "test" ).bar.findOne( { _id : 5 } ).x )
assert.eq( 5 , yetagain.getDB( "test" ).foo.findOne( { _id : 5 } ).x )

assert.eq( 5 , dbother.bar.findOne( { _id : 5 } ).x );
assert.eq( 5 , dbother.foo.findOne( { _id : 5 } ).x );


s.stop();