summaryrefslogtreecommitdiff
path: root/jstests/core
diff options
context:
space:
mode:
authorHaley Connelly <haley.connelly@mongodb.com>2021-10-27 21:09:21 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-10-27 21:49:01 +0000
commit14c24398c1ed8e2c680ed133c48c976d205868f9 (patch)
treef2dec6a98c948e1b41803f6b08520dd6a6e754d9 /jstests/core
parentdea0353a2927370505ae22307d5d72362af9017b (diff)
downloadmongo-14c24398c1ed8e2c680ed133c48c976d205868f9.tar.gz
SERVER-61019 Move clustered_indexes_utils.js content under ClusteredCollectionUtil class
Diffstat (limited to 'jstests/core')
-rw-r--r--jstests/core/clustered_collection_basic.js (renamed from jstests/core/clustered_indexes.js)6
-rw-r--r--jstests/core/clustered_collection_creation.js74
-rw-r--r--jstests/core/clustered_collection_nonreplicated_basic.js (renamed from jstests/core/clustered_indexes_nonreplicated.js)6
3 files changed, 26 insertions, 60 deletions
diff --git a/jstests/core/clustered_indexes.js b/jstests/core/clustered_collection_basic.js
index 5fa3672fd52..2f56ce4d211 100644
--- a/jstests/core/clustered_indexes.js
+++ b/jstests/core/clustered_collection_basic.js
@@ -15,9 +15,9 @@
(function() {
"use strict";
-load("jstests/libs/clustered_indexes_utils.js");
+load("jstests/libs/clustered_collection_util.js");
-if (areClusteredIndexesEnabled(db.getMongo()) == false) {
+if (ClusteredCollectionUtil.areClusteredIndexesEnabled(db.getMongo()) == false) {
jsTestLog('Skipping test because the clustered indexes feature flag is disabled');
return;
}
@@ -28,5 +28,5 @@ const replicatedColl = replicatedDB[collName];
replicatedColl.drop();
-validateClusteredCollection(replicatedDB, collName, '_id');
+ClusteredCollectionUtil.testBasicClusteredCollection(replicatedDB, collName, '_id');
})();
diff --git a/jstests/core/clustered_collection_creation.js b/jstests/core/clustered_collection_creation.js
index ac442edc418..e8483ebe700 100644
--- a/jstests/core/clustered_collection_creation.js
+++ b/jstests/core/clustered_collection_creation.js
@@ -1,7 +1,7 @@
/**
* Tests the options used to create a clustered collection. Validates the created collection's
* listIndexes and listCollections outputs and ensures the clusteredIndex cannot be dropped
- * regardless of the creation options used.
+ * regardless of the create options used.
* Covers clustering on {_id: 1} for replicated collections, and clustering on non-_id fields for
* non-replicated collections.
*
@@ -15,36 +15,16 @@
(function() {
"use strict";
-const clusteredIndexesEnabled = assert
- .commandWorked(db.getMongo().adminCommand(
- {getParameter: 1, featureFlagClusteredIndexes: 1}))
- .featureFlagClusteredIndexes.value;
+load("jstests/libs/clustered_collection_util.js");
-if (!clusteredIndexesEnabled) {
+if (!ClusteredCollectionUtil.areClusteredIndexesEnabled(db.getMongo())) {
jsTestLog('Skipping test because the clustered indexes feature flag is disabled');
return;
}
-// listCollections should include the clusteredIndex.
-const validateListCollections = function(db, collName, fullCreationOptions) {
- const listColls =
- assert.commandWorked(db.runCommand({listCollections: 1, filter: {name: collName}}));
- const listCollsOptions = listColls.cursor.firstBatch[0].options;
- assert(listCollsOptions.clusteredIndex);
- assert.docEq(listCollsOptions.clusteredIndex, fullCreationOptions.clusteredIndex);
-};
-
-// The clusteredIndex should appear in listIndexes with additional "clustered" field.
-const validateListIndexes = function(db, collName, fullCreationOptions) {
- const listIndexes = assert.commandWorked(db[collName].runCommand("listIndexes"));
- const expectedListIndexesOutput =
- Object.extend({clustered: true}, fullCreationOptions.clusteredIndex);
- assert.docEq(listIndexes.cursor.firstBatch[0], expectedListIndexesOutput);
-};
-
// Cannot create an index with the same key as the cluster key
-const validateClusteredIndexAlreadyExists = function(db, collName, fullCreationOptions) {
- const clusterKey = fullCreationOptions.clusteredIndex.key;
+const validateClusteredIndexAlreadyExists = function(db, collName, fullCreateOptions) {
+ const clusterKey = fullCreateOptions.clusteredIndex.key;
const res = db[collName].createIndex(clusterKey);
assert.commandFailedWithCode(res, ErrorCodes.CannotCreateIndex);
const clusterKeyField = Object.keys(clusterKey)[0];
@@ -57,9 +37,9 @@ const validateClusteredIndexAlreadyExists = function(db, collName, fullCreationO
// It is illegal to drop the clusteredIndex. Verify that the various ways of dropping the
// clusteredIndex fail accordingly.
-const validateClusteredIndexUndroppable = function(db, collName, fullCreationOptions) {
- const expectedIndexName = fullCreationOptions.clusteredIndex.name;
- const expectedIndexKey = fullCreationOptions.clusteredIndex.key;
+const validateClusteredIndexUndroppable = function(db, collName, fullCreateOptions) {
+ const expectedIndexName = fullCreateOptions.clusteredIndex.name;
+ const expectedIndexKey = fullCreateOptions.clusteredIndex.key;
assert.commandFailedWithCode(db[collName].dropIndex(expectedIndexKey), 5979800);
@@ -69,39 +49,25 @@ const validateClusteredIndexUndroppable = function(db, collName, fullCreationOpt
5979800);
};
-const validateCreatedCollection = function(db, collName, creationOptions) {
- // Upon creating a collection, fields absent in the user provided creation options are filled in
- // with default values. The fullCreationOptions should contain default values for the fields not
+const validateCreatedCollection = function(db, collName, createOptions) {
+ // Upon creating a collection, fields absent in the user provided create options are filled in
+ // with default values. The fullCreateOptions should contain default values for the fields not
// specified by the user.
- let fullCreationOptions = creationOptions;
+ const fullCreateOptions = ClusteredCollectionUtil.constructFullCreateOptions(createOptions);
- // If the creationOptions don't specify the name, expect the default.
- if (!creationOptions.clusteredIndex.name) {
- const clusterKey = Object.keys(creationOptions.clusteredIndex.key)[0];
- if (clusterKey == "_id") {
- fullCreationOptions.clusteredIndex.name = "_id_";
- } else {
- fullCreationOptions.clusteredIndex.name = clusterKey + "_1";
- }
- }
-
- // If the creationOptions don't specify 'v', expect the default.
- if (!creationOptions.clusteredIndex.v) {
- fullCreationOptions.clusteredIndex.v = 2;
- }
+ ClusteredCollectionUtil.validateListCollections(db, collName, fullCreateOptions);
+ ClusteredCollectionUtil.validateListIndexes(db, collName, fullCreateOptions);
- validateListCollections(db, collName, fullCreationOptions);
- validateListIndexes(db, collName, fullCreationOptions);
- validateClusteredIndexAlreadyExists(db, collName, fullCreationOptions);
- validateClusteredIndexUndroppable(db, collName, fullCreationOptions);
+ validateClusteredIndexAlreadyExists(db, collName, fullCreateOptions);
+ validateClusteredIndexUndroppable(db, collName, fullCreateOptions);
};
/**
- * Creates, validates, and drops a clustered collection with the provided creationOptions.
+ * Creates, validates, and drops a clustered collection with the provided createOptions.
*/
-const runSuccessfulCreate = function(db, coll, creationOptions) {
- assert.commandWorked(db.createCollection(coll.getName(), creationOptions));
- validateCreatedCollection(db, coll.getName(), creationOptions);
+const runSuccessfulCreate = function(db, coll, createOptions) {
+ assert.commandWorked(db.createCollection(coll.getName(), createOptions));
+ validateCreatedCollection(db, coll.getName(), createOptions);
coll.drop();
};
diff --git a/jstests/core/clustered_indexes_nonreplicated.js b/jstests/core/clustered_collection_nonreplicated_basic.js
index f9117814650..47e14c04a89 100644
--- a/jstests/core/clustered_indexes_nonreplicated.js
+++ b/jstests/core/clustered_collection_nonreplicated_basic.js
@@ -21,9 +21,9 @@
(function() {
"use strict";
-load("jstests/libs/clustered_indexes_utils.js");
+load("jstests/libs/clustered_collection_util.js");
-if (areClusteredIndexesEnabled(db.getMongo()) == false) {
+if (ClusteredCollectionUtil.areClusteredIndexesEnabled(db.getMongo()) == false) {
jsTestLog('Skipping test because the clustered indexes feature flag is disabled');
return;
}
@@ -34,5 +34,5 @@ const nonReplicatedColl = nonReplicatedDB[collName];
nonReplicatedColl.drop();
-validateClusteredCollection(nonReplicatedDB, collName, 'ts');
+ClusteredCollectionUtil.testBasicClusteredCollection(nonReplicatedDB, collName, 'ts');
})();