diff options
author | David Storch <david.storch@10gen.com> | 2015-08-06 18:20:35 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2015-08-11 09:44:10 -0400 |
commit | 1ed8f6130f9bcb6d72a8f953018b0e2ab9660bf9 (patch) | |
tree | 39d1783ea541c7002190af6bfae3b01377c311b3 /jstests/sharding/find_getmore_cmd.js | |
parent | a067d03eca22d67a1ca036ea61544cd51df1490b (diff) | |
download | mongo-1ed8f6130f9bcb6d72a8f953018b0e2ab9660bf9.tar.gz |
SERVER-19797 hook up find command in mongos to ClusterCursorManager
Diffstat (limited to 'jstests/sharding/find_getmore_cmd.js')
-rw-r--r-- | jstests/sharding/find_getmore_cmd.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/jstests/sharding/find_getmore_cmd.js b/jstests/sharding/find_getmore_cmd.js new file mode 100644 index 00000000000..3b9a76e0b7d --- /dev/null +++ b/jstests/sharding/find_getmore_cmd.js @@ -0,0 +1,83 @@ +/** + * Test issuing raw find and getMore commands to mongos using db.runCommand(). + */ +(function() { + "use strict"; + + var cmdRes; + var cursorId; + + var st = new ShardingTest({shards: 2}); + st.stopBalancer(); + + // Set up a collection sharded by "_id" with one chunk on each of the two shards. + var db = st.s.getDB("test"); + var coll = db.getCollection("find_getmore_cmd"); + + coll.drop(); + assert.writeOK(coll.insert({_id: -9})); + assert.writeOK(coll.insert({_id: -5})); + assert.writeOK(coll.insert({_id: -1})); + assert.writeOK(coll.insert({_id: 1})); + assert.writeOK(coll.insert({_id: 5})); + assert.writeOK(coll.insert({_id: 9})); + + assert.commandWorked(db.adminCommand({enableSharding: db.getName()})); + st.ensurePrimaryShard(db.getName(), "shard0000"); + db.adminCommand({shardCollection: coll.getFullName(), key: {_id: 1}}); + assert.commandWorked(db.adminCommand({split: coll.getFullName(), middle: {_id: 0}})); + assert.commandWorked(db.adminCommand({ + moveChunk: coll.getFullName(), + find: {_id: 1}, + to: "shard0001" + })); + + // Find with no options. + cmdRes = db.runCommand({find: coll.getName()}); + assert.commandWorked(cmdRes); + assert.eq(cmdRes.cursor.id, NumberLong(0)); + assert.eq(cmdRes.cursor.ns, coll.getFullName()); + assert.eq(cmdRes.cursor.firstBatch.length, 6); + + // Find with batchSize greater than the number of docs residing on each shard. This means that a + // getMore is required between mongos and the shell, but no getMores are issued between mongos + // and mongod. + cmdRes = db.runCommand({find: coll.getName(), batchSize: 4}); + assert.commandWorked(cmdRes); + assert.gt(cmdRes.cursor.id, NumberLong(0)); + assert.eq(cmdRes.cursor.ns, coll.getFullName()); + assert.eq(cmdRes.cursor.firstBatch.length, 4); + cmdRes = db.runCommand({getMore: cmdRes.cursor.id, collection: coll.getName()}); + assert.commandWorked(cmdRes); + assert.eq(cmdRes.cursor.id, NumberLong(0)); + assert.eq(cmdRes.cursor.ns, coll.getFullName()); + assert.eq(cmdRes.cursor.nextBatch.length, 2); + + // Find with batchSize less than the number of docs residing on each shard. This time getMores + // will be issued between mongos and mongod. + cmdRes = db.runCommand({find: coll.getName(), batchSize: 2}); + assert.commandWorked(cmdRes); + assert.gt(cmdRes.cursor.id, NumberLong(0)); + assert.eq(cmdRes.cursor.ns, coll.getFullName()); + assert.eq(cmdRes.cursor.firstBatch.length, 2); + cursorId = cmdRes.cursor.id; + cmdRes = db.runCommand({getMore: cursorId, collection: coll.getName(), batchSize: 2}); + assert.commandWorked(cmdRes); + assert.eq(cmdRes.cursor.id, cursorId); + assert.eq(cmdRes.cursor.ns, coll.getFullName()); + assert.eq(cmdRes.cursor.nextBatch.length, 2); + cmdRes = db.runCommand({getMore: cursorId, collection: coll.getName()}); + assert.eq(cmdRes.cursor.id, NumberLong(0)); + assert.eq(cmdRes.cursor.ns, coll.getFullName()); + assert.eq(cmdRes.cursor.nextBatch.length, 2); + + // Combine skip, limit, and sort. + cmdRes = db.runCommand({find: coll.getName(), skip: 4, limit: 1, sort: {_id: -1}}); + assert.commandWorked(cmdRes); + assert.eq(cmdRes.cursor.id, NumberLong(0)); + assert.eq(cmdRes.cursor.ns, coll.getFullName()); + assert.eq(cmdRes.cursor.firstBatch.length, 1); + assert.eq(cmdRes.cursor.firstBatch[0], {_id: -5}); + + st.stop(); +})(); |