diff options
author | Kevin Matulef <matulef@10gen.com> | 2012-11-29 13:30:23 -0500 |
---|---|---|
committer | Kevin Matulef <matulef@10gen.com> | 2012-11-29 13:30:39 -0500 |
commit | a54fd9e2707aa441a449a5cfe41c230ebc8ff80a (patch) | |
tree | 8334bec1203b9807b40a5b5a135daf228e31aa52 /jstests/sharding/hash_shard1.js | |
parent | f14a9e79cf5f9b09dec4758d2d2032ddf47373a3 (diff) | |
download | mongo-a54fd9e2707aa441a449a5cfe41c230ebc8ff80a.tar.gz |
SERVER-7674 add option to specify a chunk via its bounds
Diffstat (limited to 'jstests/sharding/hash_shard1.js')
-rw-r--r-- | jstests/sharding/hash_shard1.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/jstests/sharding/hash_shard1.js b/jstests/sharding/hash_shard1.js new file mode 100644 index 00000000000..d98ad302c23 --- /dev/null +++ b/jstests/sharding/hash_shard1.js @@ -0,0 +1,61 @@ +// Basic test of sharding with a hashed shard key +// - Test basic migrations with moveChunk, using different chunk specification methods + +var s = new ShardingTest( { name : jsTestName() , shards : 3 , mongos : 1, verbose : 1 } ); +var dbname = "test"; +var coll = "foo"; +var ns = dbname + "." + coll; +var db = s.getDB( dbname ); +var t = db.getCollection( coll ); +db.adminCommand( { enablesharding : dbname } ); + +// for simplicity start by turning off balancer +s.stopBalancer(); + +// shard a fresh collection using a hashed shard key +t.drop(); +var res = db.adminCommand( { shardcollection : ns , key : { a : "hashed" } } ); +assert.eq( res.ok , 1 , "shardcollection didn't work" ); +db.printShardingStatus(); + +// insert stuff +var numitems = 1000; +for(i = 0; i < numitems; i++ ){ + t.insert( { a: i } ) +} +// check they all got inserted +assert.eq( t.find().count() , numitems , "count off after inserts" ); +printjson( t.find().explain() ); + +// find a chunk that's not on shard0000 +var chunk = s.config.chunks.findOne( {shard : {$ne : "shard0000"} } ); +printjson(chunk); + +// try to move the chunk using an invalid specification method. should fail. +var res = db.adminCommand( { movechunk : ns , + find : { a : 0 } , + bounds : [ chunk.min , chunk.max ] , + to: "shard0000" } ); +assert.eq( res.ok , 0 , "moveChunk shouldn't work with invalid specification method") + +// now move a chunk using the lower/upper bound method. should work. +var res = db.adminCommand( { movechunk : ns , + bounds : [ chunk.min , chunk.max ] , + to: "shard0000" } ); +printjson( res ); +assert.eq( res.ok , 1 , "movechunk using lower/upper bound method didn't work " ); + +// check count still correct. +assert.eq( t.find().itcount() , numitems , "count off after migrate" ); +printjson( t.find().explain() ); + +// move a chunk using the find method +var res = db.adminCommand( { movechunk : ns , find : { a : 2 } , to: "shard0002" } ); +printjson( res ); +assert.eq( res.ok , 1 , "movechunk using find query didn't work" ); + +// check counts still correct +assert.eq( t.find().itcount() , numitems , "count off after migrate" ); +printjson( t.find().explain() ); + +s.stop() |