diff options
Diffstat (limited to 'jstests/noPassthroughWithMongod/renameWithWCE.js')
-rw-r--r-- | jstests/noPassthroughWithMongod/renameWithWCE.js | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/jstests/noPassthroughWithMongod/renameWithWCE.js b/jstests/noPassthroughWithMongod/renameWithWCE.js index f09c45ebeff..0c232ec0b37 100644 --- a/jstests/noPassthroughWithMongod/renameWithWCE.js +++ b/jstests/noPassthroughWithMongod/renameWithWCE.js @@ -4,52 +4,52 @@ */ // @tags: [requires_profiling] (function() { - // Set up namespaces a and b. - var admin = db.getMongo().getDB("admin"); - var db_a = db.getMongo().getDB("db_a"); - var db_b = db.getMongo().getDB("db_b"); - - var a = db_a.rename7; - var b = db_b.rename7; - - // Ensure that the databases are created - db_a.coll.insert({}); - db_b.coll.insert({}); - - a.drop(); - b.drop(); - - // Put some documents and indexes in a. - a.save({a: 1}); - a.save({a: 2}); - a.save({a: 3}); - a.ensureIndex({a: 1}); - a.ensureIndex({b: 1}); - - assert.commandWorked(admin.runCommand({renameCollection: "db_a.rename7", to: "db_b.rename7"})); - - assert.eq(0, a.find().count()); - assert(db_a.getCollectionNames().indexOf("rename7") < 0); - - assert.eq(3, b.find().count()); - assert(db_b.getCollectionNames().indexOf("rename7") >= 0); - - a.drop(); - b.drop(); - - // Test that the dropTarget option works when renaming across databases. - a.save({}); - b.save({}); - assert.commandFailed(admin.runCommand({renameCollection: "db_a.rename7", to: "db_b.rename7"})); - - // Ensure that a WCE during renaming doesn't cause a failure. - assert.commandWorked(db_a.setProfilingLevel(2)); // So we can check WCE happens. - assert.commandWorked(db_a.adminCommand( - {"configureFailPoint": 'writeConflictInRenameCollCopyToTmp', "mode": {times: 1}})); - assert.commandWorked( - admin.runCommand({renameCollection: "db_a.rename7", to: "db_b.rename7", dropTarget: true})); - assert.gte(db_a.system.profile.findOne().writeConflicts, 1); // Make sure that our WCE happened - assert.commandWorked(db_a.setProfilingLevel(0)); - a.drop(); - b.drop(); +// Set up namespaces a and b. +var admin = db.getMongo().getDB("admin"); +var db_a = db.getMongo().getDB("db_a"); +var db_b = db.getMongo().getDB("db_b"); + +var a = db_a.rename7; +var b = db_b.rename7; + +// Ensure that the databases are created +db_a.coll.insert({}); +db_b.coll.insert({}); + +a.drop(); +b.drop(); + +// Put some documents and indexes in a. +a.save({a: 1}); +a.save({a: 2}); +a.save({a: 3}); +a.ensureIndex({a: 1}); +a.ensureIndex({b: 1}); + +assert.commandWorked(admin.runCommand({renameCollection: "db_a.rename7", to: "db_b.rename7"})); + +assert.eq(0, a.find().count()); +assert(db_a.getCollectionNames().indexOf("rename7") < 0); + +assert.eq(3, b.find().count()); +assert(db_b.getCollectionNames().indexOf("rename7") >= 0); + +a.drop(); +b.drop(); + +// Test that the dropTarget option works when renaming across databases. +a.save({}); +b.save({}); +assert.commandFailed(admin.runCommand({renameCollection: "db_a.rename7", to: "db_b.rename7"})); + +// Ensure that a WCE during renaming doesn't cause a failure. +assert.commandWorked(db_a.setProfilingLevel(2)); // So we can check WCE happens. +assert.commandWorked(db_a.adminCommand( + {"configureFailPoint": 'writeConflictInRenameCollCopyToTmp', "mode": {times: 1}})); +assert.commandWorked( + admin.runCommand({renameCollection: "db_a.rename7", to: "db_b.rename7", dropTarget: true})); +assert.gte(db_a.system.profile.findOne().writeConflicts, 1); // Make sure that our WCE happened +assert.commandWorked(db_a.setProfilingLevel(0)); +a.drop(); +b.drop(); })(); |