summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Mulrow <jack.mulrow@mongodb.com>2017-04-10 11:55:13 -0400
committerJack Mulrow <jack.mulrow@mongodb.com>2017-04-19 13:26:47 -0400
commit3483a1c42f9d5f3fd38e671684e9157821cf48df (patch)
treecdfb706389798ffb217f4955fc3dc40b8a2d926a
parent41d5d369508592a2c1ebaaaac48fe2b3680e0615 (diff)
downloadmongo-3483a1c42f9d5f3fd38e671684e9157821cf48df.tar.gz
SERVER-28451 API integration test for logicalTime
-rw-r--r--buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml3
-rw-r--r--jstests/sharding/logical_time_api.js98
2 files changed, 100 insertions, 1 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
index 9ba49b790f3..1b2fd9cb6b3 100644
--- a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
+++ b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos_and_mixed_shards.yml
@@ -19,7 +19,8 @@ selector:
- jstests/sharding/view_rewrite.js
# New feature in v3.6 mongos
- jstests/sharding/logical_time_metadata.js
- # New feature in v3.6 mongos and mongods.
+ # New feature in v3.6 mongos and mongod.
+ - jstests/sharding/logical_time_api.js
- jstests/sharding/operation_time_api.js
executor:
diff --git a/jstests/sharding/logical_time_api.js b/jstests/sharding/logical_time_api.js
new file mode 100644
index 00000000000..fc8a03ceb35
--- /dev/null
+++ b/jstests/sharding/logical_time_api.js
@@ -0,0 +1,98 @@
+/**
+ * Tests the logicalTime API for the following topologies:
+ * - mongos talking to a sharded replica set (sharded and unsharded collections)
+ * - mongod from a sharded replica set
+ * - mongod from a non-sharded replica set
+ * - standalone mongod
+ *
+ * Expects logicalTime to come in the commandReply from a mongos and the metadata from a mongod.
+ */
+(function() {
+ "use strict";
+
+ // Returns true if the given object contains a logicalTime BSON object in the following format:
+ // logicalTime: {
+ // clusterTime: <Timestamp>
+ // signature: {
+ // hash: <BinData>
+ // keyId: <NumberLong>
+ // }
+ // }
+ function containsValidLogicalTimeBson(obj) {
+ if (!obj) {
+ return false;
+ }
+
+ var logicalTime = obj.logicalTime;
+ return logicalTime && isType(logicalTime, "BSON") &&
+ isType(logicalTime.clusterTime, "Timestamp") && isType(logicalTime.signature, "BSON") &&
+ isType(logicalTime.signature.hash, "BinData") &&
+ isType(logicalTime.signature.keyId, "NumberLong");
+ }
+
+ function isType(val, typeString) {
+ assert.eq(Object.prototype.toString.call(val),
+ "[object " + typeString + "]",
+ "expected: " + val + ", to be of type: " + typeString);
+ return true;
+ }
+
+ // A mongos that talks to a non-sharded collection on a sharded replica set returns a
+ // logicalTime BSON object that matches the expected format.
+ var st = new ShardingTest({name: "logical_time_api", shards: {rs0: {nodes: 1}}});
+
+ var testDB = st.s.getDB("test");
+ var res = testDB.runCommandWithMetadata("insert", {insert: "foo", documents: [{x: 1}]}, {});
+ assert.commandWorked(res.commandReply);
+ assert(containsValidLogicalTimeBson(res.commandReply),
+ "Expected commandReply from a mongos talking to a non-sharded collection on a sharded " +
+ "replica set to contain logicalTime, received: " + tojson(res.commandReply));
+
+ // A mongos that talks to a sharded collection on a sharded replica set returns a
+ // logicalTime BSON object that matches the expected format.
+ assert.commandWorked(st.s.adminCommand({enableSharding: "test"}));
+ assert.commandWorked(st.s.adminCommand({shardCollection: "test.bar", key: {x: 1}}));
+
+ res = testDB.runCommandWithMetadata("insert", {insert: "bar", documents: [{x: 2}]}, {});
+ assert.commandWorked(res.commandReply);
+ assert(containsValidLogicalTimeBson(res.commandReply),
+ "Expected commandReply from a mongos talking to a sharded collection on a sharded " +
+ "replica set to contain logicalTime, received: " + tojson(res.commandReply));
+
+ // A mongod in a sharded replica set returns a logicalTime bson that matches the expected
+ // format.
+ testDB = st.rs0.getPrimary().getDB("test");
+ res = testDB.runCommandWithMetadata("insert", {insert: "foo", documents: [{x: 3}]}, {});
+ assert.commandWorked(res.commandReply);
+ assert(containsValidLogicalTimeBson(res.metadata),
+ "Expected metadata in response from a mongod in a sharded replica set to contain " +
+ "logicalTime, received: " + tojson(res.metadata));
+
+ st.stop();
+
+ // A mongod from a non-sharded replica set does not return logicalTime.
+ var replTest = new ReplSetTest({name: "logical_time_api_non_sharded_replset", nodes: 1});
+ replTest.startSet();
+ replTest.initiate();
+
+ testDB = replTest.getPrimary().getDB("test");
+ res = testDB.runCommandWithMetadata("insert", {insert: "foo", documents: [{x: 4}]}, {});
+ assert.commandWorked(res.commandReply);
+ assert(!containsValidLogicalTimeBson(res.metadata),
+ "Expected metadata in response from a mongod in a non-sharded replica set to not " +
+ "contain logicalTime, received: " + tojson(res.metadata));
+
+ replTest.stopSet();
+
+ // A standalone mongod does not return logicalTime.
+ var standalone = MongoRunner.runMongod();
+
+ testDB = standalone.getDB("test");
+ res = testDB.runCommandWithMetadata("insert", {insert: "foo", documents: [{x: 5}]}, {});
+ assert.commandWorked(res.commandReply);
+ assert(!containsValidLogicalTimeBson(res.metadata),
+ "Expected metadata in response from a standalone mongod to not contain logicalTime, " +
+ "received: " + tojson(res.metadata));
+
+ MongoRunner.stopMongod(standalone);
+})();