3
s = new ShardingTest( "shard3" , 2 , 50 , 2 );
7
s.adminCommand( { enablesharding : "test" } );
8
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
10
a = s.getDB( "test" ).foo;
11
b = s2.getDB( "test" ).foo;
13
primary = s.getServer( "test" ).getDB( "test" ).foo;
14
secondary = s.getOther( primary.name ).getDB( "test" ).foo;
16
a.save( { num : 1 } );
17
a.save( { num : 2 } );
18
a.save( { num : 3 } );
20
assert.eq( 3 , a.find().toArray().length , "normal A" );
21
assert.eq( 3 , b.find().toArray().length , "other A" );
23
assert.eq( 3 , primary.count() , "p1" )
24
assert.eq( 0 , secondary.count() , "s1" )
26
assert.eq( 1 , s.onNumShards( "foo" ) , "on 1 shards" );
28
s.adminCommand( { split : "test.foo" , middle : { num : 2 } } );
29
s.adminCommand( { movechunk : "test.foo" , find : { num : 3 } , to : s.getOther( s.getServer( "test" ) ).name } );
31
assert( primary.find().toArray().length > 0 , "blah 1" );
32
assert( secondary.find().toArray().length > 0 , "blah 2" );
33
assert.eq( 3 , primary.find().itcount() + secondary.find().itcount() , "blah 3" )
35
assert.eq( 3 , a.find().toArray().length , "normal B" );
36
assert.eq( 3 , b.find().toArray().length , "other B" );
40
function doCounts( name , total ){
41
total = total || ( primary.count() + secondary.count() );
42
assert.eq( total , a.count() , name + " count" );
43
assert.eq( total , a.find().sort( { n : 1 } ).itcount() , name + " itcount - sort n" );
44
assert.eq( total , a.find().itcount() , name + " itcount" );
45
assert.eq( total , a.find().sort( { _id : 1 } ).itcount() , name + " itcount - sort _id" );
49
var total = doCounts( "before wrong save" )
50
secondary.save( { num : -3 } );
51
doCounts( "after wrong save" , total )
53
// --- move all to 1 ---
54
print( "MOVE ALL TO 1" );
56
assert.eq( 2 , s.onNumShards( "foo" ) , "on 2 shards" );
57
s.printCollectionInfo( "test.foo" );
59
assert( a.findOne( { num : 1 } ) )
60
assert( b.findOne( { num : 1 } ) )
62
print( "GOING TO MOVE" );
63
s.printCollectionInfo( "test.foo" );
64
s.adminCommand( { movechunk : "test.foo" , find : { num : 1 } , to : s.getOther( s.getServer( "test" ) ).name } );
65
s.printCollectionInfo( "test.foo" );
66
assert.eq( 1 , s.onNumShards( "foo" ) , "on 1 shard again" );
67
assert( a.findOne( { num : 1 } ) )
68
assert( b.findOne( { num : 1 } ) )
72
s.printCollectionInfo( "test.foo" , "before drop" );
74
s.printCollectionInfo( "test.foo" , "after drop" );
76
assert.eq( 0 , a.count() , "a count after drop" )
77
assert.eq( 0 , b.count() , "b count after drop" )
79
s.printCollectionInfo( "test.foo" , "after counts" );
81
assert.eq( 0 , primary.count() , "p count after drop" )
82
assert.eq( 0 , secondary.count() , "s count after drop" )
84
primary.save( { num : 1 } );
85
secondary.save( { num : 4 } );
87
assert.eq( 1 , primary.count() , "p count after drop adn save" )
88
assert.eq( 1 , secondary.count() , "s count after drop save " )
91
print("*** makes sure that sharding knows where things live" );
93
assert.eq( 1 , a.count() , "a count after drop and save" )
94
s.printCollectionInfo( "test.foo" , "after a count" );
95
assert.eq( 1 , b.count() , "b count after drop and save" )
96
s.printCollectionInfo( "test.foo" , "after b count" );
98
assert( a.findOne( { num : 1 } ) , "a drop1" );
99
assert.isnull( a.findOne( { num : 4 } ) , "a drop1" );
101
s.printCollectionInfo( "test.foo" , "after a findOne tests" );
103
assert( b.findOne( { num : 1 } ) , "b drop1" );
104
assert.isnull( b.findOne( { num : 4 } ) , "b drop1" );
106
s.printCollectionInfo( "test.foo" , "after b findOne tests" );
108
print( "*** dropDatabase setup" )
110
s.printShardingStatus()
111
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
112
a.save( { num : 2 } );
113
a.save( { num : 3 } );
114
s.adminCommand( { split : "test.foo" , middle : { num : 2 } } );
115
s.adminCommand( { movechunk : "test.foo" , find : { num : 3 } , to : s.getOther( s.getServer( "test" ) ).name } );
116
s.printShardingStatus();
118
s.printCollectionInfo( "test.foo" , "after dropDatabase setup" );
119
doCounts( "after dropDatabase setup2" )
120
s.printCollectionInfo( "test.foo" , "after dropDatabase setup3" );
122
print( "*** ready to call dropDatabase" )
123
res = s.getDB( "test" ).dropDatabase();
124
assert.eq( 1 , res.ok , "dropDatabase failed : " + tojson( res ) );
126
s.printShardingStatus();
127
s.printCollectionInfo( "test.foo" , "after dropDatabase call 1" );
128
assert.eq( 0 , doCounts( "after dropDatabase called" ) )