diff options
author | Jonathan Abrahams <jonathan@mongodb.com> | 2015-02-17 16:40:46 -0500 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2015-02-17 16:57:53 -0500 |
commit | c678bbf6a492e79734a20f2ee768c67f026028cc (patch) | |
tree | 2b91f93aca19c6d9d14726da0ac56182d05deec4 /jstests/sharding/tag_range.js | |
parent | 490b0b2b14fa14b463ef612b79386d20d95b4057 (diff) | |
download | mongo-c678bbf6a492e79734a20f2ee768c67f026028cc.tar.gz |
SERVER-15885: addTagRange & removeTagRange additional tests
Signed-off-by: Randolph Tan <randolph@10gen.com>
Diffstat (limited to 'jstests/sharding/tag_range.js')
-rw-r--r-- | jstests/sharding/tag_range.js | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/jstests/sharding/tag_range.js b/jstests/sharding/tag_range.js index 2ac4816bdbf..8d8244c82c1 100644 --- a/jstests/sharding/tag_range.js +++ b/jstests/sharding/tag_range.js @@ -1,34 +1,79 @@ // tests to make sure that tag ranges are added/removed/updated successfully +function countTags( num, message ) { + assert.eq( s.config.tags.count() , num , message ); +} + s = new ShardingTest( "tag_range" , 2 , 0 , 1 , { nopreallocj : true } ); // this set up is not required but prevents warnings in the remove db = s.getDB( "tag_range" ); -s.adminCommand( { enableSharding : "test" } ) +s.adminCommand( { enableSharding : "test" } ); s.adminCommand( { shardCollection : "test.tag_range" , key : { _id : 1 } } ); assert.eq( 1 , s.config.chunks.count() ); -sh.addShardTag( "shard0000" , "a" ) +sh.addShardTag( "shard0000" , "a" ); // add two ranges, verify the additions sh.addTagRange( "test.tag_range" , { _id : 5 } , { _id : 10 } , "a" ); sh.addTagRange( "test.tag_range" , { _id : 10 } , { _id : 15 } , "b" ); -assert.eq( 2 , s.config.tags.count() , "tag ranges were not successfully added" ); +countTags( 2 , "tag ranges were not successfully added" ); // remove the second range, should be left with one sh.removeTagRange( "test.tag_range" , { _id : 10 } , { _id : 15 } , "b" ); -assert.eq( 1 , s.config.tags.count() , "tag range not removed successfully" ); +countTags( 1 , "tag range not removed successfully" ); // the additions are actually updates, so you can alter a range's max sh.addTagRange( "test.tag_range" , { _id : 5 } , { _id : 11 } , "a" ); assert.eq( 11 , s.config.tags.findOne().max._id , "tag range not updated successfully" ); -s.stop(); +// add range min=max, verify the additions + +try { + sh.addTagRange( "test.tag_range" , { _id : 20 } , { _id : 20 } , "a" ); +} catch (e) { + countTags( 1 , "tag range should not have been added" ); +} + +// removeTagRange tests for tag ranges that do not exist + +// Bad namespace +sh.removeTagRange("badns", { _id : 5 }, { _id : 11 }, "a"); +countTags(1 , "Bad namespace: tag range does not exist"); + +// Bad tag +sh.removeTagRange("test.tag_range", { _id : 5 }, { _id : 11 }, "badtag"); +countTags(1 , "Bad tag: tag range does not exist"); + +// Bad min +sh.removeTagRange("test.tag_range", { _id : 0 }, { _id : 11 }, "a"); +countTags(1 , "Bad min: tag range does not exist"); +// Bad max +sh.removeTagRange("test.tag_range", { _id : 5 }, { _id : 12 }, "a"); +countTags(1 , "Bad max: tag range does not exist"); + +// Invalid namesapce +sh.removeTagRange(35, { _id : 5 }, { _id : 11 }, "a"); +countTags(1 , "Invalid namespace: tag range does not exist"); + +// Invalid tag +sh.removeTagRange("test.tag_range", { _id : 5 }, { _id : 11 }, 35); +countTags(1 , "Invalid tag: tag range does not exist"); + +// Invalid min +sh.removeTagRange("test.tag_range", 35, { _id : 11 }, "a"); +countTags(1 , "Invalid min: tag range does not exist"); + +// Invalid max +sh.removeTagRange("test.tag_range", { _id : 5 }, 35, "a"); +countTags(1 , "Invalid max: tag range does not exist"); + +s.stop(); |