Skip to content

Commit

Permalink
mongo: SERVER-62520 Add test for {clusteredIndex: false}
Browse files Browse the repository at this point in the history
Commit: 62dcce62e7be38f9637cdd967070713ebfa6aaa5
  • Loading branch information
Jordi Olivares Provencio authored and sourcegraph-bot committed Jan 17, 2022
1 parent 22134c6 commit 6f9483c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mongo/jstests/core/clustered_collection_creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ const runSuccessfulCreate = function(db, coll, createOptions) {
coll.drop();
};

const validateCreatedCollectionNonClustered = function(db, collName) {
ClusteredCollectionUtil.validateListCollectionsNotClustered(db, collName);
ClusteredCollectionUtil.validateListIndexesNonClustered(db, collName);
};

const runSuccessfulCreateNonClustered = function(db, coll, createOptions) {
assert.commandWorked(db.createCollection(coll.getName(), createOptions));
validateCreatedCollectionNonClustered(db, coll.getName(), createOptions);
coll.drop();
};

const validateClusteredCappedCollections = function(db, coll, clusterKey) {
runSuccessfulCreate(
db,
Expand Down Expand Up @@ -170,6 +181,13 @@ const nonReplicatedColl = nonReplicatedDB.coll;
replicatedColl.drop();
nonReplicatedColl.drop();

runSuccessfulCreateNonClustered(
replicatedDB, replicatedColl, {clusteredIndex: false, expireAfterSeconds: 5});
runSuccessfulCreateNonClustered(
nonReplicatedDB, nonReplicatedColl, {clusteredIndex: false, expireAfterSeconds: 5});
runSuccessfulCreateNonClustered(
nonReplicatedDB, nonReplicatedColl, {clusteredIndex: false, expireAfterSeconds: 5});

runSuccessfulCreate(replicatedDB, replicatedColl, {clusteredIndex: {key: {_id: 1}, unique: true}});
runSuccessfulCreate(
nonReplicatedDB, nonReplicatedColl, {clusteredIndex: {key: {ts: 1}, unique: true}});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ var ClusteredCollectionUtil = class {
return fullCreateOptions;
}

static validateListCollectionsNotClustered(db, collName) {
const listColls =
assert.commandWorked(db.runCommand({listCollections: 1, filter: {name: collName}}));
const listCollsOptions = listColls.cursor.firstBatch[0].options;
assert.eq(
listCollsOptions.clusteredIndex, undefined, "Expected clusteredIndex to be undefined");
}

static validateListIndexesNonClustered(db, collName) {
const listIndexes = assert.commandWorked(db[collName].runCommand("listIndexes"));
assert.eq(listIndexes.cursor.firstBatch[0].clustered || false,
false,
"Index had clustering in it when it shouldn't");
}

// Provided the createOptions used to create the collection, validates the output from
// listCollections contains the correct information about the clusteredIndex.
static validateListCollections(db, collName, createOptions) {
Expand Down

0 comments on commit 6f9483c

Please sign in to comment.