summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod/ttl_repl.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/noPassthroughWithMongod/ttl_repl.js')
-rw-r--r--jstests/noPassthroughWithMongod/ttl_repl.js59
1 files changed, 28 insertions, 31 deletions
diff --git a/jstests/noPassthroughWithMongod/ttl_repl.js b/jstests/noPassthroughWithMongod/ttl_repl.js
index 4c16c7f6306..794f0c3ad90 100644
--- a/jstests/noPassthroughWithMongod/ttl_repl.js
+++ b/jstests/noPassthroughWithMongod/ttl_repl.js
@@ -7,7 +7,7 @@
load("jstests/replsets/rslib.js");
-var rt = new ReplSetTest( { name : "ttl_repl" , nodes: 2 } );
+var rt = new ReplSetTest({name: "ttl_repl", nodes: 2});
/******** Part 1 ***************/
@@ -19,10 +19,10 @@ rt.awaitSecondaryNodes();
var slave1 = rt.liveNodes.slaves[0];
// shortcuts
-var masterdb = master.getDB( 'd' );
-var slave1db = slave1.getDB( 'd' );
-var mastercol = masterdb[ 'c' ];
-var slave1col = slave1db[ 'c' ];
+var masterdb = master.getDB('d');
+var slave1db = slave1.getDB('d');
+var mastercol = masterdb['c'];
+var slave1col = slave1db['c'];
// turn off usePowerOf2Sizes as this tests the flag is set automatically
mastercol.drop();
@@ -31,36 +31,35 @@ masterdb.createCollection(mastercol.getName(), {usePowerOf2Sizes: false});
// create new collection. insert 24 docs, aged at one-hour intervalss
now = (new Date()).getTime();
var bulk = mastercol.initializeUnorderedBulkOp();
-for ( i=0; i<24; i++ ) {
- bulk.insert({ x: new Date( now - ( 3600 * 1000 * i )) });
+for (i = 0; i < 24; i++) {
+ bulk.insert({x: new Date(now - (3600 * 1000 * i))});
}
assert.writeOK(bulk.execute());
rt.awaitReplication();
-assert.eq( 24 , mastercol.count() , "docs not inserted on primary" );
-assert.eq( 24 , slave1col.count() , "docs not inserted on secondary" );
+assert.eq(24, mastercol.count(), "docs not inserted on primary");
+assert.eq(24, slave1col.count(), "docs not inserted on secondary");
print("Initial Stats:");
print("Master:");
-printjson( mastercol.stats() );
+printjson(mastercol.stats());
print("Slave1:");
-printjson( slave1col.stats() );
+printjson(slave1col.stats());
// create TTL index, wait for TTL monitor to kick in, then check that
// the correct number of docs age out
-assert.commandWorked(mastercol.ensureIndex({ x: 1 }, { expireAfterSeconds: 20000 }));
+assert.commandWorked(mastercol.ensureIndex({x: 1}, {expireAfterSeconds: 20000}));
rt.awaitReplication();
-sleep(70*1000); // TTL monitor runs every 60 seconds, so wait 70
+sleep(70 * 1000); // TTL monitor runs every 60 seconds, so wait 70
print("Stats after waiting for TTL Monitor:");
print("Master:");
-printjson( mastercol.stats() );
+printjson(mastercol.stats());
print("Slave1:");
-printjson( slave1col.stats() );
-
-assert.eq( 6 , mastercol.count() , "docs not deleted on primary" );
-assert.eq( 6 , slave1col.count() , "docs not deleted on secondary" );
+printjson(slave1col.stats());
+assert.eq(6, mastercol.count(), "docs not deleted on primary");
+assert.eq(6, slave1col.count(), "docs not deleted on secondary");
/******** Part 2 ***************/
@@ -70,33 +69,31 @@ var config = rt.getReplSetConfig();
config.version = 2;
reconfig(rt, config);
-var slave2col = slave.getDB( 'd' )[ 'c' ];
+var slave2col = slave.getDB('d')['c'];
// check that the new secondary has the correct number of docs
print("New Slave stats:");
-printjson( slave2col.stats() );
-
-assert.eq( 6 , slave2col.count() , "wrong number of docs on new secondary");
+printjson(slave2col.stats());
+assert.eq(6, slave2col.count(), "wrong number of docs on new secondary");
/******* Part 3 *****************/
-//Check that the collMod command successfully updates the expireAfterSeconds field
-masterdb.runCommand( { collMod : "c",
- index : { keyPattern : {x : 1}, expireAfterSeconds : 10000} } );
+// Check that the collMod command successfully updates the expireAfterSeconds field
+masterdb.runCommand({collMod: "c", index: {keyPattern: {x: 1}, expireAfterSeconds: 10000}});
rt.awaitReplication();
-function getTTLTime( theCollection, theKey ) {
+function getTTLTime(theCollection, theKey) {
var indexes = theCollection.getIndexes();
- for ( var i = 0; i < indexes.length; i++ ) {
- if ( friendlyEqual( theKey, indexes[i].key ) )
+ for (var i = 0; i < indexes.length; i++) {
+ if (friendlyEqual(theKey, indexes[i].key))
return indexes[i].expireAfterSeconds;
}
throw "not found";
}
-printjson( masterdb.c.getIndexes() );
-assert.eq( 10000, getTTLTime( masterdb.c, { x : 1 } ) );
-assert.eq( 10000, getTTLTime( slave1db.c, { x : 1 } ) );
+printjson(masterdb.c.getIndexes());
+assert.eq(10000, getTTLTime(masterdb.c, {x: 1}));
+assert.eq(10000, getTTLTime(slave1db.c, {x: 1}));
// finish up
rt.stopSet();