diff options
author | Jonathan Abrahams <jonathan@mongodb.com> | 2016-03-09 12:17:50 -0500 |
---|---|---|
committer | Jonathan Abrahams <jonathan@mongodb.com> | 2016-03-09 12:18:14 -0500 |
commit | 4ae691e8edc87d0e3cfb633bb91c328426be007b (patch) | |
tree | 52079a593f54382ca13a2e741633eab1b6271893 /jstests/sharding/limit_push.js | |
parent | a025d43f3ce2efc1fb1282a718f5d286fa0a4dc1 (diff) | |
download | mongo-4ae691e8edc87d0e3cfb633bb91c328426be007b.tar.gz |
SERVER-22468 Format JS code with approved style in jstests/
Diffstat (limited to 'jstests/sharding/limit_push.js')
-rw-r--r-- | jstests/sharding/limit_push.js | 104 |
1 files changed, 56 insertions, 48 deletions
diff --git a/jstests/sharding/limit_push.js b/jstests/sharding/limit_push.js index 5e7f1c32ab3..055b5c8b788 100644 --- a/jstests/sharding/limit_push.js +++ b/jstests/sharding/limit_push.js @@ -2,53 +2,61 @@ // See: http://jira.mongodb.org/browse/SERVER-1896 (function() { -var s = new ShardingTest({ name: "limit_push", shards: 2, mongos: 1 }); -var db = s.getDB( "test" ); - -// Create some data -for (i=0; i < 100; i++) { db.limit_push.insert({ _id : i, x: i}); } -db.limit_push.ensureIndex( { x : 1 } ); -assert.eq( 100 , db.limit_push.find().length() , "Incorrect number of documents" ); - -// Shard the collection -s.adminCommand( { enablesharding : "test" } ); -s.ensurePrimaryShard('test', 'shard0001'); -s.adminCommand( { shardcollection : "test.limit_push" , key : { x : 1 } } ); - -// Now split the and move the data between the shards -s.adminCommand( { split : "test.limit_push", middle : { x : 50 }} ); -s.adminCommand( { moveChunk: "test.limit_push", - find : { x : 51}, - to : s.getOther( s.getPrimaryShard( "test" ) ).name, - _waitForDelete : true }); - -// Check that the chunck have split correctly -assert.eq( 2 , s.config.chunks.count() , "wrong number of chunks"); - -// The query is asking for the maximum value below a given value -// db.limit_push.find( { x : { $lt : 60} } ).sort( { x:-1} ).limit(1) -q = { x : { $lt : 60} }; - -// Make sure the basic queries are correct -assert.eq( 60 , db.limit_push.find( q ).count() , "Did not find 60 documents" ); -//rs = db.limit_push.find( q ).sort( { x:-1} ).limit(1) -//assert.eq( rs , { _id : "1" , x : 59 } , "Did not find document with value 59" ); - -// Now make sure that the explain shos that each shard is returning a single document as indicated -// by the "n" element for each shard -exp = db.limit_push.find( q ).sort( { x:-1} ).limit(1).explain("executionStats"); -printjson( exp ); - -var execStages = exp.executionStats.executionStages; -assert.eq("SHARD_MERGE_SORT", execStages.stage, "Expected SHARD_MERGE_SORT as root stage"); - -var k = 0; -for (var j in execStages.shards) { - assert.eq( 1 , execStages.shards[j].executionStages.nReturned, - "'n' is not 1 from shard000" + k.toString()); - k++; -} - -s.stop(); + var s = new ShardingTest({name: "limit_push", shards: 2, mongos: 1}); + var db = s.getDB("test"); + + // Create some data + for (i = 0; i < 100; i++) { + db.limit_push.insert({_id: i, x: i}); + } + db.limit_push.ensureIndex({x: 1}); + assert.eq(100, db.limit_push.find().length(), "Incorrect number of documents"); + + // Shard the collection + s.adminCommand({enablesharding: "test"}); + s.ensurePrimaryShard('test', 'shard0001'); + s.adminCommand({shardcollection: "test.limit_push", key: {x: 1}}); + + // Now split the and move the data between the shards + s.adminCommand({split: "test.limit_push", middle: {x: 50}}); + s.adminCommand({ + moveChunk: "test.limit_push", + find: {x: 51}, + to: s.getOther(s.getPrimaryShard("test")).name, + _waitForDelete: true + }); + + // Check that the chunck have split correctly + assert.eq(2, s.config.chunks.count(), "wrong number of chunks"); + + // The query is asking for the maximum value below a given value + // db.limit_push.find( { x : { $lt : 60} } ).sort( { x:-1} ).limit(1) + q = { + x: {$lt: 60} + }; + + // Make sure the basic queries are correct + assert.eq(60, db.limit_push.find(q).count(), "Did not find 60 documents"); + // rs = db.limit_push.find( q ).sort( { x:-1} ).limit(1) + // assert.eq( rs , { _id : "1" , x : 59 } , "Did not find document with value 59" ); + + // Now make sure that the explain shos that each shard is returning a single document as + // indicated + // by the "n" element for each shard + exp = db.limit_push.find(q).sort({x: -1}).limit(1).explain("executionStats"); + printjson(exp); + + var execStages = exp.executionStats.executionStages; + assert.eq("SHARD_MERGE_SORT", execStages.stage, "Expected SHARD_MERGE_SORT as root stage"); + + var k = 0; + for (var j in execStages.shards) { + assert.eq(1, + execStages.shards[j].executionStages.nReturned, + "'n' is not 1 from shard000" + k.toString()); + k++; + } + + s.stop(); })(); |