From e0eafa5694b32672ffa8ce4204ecaf0d342aac0e Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Wed, 22 Apr 2009 10:53:28 -0400 Subject: [PATCH] Sharding: unit test with string as a shard key --- jstests/sharding/key_string.js | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 jstests/sharding/key_string.js diff --git a/jstests/sharding/key_string.js b/jstests/sharding/key_string.js new file mode 100644 index 00000000000..06be93f320c --- /dev/null +++ b/jstests/sharding/key_string.js @@ -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(); + +