diff options
Diffstat (limited to 'jstests')
10 files changed, 98 insertions, 1 deletions
diff --git a/jstests/auth/lib/commands_lib.js b/jstests/auth/lib/commands_lib.js index 743366749a5..d42234eef7f 100644 --- a/jstests/auth/lib/commands_lib.js +++ b/jstests/auth/lib/commands_lib.js @@ -1035,7 +1035,19 @@ var authCommandsLib = { }, ] }, - + { + testname: "clusterAggregate", + command: {clusterAggregate: "foo", pipeline: [], cursor: {}}, + skipSharded: true, + testcases: [ + { + runOnDb: firstDbName, + roles: {__system: 1}, + privileges: [{resource: {cluster: true}, actions: ["internal"]}], + expectFail: true, + }, + ] + }, { testname: "aggregate_readonly", command: {aggregate: "foo", pipeline: [], cursor: {}}, @@ -4251,6 +4263,19 @@ var authCommandsLib = { ] }, { + testname: "clusterGetMore", + command: {clusterGetMore: NumberLong(1), collection: "foo"}, + skipSharded: true, + testcases: [ + { + runOnDb: firstDbName, + roles: {__system: 1}, + privileges: [{resource: {cluster: true}, actions: ["internal"]}], + expectFail: true, + }, + ] + }, + { testname: "getMoreWithTerm", command: {getMore: NumberLong("1"), collection: "foo", term: NumberLong(1)}, testcases: [{ diff --git a/jstests/core/views/views_all_commands.js b/jstests/core/views/views_all_commands.js index aa28998a1f9..0fe746c8047 100644 --- a/jstests/core/views/views_all_commands.js +++ b/jstests/core/views/views_all_commands.js @@ -232,9 +232,11 @@ let viewsCommandTests = { expectFailure: true, }, clusterAbortTransaction: {skip: "already tested by 'abortTransaction' tests on mongos"}, + clusterAggregate: {skip: "already tested by 'aggregate' tests on mongos"}, clusterCommitTransaction: {skip: "already tested by 'commitTransaction' tests on mongos"}, clusterDelete: {skip: "already tested by 'delete' tests on mongos"}, clusterFind: {skip: "already tested by 'find' tests on mongos"}, + clusterGetMore: {skip: "already tested by 'getMore' tests on mongos"}, clusterInsert: {skip: "already tested by 'insert' tests on mongos"}, clusterUpdate: {skip: "already tested by 'update' tests on mongos"}, collMod: {command: {collMod: "view", viewOn: "other", pipeline: []}}, diff --git a/jstests/noPassthrough/cluster_commands_require_cluster_node.js b/jstests/noPassthrough/cluster_commands_require_cluster_node.js index fe146211efe..05a4e80685f 100644 --- a/jstests/noPassthrough/cluster_commands_require_cluster_node.js +++ b/jstests/noPassthrough/cluster_commands_require_cluster_node.js @@ -16,9 +16,14 @@ const kCollName = "bar"; // error was different than when a command is rejected for not having sharding enabled. const clusterCommandsCases = [ {cmd: {clusterAbortTransaction: 1}, expectedErr: ErrorCodes.InvalidOptions}, + {cmd: {clusterAggregate: kCollName, pipeline: [{$match: {}}], cursor: {}}}, {cmd: {clusterCommitTransaction: 1}, expectedErr: ErrorCodes.InvalidOptions}, {cmd: {clusterDelete: kCollName, deletes: [{q: {}, limit: 1}]}}, {cmd: {clusterFind: kCollName}}, + { + cmd: {clusterGetMore: NumberLong(1), collection: kCollName}, + expectedErr: ErrorCodes.CursorNotFound + }, {cmd: {clusterInsert: kCollName, documents: [{x: 1}]}}, {cmd: {clusterUpdate: kCollName, updates: [{q: {doesNotExist: 1}, u: {x: 1}}]}}, ]; diff --git a/jstests/replsets/db_reads_while_recovering_all_commands.js b/jstests/replsets/db_reads_while_recovering_all_commands.js index 5c09d2361b6..6a71fb16347 100644 --- a/jstests/replsets/db_reads_while_recovering_all_commands.js +++ b/jstests/replsets/db_reads_while_recovering_all_commands.js @@ -121,9 +121,11 @@ const allCommands = { clearLog: {skip: isNotAUserDataRead}, cloneCollectionAsCapped: {skip: isPrimaryOnly}, clusterAbortTransaction: {skip: "already tested by 'abortTransaction' tests on mongos"}, + clusterAggregate: {skip: "already tested by 'aggregate' tests on mongos"}, clusterCommitTransaction: {skip: "already tested by 'commitTransaction' tests on mongos"}, clusterDelete: {skip: "already tested by 'delete' tests on mongos"}, clusterFind: {skip: "already tested by 'find' tests on mongos"}, + clusterGetMore: {skip: "already tested by 'getMore' tests on mongos"}, clusterInsert: {skip: "already tested by 'insert' tests on mongos"}, clusterUpdate: {skip: "already tested by 'update' tests on mongos"}, collMod: {skip: isPrimaryOnly}, diff --git a/jstests/sharding/libs/last_lts_mongod_commands.js b/jstests/sharding/libs/last_lts_mongod_commands.js index 224c14644ab..f289ba2720d 100644 --- a/jstests/sharding/libs/last_lts_mongod_commands.js +++ b/jstests/sharding/libs/last_lts_mongod_commands.js @@ -13,9 +13,11 @@ const commandsRemovedFromMongodSinceLastLTS = [ // test defined without always existing on the mongod being used. const commandsAddedToMongodSinceLastLTS = [ "clusterAbortTransaction", + "clusterAggregate", "clusterCommitTransaction", "clusterDelete", "clusterFind", + "clusterGetMore", "clusterInsert", "clusterUpdate", "rotateCertificates", diff --git a/jstests/sharding/read_write_concern_defaults_application.js b/jstests/sharding/read_write_concern_defaults_application.js index a59f7bbb1bc..7642ce34e25 100644 --- a/jstests/sharding/read_write_concern_defaults_application.js +++ b/jstests/sharding/read_write_concern_defaults_application.js @@ -244,9 +244,11 @@ let testCases = { checkWriteConcern: true, }, clusterAbortTransaction: {skip: "already tested by 'abortTransaction' tests on mongos"}, + clusterAggregate: {skip: "already tested by 'aggregate' tests on mongos"}, clusterCommitTransaction: {skip: "already tested by 'commitTransaction' tests on mongos"}, clusterDelete: {skip: "already tested by 'delete' tests on mongos"}, clusterFind: {skip: "already tested by 'find' tests on mongos"}, + clusterGetMore: {skip: "already tested by 'getMore' tests on mongos"}, clusterInsert: {skip: "already tested by 'insert' tests on mongos"}, clusterUpdate: {skip: "already tested by 'update' tests on mongos"}, collMod: { diff --git a/jstests/sharding/safe_secondary_reads_drop_recreate.js b/jstests/sharding/safe_secondary_reads_drop_recreate.js index 3ee63252205..4835739324b 100644 --- a/jstests/sharding/safe_secondary_reads_drop_recreate.js +++ b/jstests/sharding/safe_secondary_reads_drop_recreate.js @@ -124,9 +124,11 @@ let testCases = { clone: {skip: "primary only"}, cloneCollectionAsCapped: {skip: "primary only"}, clusterAbortTransaction: {skip: "already tested by 'abortTransaction' tests on mongos"}, + clusterAggregate: {skip: "already tested by 'aggregate' tests on mongos"}, clusterCommitTransaction: {skip: "already tested by 'commitTransaction' tests on mongos"}, clusterDelete: {skip: "already tested by 'delete' tests on mongos"}, clusterFind: {skip: "already tested by 'find' tests on mongos"}, + clusterGetMore: {skip: "already tested by 'getMore' tests on mongos"}, clusterInsert: {skip: "already tested by 'insert' tests on mongos"}, clusterUpdate: {skip: "already tested by 'update' tests on mongos"}, collMod: {skip: "primary only"}, diff --git a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js index fdaeacfed34..ee81222de94 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_suspend_range_deletion.js @@ -140,9 +140,11 @@ let testCases = { clone: {skip: "primary only"}, cloneCollectionAsCapped: {skip: "primary only"}, clusterAbortTransaction: {skip: "already tested by 'abortTransaction' tests on mongos"}, + clusterAggregate: {skip: "already tested by 'aggregate' tests on mongos"}, clusterCommitTransaction: {skip: "already tested by 'commitTransaction' tests on mongos"}, clusterDelete: {skip: "already tested by 'delete' tests on mongos"}, clusterFind: {skip: "already tested by 'find' tests on mongos"}, + clusterGetMore: {skip: "already tested by 'getMore' tests on mongos"}, clusterInsert: {skip: "already tested by 'insert' tests on mongos"}, clusterUpdate: {skip: "already tested by 'update' tests on mongos"}, commitReshardCollection: {skip: "primary only"}, diff --git a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js index c212b21c39e..23eac4fe2c2 100644 --- a/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js +++ b/jstests/sharding/safe_secondary_reads_single_migration_waitForDelete.js @@ -127,9 +127,11 @@ let testCases = { clone: {skip: "primary only"}, cloneCollectionAsCapped: {skip: "primary only"}, clusterAbortTransaction: {skip: "already tested by 'abortTransaction' tests on mongos"}, + clusterAggregate: {skip: "already tested by 'aggregate' tests on mongos"}, clusterCommitTransaction: {skip: "already tested by 'commitTransaction' tests on mongos"}, clusterDelete: {skip: "already tested by 'delete' tests on mongos"}, clusterFind: {skip: "already tested by 'find' tests on mongos"}, + clusterGetMore: {skip: "already tested by 'getMore' tests on mongos"}, clusterInsert: {skip: "already tested by 'insert' tests on mongos"}, clusterUpdate: {skip: "already tested by 'update' tests on mongos"}, collMod: {skip: "primary only"}, diff --git a/jstests/sharding/transaction_api_distributed_from_shard.js b/jstests/sharding/transaction_api_distributed_from_shard.js index e44fca1850e..d4b42290ade 100644 --- a/jstests/sharding/transaction_api_distributed_from_shard.js +++ b/jstests/sharding/transaction_api_distributed_from_shard.js @@ -26,6 +26,7 @@ function runTestSuccess() { }, {dbName: kDbName, command: {delete: kCollName, deletes: [{q: {_id: 3}, limit: 1}]}}, {dbName: kDbName, command: {find: kCollName, singleBatch: true}}, + {dbName: kDbName, command: {aggregate: kCollName, pipeline: [{$match: {}}], cursor: {}}}, ]; // Insert initial data. @@ -44,6 +45,10 @@ function runTestSuccess() { assert.eq(res.responses[3], {n: 1, ok: 1}, tojson(res)); assert.sameMembers( res.responses[4].cursor.firstBatch, [{_id: 1}, {_id: 2, updated: true}], tojson(res)); + assert.eq(res.responses[4].cursor.id, 0, tojson(res)); + assert.sameMembers( + res.responses[5].cursor.firstBatch, [{_id: 1}, {_id: 2, updated: true}], tojson(res)); + assert.eq(res.responses[5].cursor.id, 0, tojson(res)); // The written documents should be visible outside the transaction. assert.sameMembers(st.s.getCollection(kNs).find().toArray(), @@ -84,12 +89,59 @@ function runTestFailure() { assert.commandWorked(st.s.getCollection(kNs).remove({}, false /* justOne */)); } +function runTestGetMore() { + // Insert initial data. + const startVal = -50; + const numDocs = 100; + + let bulk = st.s.getCollection(kNs).initializeUnorderedBulkOp(); + for (let i = startVal; i < startVal + numDocs; i++) { + bulk.insert({_id: i}); + } + assert.commandWorked(bulk.execute()); + + const commands = [ + // Use a batch size < number of documents so the API must use getMores to exhaust the + // cursor. + {dbName: kDbName, command: {find: kCollName, batchSize: 17}, exhaustCursor: true}, + ]; + + const commandMetricsBefore = shard0Primary.getDB(kDbName).serverStatus().metrics.commands; + + const res = assert.commandWorked( + shard0Primary.adminCommand({testInternalTransactions: 1, commandInfos: commands})); + assert.eq(res.responses.length, 1, tojson(res)); + + // The response from an exhausted cursor is an array of BSON objects, so we don't assert the + // command worked. + assert.eq(res.responses[0].docs.length, numDocs, tojson(res)); + for (let i = 0; i < numDocs; ++i) { + assert.eq(res.responses[0].docs[i]._id, startVal + i, tojson(res.responses[0].docs[i])); + } + + // Verify getMores were used by checking serverStatus metrics. + const commandMetricsAfter = shard0Primary.getDB(kDbName).serverStatus().metrics.commands; + + assert.gt(commandMetricsAfter.clusterFind.total, commandMetricsBefore.clusterFind.total); + if (!commandMetricsBefore.clusterGetMore) { + // The unsharded case runs before any cluster getMores are run. + assert.gt(commandMetricsAfter.clusterGetMore.total, 0); + } else { + assert.gt(commandMetricsAfter.clusterGetMore.total, + commandMetricsBefore.clusterGetMore.total); + } + + // Clean up. + assert.commandWorked(st.s.getCollection(kNs).remove({}, false /* justOne */)); +} + // // Unsharded collection case. // runTestSuccess(); runTestFailure(); +runTestGetMore(); // // Sharded collection case. @@ -105,6 +157,7 @@ assert.commandWorked(st.s.adminCommand({moveChunk: kNs, find: {x: 0}, to: st.sha runTestSuccess(); runTestFailure(); +runTestGetMore(); st.stop(); })(); |