~ubuntu-branches/ubuntu/trusty/mongodb/trusty-proposed

« back to all changes in this revision

Viewing changes to jstests/sharding/shard3.js

  • Committer: Bazaar Package Importer
  • Author(s): Antonin Kral
  • Date: 2010-01-29 19:48:45 UTC
  • Revision ID: james.westby@ubuntu.com-20100129194845-8wbmkf626fwcavc9
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// shard3.js
 
2
 
 
3
s = new ShardingTest( "shard3" , 2 , 50 , 2 );
 
4
 
 
5
s2 = s._mongos[1];
 
6
 
 
7
s.adminCommand( { enablesharding : "test" } );
 
8
s.adminCommand( { shardcollection : "test.foo" , key : { num : 1 } } );
 
9
 
 
10
a = s.getDB( "test" ).foo;
 
11
b = s2.getDB( "test" ).foo;
 
12
 
 
13
primary = s.getServer( "test" ).getDB( "test" ).foo;
 
14
secondary = s.getOther( primary.name ).getDB( "test" ).foo;
 
15
 
 
16
a.save( { num : 1 } );
 
17
a.save( { num : 2 } );
 
18
a.save( { num : 3 } );
 
19
 
 
20
assert.eq( 3 , a.find().toArray().length , "normal A" );
 
21
assert.eq( 3 , b.find().toArray().length , "other A" );
 
22
 
 
23
assert.eq( 3 , primary.count() , "p1" )
 
24
assert.eq( 0 , secondary.count() , "s1" )
 
25
 
 
26
assert.eq( 1 , s.onNumShards( "foo" ) , "on 1 shards" );
 
27
 
 
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 } );
 
30
 
 
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" )
 
34
 
 
35
assert.eq( 3 , a.find().toArray().length , "normal B" );
 
36
assert.eq( 3 , b.find().toArray().length , "other B" );
 
37
 
 
38
// --- filtering ---
 
39
 
 
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" );
 
46
    return total;
 
47
}
 
48
 
 
49
var total = doCounts( "before wrong save" )
 
50
secondary.save( { num : -3 } );
 
51
doCounts( "after wrong save" , total )
 
52
 
 
53
// --- move all to 1 ---
 
54
print( "MOVE ALL TO 1" );
 
55
 
 
56
assert.eq( 2 , s.onNumShards( "foo" ) , "on 2 shards" );
 
57
s.printCollectionInfo( "test.foo" );
 
58
 
 
59
assert( a.findOne( { num : 1 } ) )
 
60
assert( b.findOne( { num : 1 } ) )
 
61
 
 
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 } ) )
 
69
 
 
70
print( "*** drop" );
 
71
 
 
72
s.printCollectionInfo( "test.foo" , "before drop" );
 
73
a.drop();
 
74
s.printCollectionInfo( "test.foo" , "after drop" );
 
75
 
 
76
assert.eq( 0 , a.count() , "a count after drop" )
 
77
assert.eq( 0 , b.count() , "b count after drop" )
 
78
 
 
79
s.printCollectionInfo( "test.foo" , "after counts" );
 
80
 
 
81
assert.eq( 0 , primary.count() , "p count after drop" )
 
82
assert.eq( 0 , secondary.count() , "s count after drop" )
 
83
 
 
84
primary.save( { num : 1 } );
 
85
secondary.save( { num : 4 } );
 
86
 
 
87
assert.eq( 1 , primary.count() , "p count after drop adn save" )
 
88
assert.eq( 1 , secondary.count() , "s count after drop save " )
 
89
 
 
90
 
 
91
print("*** makes sure that sharding knows where things live" );
 
92
 
 
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" );
 
97
 
 
98
assert( a.findOne( { num : 1 } ) , "a drop1" );
 
99
assert.isnull( a.findOne( { num : 4 } ) , "a drop1" );
 
100
 
 
101
s.printCollectionInfo( "test.foo" , "after a findOne tests" );
 
102
 
 
103
assert( b.findOne( { num : 1 } ) , "b drop1" );
 
104
assert.isnull( b.findOne( { num : 4 } ) , "b drop1" );
 
105
 
 
106
s.printCollectionInfo( "test.foo" , "after b findOne tests" );
 
107
 
 
108
print( "*** dropDatabase setup" )
 
109
 
 
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();
 
117
 
 
118
s.printCollectionInfo( "test.foo" , "after dropDatabase setup" );
 
119
doCounts( "after dropDatabase setup2" )
 
120
s.printCollectionInfo( "test.foo" , "after dropDatabase setup3" );
 
121
 
 
122
print( "*** ready to call dropDatabase" )
 
123
res = s.getDB( "test" ).dropDatabase();
 
124
assert.eq( 1 , res.ok , "dropDatabase failed : " + tojson( res ) );
 
125
 
 
126
s.printShardingStatus();
 
127
s.printCollectionInfo( "test.foo" , "after dropDatabase call 1" );
 
128
assert.eq( 0 , doCounts( "after dropDatabase called" ) )
 
129
 
 
130
s.stop();