summaryrefslogtreecommitdiff
path: root/jstests/sharding/mongos_no_detect_sharding.js
blob: 8fedcb09ce23a4009973e75290b28303fd2df81f (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
// Tests whether new sharding is detected on insert by mongos
(function() {

    var st = new ShardingTest({name: "mongos_no_detect_sharding", shards: 1, mongos: 2});

    var mongos = st.s;
    var config = mongos.getDB("config");

    print("Creating unsharded connection...");

    var mongos2 = st._mongos[1];

    var coll = mongos2.getCollection("test.foo");
    assert.writeOK(coll.insert({i: 0}));

    print("Sharding collection...");

    var admin = mongos.getDB("admin");

    assert.eq(coll.getShardVersion().ok, 0);

    admin.runCommand({enableSharding: "test"});
    admin.runCommand({shardCollection: "test.foo", key: {_id: 1}});

    print("Seeing if data gets inserted unsharded...");
    print("No splits occur here!");

    // Insert a bunch of data which should trigger a split
    var bulk = coll.initializeUnorderedBulkOp();
    for (var i = 0; i < 100; i++) {
        bulk.insert({i: i + 1});
    }
    assert.writeOK(bulk.execute());

    st.printShardingStatus(true);

    assert.eq(coll.getShardVersion().ok, 1);
    assert.eq(101, coll.find().itcount());

    st.stop();

})();