diff options
Diffstat (limited to 'jstests/check_shard_index.js')
-rw-r--r-- | jstests/check_shard_index.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/jstests/check_shard_index.js b/jstests/check_shard_index.js new file mode 100644 index 0000000..a5a1fc1 --- /dev/null +++ b/jstests/check_shard_index.js @@ -0,0 +1,45 @@ +// ------------------------- +// CHECKSHARDINGINDEX TEST UTILS +// ------------------------- + +f = db.jstests_shardingindex; +f.drop(); + + +// ------------------------- +// Case 1: all entries filled or empty should make a valid index +// + +f.drop(); +f.ensureIndex( { x: 1 , y: 1 } ); +assert.eq( 0 , f.count() , "1. initial count should be zero" ); + +res = db.runCommand( { checkShardingIndex: "test.jstests_shardingindex" , keyPattern: {x:1, y:1} , force: true }); +assert.eq( true , res.ok, "1a" ); + +f.save( { x: 1 , y : 1 } ); +assert.eq( 1 , f.count() , "1. count after initial insert should be 1" ); +res = db.runCommand( { checkShardingIndex: "test.jstests_shardingindex" , keyPattern: {x:1, y:1} , force: true }); +assert.eq( true , res.ok , "1b" ); + + +// ------------------------- +// Case 2: entry with null values would make an index unsuitable +// + +f.drop(); +f.ensureIndex( { x: 1 , y: 1 } ); +assert.eq( 0 , f.count() , "2. initial count should be zero" ); + +f.save( { x: 1 , y : 1 } ); +f.save( { x: null , y : 1 } ); + +res = db.runCommand( { checkShardingIndex: "test.jstests_shardingindex" , keyPattern: {x:1, y:1} , force: true }); +assert.eq( true , res.ok , "2a " + tojson(res) ); + +f.save( { y: 2 } ); +assert.eq( 3 , f.count() , "2. count after initial insert should be 3" ); +res = db.runCommand( { checkShardingIndex: "test.jstests_shardingindex" , keyPattern: {x:1, y:1} , force: true }); +assert.eq( false , res.ok , "2b " + tojson(res) ); + +print("PASSED"); |