summaryrefslogtreecommitdiff
path: root/jstests/sharding/move_chunk_find_and_modify_with_write_retryability.js
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2017-09-19 14:44:36 -0400
committerRandolph Tan <randolph@10gen.com>2017-09-26 19:11:04 -0400
commit85d9721c00d7020af78fe60453f8362380fe697d (patch)
tree197240934bc6e849964449587234b526916e512d /jstests/sharding/move_chunk_find_and_modify_with_write_retryability.js
parent457ecaf9ca73456df43e442ddd758b9067a6a002 (diff)
downloadmongo-85d9721c00d7020af78fe60453f8362380fe697d.tar.gz
SERVER-30894 Implement command for transferring session information during migration
Diffstat (limited to 'jstests/sharding/move_chunk_find_and_modify_with_write_retryability.js')
-rw-r--r--jstests/sharding/move_chunk_find_and_modify_with_write_retryability.js119
1 files changed, 119 insertions, 0 deletions
diff --git a/jstests/sharding/move_chunk_find_and_modify_with_write_retryability.js b/jstests/sharding/move_chunk_find_and_modify_with_write_retryability.js
new file mode 100644
index 00000000000..c06a4cfdc9c
--- /dev/null
+++ b/jstests/sharding/move_chunk_find_and_modify_with_write_retryability.js
@@ -0,0 +1,119 @@
+load("jstests/sharding/move_chunk_with_session_helper.js");
+
+(function() {
+
+ "use strict";
+
+ var checkFindAndModifyResult = function(expected, toCheck) {
+ assert.eq(expected.ok, toCheck.ok);
+ assert.eq(expected.value, toCheck.value);
+
+ // TODO: SERVER-30532: after adding upserted, just compare the entire lastErrorObject
+ var expectedLE = expected.lastErrorObject;
+ var toCheckLE = toCheck.lastErrorObject;
+
+ assert.neq(null, toCheckLE);
+ assert.eq(expected.updatedExisting, toCheck.updatedExisting);
+ assert.eq(expected.n, toCheck.n);
+ };
+
+ var lsid = UUID();
+ var tests = [
+ {
+ coll: 'findAndMod-upsert',
+ cmd: {
+ findAndModify: 'findAndMod-upsert',
+ query: {x: 60},
+ update: {$inc: {y: 1}},
+ new: true,
+ upsert: true,
+ lsid: {id: lsid},
+ txnNumber: NumberLong(37),
+ },
+ setup: function(coll) {},
+ checkRetryResult: function(result, retryResult) {
+ checkFindAndModifyResult(result, retryResult);
+ },
+ checkDocuments: function(coll) {
+ assert.eq(1, coll.findOne({x: 60}).y);
+ },
+ },
+ {
+ coll: 'findAndMod-update-preImage',
+ cmd: {
+ findAndModify: 'findAndMod-update-preImage',
+ query: {x: 60},
+ update: {$inc: {y: 1}},
+ new: false,
+ upsert: false,
+ lsid: {id: lsid},
+ txnNumber: NumberLong(38),
+ },
+ setup: function(coll) {
+ coll.insert({x: 60});
+ },
+ checkRetryResult: function(result, retryResult) {
+ checkFindAndModifyResult(result, retryResult);
+ },
+ checkDocuments: function(coll) {
+ assert.eq(1, coll.findOne({x: 60}).y);
+ },
+ },
+ {
+ coll: 'findAndMod-update-postImage',
+ cmd: {
+ findAndModify: 'findAndMod-update-postImage',
+ query: {x: 60},
+ update: {$inc: {y: 1}},
+ new: true,
+ upsert: false,
+ lsid: {id: lsid},
+ txnNumber: NumberLong(39),
+ },
+ setup: function(coll) {
+ coll.insert({x: 60});
+ },
+ checkRetryResult: function(result, retryResult) {
+ checkFindAndModifyResult(result, retryResult);
+ },
+ checkDocuments: function(coll) {
+ assert.eq(1, coll.findOne({x: 60}).y);
+ },
+ },
+ {
+ coll: 'findAndMod-delete',
+ cmd: {
+ findAndModify: 'findAndMod-delete',
+ query: {x: 10},
+ remove: true,
+ lsid: {id: lsid},
+ txnNumber: NumberLong(40),
+ },
+ setup: function(coll) {
+ var bulk = coll.initializeUnorderedBulkOp();
+ for (let i = 0; i < 10; i++) {
+ bulk.insert({x: 10});
+ }
+ assert.writeOK(bulk.execute());
+
+ },
+ checkRetryResult: function(result, retryResult) {
+ checkFindAndModifyResult(result, retryResult);
+ },
+ checkDocuments: function(coll) {
+ assert.eq(9, coll.find({x: 10}).itcount());
+ },
+ },
+ ];
+
+ var st = new ShardingTest({shards: {rs0: {nodes: 2}, rs1: {nodes: 2}}});
+ assert.commandWorked(st.s.adminCommand({enableSharding: 'test'}));
+ st.ensurePrimaryShard('test', st.shard0.shardName);
+
+ tests.forEach(function(test) {
+ testMoveChunkWithSession(
+ st, test.coll, test.cmd, test.setup, test.checkRetryResult, test.checkDocuments);
+ });
+
+ st.stop();
+})();