summaryrefslogtreecommitdiff
path: root/jstests/sharding/server_status.js
blob: 3c6bc24d1ceadd14b20e50e3f96af88f4de31840 (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
/**
 * Basic test for the 'sharding' section of the serverStatus response object for
 * both mongos and the shard.
 */

(function() {
"use strict";

var st = new ShardingTest({shards: 1});

var testDB = st.s.getDB('test');
testDB.adminCommand({enableSharding: 'test'});
testDB.adminCommand({shardCollection: 'test.user', key: {_id: 1}});

// Initialize shard metadata in shards
testDB.user.insert({x: 1});

var checkShardingServerStatus = function(doc) {
    var shardingSection = doc.sharding;
    assert.neq(shardingSection, null);

    var configConnStr = shardingSection.configsvrConnectionString;
    var configConn = new Mongo(configConnStr);
    var configHello = configConn.getDB('admin').runCommand({hello: 1});

    var configOpTimeObj = shardingSection.lastSeenConfigServerOpTime;

    assert.gt(configConnStr.indexOf('/'), 0);
    assert.gte(configHello.configsvr, 1);  // If it's a shard, this field won't exist.
    assert.neq(null, configOpTimeObj);
    assert.neq(null, configOpTimeObj.ts);
    assert.neq(null, configOpTimeObj.t);

    assert.neq(null, shardingSection.maxChunkSizeInBytes);
};

var mongosServerStatus = testDB.adminCommand({serverStatus: 1});
checkShardingServerStatus(mongosServerStatus);

var mongodServerStatus = st.rs0.getPrimary().getDB('admin').runCommand({serverStatus: 1});
checkShardingServerStatus(mongodServerStatus);

st.stop();
})();