jstests/sharding/compound_hashed_shard_key_zoning.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 testZoningBeforeSharding({shardKey, zoneRange, failCode}) {
    assert.commandWorked(testDB.foo.createIndex(shardKey));
    assert.commandWorked(st.s.adminCommand({addShardToZone: shardName, zone: zoneName}));
    assert.commandWorked(st.s.adminCommand(
        {updateZoneKeyRange: ns, min: zoneRange[0], max: zoneRange[1], zone: zoneName}));
    assert.eq(1, configDB.tags.count({ns: ns, min: zoneRange[0], max: zoneRange[1]}));
    if (failCode) {
        assert.commandFailedWithCode(mongos.adminCommand({shardCollection: ns, key: shardKey}),
                                     failCode);
    } else {
        assert.commandWorked(mongos.adminCommand({shardCollection: ns, key: shardKey}));
    }
    assert.commandWorked(testDB.runCommand({drop: kCollName}));
}
function testZoningBeforeSharding ( { shardKey , zoneRange , failCode } ) { assert . commandWorked ( testDB . foo . createIndex ( shardKey ) ) ; assert . commandWorked ( st . s . adminCommand ( { addShardToZone : shardName , zone : zoneName } ) ) ; assert . commandWorked ( st . s . adminCommand ( { updateZoneKeyRange : ns , min : zoneRange [ 0 ] , max : zoneRange [ 1 ] , zone : zoneName } ) ) ; assert . eq ( 1 , configDB . tags . count ( { ns : ns , min : zoneRange [ 0 ] , max : zoneRange [ 1 ] } ) ) ; if ( failCode ) { assert . commandFailedWithCode ( mongos . adminCommand ( { shardCollection : ns , key : shardKey } ) , failCode ) ; } else { assert . commandWorked ( mongos . adminCommand ( { shardCollection : ns , key : shardKey } ) ) ; } 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 .
// Update zone range and verify that the 'tags' collection is updated appropriately.