summaryrefslogtreecommitdiff
path: root/jstests/replsets/capped_id.js
diff options
context:
space:
mode:
authorJonathan Abrahams <jonathan@mongodb.com>2016-03-09 12:17:50 -0500
committerJonathan Abrahams <jonathan@mongodb.com>2016-03-09 12:18:14 -0500
commit4ae691e8edc87d0e3cfb633bb91c328426be007b (patch)
tree52079a593f54382ca13a2e741633eab1b6271893 /jstests/replsets/capped_id.js
parenta025d43f3ce2efc1fb1282a718f5d286fa0a4dc1 (diff)
downloadmongo-4ae691e8edc87d0e3cfb633bb91c328426be007b.tar.gz
SERVER-22468 Format JS code with approved style in jstests/
Diffstat (limited to 'jstests/replsets/capped_id.js')
-rw-r--r--jstests/replsets/capped_id.js106
1 files changed, 48 insertions, 58 deletions
diff --git a/jstests/replsets/capped_id.js b/jstests/replsets/capped_id.js
index 8ba37ea7c14..8708f5752f8 100644
--- a/jstests/replsets/capped_id.js
+++ b/jstests/replsets/capped_id.js
@@ -8,7 +8,7 @@
// and check it got created on secondaries.
// Create a new replica set test with name 'testSet' and 3 members
-var replTest = new ReplSetTest( {name: 'testSet', nodes: 3} );
+var replTest = new ReplSetTest({name: 'testSet', nodes: 3});
// call startSet() to start each mongod in the replica set
// this returns a list of nodes
@@ -31,90 +31,86 @@ var slave2 = replTest.liveNodes.slaves[1];
// Calling getPrimary made available the liveNodes structure,
// which looks like this:
// liveNodes = {master: masterNode, slaves: [slave1, slave2] }
-printjson( replTest.liveNodes );
+printjson(replTest.liveNodes);
// define db names to use for this test
var dbname = "dbname";
-var masterdb = master.getDB( dbname );
-var slave1db = slave1.getDB( dbname );
-var slave2db = slave2.getDB( dbname );
+var masterdb = master.getDB(dbname);
+var slave1db = slave1.getDB(dbname);
+var slave2db = slave2.getDB(dbname);
function countIdIndexes(theDB, coll) {
- return theDB[coll].getIndexes().filter(function(idx) {
- return friendlyEqual(idx.key, {_id: 1});
- }).length;
+ return theDB[coll].getIndexes().filter(function(idx) {
+ return friendlyEqual(idx.key, {_id: 1});
+ }).length;
}
var numtests = 4;
-for( testnum=0; testnum < numtests; testnum++ ){
-
- //define collection name
+for (testnum = 0; testnum < numtests; testnum++) {
+ // define collection name
coll = "coll" + testnum;
// drop the coll on the master (just in case it already existed)
// and wait for the drop to replicate
- masterdb.getCollection( coll ).drop();
+ masterdb.getCollection(coll).drop();
replTest.awaitReplication();
- if ( testnum == 0 ){
+ if (testnum == 0) {
// create a capped collection on the master
// insert a bunch of things in it
// wait for it to replicate
- masterdb.runCommand( {create : coll , capped : true , size : 1024} );
- for(i=0; i < 500 ; i++){
- masterdb.getCollection( coll ).insert( {a: 1000} );
+ masterdb.runCommand({create: coll, capped: true, size: 1024});
+ for (i = 0; i < 500; i++) {
+ masterdb.getCollection(coll).insert({a: 1000});
}
replTest.awaitReplication();
- }
- else if ( testnum == 1 ){
+ } else if (testnum == 1) {
// create a non-capped collection on the master
// insert a bunch of things in it
// wait for it to replicate
- masterdb.runCommand( {create : coll } );
- for(i=0; i < 500 ; i++){
- masterdb.getCollection( coll ).insert( {a: 1000} );
+ masterdb.runCommand({create: coll});
+ for (i = 0; i < 500; i++) {
+ masterdb.getCollection(coll).insert({a: 1000});
}
replTest.awaitReplication();
// make sure _id index exists on primary
- assert.eq( 1 ,
- countIdIndexes(masterdb, coll),
- "master does not have _id index on normal collection");
+ assert.eq(1,
+ countIdIndexes(masterdb, coll),
+ "master does not have _id index on normal collection");
// then convert it to capped
- masterdb.runCommand({convertToCapped: coll , size: 1024 } );
+ masterdb.runCommand({convertToCapped: coll, size: 1024});
replTest.awaitReplication();
- }
- else if ( testnum == 2 ){
+ } else if (testnum == 2) {
// similar to first test, but check that a bunch of updates instead
// of inserts triggers the _id index creation on secondaries.
- masterdb.runCommand( {create : coll , capped : true , size : 1024} );
- masterdb.getCollection( coll ).insert( {a : 0} );
- for(i=0; i < 500 ; i++){
- masterdb.getCollection( coll ).update( {} , {$inc : {a : 1} } );
+ masterdb.runCommand({create: coll, capped: true, size: 1024});
+ masterdb.getCollection(coll).insert({a: 0});
+ for (i = 0; i < 500; i++) {
+ masterdb.getCollection(coll).update({}, {$inc: {a: 1}});
}
replTest.awaitReplication();
- }
- else if ( testnum == 3 ){
+ } else if (testnum == 3) {
// explicitly set autoIndexId : false
- masterdb.runCommand( {create : coll , capped : true , size : 1024 , autoIndexId : false } );
- for(i=0; i < 500 ; i++){
- masterdb.getCollection( coll ).insert( {a: 1000} );
+ masterdb.runCommand({create: coll, capped: true, size: 1024, autoIndexId: false});
+ for (i = 0; i < 500; i++) {
+ masterdb.getCollection(coll).insert({a: 1000});
}
replTest.awaitReplication();
- assert.eq( 0 ,
- countIdIndexes(masterdb, coll),
- "master has an _id index on capped collection when autoIndexId is false");
- assert.eq( 0 ,
- countIdIndexes(slave1db, coll),
- "slave1 has an _id index on capped collection when autoIndexId is false");
- assert.eq( 0 ,
- countIdIndexes(slave2db, coll),
- "slave2 has an _id index on capped collection when autoIndexId is false");
+ assert.eq(0,
+ countIdIndexes(masterdb, coll),
+ "master has an _id index on capped collection when autoIndexId is false");
+ assert.eq(0,
+ countIdIndexes(slave1db, coll),
+ "slave1 has an _id index on capped collection when autoIndexId is false");
+ assert.eq(0,
+ countIdIndexes(slave2db, coll),
+ "slave2 has an _id index on capped collection when autoIndexId is false");
// now create the index and make sure it works
- masterdb.getCollection( coll ).ensureIndex( { "_id" : 1 } );
+ masterdb.getCollection(coll).ensureIndex({"_id": 1});
replTest.awaitReplication();
}
@@ -132,20 +128,14 @@ for( testnum=0; testnum < numtests; testnum++ ){
print("");
// ensure all nodes have _id index
- assert.eq( 1 ,
- countIdIndexes(masterdb, coll),
- "master has an _id index on capped collection");
- assert.eq( 1 ,
- countIdIndexes(slave1db, coll),
- "slave1 does not have _id index on capped collection");
- assert.eq( 1 ,
- countIdIndexes(slave2db, coll),
- "slave2 does not have _id index on capped collection");
+ assert.eq(1, countIdIndexes(masterdb, coll), "master has an _id index on capped collection");
+ assert.eq(
+ 1, countIdIndexes(slave1db, coll), "slave1 does not have _id index on capped collection");
+ assert.eq(
+ 1, countIdIndexes(slave2db, coll), "slave2 does not have _id index on capped collection");
print("capped_id.js Test # " + testnum + " SUCCESS");
}
-//Finally, stop set
+// Finally, stop set
replTest.stopSet();
-
-