jstests/sharding/shard_collection_existing_zones.js
/**
 * Test that shardCollection correctly validates shard key against existing zones.
 */
Test that shardCollection correctly validates shard key against existing zones.
Test that shardCollection correctly validates shard key against existing zones .
function testShardKeyValidation(proposedShardKey, numberLongMin, numberLongMax, success) {
    assert.commandWorked(testDB.foo.createIndex(proposedShardKey));
    assert.commandWorked(st.s.adminCommand({addShardToZone: shardName, zone: zoneName}));
    var zoneMin = numberLongMin ? {x: NumberLong(0)} : {x: 0};
    var zoneMax = numberLongMax ? {x: NumberLong(10)} : {x: 10};
    assert.commandWorked(
        st.s.adminCommand({updateZoneKeyRange: ns, min: zoneMin, max: zoneMax, zone: zoneName}));
    var tagDoc = configDB.tags.findOne();
    jsTestLog("xxx tag doc " + tojson(tagDoc));
    assert.eq(ns, tagDoc.ns);
    assert.eq(zoneMin, tagDoc.min);
    assert.eq(zoneMax, tagDoc.max);
    assert.eq(zoneName, tagDoc.tag);
    if (success) {
        assert.commandWorked(mongos.adminCommand({shardCollection: ns, key: proposedShardKey}));
    } else {
        assert.commandFailed(mongos.adminCommand({shardCollection: ns, key: proposedShardKey}));
    }
    assert.commandWorked(testDB.runCommand({drop: kCollName}));
}
function testShardKeyValidation ( proposedShardKey , numberLongMin , numberLongMax , success ) { assert . commandWorked ( testDB . foo . createIndex ( proposedShardKey ) ) ; assert . commandWorked ( st . s . adminCommand ( { addShardToZone : shardName , zone : zoneName } ) ) ; var zoneMin = numberLongMin ? { x : NumberLong ( 0 ) } : { x : 0 } ; var zoneMax = numberLongMax ? { x : NumberLong ( 10 ) } : { x : 10 } ; assert . commandWorked ( st . s . adminCommand ( { updateZoneKeyRange : ns , min : zoneMin , max : zoneMax , zone : zoneName } ) ) ; var tagDoc = configDB . tags . findOne ( ) ; jsTestLog ( "xxx tag doc " + tojson ( tagDoc ) ) ; assert . eq ( ns , tagDoc . ns ) ; assert . eq ( zoneMin , tagDoc . min ) ; assert . eq ( zoneMax , tagDoc . max ) ; assert . eq ( zoneName , tagDoc . tag ) ; if ( success ) { assert . commandWorked ( mongos . adminCommand ( { shardCollection : ns , key : proposedShardKey } ) ) ; } else { assert . commandFailed ( mongos . adminCommand ( { shardCollection : ns , key : proposedShardKey } ) ) ; } assert . commandWorked ( testDB . runCommand ( { drop : kCollName } ) ) ; }
Test that shardCollection correctly validates shard key against existing zones.
Test that shardCollection correctly validates shard key against existing zones .