summaryrefslogtreecommitdiff
path: root/jstests/core/apply_ops_index_collation.js
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2017-11-03 16:38:34 -0400
committerMaria van Keulen <maria@mongodb.com>2017-11-06 09:36:49 -0500
commit880a044852cc099ab9edb61a3b1b173e68ec5deb (patch)
tree9d5ab56fdb63f77d426abc73df941125cbef110a /jstests/core/apply_ops_index_collation.js
parent407e2d1a1aff5ce019e1b0fb9e3259620bda3751 (diff)
downloadmongo-880a044852cc099ab9edb61a3b1b173e68ec5deb.tar.gz
SERVER-31435 Move applyOps index collation test into jsCore
Diffstat (limited to 'jstests/core/apply_ops_index_collation.js')
-rw-r--r--jstests/core/apply_ops_index_collation.js145
1 files changed, 145 insertions, 0 deletions
diff --git a/jstests/core/apply_ops_index_collation.js b/jstests/core/apply_ops_index_collation.js
new file mode 100644
index 00000000000..6ac326c6851
--- /dev/null
+++ b/jstests/core/apply_ops_index_collation.js
@@ -0,0 +1,145 @@
+// Cannot implicitly shard accessed collections because of collection existing when none
+// expected.
+// @tags: [assumes_no_implicit_collection_creation_after_drop]
+
+// Tests creation of indexes using applyOps for collections with a non-simple default collation.
+// Indexes created through applyOps should be built exactly according to their index spec, without
+// inheriting the collection default collation, since this is how the oplog entries are replicated.
+(function() {
+ "use strict";
+
+ load("jstests/libs/get_index_helpers.js");
+ load('jstests/libs/uuid_util.js');
+
+ const coll = db.apply_ops_index_collation;
+ coll.drop();
+ assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+ const uuid = getUUIDFromListCollections(db, coll.getName());
+
+ // An index created using a createIndexes-style oplog entry with a non-simple collation does not
+ // inherit the collection default collation.
+ let res = assert.commandWorked(db.adminCommand({
+ applyOps: [{
+ op: "c",
+ ns: coll.getFullName(),
+ ui: uuid,
+ o: {
+ createIndexes: coll.getFullName(),
+ v: 2,
+ key: {a: 1},
+ name: "a_1_en",
+ collation: {
+ locale: "en_US",
+ caseLevel: false,
+ caseFirst: "off",
+ strength: 3,
+ numericOrdering: false,
+ alternate: "non-ignorable",
+ maxVariable: "punct",
+ normalization: false,
+ backwards: false,
+ version: "57.1"
+ }
+ }
+ }]
+ }));
+ let allIndexes = coll.getIndexes();
+ let spec = GetIndexHelpers.findByName(allIndexes, "a_1_en");
+ assert.neq(null, spec, "Index 'a_1_en' not found: " + tojson(allIndexes));
+ assert.eq(2, spec.v, tojson(spec));
+ assert.eq("en_US", spec.collation.locale, tojson(spec));
+
+ // An index created using a createIndexes-style oplog entry with a simple collation does not
+ // inherit the collection default collation.
+ res = assert.commandWorked(db.adminCommand({
+ applyOps: [{
+ op: "c",
+ ns: coll.getFullName(),
+ ui: uuid,
+ o: {createIndexes: coll.getFullName(), v: 2, key: {a: 1}, name: "a_1"}
+ }]
+ }));
+ allIndexes = coll.getIndexes();
+ spec = GetIndexHelpers.findByName(allIndexes, "a_1");
+ assert.neq(null, spec, "Index 'a_1' not found: " + tojson(allIndexes));
+ assert.eq(2, spec.v, tojson(spec));
+ assert(!spec.hasOwnProperty("collation"), tojson(spec));
+
+ // A v=1 index created using a createIndexes-style oplog entry does not inherit the collection
+ // default collation.
+ res = assert.commandWorked(db.adminCommand({
+ applyOps: [{
+ op: "c",
+ ns: coll.getFullName(),
+ ui: uuid,
+ o: {createIndexes: coll.getFullName(), v: 1, key: {b: 1}, name: "b_1"}
+ }]
+ }));
+ allIndexes = coll.getIndexes();
+ spec = GetIndexHelpers.findByName(allIndexes, "b_1");
+ assert.neq(null, spec, "Index 'b_1' not found: " + tojson(allIndexes));
+ assert.eq(1, spec.v, tojson(spec));
+ assert(!spec.hasOwnProperty("collation"), tojson(spec));
+
+ // An index created using an insert-style oplog entry with a non-simple collation does not
+ // inherit the collection default collation.
+ res = assert.commandWorked(db.adminCommand({
+ applyOps: [{
+ op: "i",
+ ns: db.system.indexes.getFullName(),
+ o: {
+ v: 2,
+ key: {c: 1},
+ name: "c_1_en",
+ ns: coll.getFullName(),
+ collation: {
+ locale: "en_US",
+ caseLevel: false,
+ caseFirst: "off",
+ strength: 3,
+ numericOrdering: false,
+ alternate: "non-ignorable",
+ maxVariable: "punct",
+ normalization: false,
+ backwards: false,
+ version: "57.1"
+ }
+ }
+ }]
+ }));
+ allIndexes = coll.getIndexes();
+ spec = GetIndexHelpers.findByName(allIndexes, "c_1_en");
+ assert.neq(null, spec, "Index 'c_1_en' not found: " + tojson(allIndexes));
+ assert.eq(2, spec.v, tojson(spec));
+ assert.eq("en_US", spec.collation.locale, tojson(spec));
+
+ // An index created using an insert-style oplog entry with a simple collation does not inherit
+ // the collection default collation.
+ res = assert.commandWorked(db.adminCommand({
+ applyOps: [{
+ op: "i",
+ ns: db.system.indexes.getFullName(),
+ o: {v: 2, key: {c: 1}, name: "c_1", ns: coll.getFullName()}
+ }]
+ }));
+ allIndexes = coll.getIndexes();
+ spec = GetIndexHelpers.findByName(allIndexes, "c_1");
+ assert.neq(null, spec, "Index 'c_1' not found: " + tojson(allIndexes));
+ assert.eq(2, spec.v, tojson(spec));
+ assert(!spec.hasOwnProperty("collation"), tojson(spec));
+
+ // A v=1 index created using an insert-style oplog entry does not inherit the collection default
+ // collation.
+ res = assert.commandWorked(db.adminCommand({
+ applyOps: [{
+ op: "i",
+ ns: db.system.indexes.getFullName(),
+ o: {v: 1, key: {d: 1}, name: "d_1", ns: coll.getFullName()}
+ }]
+ }));
+ allIndexes = coll.getIndexes();
+ spec = GetIndexHelpers.findByName(allIndexes, "d_1");
+ assert.neq(null, spec, "Index 'd_1' not found: " + tojson(allIndexes));
+ assert.eq(1, spec.v, tojson(spec));
+ assert(!spec.hasOwnProperty("collation"), tojson(spec));
+})();