jstests/sharding/shard_collection_existing_zones.js
/**
 * Test that shardCollection correctly validates that a zone is associated with a shard.
 */
Test that shardCollection correctly validates that a zone is associated with a shard.
Test that shardCollection correctly validates that a zone is associated with a shard .
function testShardZoneAssociationValidation(proposedShardKey, numberLongMin, numberLongMax) {
    var zoneMin = numberLongMin ? {x: NumberLong(0)} : {x: 0};
    var zoneMax = numberLongMax ? {x: NumberLong(10)} : {x: 10};
    assert.commandWorked(configDB.tags.insert(
        {_id: {ns: ns, min: zoneMin}, ns: ns, min: zoneMin, max: zoneMax, tag: zoneName}));
    var tagDoc = configDB.tags.findOne();
    assert.eq(ns, tagDoc.ns);
    assert.eq(zoneMin, tagDoc.min);
    assert.eq(zoneMax, tagDoc.max);
    assert.eq(zoneName, tagDoc.tag);
    assert.commandFailed(mongos.adminCommand({shardCollection: ns, key: proposedShardKey}));
    assert.commandWorked(st.s.adminCommand({addShardToZone: shardName, zone: zoneName}));
    assert.commandWorked(mongos.adminCommand({shardCollection: ns, key: proposedShardKey}));
    assert.commandWorked(testDB.runCommand({drop: kCollName}));
}
function testShardZoneAssociationValidation ( proposedShardKey , numberLongMin , numberLongMax ) { var zoneMin = numberLongMin ? { x : NumberLong ( 0 ) } : { x : 0 } ; var zoneMax = numberLongMax ? { x : NumberLong ( 10 ) } : { x : 10 } ; assert . commandWorked ( configDB . tags . insert ( { _id : { ns : ns , min : zoneMin } , ns : ns , min : zoneMin , max : zoneMax , tag : zoneName } ) ) ; var tagDoc = configDB . tags . findOne ( ) ; assert . eq ( ns , tagDoc . ns ) ; assert . eq ( zoneMin , tagDoc . min ) ; assert . eq ( zoneMax , tagDoc . max ) ; assert . eq ( zoneName , tagDoc . tag ) ; assert . commandFailed ( mongos . adminCommand ( { shardCollection : ns , key : proposedShardKey } ) ) ; assert . commandWorked ( st . s . adminCommand ( { addShardToZone : shardName , zone : zoneName } ) ) ; assert . commandWorked ( mongos . adminCommand ( { shardCollection : ns , key : proposedShardKey } ) ) ; assert . commandWorked ( testDB . runCommand ( { drop : kCollName } ) ) ; }
Test that shardCollection correctly validates that a zone is associated with a shard.
Test that shardCollection correctly validates that a zone is associated with a shard .