diff options
Diffstat (limited to 'jstests/core/check_shard_index.js')
| -rw-r--r-- | jstests/core/check_shard_index.js | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/jstests/core/check_shard_index.js b/jstests/core/check_shard_index.js index 2beb3c12891..23f69c6b757 100644 --- a/jstests/core/check_shard_index.js +++ b/jstests/core/check_shard_index.js @@ -21,12 +21,12 @@ f.createIndex({x: 1, y: 1}); assert.eq(0, f.count(), "1. initial count should be zero"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(true, res.ok, "1a"); +assert.commandWorked(res, "1a " + tojson(res)); f.save({x: 1, y: 1}); assert.eq(1, f.count(), "1. count after initial insert should be 1"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(true, res.ok, "1b"); +assert.commandWorked(res, "1b " + tojson(res)); // ------------------------- // Case 2: entry with null values would make an index suitable @@ -40,16 +40,16 @@ f.save({x: 1, y: 1}); f.save({x: null, y: 1}); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(true, res.ok, "2a " + tojson(res)); +assert.commandWorked(res, "2a " + tojson(res)); f.save({y: 2}); assert.eq(3, f.count(), "2. count after initial insert should be 3"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(true, res.ok, "2b " + tojson(res)); +assert.commandWorked(res, "2b " + tojson(res)); // Check _id index res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {_id: 1}}); -assert.eq(true, res.ok, "2c " + tojson(res)); +assert.commandWorked(res, "2c " + tojson(res)); assert(res.idskip, "2d " + tojson(res)); // ------------------------- @@ -65,7 +65,7 @@ f.save({x: [1, 2], y: 2}); assert.eq(2, f.count(), "3. count after initial insert should be 2"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok, "3a " + tojson(res)); +assert.commandFailed(res, "3a " + tojson(res)); f.remove({y: 2}); f.dropIndex({x: 1, y: 1}); @@ -73,13 +73,13 @@ f.createIndex({x: 1, y: 1}); assert.eq(1, f.count(), "3. count after removing array value should be 1"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(true, res.ok, "3b " + tojson(res)); +assert.commandWorked(res, "3b " + tojson(res)); f.save({x: 2, y: [1, 2]}); assert.eq(2, f.count(), "3. count after adding array value should be 2"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok, "3c " + tojson(res)); +assert.commandFailed(res, "3c " + tojson(res)); // ------------------------- // Case 4: Handles prefix shard key indexes. @@ -93,21 +93,21 @@ f.save({x: 1, y: 1, z: 1}); assert.eq(1, f.count(), "4. count after initial insert should be 1"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1}}); -assert.eq(true, res.ok, "4a " + tojson(res)); +assert.commandWorked(res, "4a " + tojson(res)); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(true, res.ok, "4b " + tojson(res)); +assert.commandWorked(res, "4b " + tojson(res)); f.save({x: [1, 2], y: 2, z: 2}); assert.eq(2, f.count(), "4. count after adding array value should be 2"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1}}); -assert.eq(false, res.ok, "4c " + tojson(res)); +assert.commandFailed(res, "4c " + tojson(res)); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok, "4d " + tojson(res)); +assert.commandFailed(res, "4d " + tojson(res)); res = db.runCommand( {checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1, z: 1}}); -assert.eq(false, res.ok, "4e " + tojson(res)); +assert.commandFailed(res, "4e " + tojson(res)); f.remove({y: 2}); f.dropIndex({x: 1, y: 1, z: 1}); @@ -116,18 +116,18 @@ f.createIndex({x: 1, y: 1, z: 1}); assert.eq(1, f.count(), "4. count after removing array value should be 1"); res = db.runCommand( {checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1, z: 1}}); -assert.eq(true, res.ok, "4f " + tojson(res)); +assert.commandWorked(res, "4f " + tojson(res)); f.save({x: 3, y: [1, 2], z: 3}); assert.eq(2, f.count(), "4. count after adding array value on second key should be 2"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1}}); -assert.eq(false, res.ok, "4g " + tojson(res)); +assert.commandFailed(res, "4g " + tojson(res)); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok, "4h " + tojson(res)); +assert.commandFailed(res, "4h " + tojson(res)); res = db.runCommand( {checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1, z: 1}}); -assert.eq(false, res.ok, "4i " + tojson(res)); +assert.commandFailed(res, "4i " + tojson(res)); f.remove({x: 3}); // Necessary so that the index is no longer marked as multikey @@ -137,18 +137,18 @@ f.createIndex({x: 1, y: 1, z: 1}); assert.eq(1, f.count(), "4. count after removing array value should be 1 again"); res = db.runCommand( {checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1, z: 1}}); -assert.eq(true, res.ok, "4e " + tojson(res)); +assert.commandWorked(res, "4e " + tojson(res)); f.save({x: 4, y: 4, z: [1, 2]}); assert.eq(2, f.count(), "4. count after adding array value on third key should be 2"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1}}); -assert.eq(false, res.ok, "4c " + tojson(res)); +assert.commandFailed(res, "4c " + tojson(res)); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok, "4d " + tojson(res)); +assert.commandFailed(res, "4d " + tojson(res)); res = db.runCommand( {checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1, z: 1}}); -assert.eq(false, res.ok, "4e " + tojson(res)); +assert.commandFailed(res, "4e " + tojson(res)); // ------------------------- // Test error messages of checkShardingIndex failing: @@ -157,21 +157,21 @@ assert.eq(false, res.ok, "4e " + tojson(res)); f.drop(); f.createIndex({x: 1}); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {y: 1}}); -assert.eq(false, res.ok); +assert.commandFailed(res); assert(res.errmsg.includes("Shard key is not a prefix of index key.")); // Index key is partial: f.drop(); f.createIndex({x: 1, y: 1}, {partialFilterExpression: {y: {$gt: 0}}}); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok); +assert.commandFailed(res); assert(res.errmsg.includes("Index key is partial.")); // Index key is sparse: f.drop(); f.createIndex({x: 1, y: 1}, {sparse: true}); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok); +assert.commandFailed(res); assert(res.errmsg.includes("Index key is sparse.")); // Index key is multikey: @@ -179,21 +179,21 @@ f.drop(); f.createIndex({x: 1, y: 1}); f.save({y: [1, 2, 3, 4, 5]}); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok); +assert.commandFailed(res); assert(res.errmsg.includes("Index key is multikey.")); // Index key has a non-simple collation: f.drop(); f.createIndex({x: 1, y: 1}, {collation: {locale: "en"}}); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok); +assert.commandFailed(res); assert(res.errmsg.includes("Index has a non-simple collation.")); // Index key is sparse and index has non-simple collation: f.drop(); f.createIndex({x: 1, y: 1}, {sparse: true, collation: {locale: "en"}}); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok); +assert.commandFailed(res); assert(res.errmsg.includes("Index key is sparse.") && res.errmsg.includes("Index has a non-simple collation.")); @@ -203,7 +203,7 @@ f.createIndex({x: 1, y: 1}, {name: "index_1_part", partialFilterExpression: {x: f.createIndex({x: 1, y: 1}, {name: "index_2"}); f.save({y: [1, 2, 3, 4, 5]}); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok); +assert.commandFailed(res); assert(res.errmsg.includes("Index key is multikey.") && res.errmsg.includes("Index key is partial.")); @@ -212,7 +212,7 @@ f.drop(); f.createIndex({x: 1, y: 1}, {name: "index_1_part", partialFilterExpression: {x: {$gt: 0}}}); f.createIndex({x: 1, y: 1}, {name: "index_2_sparse", sparse: true}); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); -assert.eq(false, res.ok); +assert.commandFailed(res); assert(res.errmsg.includes("Index key is partial.") && res.errmsg.includes("Index key is sparse.")); print("PASSED"); |
