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/replsets/cloneDb.js | |
parent | a025d43f3ce2efc1fb1282a718f5d286fa0a4dc1 (diff) | |
download | mongo-4ae691e8edc87d0e3cfb633bb91c328426be007b.tar.gz |
SERVER-22468 Format JS code with approved style in jstests/
Diffstat (limited to 'jstests/replsets/cloneDb.js')
-rw-r--r-- | jstests/replsets/cloneDb.js | 187 |
1 files changed, 98 insertions, 89 deletions
diff --git a/jstests/replsets/cloneDb.js b/jstests/replsets/cloneDb.js index ca53d370f4a..f0eb6a2171e 100644 --- a/jstests/replsets/cloneDb.js +++ b/jstests/replsets/cloneDb.js @@ -4,95 +4,104 @@ (function() { "use strict"; -if (jsTest.options().keyFile) { - jsTest.log("Skipping test because clone command doesn't work with authentication enabled:" + - " SERVER-4245"); -} else { - var numDocs = 2000; - - // 1kb string - var str = new Array(1000).toString(); - - var replsetDBName = 'cloneDBreplset'; - var standaloneDBName = 'cloneDBstandalone'; - var testColName = 'foo'; - - jsTest.log("Create replica set"); - var replTest = new ReplSetTest({name: 'testSet', nodes: 3}); - replTest.startSet(); - replTest.initiate(); - var master = replTest.getPrimary(); - var secondary = replTest.liveNodes.slaves[0]; - var masterDB = master.getDB(replsetDBName); - masterDB.dropDatabase(); - - jsTest.log("Create standalone server"); - var standalone = MongoRunner.runMongod(); - standalone.getDB("admin").runCommand({setParameter:1,logLevel:5}); - var standaloneDB = standalone.getDB(replsetDBName); - standaloneDB.dropDatabase(); - - jsTest.log("Insert data into replica set"); - var bulk = masterDB[testColName].initializeUnorderedBulkOp(); - for (var i = 0; i < numDocs; i++) { - bulk.insert({x: i, text: str}); - } - assert.writeOK(bulk.execute({w: 3})); - - jsTest.log("Clone db from replica set to standalone server"); - standaloneDB.cloneDatabase(replTest.getURL()); - assert.eq(numDocs, standaloneDB[testColName].count(), - 'cloneDatabase from replset to standalone failed (document counts do not match)'); - - jsTest.log("Clone db from replica set PRIMARY to standalone server"); - standaloneDB.dropDatabase(); - standaloneDB.cloneDatabase(master.host); - assert.eq(numDocs, standaloneDB[testColName].count(), - 'cloneDatabase from PRIMARY to standalone failed (document counts do not match)'); - - jsTest.log("Clone db from replica set SECONDARY to standalone server (should not copy)"); - standaloneDB.dropDatabase(); - standaloneDB.cloneDatabase(secondary.host); - assert.eq(0, standaloneDB[testColName].count(), - 'cloneDatabase from SECONDARY to standalone copied documents without slaveOk: true'); - - jsTest.log("Clone db from replica set SECONDARY to standalone server using slaveOk"); - standaloneDB.dropDatabase(); - standaloneDB.runCommand({clone: secondary.host, slaveOk: true}); - assert.eq(numDocs, standaloneDB[testColName].count(), - 'cloneDatabase from SECONDARY to standalone failed (document counts do not match)'); - - jsTest.log("Switch db and insert data into standalone server"); - masterDB = master.getDB(standaloneDBName); - var secondaryDB = secondary.getDB(standaloneDBName); - standaloneDB = standalone.getDB(standaloneDBName); - masterDB.dropDatabase(); - secondaryDB.dropDatabase(); - standaloneDB.dropDatabase(); - - bulk = standaloneDB[testColName].initializeUnorderedBulkOp(); - for (var i = 0; i < numDocs; i++) { - bulk.insert({x: i, text: str}); + if (jsTest.options().keyFile) { + jsTest.log("Skipping test because clone command doesn't work with authentication enabled:" + + " SERVER-4245"); + } else { + var numDocs = 2000; + + // 1kb string + var str = new Array(1000).toString(); + + var replsetDBName = 'cloneDBreplset'; + var standaloneDBName = 'cloneDBstandalone'; + var testColName = 'foo'; + + jsTest.log("Create replica set"); + var replTest = new ReplSetTest({name: 'testSet', nodes: 3}); + replTest.startSet(); + replTest.initiate(); + var master = replTest.getPrimary(); + var secondary = replTest.liveNodes.slaves[0]; + var masterDB = master.getDB(replsetDBName); + masterDB.dropDatabase(); + + jsTest.log("Create standalone server"); + var standalone = MongoRunner.runMongod(); + standalone.getDB("admin").runCommand({setParameter: 1, logLevel: 5}); + var standaloneDB = standalone.getDB(replsetDBName); + standaloneDB.dropDatabase(); + + jsTest.log("Insert data into replica set"); + var bulk = masterDB[testColName].initializeUnorderedBulkOp(); + for (var i = 0; i < numDocs; i++) { + bulk.insert({x: i, text: str}); + } + assert.writeOK(bulk.execute({w: 3})); + + jsTest.log("Clone db from replica set to standalone server"); + standaloneDB.cloneDatabase(replTest.getURL()); + assert.eq(numDocs, + standaloneDB[testColName].count(), + 'cloneDatabase from replset to standalone failed (document counts do not match)'); + + jsTest.log("Clone db from replica set PRIMARY to standalone server"); + standaloneDB.dropDatabase(); + standaloneDB.cloneDatabase(master.host); + assert.eq(numDocs, + standaloneDB[testColName].count(), + 'cloneDatabase from PRIMARY to standalone failed (document counts do not match)'); + + jsTest.log("Clone db from replica set SECONDARY to standalone server (should not copy)"); + standaloneDB.dropDatabase(); + standaloneDB.cloneDatabase(secondary.host); + assert.eq( + 0, + standaloneDB[testColName].count(), + 'cloneDatabase from SECONDARY to standalone copied documents without slaveOk: true'); + + jsTest.log("Clone db from replica set SECONDARY to standalone server using slaveOk"); + standaloneDB.dropDatabase(); + standaloneDB.runCommand({clone: secondary.host, slaveOk: true}); + assert.eq( + numDocs, + standaloneDB[testColName].count(), + 'cloneDatabase from SECONDARY to standalone failed (document counts do not match)'); + + jsTest.log("Switch db and insert data into standalone server"); + masterDB = master.getDB(standaloneDBName); + var secondaryDB = secondary.getDB(standaloneDBName); + standaloneDB = standalone.getDB(standaloneDBName); + masterDB.dropDatabase(); + secondaryDB.dropDatabase(); + standaloneDB.dropDatabase(); + + bulk = standaloneDB[testColName].initializeUnorderedBulkOp(); + for (var i = 0; i < numDocs; i++) { + bulk.insert({x: i, text: str}); + } + assert.writeOK(bulk.execute()); + + jsTest.log("Clone db from standalone server to replica set PRIMARY"); + masterDB.cloneDatabase(standalone.host); + replTest.awaitReplication(); + assert.eq(numDocs, + masterDB[testColName].count(), + 'cloneDatabase from standalone to PRIMARY failed (document counts do not match)'); + + jsTest.log("Clone db from standalone server to replica set SECONDARY"); + masterDB.dropDatabase(); + replTest.awaitReplication(); + secondaryDB.cloneDatabase(standalone.host); + assert.eq( + 0, + secondaryDB[testColName].count(), + 'cloneDatabase from standalone to SECONDARY succeeded and should not accept writes'); + + jsTest.log("Shut down replica set and standalone server"); + MongoRunner.stopMongod(standalone.port); + + replTest.stopSet(); } - assert.writeOK(bulk.execute()); - - jsTest.log("Clone db from standalone server to replica set PRIMARY"); - masterDB.cloneDatabase(standalone.host); - replTest.awaitReplication(); - assert.eq(numDocs, masterDB[testColName].count(), - 'cloneDatabase from standalone to PRIMARY failed (document counts do not match)'); - - jsTest.log("Clone db from standalone server to replica set SECONDARY"); - masterDB.dropDatabase(); - replTest.awaitReplication(); - secondaryDB.cloneDatabase(standalone.host); - assert.eq(0, secondaryDB[testColName].count(), - 'cloneDatabase from standalone to SECONDARY succeeded and should not accept writes'); - - jsTest.log("Shut down replica set and standalone server"); - MongoRunner.stopMongod(standalone.port); - - replTest.stopSet(); -} })(); |