mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
Sharding: unit test with string as a shard key
This commit is contained in:
parent
5113d30da5
commit
e0eafa5694
40
jstests/sharding/key_string.js
Normal file
40
jstests/sharding/key_string.js
Normal file
@ -0,0 +1,40 @@
|
||||
// key_string.js
|
||||
|
||||
s = new ShardingTest( "keystring" , 2 );
|
||||
|
||||
db = s.getDB( "test" );
|
||||
s.adminCommand( { partition : "test" } )
|
||||
s.adminCommand( { shard : "test.foo" , key : { name : 1 } } );
|
||||
|
||||
primary = s.getServer( "test" ).getDB( "test" );
|
||||
seconday = s.getOther( primary ).getDB( "test" );
|
||||
|
||||
assert.eq( 1 , s.config.shard.count() , "sanity check A" );
|
||||
|
||||
db.foo.save( { name : "eliot" } )
|
||||
db.foo.save( { name : "sara" } )
|
||||
db.foo.save( { name : "bob" } )
|
||||
db.foo.save( { name : "joe" } )
|
||||
db.foo.save( { name : "mark" } )
|
||||
db.foo.save( { name : "allan" } )
|
||||
|
||||
s.adminCommand( { split : "test.foo" , find : { name : "joe" } } );
|
||||
s.adminCommand( { split : "test.foo" , find : { name : "joe" } } );
|
||||
s.adminCommand( { split : "test.foo" , find : { name : "joe" } } );
|
||||
|
||||
s.adminCommand( { moveshard : "test.foo" , find : { name : "joe" } , to : seconday.getMongo().name } );
|
||||
|
||||
print( s.config.shard.find().toArray().tojson( "\n" ) );
|
||||
|
||||
assert.eq( 4 , primary.foo.find().toArray().length , "primary count" );
|
||||
assert.eq( 2 , seconday.foo.find().toArray().length , "secondary count" );
|
||||
|
||||
assert.eq( 6 , db.foo.find().toArray().length , "total count" );
|
||||
assert.eq( 6 , db.foo.find().sort( { name : 1 } ).toArray().length , "total count sorted" );
|
||||
|
||||
assert.eq( "allan,bob,eliot,joe,mark,sara" , db.foo.find().sort( { name : 1 } ).toArray().map( function(z){ return z.name; } ) , "sort 1" );
|
||||
assert.eq( "sara,mark,joe,eliot,bob,allan" , db.foo.find().sort( { name : -1 } ).toArray().map( function(z){ return z.name; } ) , "sort 2" );
|
||||
|
||||
s.stop();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user