From 5eda33f9fa40a1a17f9f63f904a8c147700d648c Mon Sep 17 00:00:00 2001 From: Xiangyu Yao Date: Mon, 17 Jun 2019 21:04:19 -0400 Subject: SERVER-41583 Refactor the registration and de-registration of collection and catalog entry --- .../document_source_change_stream_test.cpp | 45 +++++++--------------- 1 file changed, 14 insertions(+), 31 deletions(-) (limited to 'src/mongo/db/pipeline/document_source_change_stream_test.cpp') diff --git a/src/mongo/db/pipeline/document_source_change_stream_test.cpp b/src/mongo/db/pipeline/document_source_change_stream_test.cpp index 40a55a2c2f8..cc1a9916609 100644 --- a/src/mongo/db/pipeline/document_source_change_stream_test.cpp +++ b/src/mongo/db/pipeline/document_source_change_stream_test.cpp @@ -418,9 +418,7 @@ TEST_F(ChangeStreamStageTest, ShouldRejectBothStartAtOperationTimeAndResumeAfter auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); CollectionCatalog::get(getExpCtx()->opCtx) - .registerCatalogEntry(testUuid(), std::move(catalogEntry)); - CollectionCatalog::get(expCtx->opCtx) - .onCreateCollection(expCtx->opCtx, std::move(collection), testUuid()); + .registerCollection(testUuid(), std::move(catalogEntry), std::move(collection)); ASSERT_THROWS_CODE( DSChangeStream::createFromBson( @@ -443,8 +441,7 @@ TEST_F(ChangeStreamStageTest, ShouldRejectBothStartAfterAndResumeAfterOptions) { auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); auto& catalog = CollectionCatalog::get(opCtx); - catalog.registerCatalogEntry(testUuid(), std::move(catalogEntry)); - catalog.onCreateCollection(expCtx->opCtx, std::move(collection), testUuid()); + catalog.registerCollection(testUuid(), std::move(catalogEntry), std::move(collection)); ASSERT_THROWS_CODE( DSChangeStream::createFromBson( @@ -467,8 +464,7 @@ TEST_F(ChangeStreamStageTest, ShouldRejectBothStartAtOperationTimeAndStartAfterO auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); auto& catalog = CollectionCatalog::get(opCtx); - catalog.registerCatalogEntry(testUuid(), std::move(catalogEntry)); - catalog.onCreateCollection(expCtx->opCtx, std::move(collection), testUuid()); + catalog.registerCollection(testUuid(), std::move(catalogEntry), std::move(collection)); ASSERT_THROWS_CODE( DSChangeStream::createFromBson( @@ -491,8 +487,7 @@ TEST_F(ChangeStreamStageTest, ShouldRejectResumeAfterWithResumeTokenMissingUUID) auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); auto& catalog = CollectionCatalog::get(opCtx); - catalog.registerCatalogEntry(testUuid(), std::move(catalogEntry)); - catalog.onCreateCollection(expCtx->opCtx, std::move(collection), testUuid()); + catalog.registerCollection(testUuid(), std::move(catalogEntry), std::move(collection)); ASSERT_THROWS_CODE( DSChangeStream::createFromBson( @@ -1520,9 +1515,8 @@ TEST_F(ChangeStreamStageTest, DocumentKeyShouldIncludeShardKeyFromResumeToken) { auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); - CollectionCatalog::get(getExpCtx()->opCtx).registerCatalogEntry(uuid, std::move(catalogEntry)); CollectionCatalog::get(getExpCtx()->opCtx) - .onCreateCollection(getExpCtx()->opCtx, std::move(collection), uuid); + .registerCollection(uuid, std::move(catalogEntry), std::move(collection)); BSONObj o2 = BSON("_id" << 1 << "shardKey" << 2); auto resumeToken = makeResumeToken(ts, uuid, o2); @@ -1568,9 +1562,8 @@ TEST_F(ChangeStreamStageTest, DocumentKeyShouldNotIncludeShardKeyFieldsIfNotPres auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); - CollectionCatalog::get(getExpCtx()->opCtx).registerCatalogEntry(uuid, std::move(catalogEntry)); CollectionCatalog::get(getExpCtx()->opCtx) - .onCreateCollection(getExpCtx()->opCtx, std::move(collection), uuid); + .registerCollection(uuid, std::move(catalogEntry), std::move(collection)); BSONObj o2 = BSON("_id" << 1 << "shardKey" << 2); auto resumeToken = makeResumeToken(ts, uuid, o2); @@ -1613,9 +1606,8 @@ TEST_F(ChangeStreamStageTest, ResumeAfterFailsIfResumeTokenDoesNotContainUUID) { auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); - CollectionCatalog::get(getExpCtx()->opCtx).registerCatalogEntry(uuid, std::move(catalogEntry)); CollectionCatalog::get(getExpCtx()->opCtx) - .onCreateCollection(getExpCtx()->opCtx, std::move(collection), uuid); + .registerCollection(uuid, std::move(catalogEntry), std::move(collection)); // Create a resume token from only the timestamp. auto resumeToken = makeResumeToken(ts); @@ -1670,9 +1662,7 @@ TEST_F(ChangeStreamStageTest, ResumeAfterWithTokenFromInvalidateShouldFail) { auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); CollectionCatalog::get(getExpCtx()->opCtx) - .registerCatalogEntry(testUuid(), std::move(catalogEntry)); - CollectionCatalog::get(expCtx->opCtx) - .onCreateCollection(expCtx->opCtx, std::move(collection), testUuid()); + .registerCollection(testUuid(), std::move(catalogEntry), std::move(collection)); const auto resumeTokenInvalidate = makeResumeToken(kDefaultTs, @@ -2108,9 +2098,8 @@ TEST_F(ChangeStreamStageDBTest, DocumentKeyShouldIncludeShardKeyFromResumeToken) auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); - CollectionCatalog::get(getExpCtx()->opCtx).registerCatalogEntry(uuid, std::move(catalogEntry)); CollectionCatalog::get(getExpCtx()->opCtx) - .onCreateCollection(getExpCtx()->opCtx, std::move(collection), uuid); + .registerCollection(uuid, std::move(catalogEntry), std::move(collection)); BSONObj o2 = BSON("_id" << 1 << "shardKey" << 2); auto resumeToken = makeResumeToken(ts, uuid, o2); @@ -2147,9 +2136,8 @@ TEST_F(ChangeStreamStageDBTest, DocumentKeyShouldNotIncludeShardKeyFieldsIfNotPr auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); - CollectionCatalog::get(getExpCtx()->opCtx).registerCatalogEntry(uuid, std::move(catalogEntry)); CollectionCatalog::get(getExpCtx()->opCtx) - .onCreateCollection(getExpCtx()->opCtx, std::move(collection), uuid); + .registerCollection(uuid, std::move(catalogEntry), std::move(collection)); BSONObj o2 = BSON("_id" << 1 << "shardKey" << 2); auto resumeToken = makeResumeToken(ts, uuid, o2); @@ -2187,9 +2175,8 @@ TEST_F(ChangeStreamStageDBTest, DocumentKeyShouldNotIncludeShardKeyIfResumeToken auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); - CollectionCatalog::get(getExpCtx()->opCtx).registerCatalogEntry(uuid, std::move(catalogEntry)); CollectionCatalog::get(getExpCtx()->opCtx) - .onCreateCollection(getExpCtx()->opCtx, std::move(collection), uuid); + .registerCollection(uuid, std::move(catalogEntry), std::move(collection)); // Create a resume token from only the timestamp. auto resumeToken = makeResumeToken(ts); @@ -2227,9 +2214,7 @@ TEST_F(ChangeStreamStageDBTest, ResumeAfterWithTokenFromInvalidateShouldFail) { auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); CollectionCatalog::get(getExpCtx()->opCtx) - .registerCatalogEntry(testUuid(), std::move(catalogEntry)); - CollectionCatalog::get(expCtx->opCtx) - .onCreateCollection(expCtx->opCtx, std::move(collection), testUuid()); + .registerCollection(testUuid(), std::move(catalogEntry), std::move(collection)); const auto resumeTokenInvalidate = makeResumeToken(kDefaultTs, @@ -2251,9 +2236,8 @@ TEST_F(ChangeStreamStageDBTest, ResumeAfterWithTokenFromDropDatabase) { auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); - CollectionCatalog::get(getExpCtx()->opCtx).registerCatalogEntry(uuid, std::move(catalogEntry)); CollectionCatalog::get(getExpCtx()->opCtx) - .onCreateCollection(getExpCtx()->opCtx, std::move(collection), uuid); + .registerCollection(uuid, std::move(catalogEntry), std::move(collection)); // Create a resume token from only the timestamp, similar to a 'dropDatabase' entry. auto resumeToken = makeResumeToken( @@ -2283,9 +2267,8 @@ TEST_F(ChangeStreamStageDBTest, StartAfterSucceedsEvenIfResumeTokenDoesNotContai auto collection = std::make_unique(nss); auto catalogEntry = std::make_unique(nss.ns()); - CollectionCatalog::get(getExpCtx()->opCtx).registerCatalogEntry(uuid, std::move(catalogEntry)); CollectionCatalog::get(getExpCtx()->opCtx) - .onCreateCollection(getExpCtx()->opCtx, std::move(collection), uuid); + .registerCollection(uuid, std::move(catalogEntry), std::move(collection)); // Create a resume token from only the timestamp, similar to a 'dropDatabase' entry. auto resumeToken = makeResumeToken(kDefaultTs); -- cgit v1.2.1