diff options
Diffstat (limited to 'jstests/sharding/index1.js')
-rw-r--r-- | jstests/sharding/index1.js | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/jstests/sharding/index1.js b/jstests/sharding/index1.js index 57092b3a566..7f0cea49cf0 100644 --- a/jstests/sharding/index1.js +++ b/jstests/sharding/index1.js @@ -6,8 +6,8 @@ var s = new ShardingTest({ name: "shard_index", shards: 2, mongos: 1 }); // Regenerate fully because of SERVER-2782 for ( var i = 0; i < 22; i++ ) { - var coll = s.admin._mongo.getDB( "test" ).getCollection( "foo" + i ) - coll.drop() + var coll = s.admin._mongo.getDB( "test" ).getCollection( "foo" + i ); + coll.drop(); var bulk = coll.initializeUnorderedBulkOp(); for ( var j = 0; j < 300; j++ ) { @@ -20,150 +20,150 @@ for ( var i = 0; i < 22; i++ ) { s.ensurePrimaryShard(coll.getDB().getName(), 'shard0001'); } - print("\n\n\n\n\nTest # " + i) + print("\n\n\n\n\nTest # " + i); if ( i == 0 ) { // Unique index exists, but not the right one. - coll.ensureIndex( { num : 1 }, { unique : true } ) - coll.ensureIndex( { x : 1 } ) + coll.ensureIndex( { num : 1 }, { unique : true } ); + coll.ensureIndex( { x : 1 } ); - passed = false + passed = false; try { - s.adminCommand( { shardcollection : "" + coll, key : { x : 1 } } ) - passed = true + s.adminCommand( { shardcollection : "" + coll, key : { x : 1 } } ); + passed = true; } catch (e) { - print( e ) + print( e ); } - assert( !passed, "Should not shard collection when another unique index exists!") + assert( !passed, "Should not shard collection when another unique index exists!"); } if ( i == 1 ) { // Unique index exists as prefix, also index exists - coll.ensureIndex( { x : 1 } ) - coll.ensureIndex( { x : 1, num : 1 }, { unique : true } ) + coll.ensureIndex( { x : 1 } ); + coll.ensureIndex( { x : 1, num : 1 }, { unique : true } ); try{ - s.adminCommand({ shardcollection : "" + coll, key : { x : 1 } }) + s.adminCommand({ shardcollection : "" + coll, key : { x : 1 } }); } catch(e){ - print(e) - assert( false, "Should be able to shard non-unique index without unique option.") + print(e); + assert( false, "Should be able to shard non-unique index without unique option."); } } if ( i == 2 ) { // Non-unique index exists as prefix, also index exists. No unique index. - coll.ensureIndex( { x : 1 } ) - coll.ensureIndex( { x : 1, num : 1 } ) + coll.ensureIndex( { x : 1 } ); + coll.ensureIndex( { x : 1, num : 1 } ); passed = false; try{ - s.adminCommand({ shardcollection : "" + coll, key : { x : 1 } }) + s.adminCommand({ shardcollection : "" + coll, key : { x : 1 } }); passed = true; } catch( e ){ - print(e) - assert( !passed, "Should be able to shard collection with no unique index if unique not specified.") + print(e); + assert( !passed, "Should be able to shard collection with no unique index if unique not specified."); } } if ( i == 3 ) { // Unique index exists as prefix, also unique index exists - coll.ensureIndex( { num : 1 }, { unique : true }) - coll.ensureIndex( { num : 1 , x : 1 }, { unique : true } ) + coll.ensureIndex( { num : 1 }, { unique : true }); + coll.ensureIndex( { num : 1 , x : 1 }, { unique : true } ); try{ - s.adminCommand({ shardcollection : "" + coll, key : { num : 1 }, unique : true }) + s.adminCommand({ shardcollection : "" + coll, key : { num : 1 }, unique : true }); } catch( e ){ - print(e) - assert( false, "Should be able to shard collection with unique prefix index.") + print(e); + assert( false, "Should be able to shard collection with unique prefix index."); } } if ( i == 4 ) { // Unique index exists as id, also unique prefix index exists - coll.ensureIndex( { _id : 1, num : 1 }, { unique : true } ) + coll.ensureIndex( { _id : 1, num : 1 }, { unique : true } ); try{ - s.adminCommand({ shardcollection : "" + coll, key : { _id : 1 }, unique : true }) + s.adminCommand({ shardcollection : "" + coll, key : { _id : 1 }, unique : true }); } catch( e ){ - print(e) - assert( false, "Should be able to shard collection with unique id index.") + print(e); + assert( false, "Should be able to shard collection with unique id index."); } } if ( i == 5 ) { // Unique index exists as id, also unique prefix index exists - coll.ensureIndex( { _id : 1, num : 1 }, { unique : true } ) + coll.ensureIndex( { _id : 1, num : 1 }, { unique : true } ); try{ - s.adminCommand({ shardcollection : "" + coll, key : { _id : 1, num : 1 }, unique : true }) + s.adminCommand({ shardcollection : "" + coll, key : { _id : 1, num : 1 }, unique : true }); } catch( e ){ - print(e) - assert( false, "Should be able to shard collection with unique combination id index.") + print(e); + assert( false, "Should be able to shard collection with unique combination id index."); } } if ( i == 6 ) { - coll.remove({}) + coll.remove({}); // Unique index does not exist, also unique prefix index exists - coll.ensureIndex( { num : 1, _id : 1 }, { unique : true } ) + coll.ensureIndex( { num : 1, _id : 1 }, { unique : true } ); try{ - s.adminCommand({ shardcollection : "" + coll, key : { num : 1 }, unique : true }) + s.adminCommand({ shardcollection : "" + coll, key : { num : 1 }, unique : true }); } catch( e ){ - print(e) - assert( false, "Should be able to shard collection with no unique index but with a unique prefix index.") + print(e); + assert( false, "Should be able to shard collection with no unique index but with a unique prefix index."); } - printjson( coll.getIndexes() ) + printjson( coll.getIndexes() ); // Make sure the index created is unique! assert.eq( 1, coll.getIndexes().filter( function(z) { return friendlyEqual( z.key, { num : 1 } ) && z.unique; } ).length ); } if ( i == 7 ) { - coll.remove({}) + coll.remove({}); // No index exists try{ - assert.eq( coll.find().itcount(), 0 ) - s.adminCommand({ shardcollection : "" + coll, key : { num : 1 } }) + assert.eq( coll.find().itcount(), 0 ); + s.adminCommand({ shardcollection : "" + coll, key : { num : 1 } }); } catch( e ){ - print(e) - assert( false, "Should be able to shard collection with no index on shard key.") + print(e); + assert( false, "Should be able to shard collection with no index on shard key."); } } if ( i == 8 ) { - coll.remove({}) + coll.remove({}); // No index exists - passed = false + passed = false; try{ - assert.eq( coll.find().itcount(), 0 ) - s.adminCommand({ shardcollection : "" + coll, key : { num : 1 }, unique : true }) - passed = true + assert.eq( coll.find().itcount(), 0 ); + s.adminCommand({ shardcollection : "" + coll, key : { num : 1 }, unique : true }); + passed = true; } catch( e ){ - print(e) + print(e); } - assert( passed, "Should be able to shard collection with unique flag but with no unique index on shard key, if coll empty.") + assert( passed, "Should be able to shard collection with unique flag but with no unique index on shard key, if coll empty."); - printjson( coll.getIndexes() ) + printjson( coll.getIndexes() ); // Make sure the index created is unique! assert.eq( 1, coll.getIndexes().filter( function(z) { return friendlyEqual( z.key, { num : 1 } ) && z.unique; } ).length ); @@ -171,17 +171,17 @@ for ( var i = 0; i < 22; i++ ) { if ( i == 9 ) { // Unique index exists on a different field as well - coll.ensureIndex( { num : 1 }, { unique : true } ) - coll.ensureIndex( { x : 1 } ) + coll.ensureIndex( { num : 1 }, { unique : true } ); + coll.ensureIndex( { x : 1 } ); - passed = false + passed = false; try { - s.adminCommand( { shardcollection : "" + coll, key : { x : 1 } } ) - passed = true + s.adminCommand( { shardcollection : "" + coll, key : { x : 1 } } ); + passed = true; } catch (e) { - print( e ) + print( e ); } - assert( !passed, "Should not shard collection when another unique index exists!" ) + assert( !passed, "Should not shard collection when another unique index exists!" ); } if ( i == 10 ){ @@ -214,7 +214,7 @@ for ( var i = 0; i < 22; i++ ) { assert.eq( 2, coll.getIndexes().length ); } if ( i == 11 ){ - coll.remove({}) + coll.remove({}); //empty collection with useful index. check new index not created coll.ensureIndex( {num : 1, x : 1} ); @@ -297,7 +297,7 @@ for ( var i = 0; i < 22; i++ ) { if ( i == 16 ) { // create hashed index, but try to declare it unique when sharding - coll.ensureIndex( { num : "hashed"} ) + coll.ensureIndex( { num : "hashed"} ); passed = false; try{ |