jstests/sharding/compound_hashed_shard_key_presplitting.js
/**
 * Helper function to validate that the chunks ranges have all the shard key fields and each shard
 * has expected number of chunks.
 */
Helper function to validate that the chunks ranges have all the shard key fields and each shard
has expected number of chunks.
Helper function to validate that the chunks ranges have all the shard key fields and each shard has expected number of chunks .
function checkValidChunks(coll, shardKey, expectedChunks) {
    const chunks = findChunksUtil.findChunksByNs(st.config, coll.getFullName()).toArray();
    let shardCountsMap =
        {[st.shard0.shardName]: 0, [st.shard1.shardName]: 0, [st.shard2.shardName]: 0};
    for (let chunk of chunks) {
        shardCountsMap[chunk.shard]++;
        const assertHasAllShardKeyFields = function(obj) {
            assert.eq(Object.keys(shardKey).length, Object.keys(obj).length, tojson(obj));
            for (let key in obj) {
                assert(key in shardKey, tojson(obj));
            }
        };
        assertHasAllShardKeyFields(chunk.min);
        assertHasAllShardKeyFields(chunk.max);
    }
    let index = 0;
    for (let shardName in shardCountsMap) {
        assert.eq(expectedChunks[index++],
                  shardCountsMap[shardName],
                  "Expected chunks did not match for " + shardName + ". " + tojson(chunks));
    }
}
function checkValidChunks ( coll , shardKey , expectedChunks ) { const chunks = findChunksUtil . findChunksByNs ( st . config , coll . getFullName ( ) ) . toArray ( ) ; let shardCountsMap = { [ st . shard0 . shardName ] : 0 , [ st . shard1 . shardName ] : 0 , [ st . shard2 . shardName ] : 0 } ; for ( let chunk of chunks ) { shardCountsMap [ chunk . shard ] ++ ; const assertHasAllShardKeyFields = function ( obj ) { assert . eq ( Object . keys ( shardKey ) . length , Object . keys ( obj ) . length , tojson ( obj ) ) ; for ( let key in obj ) { assert ( key in shardKey , tojson ( obj ) ) ; } } ; assertHasAllShardKeyFields ( chunk . min ) ; assertHasAllShardKeyFields ( chunk . max ) ; } let index = 0 ; for ( let shardName in shardCountsMap ) { assert . eq ( expectedChunks [ index ++ ] , shardCountsMap [ shardName ] , "Expected chunks did not match for " + shardName + ". " + tojson ( chunks ) ) ; } }
Helper function to validate that the chunks ranges have all the shard key fields and each shard
 has expected number of chunks.
Helper function to validate that the chunks ranges have all the shard key fields and each shard has expected number of chunks .