summaryrefslogtreecommitdiff
path: root/jstests/sharding/update_zone_key_range.js
blob: b4babb0f4411077ac54a25c0a5f4b1e0569760b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
 * Basic integration tests for updateZoneKeyRange command. More detailed tests can be found
 * in sharding_catalog_assign_key_range_to_zone_test.cpp.
 */
(function() {
    var st = new ShardingTest({shards: 1});

    var configDB = st.s.getDB('config');
    var shardName = configDB.shards.findOne()._id;

    assert.commandWorked(st.s.adminCommand({addShardToZone: shardName, zone: 'x'}));
    assert.commandWorked(st.s.adminCommand({enableSharding: 'test'}));
    assert.commandWorked(st.s.adminCommand({shardCollection: 'test.user', key: {x: 1}}));

    // Testing basic assign.
    assert.commandWorked(
        st.s.adminCommand({updateZoneKeyRange: 'test.user', min: {x: 0}, max: {x: 10}, zone: 'x'}));

    var tagDoc = configDB.tags.findOne();

    assert.eq('test.user', tagDoc.ns);
    assert.eq({x: 0}, tagDoc.min);
    assert.eq({x: 10}, tagDoc.max);
    assert.eq('x', tagDoc.tag);

    // Cannot assign overlapping ranges
    assert.commandFailedWithCode(
        st.s.adminCommand(
            {updateZoneKeyRange: 'test.user', min: {x: -10}, max: {x: 20}, zone: 'x'}),
        ErrorCodes.RangeOverlapConflict);

    tagDoc = configDB.tags.findOne();
    assert.eq('test.user', tagDoc.ns);
    assert.eq({x: 0}, tagDoc.min);
    assert.eq({x: 10}, tagDoc.max);
    assert.eq('x', tagDoc.tag);

    // Testing basic remove.
    assert.commandWorked(st.s.adminCommand(
        {updateZoneKeyRange: 'test.user', min: {x: 0}, max: {x: 10}, zone: null}));

    assert.eq(null, configDB.tags.findOne());

    st.stop();
})();