diff options
Diffstat (limited to 'jstests/replsets')
-rw-r--r-- | jstests/replsets/apply_ops_create_indexes.js | 48 | ||||
-rw-r--r-- | jstests/replsets/background_index.js | 2 | ||||
-rw-r--r-- | jstests/replsets/buildindexes.js | 2 | ||||
-rw-r--r-- | jstests/replsets/bulk_api_wc.js | 2 | ||||
-rw-r--r-- | jstests/replsets/drop_collections_two_phase_rename_drop_target.js | 4 | ||||
-rw-r--r-- | jstests/replsets/initial_sync4.js | 2 | ||||
-rw-r--r-- | jstests/replsets/initial_sync_ambiguous_index.js | 2 | ||||
-rw-r--r-- | jstests/replsets/initial_sync_move_forward.js | 2 | ||||
-rw-r--r-- | jstests/replsets/reindex.js | 4 | ||||
-rw-r--r-- | jstests/replsets/replset1.js | 2 | ||||
-rw-r--r-- | jstests/replsets/temp_namespace.js | 4 |
11 files changed, 61 insertions, 13 deletions
diff --git a/jstests/replsets/apply_ops_create_indexes.js b/jstests/replsets/apply_ops_create_indexes.js index e3641965ce6..ebeffbb1593 100644 --- a/jstests/replsets/apply_ops_create_indexes.js +++ b/jstests/replsets/apply_ops_create_indexes.js @@ -7,6 +7,54 @@ load('jstests/noPassthrough/libs/index_build.js'); +let ensureIndexExists = function(testDB, collName, indexName, expectedNumIndexes) { + let cmd = {listIndexes: collName}; + let res = testDB.runCommand(cmd); + assert.commandWorked(res, "could not run " + tojson(cmd)); + let indexes = new DBCommandCursor(testDB, res).toArray(); + + assert.eq(indexes.length, expectedNumIndexes); + + let foundIndex = false; + for (let i = 0; i < indexes.length; ++i) { + if (indexes[i].name == indexName) { + foundIndex = true; + } + } + assert(foundIndex, + "did not find the index '" + indexName + + "' amongst the collection indexes: " + tojson(indexes)); +}; + +let ensureOplogEntryExists = function(localDB, indexName) { + // Make sure the oplog entry for index creation exists in the oplog. + let cmd = {find: "oplog.rs"}; + let res = localDB.runCommand(cmd); + assert.commandWorked(res, "could not run " + tojson(cmd)); + let cursor = new DBCommandCursor(localDB, res); + let errMsg = "expected more data from command " + tojson(cmd) + ", with result " + tojson(res); + assert(cursor.hasNext(), errMsg); + let oplog = localDB.getCollection("oplog.rs"); + + // If two phase index builds are enabled, index creation will show up in the oplog as a pair of + // startIndexBuild and commitIndexBuild oplog entries rather than a single createIndexes entry. + let query = { + $and: [ + {"o.startIndexBuild": {$exists: true}}, + {"o.indexes.0.name": indexName}, + ], + }; + let resCursor = oplog.find(query); + assert.eq(resCursor.count(), + 1, + "Expected the query " + tojson(query) + " to return exactly 1 document"); + query = {$and: [{"o.commitIndexBuild": {$exists: true}}, {"o.indexes.0.name": indexName}]}; + resCursor = oplog.find(query); + assert.eq(resCursor.count(), + 1, + "Expected the query " + tojson(query) + " to return exactly 1 document"); +}; + let rst = new ReplSetTest({nodes: 3}); rst.startSet(); rst.initiate(); diff --git a/jstests/replsets/background_index.js b/jstests/replsets/background_index.js index a09138a9e19..662abef771d 100644 --- a/jstests/replsets/background_index.js +++ b/jstests/replsets/background_index.js @@ -23,7 +23,7 @@ for (var i = 0; i < 100; i++) { } // Add a background index. -coll.createIndex({x: 1}, {background: true}); +coll.ensureIndex({x: 1}, {background: true}); // Rename the collection. assert.commandWorked( diff --git a/jstests/replsets/buildindexes.js b/jstests/replsets/buildindexes.js index 95356d24e1b..3be0ba68896 100644 --- a/jstests/replsets/buildindexes.js +++ b/jstests/replsets/buildindexes.js @@ -26,7 +26,7 @@ for (var i in secondaryConns) { } replTest.awaitReplication(); -primary.x.createIndex({y: 1}); +primary.x.ensureIndex({y: 1}); for (i = 0; i < 100; i++) { primary.x.insert({x: 1, y: "abc", c: 1}); diff --git a/jstests/replsets/bulk_api_wc.js b/jstests/replsets/bulk_api_wc.js index 1c90537d2be..591ad1aef58 100644 --- a/jstests/replsets/bulk_api_wc.js +++ b/jstests/replsets/bulk_api_wc.js @@ -28,7 +28,7 @@ var executeTests = function() { // Create a unique index, legacy writes validate too early to use invalid documents for // write // error testing - coll.createIndex({a: 1}, {unique: true}); + coll.ensureIndex({a: 1}, {unique: true}); // // Ordered diff --git a/jstests/replsets/drop_collections_two_phase_rename_drop_target.js b/jstests/replsets/drop_collections_two_phase_rename_drop_target.js index 9aa9a15c9c1..5191fb47127 100644 --- a/jstests/replsets/drop_collections_two_phase_rename_drop_target.js +++ b/jstests/replsets/drop_collections_two_phase_rename_drop_target.js @@ -52,8 +52,8 @@ let shortIndexName = "short_name"; // In the target collection, which will be dropped, create one index with a "too long" name, and // one with a name of acceptable size. -assert.commandWorked(toColl.createIndex({a: 1}, {name: longIndexName})); -assert.commandWorked(toColl.createIndex({b: 1}, {name: shortIndexName})); +assert.commandWorked(toColl.ensureIndex({a: 1}, {name: longIndexName})); +assert.commandWorked(toColl.ensureIndex({b: 1}, {name: shortIndexName})); // Insert documents into both collections so that we can tell them apart. assert.commandWorked(fromColl.insert({_id: 'from'})); diff --git a/jstests/replsets/initial_sync4.js b/jstests/replsets/initial_sync4.js index 1860db6d1c8..35dbd632715 100644 --- a/jstests/replsets/initial_sync4.js +++ b/jstests/replsets/initial_sync4.js @@ -17,7 +17,7 @@ jsTestLog("2. Insert some data"); var N = 5000; - mc.createIndex({x: 1}); + mc.ensureIndex({x: 1}); var bulk = mc.initializeUnorderedBulkOp(); for (var i = 0; i < N; ++i) { bulk.insert({_id: i, x: i, a: {}}); diff --git a/jstests/replsets/initial_sync_ambiguous_index.js b/jstests/replsets/initial_sync_ambiguous_index.js index 2398243f301..c50324db935 100644 --- a/jstests/replsets/initial_sync_ambiguous_index.js +++ b/jstests/replsets/initial_sync_ambiguous_index.js @@ -32,7 +32,7 @@ rst.initiate(); const primaryColl = rst.getPrimary().getDB(dbName).getCollection(collectionName); // Create the index. -primaryColl.createIndex({"a.0": 1}); +primaryColl.ensureIndex({"a.0": 1}); // Insert the initial document set. for (let i = 0; i < initialDocs; ++i) { diff --git a/jstests/replsets/initial_sync_move_forward.js b/jstests/replsets/initial_sync_move_forward.js index 8a2c6589d41..311ab315536 100644 --- a/jstests/replsets/initial_sync_move_forward.js +++ b/jstests/replsets/initial_sync_move_forward.js @@ -36,7 +36,7 @@ bulk.insert({_id: count - 1, x: count - 1, longString: longString}); assert.commandWorked(bulk.execute()); // Create a unique index on {x: 1}. -assert.commandWorked(primaryColl.createIndex({x: 1}, {unique: true})); +assert.commandWorked(primaryColl.ensureIndex({x: 1}, {unique: true})); // Add a secondary. var secondary = diff --git a/jstests/replsets/reindex.js b/jstests/replsets/reindex.js index 211fbe55001..454e72f25e8 100644 --- a/jstests/replsets/reindex.js +++ b/jstests/replsets/reindex.js @@ -26,7 +26,7 @@ const secondaryDB = secondary.getDB(dbName); const secondaryColl = secondaryDB.getCollection(collName); assert.commandWorked(primaryColl.insert({a: 1000})); -assert.commandWorked(primaryColl.createIndex({a: 1})); +assert.commandWorked(primaryColl.ensureIndex({a: 1})); replTest.awaitReplication(); replTest.awaitReplication(); @@ -59,7 +59,7 @@ const testDB = standalone.getDB(dbName); const testColl = testDB.getCollection(collName); assert.commandWorked(testColl.insert({a: 1000})); -assert.commandWorked(testColl.createIndex({a: 1})); +assert.commandWorked(testColl.ensureIndex({a: 1})); assert.eq(2, testColl.getIndexes().length, "Standalone didn't have proper indexes before reindex"); assert.commandWorked(testColl.reIndex()); diff --git a/jstests/replsets/replset1.js b/jstests/replsets/replset1.js index 7ce4610495e..3ad42615db9 100644 --- a/jstests/replsets/replset1.js +++ b/jstests/replsets/replset1.js @@ -123,7 +123,7 @@ var doTest = function(signal) { }); t.save({a: 1000}); - t.createIndex({a: 1}); + t.ensureIndex({a: 1}); replTest.awaitReplication(); ts.forEach(function(z) { diff --git a/jstests/replsets/temp_namespace.js b/jstests/replsets/temp_namespace.js index a6a7a839ea6..f8a6f854a68 100644 --- a/jstests/replsets/temp_namespace.js +++ b/jstests/replsets/temp_namespace.js @@ -26,10 +26,10 @@ var secondaryDB = secondary.getDB('test'); // set up collections assert.commandWorked(primaryDB.runCommand( {applyOps: [{op: "c", ns: primaryDB.getName() + ".$cmd", o: {create: "temp1", temp: true}}]})); -primaryDB.temp1.createIndex({x: 1}); +primaryDB.temp1.ensureIndex({x: 1}); assert.commandWorked(primaryDB.runCommand( {applyOps: [{op: "c", ns: primaryDB.getName() + ".$cmd", o: {create: "temp2", temp: 1}}]})); -primaryDB.temp2.createIndex({x: 1}); +primaryDB.temp2.ensureIndex({x: 1}); assert.commandWorked(primaryDB.runCommand( {applyOps: [{op: "c", ns: primaryDB.getName() + ".$cmd", o: {create: "keep1", temp: false}}]})); assert.commandWorked(primaryDB.runCommand( |