summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authormathisbessamdb <mathis.bessa@mongodb.com>2023-04-11 22:02:26 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-17 23:09:15 +0000
commit3c5d9c099046af67ee02564cf5eeabd2031b5da2 (patch)
tree65931a95e185cf43382f8b8609645bd1cf160a81 /src/mongo/db
parent7e2837b75aef36024e9050ec183b0997a0afc143 (diff)
downloadmongo-3c5d9c099046af67ee02564cf5eeabd2031b5da2.tar.gz
SERVER-76085 Create createDatabaseName_forTest to be used in unit testing
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/auth/builtin_roles_test.cpp5
-rw-r--r--src/mongo/db/catalog/collection_catalog_test.cpp74
-rw-r--r--src/mongo/db/catalog/rename_collection_test.cpp3
-rw-r--r--src/mongo/db/catalog_raii_test.cpp6
-rw-r--r--src/mongo/db/commands/external_data_source_commands_test.cpp2
-rw-r--r--src/mongo/db/commands_test.cpp12
-rw-r--r--src/mongo/db/concurrency/d_concurrency_bm.cpp8
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp179
-rw-r--r--src/mongo/db/concurrency/lock_state_test.cpp57
-rw-r--r--src/mongo/db/database_name.h5
-rw-r--r--src/mongo/db/database_name_test.cpp36
-rw-r--r--src/mongo/db/namespace_string_test.cpp9
-rw-r--r--src/mongo/db/op_observer/op_observer_registry_test.cpp10
-rw-r--r--src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp5
-rw-r--r--src/mongo/db/pipeline/aggregation_request_test.cpp14
-rw-r--r--src/mongo/db/pipeline/change_stream_event_transform_test.cpp21
-rw-r--r--src/mongo/db/pipeline/document_source_change_stream_add_post_image_test.cpp6
-rw-r--r--src/mongo/db/pipeline/document_source_change_stream_test.cpp7
-rw-r--r--src/mongo/db/pipeline/document_source_current_op_test.cpp7
-rw-r--r--src/mongo/db/pipeline/document_source_facet_test.cpp4
-rw-r--r--src/mongo/db/pipeline/document_source_telemetry_test.cpp7
-rw-r--r--src/mongo/db/pipeline/pipeline_test.cpp13
-rw-r--r--src/mongo/db/repl/all_database_cloner_test.cpp48
-rw-r--r--src/mongo/db/repl/database_cloner_test.cpp6
-rw-r--r--src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp2
-rw-r--r--src/mongo/db/repl/storage_timestamp_test.cpp8
-rw-r--r--src/mongo/db/repl/tenant_migration_access_blocker_registry_test.cpp60
-rw-r--r--src/mongo/db/repl/tenant_oplog_applier_test.cpp5
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp22
-rw-r--r--src/mongo/db/s/database_sharding_state_test.cpp10
-rw-r--r--src/mongo/db/s/global_index/global_index_cloning_service_test.cpp2
-rw-r--r--src/mongo/db/s/global_index/global_index_inserter_test.cpp2
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp5
-rw-r--r--src/mongo/db/shard_role_test.cpp2
-rw-r--r--src/mongo/db/stats/fill_locker_info_test.cpp4
-rw-r--r--src/mongo/db/storage/storage_repair_observer_test.cpp4
-rw-r--r--src/mongo/db/transaction/transaction_api_test.cpp487
-rw-r--r--src/mongo/db/transaction/transaction_participant_test.cpp33
-rw-r--r--src/mongo/db/views/view_catalog_test.cpp11
-rw-r--r--src/mongo/db/views/view_graph_test.cpp6
40 files changed, 691 insertions, 516 deletions
diff --git a/src/mongo/db/auth/builtin_roles_test.cpp b/src/mongo/db/auth/builtin_roles_test.cpp
index 22c8d5af515..ff5745501e6 100644
--- a/src/mongo/db/auth/builtin_roles_test.cpp
+++ b/src/mongo/db/auth/builtin_roles_test.cpp
@@ -75,7 +75,7 @@ TEST(BuiltinRoles, BuiltinRolesOnlyOnAppropriateDatabases) {
}
TEST(BuiltinRoles, getBuiltinRolesForDB) {
- auto adminRoles = auth::getBuiltinRoleNamesForDB({boost::none, "admin"});
+ auto adminRoles = auth::getBuiltinRoleNamesForDB(DatabaseName::kAdmin);
ASSERT(adminRoles.contains(RoleName("read", "admin")));
ASSERT(adminRoles.contains(RoleName("readAnyDatabase", "admin")));
for (const auto& role : adminRoles) {
@@ -83,7 +83,8 @@ TEST(BuiltinRoles, getBuiltinRolesForDB) {
ASSERT(auth::isBuiltinRole(role));
}
- auto testRoles = auth::getBuiltinRoleNamesForDB({boost::none, "test"});
+ auto testRoles = auth::getBuiltinRoleNamesForDB(
+ DatabaseName::createDatabaseName_forTest(boost::none, "test"));
ASSERT(testRoles.contains(RoleName("read", "test")));
ASSERT(!testRoles.contains(RoleName("readAnyDatabase", "test")));
for (const auto& role : testRoles) {
diff --git a/src/mongo/db/catalog/collection_catalog_test.cpp b/src/mongo/db/catalog/collection_catalog_test.cpp
index 2fdb7571359..227ec0ca5b0 100644
--- a/src/mongo/db/catalog/collection_catalog_test.cpp
+++ b/src/mongo/db/catalog/collection_catalog_test.cpp
@@ -198,7 +198,8 @@ public:
}
int numEntries = 0;
- for (auto it = catalog.begin(opCtx.get(), DatabaseName(boost::none, "resourceDb"));
+ for (auto it = catalog.begin(
+ opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "resourceDb"));
it != catalog.end(opCtx.get());
it++) {
auto coll = *it;
@@ -213,7 +214,8 @@ public:
void tearDown() {
std::vector<UUID> collectionsToDeregister;
- for (auto it = catalog.begin(opCtx.get(), DatabaseName(boost::none, "resourceDb"));
+ for (auto it = catalog.begin(
+ opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "resourceDb"));
it != catalog.end(opCtx.get());
++it) {
auto coll = *it;
@@ -230,7 +232,8 @@ public:
}
int numEntries = 0;
- for (auto it = catalog.begin(opCtx.get(), DatabaseName(boost::none, "resourceDb"));
+ for (auto it = catalog.begin(
+ opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "resourceDb"));
it != catalog.end(opCtx.get());
it++) {
numEntries++;
@@ -248,7 +251,7 @@ protected:
TEST_F(CollectionCatalogResourceTest, RemoveAllResources) {
catalog.deregisterAllCollectionsAndViews(getServiceContext());
- const DatabaseName dbName = DatabaseName(boost::none, "resourceDb");
+ const DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "resourceDb");
auto rid = ResourceId(RESOURCE_DATABASE, dbName);
ASSERT_EQ(boost::none, ResourceCatalog::get(getServiceContext()).name(rid));
@@ -261,7 +264,7 @@ TEST_F(CollectionCatalogResourceTest, RemoveAllResources) {
}
TEST_F(CollectionCatalogResourceTest, LookupDatabaseResource) {
- const DatabaseName dbName = DatabaseName(boost::none, "resourceDb");
+ const DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "resourceDb");
auto rid = ResourceId(RESOURCE_DATABASE, dbName);
auto ridStr = ResourceCatalog::get(getServiceContext()).name(rid);
@@ -270,7 +273,7 @@ TEST_F(CollectionCatalogResourceTest, LookupDatabaseResource) {
}
TEST_F(CollectionCatalogResourceTest, LookupMissingDatabaseResource) {
- const DatabaseName dbName = DatabaseName(boost::none, "missingDb");
+ const DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "missingDb");
auto rid = ResourceId(RESOURCE_DATABASE, dbName);
ASSERT(!ResourceCatalog::get(getServiceContext()).name(rid));
}
@@ -304,18 +307,19 @@ TEST_F(CollectionCatalogResourceTest, RemoveCollection) {
// Create an iterator over the CollectionCatalog and assert that all collections are present.
// Iteration ends when the end of the catalog is reached.
TEST_F(CollectionCatalogIterationTest, EndAtEndOfCatalog) {
- checkCollections(DatabaseName(boost::none, "foo"));
+ checkCollections(DatabaseName::createDatabaseName_forTest(boost::none, "foo"));
}
// Create an iterator over the CollectionCatalog and test that all collections are present.
// Iteration ends
// when the end of a database-specific section of the catalog is reached.
TEST_F(CollectionCatalogIterationTest, EndAtEndOfSection) {
- checkCollections(DatabaseName(boost::none, "bar"));
+ checkCollections(DatabaseName::createDatabaseName_forTest(boost::none, "bar"));
}
TEST_F(CollectionCatalogIterationTest, GetUUIDWontRepositionEvenIfEntryIsDropped) {
- auto it = catalog.begin(opCtx.get(), DatabaseName(boost::none, "bar"));
+ auto it =
+ catalog.begin(opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "bar"));
auto collsIt = collsIterator("bar");
auto uuid = collsIt->first;
catalog.deregisterCollection(opCtx.get(), uuid, /*isDropPending=*/false, boost::none);
@@ -552,11 +556,12 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNames) {
std::sort(res.begin(), res.end());
ASSERT(res == dCollList);
- std::vector<DatabaseName> dbNames = {DatabaseName(boost::none, "dbA"),
- DatabaseName(boost::none, "dbB"),
- DatabaseName(boost::none, "dbC"),
- DatabaseName(boost::none, "dbD"),
- DatabaseName(boost::none, "testdb")};
+ std::vector<DatabaseName> dbNames = {
+ DatabaseName::createDatabaseName_forTest(boost::none, "dbA"),
+ DatabaseName::createDatabaseName_forTest(boost::none, "dbB"),
+ DatabaseName::createDatabaseName_forTest(boost::none, "dbC"),
+ DatabaseName::createDatabaseName_forTest(boost::none, "dbD"),
+ DatabaseName::createDatabaseName_forTest(boost::none, "testdb")};
ASSERT(catalog.getAllDbNames() == dbNames);
catalog.deregisterAllCollectionsAndViews(getServiceContext());
@@ -578,10 +583,13 @@ TEST_F(CollectionCatalogTest, GetAllDbNamesForTenant) {
}
std::vector<DatabaseName> dbNamesForTid1 = {
- DatabaseName(tid1, "dbA"), DatabaseName(tid1, "dbB"), DatabaseName(tid1, "dbC")};
+ DatabaseName::createDatabaseName_forTest(tid1, "dbA"),
+ DatabaseName::createDatabaseName_forTest(tid1, "dbB"),
+ DatabaseName::createDatabaseName_forTest(tid1, "dbC")};
ASSERT(catalog.getAllDbNamesForTenant(tid1) == dbNamesForTid1);
- std::vector<DatabaseName> dbNamesForTid2 = {DatabaseName(tid2, "dbB")};
+ std::vector<DatabaseName> dbNamesForTid2 = {
+ DatabaseName::createDatabaseName_forTest(tid2, "dbB")};
ASSERT(catalog.getAllDbNamesForTenant(tid2) == dbNamesForTid2);
catalog.deregisterAllCollectionsAndViews(getServiceContext());
@@ -589,8 +597,10 @@ TEST_F(CollectionCatalogTest, GetAllDbNamesForTenant) {
// Test setting and fetching the profile level for a database.
TEST_F(CollectionCatalogTest, DatabaseProfileLevel) {
- DatabaseName testDBNameFirst(boost::none, "testdbfirst");
- DatabaseName testDBNameSecond(boost::none, "testdbsecond");
+ DatabaseName testDBNameFirst =
+ DatabaseName::createDatabaseName_forTest(boost::none, "testdbfirst");
+ DatabaseName testDBNameSecond =
+ DatabaseName::createDatabaseName_forTest(boost::none, "testdbsecond");
// Requesting a profile level that is not in the _databaseProfileLevel map should return the
// default server-wide setting
@@ -632,13 +642,15 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNamesWithUncommitt
invisibleCollA->setCommitted(false);
Lock::DBLock dbLock(opCtx.get(), aColl.dbName(), MODE_S);
- auto res = catalog.getAllCollectionNamesFromDb(opCtx.get(), DatabaseName(boost::none, "dbA"));
+ auto res = catalog.getAllCollectionNamesFromDb(
+ opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "dbA"));
ASSERT(res.empty());
- std::vector<DatabaseName> dbNames = {DatabaseName(boost::none, "dbB"),
- DatabaseName(boost::none, "dbC"),
- DatabaseName(boost::none, "dbD"),
- DatabaseName(boost::none, "testdb")};
+ std::vector<DatabaseName> dbNames = {
+ DatabaseName::createDatabaseName_forTest(boost::none, "dbB"),
+ DatabaseName::createDatabaseName_forTest(boost::none, "dbC"),
+ DatabaseName::createDatabaseName_forTest(boost::none, "dbD"),
+ DatabaseName::createDatabaseName_forTest(boost::none, "testdb")};
ASSERT(catalog.getAllDbNames() == dbNames);
// One dbName with both visible and invisible collections is still visible.
@@ -656,7 +668,8 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNamesWithUncommitt
invisibleCollD->setCommitted(false);
Lock::DBLock dbLock(opCtx.get(), d1Coll.dbName(), MODE_S);
- res = catalog.getAllCollectionNamesFromDb(opCtx.get(), DatabaseName(boost::none, "dbD"));
+ res = catalog.getAllCollectionNamesFromDb(
+ opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "dbD"));
std::sort(res.begin(), res.end());
ASSERT(res == dCollList);
@@ -675,7 +688,8 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNamesWithUncommitt
invisibleColl->setCommitted(false);
}
- std::vector<DatabaseName> dbList = {DatabaseName(boost::none, "testdb")};
+ std::vector<DatabaseName> dbList = {
+ DatabaseName::createDatabaseName_forTest(boost::none, "testdb")};
ASSERT(catalog.getAllDbNames() == dbList);
catalog.deregisterAllCollectionsAndViews(getServiceContext());
@@ -713,7 +727,7 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDb) {
auto opCtx = operationContext();
{
- const DatabaseName dbName(boost::none, "db");
+ const DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "db");
auto dbLock = std::make_unique<Lock::DBLock>(opCtx, dbName, MODE_IX);
int numCollectionsTraversed = 0;
catalog::forEachCollectionFromDb(opCtx, dbName, MODE_X, [&](const Collection* collection) {
@@ -726,7 +740,7 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDb) {
}
{
- const DatabaseName dbName(boost::none, "db2");
+ const DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "db2");
auto dbLock = std::make_unique<Lock::DBLock>(opCtx, dbName, MODE_IX);
int numCollectionsTraversed = 0;
catalog::forEachCollectionFromDb(opCtx, dbName, MODE_IS, [&](const Collection* collection) {
@@ -739,7 +753,7 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDb) {
}
{
- const DatabaseName dbName(boost::none, "db3");
+ const DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "db3");
auto dbLock = std::make_unique<Lock::DBLock>(opCtx, dbName, MODE_IX);
int numCollectionsTraversed = 0;
catalog::forEachCollectionFromDb(opCtx, dbName, MODE_S, [&](const Collection* collection) {
@@ -756,7 +770,7 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDbWithPredicate) {
auto opCtx = operationContext();
{
- const DatabaseName dbName(boost::none, "db");
+ const DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "db");
auto dbLock = std::make_unique<Lock::DBLock>(opCtx, dbName, MODE_IX);
int numCollectionsTraversed = 0;
catalog::forEachCollectionFromDb(
@@ -779,7 +793,7 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDbWithPredicate) {
}
{
- const DatabaseName dbName(boost::none, "db");
+ const DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "db");
auto dbLock = std::make_unique<Lock::DBLock>(opCtx, dbName, MODE_IX);
int numCollectionsTraversed = 0;
catalog::forEachCollectionFromDb(
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp
index 6fcbbf47d8e..3eed69b554a 100644
--- a/src/mongo/db/catalog/rename_collection_test.cpp
+++ b/src/mongo/db/catalog/rename_collection_test.cpp
@@ -508,7 +508,8 @@ void _insertDocument(OperationContext* opCtx, const NamespaceString& nss, const
CollectionPtr _getCollection_inlock(OperationContext* opCtx, const NamespaceString& nss) {
invariant(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_IS));
auto databaseHolder = DatabaseHolder::get(opCtx);
- auto* db = databaseHolder->getDb(opCtx, DatabaseName(boost::none, nss.db()));
+ auto* db = databaseHolder->getDb(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, nss.db()));
if (!db) {
return CollectionPtr();
}
diff --git a/src/mongo/db/catalog_raii_test.cpp b/src/mongo/db/catalog_raii_test.cpp
index e273eb65639..3aafca7c0ad 100644
--- a/src/mongo/db/catalog_raii_test.cpp
+++ b/src/mongo/db/catalog_raii_test.cpp
@@ -472,8 +472,8 @@ TEST_F(CatalogRAIITestFixture, AutoGetDBDifferentTenantsConflictingNamespaces) {
auto tenant1 = TenantId(OID::gen());
auto tenant2 = TenantId(OID::gen());
- DatabaseName dbName1(tenant1, db);
- DatabaseName dbName2(tenant2, db);
+ DatabaseName dbName1 = DatabaseName::createDatabaseName_forTest(tenant1, db);
+ DatabaseName dbName2 = DatabaseName::createDatabaseName_forTest(tenant2, db);
AutoGetDb db1(client1.second.get(), dbName1, MODE_X);
AutoGetDb db2(client2.second.get(), dbName2, MODE_X);
@@ -484,7 +484,7 @@ TEST_F(CatalogRAIITestFixture, AutoGetDBDifferentTenantsConflictingNamespaces) {
TEST_F(CatalogRAIITestFixture, AutoGetDBWithTenantHitsDeadline) {
auto db = "db1";
- DatabaseName dbName(TenantId(OID::gen()), db);
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(TenantId(OID::gen()), db);
Lock::DBLock dbLock1(client1.second.get(), dbName, MODE_X);
ASSERT(client1.second->lockState()->isDbLockedForMode(dbName, MODE_X));
diff --git a/src/mongo/db/commands/external_data_source_commands_test.cpp b/src/mongo/db/commands/external_data_source_commands_test.cpp
index 8c662446995..87877e7f870 100644
--- a/src/mongo/db/commands/external_data_source_commands_test.cpp
+++ b/src/mongo/db/commands/external_data_source_commands_test.cpp
@@ -137,7 +137,7 @@ protected:
};
const DatabaseName ExternalDataSourceCommandsTest::kDatabaseName =
- DatabaseName(boost::none, "external_data_source");
+ DatabaseName::createDatabaseName_forTest(boost::none, "external_data_source");
TEST_F(ExternalDataSourceCommandsTest, SimpleScanAggRequest) {
const auto nDocs = _random.nextInt32(100) + 1;
diff --git a/src/mongo/db/commands_test.cpp b/src/mongo/db/commands_test.cpp
index c34814bf027..d8242f4cc3d 100644
--- a/src/mongo/db/commands_test.cpp
+++ b/src/mongo/db/commands_test.cpp
@@ -142,7 +142,8 @@ public:
TEST_F(ParseNsOrUUID, FailWrongType) {
auto cmd = BSON("query" << BSON("a" << BSON("$gte" << 11)));
- ASSERT_THROWS_CODE(CommandHelpers::parseNsOrUUID(DatabaseName(boost::none, "db"), cmd),
+ ASSERT_THROWS_CODE(CommandHelpers::parseNsOrUUID(
+ DatabaseName::createDatabaseName_forTest(boost::none, "db"), cmd),
DBException,
ErrorCodes::InvalidNamespace);
}
@@ -158,7 +159,8 @@ TEST_F(ParseNsOrUUID, FailEmptyDbName) {
TEST_F(ParseNsOrUUID, FailInvalidDbName) {
auto cmd = BSON("query"
<< "coll");
- ASSERT_THROWS_CODE(CommandHelpers::parseNsOrUUID(DatabaseName(boost::none, "test.coll"), cmd),
+ ASSERT_THROWS_CODE(CommandHelpers::parseNsOrUUID(
+ DatabaseName::createDatabaseName_forTest(boost::none, "test.coll"), cmd),
DBException,
ErrorCodes::InvalidNamespace);
}
@@ -166,14 +168,16 @@ TEST_F(ParseNsOrUUID, FailInvalidDbName) {
TEST_F(ParseNsOrUUID, ParseValidColl) {
auto cmd = BSON("query"
<< "coll");
- auto parsedNss = CommandHelpers::parseNsOrUUID(DatabaseName(boost::none, "test"), cmd);
+ auto parsedNss = CommandHelpers::parseNsOrUUID(
+ DatabaseName::createDatabaseName_forTest(boost::none, "test"), cmd);
ASSERT_EQ(*parsedNss.nss(), NamespaceString::createNamespaceString_forTest("test.coll"));
}
TEST_F(ParseNsOrUUID, ParseValidUUID) {
const UUID uuid = UUID::gen();
auto cmd = BSON("query" << uuid);
- auto parsedNsOrUUID = CommandHelpers::parseNsOrUUID(DatabaseName(boost::none, "test"), cmd);
+ auto parsedNsOrUUID = CommandHelpers::parseNsOrUUID(
+ DatabaseName::createDatabaseName_forTest(boost::none, "test"), cmd);
ASSERT_EQUALS(uuid, *parsedNsOrUUID.uuid());
}
diff --git a/src/mongo/db/concurrency/d_concurrency_bm.cpp b/src/mongo/db/concurrency/d_concurrency_bm.cpp
index e8c4f5639f1..08b8e7fc547 100644
--- a/src/mongo/db/concurrency/d_concurrency_bm.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_bm.cpp
@@ -133,7 +133,7 @@ BENCHMARK_DEFINE_F(DConcurrencyTest, BM_CollectionIntentSharedLock)(benchmark::S
makeKClientsWithLockers(state.threads);
}
- DatabaseName dbName(boost::none, "test");
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "test");
for (auto keepRunning : state) {
Lock::DBLock dlk(clients[state.thread_index].second.get(), dbName, MODE_IS);
Lock::CollectionLock clk(
@@ -150,7 +150,7 @@ BENCHMARK_DEFINE_F(DConcurrencyTest, BM_CollectionIntentExclusiveLock)(benchmark
makeKClientsWithLockers(state.threads);
}
- DatabaseName dbName(boost::none, "test");
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "test");
for (auto keepRunning : state) {
Lock::DBLock dlk(clients[state.thread_index].second.get(), dbName, MODE_IX);
Lock::CollectionLock clk(
@@ -167,7 +167,7 @@ BENCHMARK_DEFINE_F(DConcurrencyTest, BM_CollectionSharedLock)(benchmark::State&
makeKClientsWithLockers(state.threads);
}
- DatabaseName dbName(boost::none, "test");
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "test");
for (auto keepRunning : state) {
Lock::DBLock dlk(clients[state.thread_index].second.get(), dbName, MODE_IS);
Lock::CollectionLock clk(
@@ -184,7 +184,7 @@ BENCHMARK_DEFINE_F(DConcurrencyTest, BM_CollectionExclusiveLock)(benchmark::Stat
makeKClientsWithLockers(state.threads);
}
- DatabaseName dbName(boost::none, "test");
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "test");
for (auto keepRunning : state) {
Lock::DBLock dlk(clients[state.thread_index].second.get(), dbName, MODE_IX);
Lock::CollectionLock clk(
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index 354b09dba19..d869a17bacd 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -361,7 +361,8 @@ TEST_F(DConcurrencyTestFixture,
ASSERT_EQ(lockState->getLockMode(resourceIdReplicationStateTransitionLock), MODE_IX);
{
- Lock::DBLock dbWrite(opCtx.get(), DatabaseName(boost::none, "db"), MODE_IX);
+ Lock::DBLock dbWrite(
+ opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_IX);
ASSERT(lockState->isW());
ASSERT(MODE_X == lockState->getLockMode(resourceIdGlobal))
<< "unexpected global lock mode " << modeName(lockState->getLockMode(resourceIdGlobal));
@@ -403,7 +404,8 @@ TEST_F(DConcurrencyTestFixture,
ASSERT_EQ(lockState->getLockMode(resourceIdReplicationStateTransitionLock), MODE_IX);
{
- Lock::DBLock dbWrite(opCtx.get(), DatabaseName(boost::none, "db"), MODE_IX);
+ Lock::DBLock dbWrite(
+ opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_IX);
ASSERT(lockState->isW());
ASSERT(MODE_X == lockState->getLockMode(resourceIdGlobal))
<< "unexpected global lock mode " << modeName(lockState->getLockMode(resourceIdGlobal));
@@ -442,7 +444,8 @@ TEST_F(DConcurrencyTestFixture,
ASSERT_EQ(lockState->getLockMode(resourceIdReplicationStateTransitionLock), MODE_IX);
{
- Lock::DBLock dbWrite(opCtx.get(), DatabaseName(boost::none, "db"), MODE_IX);
+ Lock::DBLock dbWrite(
+ opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_IX);
ASSERT(lockState->isW());
ASSERT(MODE_X == lockState->getLockMode(resourceIdGlobal))
<< "unexpected global lock mode " << modeName(lockState->getLockMode(resourceIdGlobal));
@@ -606,7 +609,10 @@ TEST_F(DConcurrencyTestFixture, DBLockXSetsGlobalWriteLockedOnOperationContext)
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTakenForWrite());
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTaken());
- { Lock::DBLock dbWrite(opCtx, DatabaseName(boost::none, "db"), MODE_X); }
+ {
+ Lock::DBLock dbWrite(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_X);
+ }
ASSERT_TRUE(opCtx->lockState()->wasGlobalLockTakenForWrite());
ASSERT_TRUE(opCtx->lockState()->wasGlobalLockTaken());
}
@@ -617,7 +623,10 @@ TEST_F(DConcurrencyTestFixture, DBLockSDoesNotSetGlobalWriteLockedOnOperationCon
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTakenForWrite());
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTaken());
- { Lock::DBLock dbRead(opCtx, DatabaseName(boost::none, "db"), MODE_S); }
+ {
+ Lock::DBLock dbRead(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_S);
+ }
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTakenForWrite());
ASSERT_TRUE(opCtx->lockState()->wasGlobalLockTaken());
}
@@ -677,8 +686,9 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesTenantLock) {
{
Lock::DBLock dbLock(
opCtx.get(),
- DatabaseName(testCase.tenantOwned ? boost::make_optional(tenantId) : boost::none,
- testDatabaseName),
+ DatabaseName::createDatabaseName_forTest(
+ testCase.tenantOwned ? boost::make_optional(tenantId) : boost::none,
+ testDatabaseName),
testCase.databaseLockMode,
Date_t::max(),
testCase.tenantLockMode);
@@ -696,7 +706,10 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesTenantLock) {
// Verify that tenant lock survives move.
{
auto lockBuilder = [&]() {
- return Lock::DBLock{opCtx.get(), DatabaseName(tenantId, testDatabaseName), MODE_S};
+ return Lock::DBLock{
+ opCtx.get(),
+ DatabaseName::createDatabaseName_forTest(tenantId, testDatabaseName),
+ MODE_S};
};
Lock::DBLock dbLockCopy{lockBuilder()};
ASSERT(opCtx->lockState()->isLockHeldForMode(tenantResourceId, MODE_IS));
@@ -775,7 +788,10 @@ TEST_F(DConcurrencyTestFixture, DBLockSDoesNotSetGlobalLockTakenInModeConflictin
auto opCtx = clients[0].second.get();
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTakenInModeConflictingWithWrites());
- { Lock::DBLock dbWrite(opCtx, DatabaseName(boost::none, "db"), MODE_S); }
+ {
+ Lock::DBLock dbWrite(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_S);
+ }
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTakenInModeConflictingWithWrites());
}
@@ -784,7 +800,10 @@ TEST_F(DConcurrencyTestFixture, DBLockISDoesNotSetGlobalLockTakenInModeConflicti
auto opCtx = clients[0].second.get();
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTakenInModeConflictingWithWrites());
- { Lock::DBLock dbWrite(opCtx, DatabaseName(boost::none, "db"), MODE_IS); }
+ {
+ Lock::DBLock dbWrite(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_IS);
+ }
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTakenInModeConflictingWithWrites());
}
@@ -793,7 +812,10 @@ TEST_F(DConcurrencyTestFixture, DBLockIXSetsGlobalLockTakenInModeConflictingWith
auto opCtx = clients[0].second.get();
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTakenInModeConflictingWithWrites());
- { Lock::DBLock dbWrite(opCtx, DatabaseName(boost::none, "db"), MODE_IX); }
+ {
+ Lock::DBLock dbWrite(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_IX);
+ }
ASSERT_TRUE(opCtx->lockState()->wasGlobalLockTakenInModeConflictingWithWrites());
}
@@ -802,7 +824,10 @@ TEST_F(DConcurrencyTestFixture, DBLockXSetsGlobalLockTakenInModeConflictingWithW
auto opCtx = clients[0].second.get();
ASSERT_FALSE(opCtx->lockState()->wasGlobalLockTakenInModeConflictingWithWrites());
- { Lock::DBLock dbRead(opCtx, DatabaseName(boost::none, "db"), MODE_X); }
+ {
+ Lock::DBLock dbRead(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_X);
+ }
ASSERT_TRUE(opCtx->lockState()->wasGlobalLockTakenInModeConflictingWithWrites());
}
@@ -1127,7 +1152,7 @@ TEST_F(DConcurrencyTestFixture, DBLockWaitIsInterruptible) {
// The main thread takes an exclusive lock, causing the spawned thread to wait when it attempts
// to acquire a conflicting lock.
- DatabaseName dbName(boost::none, "db");
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "db");
Lock::DBLock dbLock(opCtx1, dbName, MODE_X);
auto result = runTaskAndKill(opCtx2, [&]() {
@@ -1167,14 +1192,15 @@ TEST_F(DConcurrencyTestFixture, DBLockWaitIsNotInterruptibleWithLockGuard) {
// The main thread takes an exclusive lock, causing the spawned thread to wait when it attempts
// to acquire a conflicting lock.
boost::optional<Lock::DBLock> dbLock =
- Lock::DBLock(opCtx1, DatabaseName(boost::none, "db"), MODE_X);
+ Lock::DBLock(opCtx1, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_X);
// Killing the lock wait should not interrupt it.
auto result = runTaskAndKill(
opCtx2,
[&]() {
UninterruptibleLockGuard noInterrupt(opCtx2->lockState()); // NOLINT.
- Lock::DBLock d(opCtx2, DatabaseName(boost::none, "db"), MODE_S);
+ Lock::DBLock d(
+ opCtx2, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_S);
},
[&] { dbLock.reset(); });
// Should not throw an exception.
@@ -1212,25 +1238,29 @@ TEST_F(DConcurrencyTestFixture, LockCompleteInterruptedWhenUncontested) {
TEST_F(DConcurrencyTestFixture, DBLockTakesS) {
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
- Lock::DBLock dbRead(opCtx.get(), DatabaseName(boost::none, "db"), MODE_S);
+ Lock::DBLock dbRead(
+ opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_S);
- const ResourceId resIdDb(RESOURCE_DATABASE, DatabaseName(boost::none, "db"));
+ const ResourceId resIdDb(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "db"));
ASSERT(opCtx->lockState()->getLockMode(resIdDb) == MODE_S);
}
TEST_F(DConcurrencyTestFixture, DBLockTakesX) {
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
- Lock::DBLock dbWrite(opCtx.get(), DatabaseName(boost::none, "db"), MODE_X);
+ Lock::DBLock dbWrite(
+ opCtx.get(), DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_X);
- const ResourceId resIdDb(RESOURCE_DATABASE, DatabaseName(boost::none, "db"));
+ const ResourceId resIdDb(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "db"));
ASSERT(opCtx->lockState()->getLockMode(resIdDb) == MODE_X);
}
TEST_F(DConcurrencyTestFixture, DBLockTakesISForAdminIS) {
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
- Lock::DBLock dbRead(opCtx.get(), DatabaseName(boost::none, "admin"), MODE_IS);
+ Lock::DBLock dbRead(opCtx.get(), DatabaseName::kAdmin, MODE_IS);
ASSERT(opCtx->lockState()->getLockMode(resourceIdAdminDB) == MODE_IS);
}
@@ -1238,7 +1268,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesISForAdminIS) {
TEST_F(DConcurrencyTestFixture, DBLockTakesSForAdminS) {
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
- Lock::DBLock dbRead(opCtx.get(), DatabaseName(boost::none, "admin"), MODE_S);
+ Lock::DBLock dbRead(opCtx.get(), DatabaseName::kAdmin, MODE_S);
ASSERT(opCtx->lockState()->getLockMode(resourceIdAdminDB) == MODE_S);
}
@@ -1246,7 +1276,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesSForAdminS) {
TEST_F(DConcurrencyTestFixture, DBLockTakesIXForAdminIX) {
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
- Lock::DBLock dbWrite(opCtx.get(), DatabaseName(boost::none, "admin"), MODE_IX);
+ Lock::DBLock dbWrite(opCtx.get(), DatabaseName::kAdmin, MODE_IX);
ASSERT(opCtx->lockState()->getLockMode(resourceIdAdminDB) == MODE_IX);
}
@@ -1254,7 +1284,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesIXForAdminIX) {
TEST_F(DConcurrencyTestFixture, DBLockTakesXForAdminX) {
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
- Lock::DBLock dbWrite(opCtx.get(), DatabaseName(boost::none, "admin"), MODE_X);
+ Lock::DBLock dbWrite(opCtx.get(), DatabaseName::kAdmin, MODE_X);
ASSERT(opCtx->lockState()->getLockMode(resourceIdAdminDB) == MODE_X);
}
@@ -1262,7 +1292,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTakesXForAdminX) {
TEST_F(DConcurrencyTestFixture, MultipleWriteDBLocksOnSameThread) {
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
- DatabaseName dbName(boost::none, "db1");
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "db1");
Lock::DBLock r1(opCtx.get(), dbName, MODE_X);
Lock::DBLock r2(opCtx.get(), dbName, MODE_X);
@@ -1273,7 +1303,7 @@ TEST_F(DConcurrencyTestFixture, MultipleConflictingDBLocksOnSameThread) {
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
auto lockState = opCtx->lockState();
- DatabaseName dbName(boost::none, "db1");
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "db1");
Lock::DBLock r1(opCtx.get(), dbName, MODE_X);
Lock::DBLock r2(opCtx.get(), dbName, MODE_S);
@@ -1359,7 +1389,7 @@ TEST_F(DConcurrencyTestFixture, IsDbLockedForMode_IsCollectionLockedForMode) {
if (!tenantOwned && kTenantOwned == testCase.databaseOwnership) {
continue;
}
- const DatabaseName databaseName(
+ const DatabaseName databaseName = DatabaseName::createDatabaseName_forTest(
tenantOwned ? boost::make_optional(tenantId) : boost::none, testDatabaseName);
boost::optional<Lock::GlobalLock> globalLock;
boost::optional<Lock::TenantLock> tenantLock;
@@ -1466,8 +1496,8 @@ TEST_F(DConcurrencyTestFixture, Stress) {
AtomicWord<int> ready{0};
std::vector<stdx::thread> threads;
- DatabaseName fooDb(boost::none, "foo");
- DatabaseName localDb(boost::none, "local");
+ DatabaseName fooDb = DatabaseName::createDatabaseName_forTest(boost::none, "foo");
+ DatabaseName localDb = DatabaseName::kLocal;
for (int threadId = 0; threadId < kMaxStressThreads; threadId++) {
threads.emplace_back([&, threadId]() {
@@ -1502,7 +1532,7 @@ TEST_F(DConcurrencyTestFixture, Stress) {
{ Lock::DBLock r(clients[threadId].second.get(), fooDb, MODE_S); }
{
Lock::DBLock r(clients[threadId].second.get(),
- DatabaseName(boost::none, "bar"),
+ DatabaseName::createDatabaseName_forTest(boost::none, "bar"),
MODE_S);
}
} else if (i % 7 == 6) {
@@ -1531,27 +1561,24 @@ TEST_F(DConcurrencyTestFixture, Stress) {
} else if (q == 2) {
{
- Lock::DBLock x(clients[threadId].second.get(),
- DatabaseName(boost::none, "admin"),
- MODE_S);
+ Lock::DBLock x(
+ clients[threadId].second.get(), DatabaseName::kAdmin, MODE_S);
}
{
- Lock::DBLock x(clients[threadId].second.get(),
- DatabaseName(boost::none, "admin"),
- MODE_X);
+ Lock::DBLock x(
+ clients[threadId].second.get(), DatabaseName::kAdmin, MODE_X);
}
} else if (q == 3) {
Lock::DBLock x(clients[threadId].second.get(), fooDb, MODE_X);
- Lock::DBLock y(clients[threadId].second.get(),
- DatabaseName(boost::none, "admin"),
- MODE_S);
+ Lock::DBLock y(
+ clients[threadId].second.get(), DatabaseName::kAdmin, MODE_S);
} else if (q == 4) {
- Lock::DBLock x(clients[threadId].second.get(),
- DatabaseName(boost::none, "foo2"),
- MODE_S);
- Lock::DBLock y(clients[threadId].second.get(),
- DatabaseName(boost::none, "admin"),
- MODE_S);
+ Lock::DBLock x(
+ clients[threadId].second.get(),
+ DatabaseName::createDatabaseName_forTest(boost::none, "foo2"),
+ MODE_S);
+ Lock::DBLock y(
+ clients[threadId].second.get(), DatabaseName::kAdmin, MODE_S);
} else if (q == 5) {
Lock::DBLock x(clients[threadId].second.get(), fooDb, MODE_IS);
} else if (q == 6) {
@@ -1615,14 +1642,14 @@ TEST_F(DConcurrencyTestFixture, StressPartitioned) {
}
if (i % 2 == 0) {
- Lock::DBLock x(
- clients[threadId].second.get(), DatabaseName(boost::none, "foo"), MODE_IS);
+ Lock::DBLock x(clients[threadId].second.get(),
+ DatabaseName::createDatabaseName_forTest(boost::none, "foo"),
+ MODE_IS);
} else {
- Lock::DBLock x(
- clients[threadId].second.get(), DatabaseName(boost::none, "foo"), MODE_IX);
- Lock::DBLock y(clients[threadId].second.get(),
- DatabaseName(boost::none, "local"),
+ Lock::DBLock x(clients[threadId].second.get(),
+ DatabaseName::createDatabaseName_forTest(boost::none, "foo"),
MODE_IX);
+ Lock::DBLock y(clients[threadId].second.get(), DatabaseName::kLocal, MODE_IX);
}
if (threadId == kMaxStressThreads - 1)
@@ -1914,7 +1941,7 @@ TEST_F(DConcurrencyTestFixture,
auto opCtx1 = clientOpctxPairs[0].second.get();
auto opCtx2 = clientOpctxPairs[1].second.get();
- DatabaseName dbName{boost::none, "test"};
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(boost::none, "test");
boost::optional<Lock::GlobalLock> globalIX = Lock::GlobalLock{opCtx1, LockMode::MODE_IX};
boost::optional<Lock::DBLock> dbIX = Lock::DBLock{opCtx1, dbName, LockMode::MODE_IX};
@@ -1997,23 +2024,27 @@ TEST_F(DConcurrencyTestFixture, DBLockInInterruptedContextThrowsEvenWhenUncontes
opCtx->markKilled();
boost::optional<Lock::DBLock> dbWriteLock;
- ASSERT_THROWS_CODE(dbWriteLock.emplace(opCtx, DatabaseName(boost::none, "db"), MODE_IX),
- AssertionException,
- ErrorCodes::Interrupted);
+ ASSERT_THROWS_CODE(
+ dbWriteLock.emplace(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_IX),
+ AssertionException,
+ ErrorCodes::Interrupted);
}
TEST_F(DConcurrencyTestFixture, DBLockInInterruptedContextThrowsEvenWhenAcquiringRecursively) {
auto clients = makeKClientsWithLockers(1);
auto opCtx = clients[0].second.get();
- Lock::DBLock dbWriteLock(opCtx, DatabaseName(boost::none, "db"), MODE_X);
+ Lock::DBLock dbWriteLock(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_X);
opCtx->markKilled();
{
boost::optional<Lock::DBLock> recursiveDBWriteLock;
ASSERT_THROWS_CODE(
- recursiveDBWriteLock.emplace(opCtx, DatabaseName(boost::none, "db"), MODE_X),
+ recursiveDBWriteLock.emplace(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_X),
AssertionException,
ErrorCodes::Interrupted);
}
@@ -2025,8 +2056,10 @@ TEST_F(DConcurrencyTestFixture, DBLockInInterruptedContextRespectsUninterruptibl
opCtx->markKilled();
- UninterruptibleLockGuard noInterrupt(opCtx->lockState()); // NOLINT.
- Lock::DBLock dbWriteLock(opCtx, DatabaseName(boost::none, "db"), MODE_X); // Does not throw.
+ UninterruptibleLockGuard noInterrupt(opCtx->lockState()); // NOLINT.
+ Lock::DBLock dbWriteLock(opCtx,
+ DatabaseName::createDatabaseName_forTest(boost::none, "db"),
+ MODE_X); // Does not throw.
}
TEST_F(DConcurrencyTestFixture, DBLockTimeout) {
@@ -2036,7 +2069,7 @@ TEST_F(DConcurrencyTestFixture, DBLockTimeout) {
const Milliseconds timeoutMillis = Milliseconds(1500);
- DatabaseName testDb(boost::none, "testdb");
+ DatabaseName testDb = DatabaseName::createDatabaseName_forTest(boost::none, "testdb");
Lock::DBLock L1(opctx1, testDb, MODE_X, Date_t::max());
ASSERT(opctx1->lockState()->isDbLockedForMode(testDb, MODE_X));
@@ -2061,11 +2094,12 @@ TEST_F(DConcurrencyTestFixture, DBLockTimeoutDueToGlobalLock) {
ASSERT(G1.isLocked());
Date_t t1 = Date_t::now();
- ASSERT_THROWS_CODE(
- Lock::DBLock(
- opctx2, DatabaseName(boost::none, "testdb"), MODE_X, Date_t::now() + timeoutMillis),
- AssertionException,
- ErrorCodes::LockTimeout);
+ ASSERT_THROWS_CODE(Lock::DBLock(opctx2,
+ DatabaseName::createDatabaseName_forTest(boost::none, "testdb"),
+ MODE_X,
+ Date_t::now() + timeoutMillis),
+ AssertionException,
+ ErrorCodes::LockTimeout);
Date_t t2 = Date_t::now();
ASSERT_GTE(t2 - t1 + kMaxClockJitterMillis, Milliseconds(timeoutMillis));
}
@@ -2074,7 +2108,8 @@ TEST_F(DConcurrencyTestFixture, CollectionLockInInterruptedContextThrowsEvenWhen
auto clients = makeKClientsWithLockers(1);
auto opCtx = clients[0].second.get();
- Lock::DBLock dbLock(opCtx, DatabaseName(boost::none, "db"), MODE_IX);
+ Lock::DBLock dbLock(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_IX);
opCtx->markKilled();
{
@@ -2092,7 +2127,8 @@ TEST_F(DConcurrencyTestFixture,
auto clients = makeKClientsWithLockers(1);
auto opCtx = clients[0].second.get();
- Lock::DBLock dbLock(opCtx, DatabaseName(boost::none, "db"), MODE_IX);
+ Lock::DBLock dbLock(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_IX);
Lock::CollectionLock collLock(
opCtx, NamespaceString::createNamespaceString_forTest("db.coll"), MODE_IX);
@@ -2112,7 +2148,8 @@ TEST_F(DConcurrencyTestFixture, CollectionLockInInterruptedContextRespectsUninte
auto clients = makeKClientsWithLockers(1);
auto opCtx = clients[0].second.get();
- Lock::DBLock dbLock(opCtx, DatabaseName(boost::none, "db"), MODE_IX);
+ Lock::DBLock dbLock(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "db"), MODE_IX);
opCtx->markKilled();
@@ -2129,7 +2166,7 @@ TEST_F(DConcurrencyTestFixture, CollectionLockTimeout) {
const Milliseconds timeoutMillis = Milliseconds(1500);
- DatabaseName testDb(boost::none, "testdb");
+ DatabaseName testDb = DatabaseName::createDatabaseName_forTest(boost::none, "testdb");
Lock::DBLock DBL1(opctx1, testDb, MODE_IX, Date_t::max());
ASSERT(opctx1->lockState()->isDbLockedForMode(testDb, MODE_IX));
@@ -2675,8 +2712,8 @@ TEST_F(DConcurrencyTestFixture, DifferentTenantsTakeDBLockOnConflictingNamespace
auto tenant1 = TenantId(OID::gen());
auto tenant2 = TenantId(OID::gen());
- DatabaseName dbName1(tenant1, db);
- DatabaseName dbName2(tenant2, db);
+ DatabaseName dbName1 = DatabaseName::createDatabaseName_forTest(tenant1, db);
+ DatabaseName dbName2 = DatabaseName::createDatabaseName_forTest(tenant2, db);
Lock::DBLock r1(opCtx1, dbName1, MODE_X);
Lock::DBLock r2(opCtx2, dbName2, MODE_X);
@@ -2691,7 +2728,7 @@ TEST_F(DConcurrencyTestFixture, ConflictingTenantDBLockThrows) {
auto opCtx2 = clients[1].second.get();
auto db = "db1";
- DatabaseName dbName1(TenantId(OID::gen()), db);
+ DatabaseName dbName1 = DatabaseName::createDatabaseName_forTest(TenantId(OID::gen()), db);
Lock::DBLock r1(opCtx1, dbName1, MODE_X);
ASSERT(opCtx1->lockState()->isDbLockedForMode(dbName1, MODE_X));
diff --git a/src/mongo/db/concurrency/lock_state_test.cpp b/src/mongo/db/concurrency/lock_state_test.cpp
index 3e99da1dd00..7e680e0e997 100644
--- a/src/mongo/db/concurrency/lock_state_test.cpp
+++ b/src/mongo/db/concurrency/lock_state_test.cpp
@@ -279,7 +279,8 @@ TEST_F(LockerImplTest, saveAndRestoreRSTL) {
LockerImpl locker(opCtx->getServiceContext());
- const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
+ const ResourceId resIdDatabase(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB"));
// Acquire locks.
locker.lock(resourceIdReplicationStateTransitionLock, MODE_IX);
@@ -346,7 +347,8 @@ TEST_F(LockerImplTest, saveAndRestoreDBAndCollection) {
LockerImpl locker(opCtx->getServiceContext());
- const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
+ const ResourceId resIdDatabase(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB"));
const ResourceId resIdCollection(
RESOURCE_COLLECTION,
NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
@@ -378,7 +380,8 @@ TEST_F(LockerImplTest, releaseWriteUnitOfWork) {
LockerImpl locker(opCtx->getServiceContext());
- const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
+ const ResourceId resIdDatabase(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB"));
const ResourceId resIdCollection(
RESOURCE_COLLECTION,
NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
@@ -410,7 +413,8 @@ TEST_F(LockerImplTest, restoreWriteUnitOfWork) {
LockerImpl locker(opCtx->getServiceContext());
- const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
+ const ResourceId resIdDatabase(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB"));
const ResourceId resIdCollection(
RESOURCE_COLLECTION,
NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
@@ -454,7 +458,8 @@ TEST_F(LockerImplTest, releaseAndRestoreWriteUnitOfWorkWithoutUnlock) {
LockerImpl locker(opCtx->getServiceContext());
- const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
+ const ResourceId resIdDatabase(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB"));
const ResourceId resIdCollection(
RESOURCE_COLLECTION,
NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
@@ -574,7 +579,8 @@ TEST_F(LockerImplTest, releaseAndRestoreReadOnlyWriteUnitOfWork) {
LockerImpl locker(opCtx->getServiceContext());
- const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
+ const ResourceId resIdDatabase(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB"));
const ResourceId resIdCollection(
RESOURCE_COLLECTION,
NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
@@ -643,7 +649,8 @@ TEST_F(LockerImplTest, releaseAndRestoreWriteUnitOfWorkWithRecursiveLocks) {
LockerImpl locker(opCtx->getServiceContext());
- const ResourceId resIdDatabase(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
+ const ResourceId resIdDatabase(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB"));
const ResourceId resIdCollection(
RESOURCE_COLLECTION,
NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
@@ -726,7 +733,8 @@ TEST_F(LockerImplTest, releaseAndRestoreWriteUnitOfWorkWithRecursiveLocks) {
TEST_F(LockerImplTest, DefaultLocker) {
auto opCtx = makeOperationContext();
- const ResourceId resId(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
+ const ResourceId resId(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB"));
LockerImpl locker(opCtx->getServiceContext());
locker.lockGlobal(opCtx.get(), MODE_IX);
@@ -750,8 +758,10 @@ TEST_F(LockerImplTest, SharedLocksShouldTwoPhaseLockIsTrue) {
auto opCtx = makeOperationContext();
- const ResourceId resId1(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB1"));
- const ResourceId resId2(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB2"));
+ const ResourceId resId1(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB1"));
+ const ResourceId resId2(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB2"));
const ResourceId resId3(
RESOURCE_COLLECTION,
NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection3"));
@@ -810,8 +820,10 @@ TEST_F(LockerImplTest, ModeIXAndXLockParticipatesInTwoPhaseLocking) {
auto opCtx = makeOperationContext();
- const ResourceId resId1(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB1"));
- const ResourceId resId2(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB2"));
+ const ResourceId resId1(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB1"));
+ const ResourceId resId2(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB2"));
const ResourceId resId3(
RESOURCE_COLLECTION,
NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection3"));
@@ -959,8 +971,10 @@ TEST_F(LockerImplTest, RSTLTwoPhaseLockingBehaviorModeIS) {
TEST_F(LockerImplTest, OverrideLockRequestTimeout) {
auto opCtx = makeOperationContext();
- const ResourceId resIdFirstDB(RESOURCE_DATABASE, DatabaseName(boost::none, "FirstDB"));
- const ResourceId resIdSecondDB(RESOURCE_DATABASE, DatabaseName(boost::none, "SecondDB"));
+ const ResourceId resIdFirstDB(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "FirstDB"));
+ const ResourceId resIdSecondDB(
+ RESOURCE_DATABASE, DatabaseName::createDatabaseName_forTest(boost::none, "SecondDB"));
LockerImpl locker1(opCtx->getServiceContext());
LockerImpl locker2(opCtx->getServiceContext());
@@ -996,8 +1010,10 @@ TEST_F(LockerImplTest, OverrideLockRequestTimeout) {
TEST_F(LockerImplTest, DoNotWaitForLockAcquisition) {
auto opCtx = makeOperationContext();
- const ResourceId resIdFirstDB(RESOURCE_DATABASE, DatabaseName(boost::none, "FirstDB"));
- const ResourceId resIdSecondDB(RESOURCE_DATABASE, DatabaseName(boost::none, "SecondDB"));
+ const ResourceId resIdFirstDB(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "FirstDB"));
+ const ResourceId resIdSecondDB(
+ RESOURCE_DATABASE, DatabaseName::createDatabaseName_forTest(boost::none, "SecondDB"));
LockerImpl locker1(opCtx->getServiceContext());
LockerImpl locker2(opCtx->getServiceContext());
@@ -1051,7 +1067,8 @@ bool lockerInfoContainsLock(const Locker::LockerInfo& lockerInfo,
TEST_F(LockerImplTest, GetLockerInfoShouldReportHeldLocks) {
auto opCtx = makeOperationContext();
- const ResourceId dbId(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
+ const ResourceId dbId(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB"));
const ResourceId collectionId(
RESOURCE_COLLECTION,
NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
@@ -1079,7 +1096,8 @@ TEST_F(LockerImplTest, GetLockerInfoShouldReportHeldLocks) {
TEST_F(LockerImplTest, GetLockerInfoShouldReportPendingLocks) {
auto opCtx = makeOperationContext();
- const ResourceId dbId(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB"));
+ const ResourceId dbId(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB"));
const ResourceId collectionId(
RESOURCE_COLLECTION,
NamespaceString::createNamespaceString_forTest(boost::none, "TestDB.collection"));
@@ -1127,7 +1145,8 @@ TEST_F(LockerImplTest, GetLockerInfoShouldReportPendingLocks) {
TEST_F(LockerImplTest, GetLockerInfoShouldSubtractBase) {
auto opCtx = makeOperationContext();
auto locker = opCtx->lockState();
- const ResourceId dbId(RESOURCE_DATABASE, DatabaseName(boost::none, "SubtractTestDB"));
+ const ResourceId dbId(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "SubtractTestDB"));
auto numAcquisitions = [&](boost::optional<SingleThreadedLockStats> baseStats) {
Locker::LockerInfo info;
diff --git a/src/mongo/db/database_name.h b/src/mongo/db/database_name.h
index 63649f5c50d..3be644cedc4 100644
--- a/src/mongo/db/database_name.h
+++ b/src/mongo/db/database_name.h
@@ -127,6 +127,11 @@ public:
dbString.find('\0') == std::string::npos);
}
+ static DatabaseName createDatabaseName_forTest(boost::optional<TenantId> tenantId,
+ StringData dbString) {
+ return DatabaseName(tenantId, dbString);
+ }
+
/**
* Prefer to use the constructor above.
* TODO SERVER-65456 Remove this constructor.
diff --git a/src/mongo/db/database_name_test.cpp b/src/mongo/db/database_name_test.cpp
index 7488e13820f..a0b01a8142d 100644
--- a/src/mongo/db/database_name_test.cpp
+++ b/src/mongo/db/database_name_test.cpp
@@ -40,14 +40,14 @@ namespace mongo {
namespace {
TEST(DatabaseNameTest, MultitenancySupportDisabled) {
- DatabaseName dbnWithoutTenant1(boost::none, "a");
+ DatabaseName dbnWithoutTenant1 = DatabaseName::createDatabaseName_forTest(boost::none, "a");
ASSERT(!dbnWithoutTenant1.tenantId());
ASSERT_EQUALS(std::string("a"), dbnWithoutTenant1.db());
ASSERT_EQUALS(std::string("a"), dbnWithoutTenant1.toString());
TenantId tenantId(OID::gen());
- DatabaseName dbnWithTenant(tenantId, "a");
+ DatabaseName dbnWithTenant = DatabaseName::createDatabaseName_forTest(tenantId, "a");
ASSERT(dbnWithTenant.tenantId());
ASSERT_EQUALS(tenantId, *dbnWithTenant.tenantId());
ASSERT_EQUALS(std::string("a"), dbnWithTenant.db());
@@ -59,13 +59,13 @@ TEST(DatabaseNameTest, MultitenancySupportEnabledTenantIDNotRequired) {
// TODO SERVER-62114 remove this test case.
RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true);
- DatabaseName dbnWithoutTenant(boost::none, "a");
+ DatabaseName dbnWithoutTenant = DatabaseName::createDatabaseName_forTest(boost::none, "a");
ASSERT(!dbnWithoutTenant.tenantId());
ASSERT_EQUALS(std::string("a"), dbnWithoutTenant.db());
ASSERT_EQUALS(std::string("a"), dbnWithoutTenant.toString());
TenantId tenantId(OID::gen());
- DatabaseName dbnWithTenant(tenantId, "a");
+ DatabaseName dbnWithTenant = DatabaseName::createDatabaseName_forTest(tenantId, "a");
ASSERT(dbnWithTenant.tenantId());
ASSERT_EQUALS(tenantId, *dbnWithTenant.tenantId());
ASSERT_EQUALS(std::string("a"), dbnWithTenant.db());
@@ -75,21 +75,21 @@ TEST(DatabaseNameTest, MultitenancySupportEnabledTenantIDNotRequired) {
TEST(DatabaseNameTest, VerifyEqualsOperator) {
TenantId tenantId(OID::gen());
- DatabaseName dbn(tenantId, "a");
- ASSERT_TRUE(DatabaseName(tenantId, "a") == dbn);
- ASSERT_TRUE(DatabaseName(tenantId, "b") != dbn);
+ DatabaseName dbn = DatabaseName::createDatabaseName_forTest(tenantId, "a");
+ ASSERT_TRUE(DatabaseName::createDatabaseName_forTest(tenantId, "a") == dbn);
+ ASSERT_TRUE(DatabaseName::createDatabaseName_forTest(tenantId, "b") != dbn);
TenantId otherTenantId = TenantId(OID::gen());
- ASSERT_TRUE(DatabaseName(otherTenantId, "a") != dbn);
- ASSERT_TRUE(DatabaseName(boost::none, "a") != dbn);
+ ASSERT_TRUE(DatabaseName::createDatabaseName_forTest(otherTenantId, "a") != dbn);
+ ASSERT_TRUE(DatabaseName::createDatabaseName_forTest(boost::none, "a") != dbn);
}
TEST(DatabaseNameTest, VerifyHashFunction) {
TenantId tenantId1(OID::gen());
TenantId tenantId2(OID::gen());
- DatabaseName dbn1 = DatabaseName(tenantId1, "a");
- DatabaseName dbn2 = DatabaseName(tenantId2, "a");
- DatabaseName dbn3 = DatabaseName(boost::none, "a");
+ DatabaseName dbn1 = DatabaseName::createDatabaseName_forTest(tenantId1, "a");
+ DatabaseName dbn2 = DatabaseName::createDatabaseName_forTest(tenantId2, "a");
+ DatabaseName dbn3 = DatabaseName::createDatabaseName_forTest(boost::none, "a");
stdx::unordered_map<DatabaseName, std::string> dbMap;
@@ -97,7 +97,7 @@ TEST(DatabaseNameTest, VerifyHashFunction) {
ASSERT_EQUALS(dbMap[dbn1], "value T1 a1");
dbMap[dbn1] = "value T1 a2";
ASSERT_EQUALS(dbMap[dbn1], "value T1 a2");
- dbMap[DatabaseName(tenantId1, "a")] = "value T1 a3";
+ dbMap[DatabaseName::createDatabaseName_forTest(tenantId1, "a")] = "value T1 a3";
ASSERT_EQUALS(dbMap[dbn1], "value T1 a3");
dbMap[dbn2] = "value T2 a1";
@@ -121,10 +121,10 @@ TEST(DatabaseNameTest, VerifyCompareFunction) {
// OID's generated by the same process are monotonically increasing.
ASSERT(tenantId1 < tenantId2);
- DatabaseName dbn1a = DatabaseName(tenantId1, "a");
- DatabaseName dbn1b = DatabaseName(tenantId1, "b");
- DatabaseName dbn2a = DatabaseName(tenantId2, "a");
- DatabaseName dbn3a = DatabaseName(boost::none, "a");
+ DatabaseName dbn1a = DatabaseName::createDatabaseName_forTest(tenantId1, "a");
+ DatabaseName dbn1b = DatabaseName::createDatabaseName_forTest(tenantId1, "b");
+ DatabaseName dbn2a = DatabaseName::createDatabaseName_forTest(tenantId2, "a");
+ DatabaseName dbn3a = DatabaseName::createDatabaseName_forTest(boost::none, "a");
ASSERT(dbn1a < dbn1b);
ASSERT(dbn1b < dbn2a);
@@ -134,7 +134,7 @@ TEST(DatabaseNameTest, VerifyCompareFunction) {
TEST(DatabaseNameTest, CheckDatabaseNameLogAttrs) {
TenantId tenantId(OID::gen());
- DatabaseName dbWithTenant(tenantId, "myLongDbName");
+ DatabaseName dbWithTenant = DatabaseName::createDatabaseName_forTest(tenantId, "myLongDbName");
startCapturingLogMessages();
LOGV2(7448500, "Msg db:", logAttrs(dbWithTenant));
diff --git a/src/mongo/db/namespace_string_test.cpp b/src/mongo/db/namespace_string_test.cpp
index 69e4b6348ac..bf2b309c869 100644
--- a/src/mongo/db/namespace_string_test.cpp
+++ b/src/mongo/db/namespace_string_test.cpp
@@ -48,7 +48,7 @@ using namespace fmt::literals;
TEST(NamespaceStringTest, CheckNamespaceStringLogAttrs) {
TenantId tenantId(OID::gen());
- DatabaseName dbName(tenantId, "foo");
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(tenantId, "foo");
NamespaceString nss = NamespaceString::createNamespaceString_forTest(dbName, "bar");
startCapturingLogMessages();
@@ -302,7 +302,8 @@ TEST(NamespaceStringTest, NamespaceStringParse5) {
}
TEST(NamespaceStringTest, makeListCollectionsNSIsCorrect) {
- NamespaceString ns = NamespaceString::makeListCollectionsNSS(DatabaseName(boost::none, "DB"));
+ NamespaceString ns = NamespaceString::makeListCollectionsNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "DB"));
ASSERT_EQUALS("DB", ns.db());
ASSERT_EQUALS("$cmd.listCollections", ns.coll());
ASSERT(ns.isValid());
@@ -332,7 +333,7 @@ TEST(NamespaceStringTest, NSSWithTenantId) {
ASSERT(nss.tenantId());
ASSERT_EQ(*nss.tenantId(), tenantId);
- DatabaseName dbName(tenantId, "foo");
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(tenantId, "foo");
NamespaceString nss2 = NamespaceString::createNamespaceString_forTest(dbName, "bar");
ASSERT_EQ(nss2.ns(), "foo.bar");
ASSERT_EQ(nss2.toString(), "foo.bar");
@@ -366,7 +367,7 @@ TEST(NamespaceStringTest, NSSNoCollectionWithTenantId) {
ASSERT(nss.tenantId());
ASSERT_EQ(*nss.tenantId(), tenantId);
- DatabaseName dbName(tenantId, "foo");
+ DatabaseName dbName = DatabaseName::createDatabaseName_forTest(tenantId, "foo");
NamespaceString nss2 = NamespaceString::createNamespaceString_forTest(dbName, "");
ASSERT(nss2.tenantId());
ASSERT_EQ(*nss2.tenantId(), tenantId);
diff --git a/src/mongo/db/op_observer/op_observer_registry_test.cpp b/src/mongo/db/op_observer/op_observer_registry_test.cpp
index 3f81f4219ff..43d8df29ad5 100644
--- a/src/mongo/db/op_observer/op_observer_registry_test.cpp
+++ b/src/mongo/db/op_observer/op_observer_registry_test.cpp
@@ -138,7 +138,7 @@ struct OpObserverRegistryTest : public unittest::Test {
TEST_F(OpObserverRegistryTest, NoObservers) {
OperationContextNoop opCtx;
// Check that it's OK to call observer methods with no observers registered.
- registry.onDropDatabase(&opCtx, DatabaseName(boost::none, "test"));
+ registry.onDropDatabase(&opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "test"));
}
TEST_F(OpObserverRegistryTest, TwoObservers) {
@@ -146,7 +146,7 @@ TEST_F(OpObserverRegistryTest, TwoObservers) {
ASSERT_EQUALS(testObservers, 2);
registry.addObserver(std::move(unique1));
registry.addObserver(std::move(unique2));
- registry.onDropDatabase(&opCtx, DatabaseName(boost::none, "test"));
+ registry.onDropDatabase(&opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "test"));
ASSERT_EQUALS(observer1->drops, 1);
ASSERT_EQUALS(observer2->drops, 1);
}
@@ -157,7 +157,8 @@ TEST_F(OpObserverRegistryTest, ThrowingObserver1) {
observer1 = unique1.get();
registry.addObserver(std::move(unique1));
registry.addObserver(std::move(unique2));
- ASSERT_THROWS(registry.onDropDatabase(&opCtx, DatabaseName(boost::none, "test")),
+ ASSERT_THROWS(registry.onDropDatabase(
+ &opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "test")),
AssertionException);
ASSERT_EQUALS(observer1->drops, 1);
ASSERT_EQUALS(observer2->drops, 0);
@@ -169,7 +170,8 @@ TEST_F(OpObserverRegistryTest, ThrowingObserver2) {
observer2 = unique1.get();
registry.addObserver(std::move(unique1));
registry.addObserver(std::move(unique2));
- ASSERT_THROWS(registry.onDropDatabase(&opCtx, DatabaseName(boost::none, "test")),
+ ASSERT_THROWS(registry.onDropDatabase(
+ &opCtx, DatabaseName::createDatabaseName_forTest(boost::none, "test")),
AssertionException);
ASSERT_EQUALS(observer1->drops, 1);
ASSERT_EQUALS(observer2->drops, 1);
diff --git a/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp b/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp
index e435f523198..e0256883521 100644
--- a/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp
+++ b/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp
@@ -153,7 +153,7 @@ protected:
opObserver.onCreateCollection(
opCtx, CollectionPtr(), nss, {}, BSONObj(), OplogSlot(), false);
opObserver.onCollMod(opCtx, nss, uuid, BSONObj(), {}, boost::none);
- opObserver.onDropDatabase(opCtx, DatabaseName(boost::none, nss.db()));
+ opObserver.onDropDatabase(opCtx, nss.dbName());
opObserver.onDropCollection(
opCtx,
nss,
@@ -182,8 +182,7 @@ protected:
AssertionException);
ASSERT_THROWS(opObserver.onCollMod(opCtx, nss, uuid, BSONObj(), {}, boost::none),
AssertionException);
- ASSERT_THROWS(opObserver.onDropDatabase(opCtx, DatabaseName(boost::none, nss.db())),
- AssertionException);
+ ASSERT_THROWS(opObserver.onDropDatabase(opCtx, nss.dbName()), AssertionException);
ASSERT_THROWS(opObserver.onDropCollection(
opCtx,
nss,
diff --git a/src/mongo/db/pipeline/aggregation_request_test.cpp b/src/mongo/db/pipeline/aggregation_request_test.cpp
index 04c8aef0dc8..5e4e566da6c 100644
--- a/src/mongo/db/pipeline/aggregation_request_test.cpp
+++ b/src/mongo/db/pipeline/aggregation_request_test.cpp
@@ -256,8 +256,8 @@ TEST(AggregationRequestTest, ShouldSerializeBatchSizeIfSetAndExplainFalse) {
}
TEST(AggregationRequestTest, ShouldSerialiseAggregateFieldToOneIfCollectionIsAggregateOneNSS) {
- NamespaceString nss =
- NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "a"));
+ NamespaceString nss = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "a"));
AggregateCommandRequest request(nss, std::vector<mongo::BSONObj>());
auto expectedSerialization =
@@ -384,14 +384,15 @@ void parseNSHelper(const std::string& dbName,
const BSONObj& invalidFields,
ErrorCodes::Error expectedCode) {
// Verify that 'validRequest' parses correctly.
- auto shouldNotThrow =
- aggregation_request_helper::parseNs(DatabaseName(boost::none, dbName), validRequest);
+ auto shouldNotThrow = aggregation_request_helper::parseNs(
+ DatabaseName::createDatabaseName_forTest(boost::none, dbName), validRequest);
auto invalidRequest = constructInvalidRequest(validRequest, invalidFields);
// Verify that the constructed invalid request fails to parse with 'expectedCode'.
ASSERT_THROWS_CODE(
- aggregation_request_helper::parseNs(DatabaseName(boost::none, "a"), invalidRequest),
+ aggregation_request_helper::parseNs(
+ DatabaseName::createDatabaseName_forTest(boost::none, "a"), invalidRequest),
AssertionException,
expectedCode);
}
@@ -667,7 +668,8 @@ TEST(AggregationRequestTest, ParseNSShouldReturnAggregateOneNSIfAggregateFieldIs
for (auto& one : ones) {
const BSONObj inputBSON =
fromjson(str::stream() << "{aggregate: " << one << ", pipeline: [], $db: 'a'}");
- ASSERT(aggregation_request_helper::parseNs(DatabaseName(boost::none, "a"), inputBSON)
+ ASSERT(aggregation_request_helper::parseNs(
+ DatabaseName::createDatabaseName_forTest(boost::none, "a"), inputBSON)
.isCollectionlessAggregateNS());
}
}
diff --git a/src/mongo/db/pipeline/change_stream_event_transform_test.cpp b/src/mongo/db/pipeline/change_stream_event_transform_test.cpp
index 8f09356c895..80a0c50a30f 100644
--- a/src/mongo/db/pipeline/change_stream_event_transform_test.cpp
+++ b/src/mongo/db/pipeline/change_stream_event_transform_test.cpp
@@ -100,8 +100,8 @@ TEST(ChangeStreamEventTransformTest, TestDefaultUpdateTransform) {
}
TEST(ChangeStreamEventTransformTest, TestCreateViewTransform) {
- const NamespaceString systemViewNss =
- NamespaceString::makeSystemDotViewsNamespace({boost::none, "viewDB"});
+ const NamespaceString systemViewNss = NamespaceString::makeSystemDotViewsNamespace(
+ DatabaseName::createDatabaseName_forTest(boost::none, "viewDB"));
const NamespaceString viewNss =
NamespaceString::createNamespaceString_forTest(boost::none, "viewDB.view.name");
const auto viewPipeline =
@@ -128,15 +128,16 @@ TEST(ChangeStreamEventTransformTest, TestCreateViewTransform) {
Document{{"db", viewNss.db()}, {"coll", viewNss.coll()}}},
{DocumentSourceChangeStream::kOperationDescriptionField, opDescription}};
- ASSERT_DOCUMENT_EQ(applyTransformation(oplogEntry,
- NamespaceString::makeCollectionlessAggregateNSS(
- DatabaseName(boost::none, "viewDB"))),
- expectedDoc);
+ ASSERT_DOCUMENT_EQ(
+ applyTransformation(oplogEntry,
+ NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "viewDB"))),
+ expectedDoc);
}
TEST(ChangeStreamEventTransformTest, TestCreateViewOnSingleCollection) {
- const NamespaceString systemViewNss =
- NamespaceString::makeSystemDotViewsNamespace({boost::none, "viewDB"});
+ const NamespaceString systemViewNss = NamespaceString::makeSystemDotViewsNamespace(
+ DatabaseName::createDatabaseName_forTest(boost::none, "viewDB"));
const NamespaceString viewNss =
NamespaceString::createNamespaceString_forTest(boost::none, "viewDB.view.name");
const auto viewPipeline =
@@ -363,8 +364,8 @@ TEST(ChangeStreamEventTransformTest, TestCreateViewTransformWithTenantId) {
const auto tenantId = TenantId(OID::gen());
- const NamespaceString systemViewNss =
- NamespaceString::makeSystemDotViewsNamespace({tenantId, "viewDB"});
+ const NamespaceString systemViewNss = NamespaceString::makeSystemDotViewsNamespace(
+ DatabaseName::createDatabaseName_forTest(tenantId, "viewDB"));
const NamespaceString viewNss =
NamespaceString::createNamespaceString_forTest(tenantId, "viewDB.view.name");
const auto viewPipeline =
diff --git a/src/mongo/db/pipeline/document_source_change_stream_add_post_image_test.cpp b/src/mongo/db/pipeline/document_source_change_stream_add_post_image_test.cpp
index ba6b8e751a8..a9f5738d0e3 100644
--- a/src/mongo/db/pipeline/document_source_change_stream_add_post_image_test.cpp
+++ b/src/mongo/db/pipeline/document_source_change_stream_add_post_image_test.cpp
@@ -246,7 +246,8 @@ TEST_F(DocumentSourceChangeStreamAddPostImageTest,
ShouldErrorIfDatabaseMismatchOnCollectionlessNss) {
auto expCtx = getExpCtx();
- expCtx->ns = NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "test"));
+ expCtx->ns = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "test"));
// Set up the lookup change post image stage.
auto lookupChangeStage = DocumentSourceChangeStreamAddPostImage::create(expCtx, getSpec());
@@ -271,7 +272,8 @@ TEST_F(DocumentSourceChangeStreamAddPostImageTest,
TEST_F(DocumentSourceChangeStreamAddPostImageTest, ShouldPassIfDatabaseMatchesOnCollectionlessNss) {
auto expCtx = getExpCtx();
- expCtx->ns = NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "test"));
+ expCtx->ns = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "test"));
// Set up the lookup change post image stage.
auto lookupChangeStage = DocumentSourceChangeStreamAddPostImage::create(expCtx, getSpec());
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 278d8760d9a..d84412e5284 100644
--- a/src/mongo/db/pipeline/document_source_change_stream_test.cpp
+++ b/src/mongo/db/pipeline/document_source_change_stream_test.cpp
@@ -2980,8 +2980,7 @@ TEST_F(ChangeStreamStageTest, UsesResumeTokenAsSortKeyIfNeedsMergeIsFalse) {
class ChangeStreamStageDBTest : public ChangeStreamStageTest {
public:
ChangeStreamStageDBTest()
- : ChangeStreamStageTest(NamespaceString::makeCollectionlessAggregateNSS(
- DatabaseName(boost::none, nss.db()))) {}
+ : ChangeStreamStageTest(NamespaceString::makeCollectionlessAggregateNSS(nss.dbName())) {}
};
TEST_F(ChangeStreamStageDBTest, TransformInsert) {
@@ -4424,8 +4423,8 @@ TEST_F(MultiTokenFormatVersionTest, CanResumeFromV1HighWaterMark) {
ResumeTokenData resumeToken = ResumeToken::makeHighWaterMarkToken(resumeTs, 2).getData();
resumeToken.version = 1;
auto expCtx = getExpCtxRaw();
- expCtx->ns =
- NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "unittests"));
+ expCtx->ns = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "unittests"));
// Create a change stream spec that resumes after 'resumeToken'.
const auto spec =
diff --git a/src/mongo/db/pipeline/document_source_current_op_test.cpp b/src/mongo/db/pipeline/document_source_current_op_test.cpp
index 01596237e6f..aae2de6f926 100644
--- a/src/mongo/db/pipeline/document_source_current_op_test.cpp
+++ b/src/mongo/db/pipeline/document_source_current_op_test.cpp
@@ -54,8 +54,7 @@ class DocumentSourceCurrentOpTest : public AggregationContextFixture {
public:
DocumentSourceCurrentOpTest()
: AggregationContextFixture(
- NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "admin"))) {
- }
+ NamespaceString::makeCollectionlessAggregateNSS(DatabaseName::kAdmin)) {}
};
/**
@@ -100,8 +99,8 @@ TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIfSpecIsNotObject) {
TEST_F(DocumentSourceCurrentOpTest, ShouldFailToParseIfNotRunOnAdmin) {
const auto specObj = fromjson("{$currentOp:{}}");
- getExpCtx()->ns =
- NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "foo"));
+ getExpCtx()->ns = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "foo"));
ASSERT_THROWS_CODE(DocumentSourceCurrentOp::createFromBson(specObj.firstElement(), getExpCtx()),
AssertionException,
ErrorCodes::InvalidNamespace);
diff --git a/src/mongo/db/pipeline/document_source_facet_test.cpp b/src/mongo/db/pipeline/document_source_facet_test.cpp
index 73d11545ba6..96331a22ba3 100644
--- a/src/mongo/db/pipeline/document_source_facet_test.cpp
+++ b/src/mongo/db/pipeline/document_source_facet_test.cpp
@@ -116,8 +116,8 @@ TEST_F(DocumentSourceFacetTest, ShouldSucceedWhenNamespaceIsCollectionless) {
auto ctx = getExpCtx();
auto spec = fromjson("{$facet: {a: [{$match: {}}]}}");
- ctx->ns =
- NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "unittests"));
+ ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "unittests"));
ASSERT_TRUE(DocumentSourceFacet::createFromBson(spec.firstElement(), ctx).get());
}
diff --git a/src/mongo/db/pipeline/document_source_telemetry_test.cpp b/src/mongo/db/pipeline/document_source_telemetry_test.cpp
index 25e24164507..d08ce06b98c 100644
--- a/src/mongo/db/pipeline/document_source_telemetry_test.cpp
+++ b/src/mongo/db/pipeline/document_source_telemetry_test.cpp
@@ -49,8 +49,7 @@ class DocumentSourceTelemetryTest : public AggregationContextFixture {
public:
DocumentSourceTelemetryTest()
: AggregationContextFixture(
- NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "admin"))) {
- }
+ NamespaceString::makeCollectionlessAggregateNSS(DatabaseName::kAdmin)) {}
};
TEST_F(DocumentSourceTelemetryTest, ShouldFailToParseIfSpecIsNotObject) {
@@ -61,8 +60,8 @@ TEST_F(DocumentSourceTelemetryTest, ShouldFailToParseIfSpecIsNotObject) {
}
TEST_F(DocumentSourceTelemetryTest, ShouldFailToParseIfNotRunOnAdmin) {
- getExpCtx()->ns =
- NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "foo"));
+ getExpCtx()->ns = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "foo"));
ASSERT_THROWS_CODE(DocumentSourceTelemetry::createFromBson(
fromjson("{$telemetry: {}}").firstElement(), getExpCtx()),
AssertionException,
diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp
index 9278b81455d..36b2f3cae17 100644
--- a/src/mongo/db/pipeline/pipeline_test.cpp
+++ b/src/mongo/db/pipeline/pipeline_test.cpp
@@ -4620,7 +4620,8 @@ TEST_F(PipelineValidateTest, AggregateOneNSNotValidForEmptyPipeline) {
const std::vector<BSONObj> rawPipeline = {};
auto ctx = getExpCtx();
- ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "a"));
+ ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "a"));
ASSERT_THROWS_CODE(
Pipeline::parse(rawPipeline, ctx), AssertionException, ErrorCodes::InvalidNamespace);
@@ -4630,7 +4631,8 @@ TEST_F(PipelineValidateTest, AggregateOneNSNotValidIfInitialStageRequiresCollect
const std::vector<BSONObj> rawPipeline = {fromjson("{$match: {}}")};
auto ctx = getExpCtx();
- ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "a"));
+ ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "a"));
ASSERT_THROWS_CODE(
Pipeline::parse(rawPipeline, ctx), AssertionException, ErrorCodes::InvalidNamespace);
@@ -4640,7 +4642,8 @@ TEST_F(PipelineValidateTest, AggregateOneNSValidIfInitialStageIsCollectionless)
auto ctx = getExpCtx();
auto collectionlessSource = DocumentSourceCollectionlessMock::create(ctx);
- ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "a"));
+ ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "a"));
Pipeline::create({collectionlessSource}, ctx);
}
@@ -4661,8 +4664,8 @@ TEST_F(PipelineValidateTest, AggregateOneNSValidForFacetPipelineRegardlessOfInit
const std::vector<BSONObj> rawPipeline = {fromjson("{$facet: {subPipe: [{$match: {}}]}}")};
auto ctx = getExpCtx();
- ctx->ns =
- NamespaceString::makeCollectionlessAggregateNSS(DatabaseName(boost::none, "unittests"));
+ ctx->ns = NamespaceString::makeCollectionlessAggregateNSS(
+ DatabaseName::createDatabaseName_forTest(boost::none, "unittests"));
ASSERT_THROWS_CODE(
Pipeline::parse(rawPipeline, ctx), AssertionException, ErrorCodes::InvalidNamespace);
diff --git a/src/mongo/db/repl/all_database_cloner_test.cpp b/src/mongo/db/repl/all_database_cloner_test.cpp
index b5310021a5b..c407c91a661 100644
--- a/src/mongo/db/repl/all_database_cloner_test.cpp
+++ b/src/mongo/db/repl/all_database_cloner_test.cpp
@@ -573,9 +573,11 @@ TEST_F(AllDatabaseClonerTest, DatabaseStats) {
auto stats = cloner->getStats();
ASSERT_EQUALS(0, stats.databasesCloned);
ASSERT_EQUALS(3, stats.databaseStats.size());
- ASSERT_EQUALS(DatabaseName(boost::none, "admin"), stats.databaseStats[0].dbname);
- ASSERT_EQUALS(DatabaseName(boost::none, "aab"), stats.databaseStats[1].dbname);
- ASSERT_EQUALS(DatabaseName(boost::none, "a"), stats.databaseStats[2].dbname);
+ ASSERT_EQUALS(DatabaseName::kAdmin, stats.databaseStats[0].dbname);
+ ASSERT_EQUALS(DatabaseName::createDatabaseName_forTest(boost::none, "aab"),
+ stats.databaseStats[1].dbname);
+ ASSERT_EQUALS(DatabaseName::createDatabaseName_forTest(boost::none, "a"),
+ stats.databaseStats[2].dbname);
ASSERT_EQUALS(_clock.now(), stats.databaseStats[0].start);
ASSERT_EQUALS(Date_t(), stats.databaseStats[0].end);
ASSERT_EQUALS(Date_t(), stats.databaseStats[1].start);
@@ -599,9 +601,11 @@ TEST_F(AllDatabaseClonerTest, DatabaseStats) {
stats = cloner->getStats();
ASSERT_EQUALS(1, stats.databasesCloned);
ASSERT_EQUALS(3, stats.databaseStats.size());
- ASSERT_EQUALS(DatabaseName(boost::none, "admin"), stats.databaseStats[0].dbname);
- ASSERT_EQUALS(DatabaseName(boost::none, "aab"), stats.databaseStats[1].dbname);
- ASSERT_EQUALS(DatabaseName(boost::none, "a"), stats.databaseStats[2].dbname);
+ ASSERT_EQUALS(DatabaseName::kAdmin, stats.databaseStats[0].dbname);
+ ASSERT_EQUALS(DatabaseName::createDatabaseName_forTest(boost::none, "aab"),
+ stats.databaseStats[1].dbname);
+ ASSERT_EQUALS(DatabaseName::createDatabaseName_forTest(boost::none, "a"),
+ stats.databaseStats[2].dbname);
ASSERT_EQUALS(_clock.now(), stats.databaseStats[0].end);
ASSERT_EQUALS(_clock.now(), stats.databaseStats[1].start);
ASSERT_EQUALS(Date_t(), stats.databaseStats[1].end);
@@ -625,9 +629,11 @@ TEST_F(AllDatabaseClonerTest, DatabaseStats) {
stats = cloner->getStats();
ASSERT_EQUALS(2, stats.databasesCloned);
ASSERT_EQUALS(3, stats.databaseStats.size());
- ASSERT_EQUALS(DatabaseName(boost::none, "admin"), stats.databaseStats[0].dbname);
- ASSERT_EQUALS(DatabaseName(boost::none, "aab"), stats.databaseStats[1].dbname);
- ASSERT_EQUALS(DatabaseName(boost::none, "a"), stats.databaseStats[2].dbname);
+ ASSERT_EQUALS(DatabaseName::kAdmin, stats.databaseStats[0].dbname);
+ ASSERT_EQUALS(DatabaseName::createDatabaseName_forTest(boost::none, "aab"),
+ stats.databaseStats[1].dbname);
+ ASSERT_EQUALS(DatabaseName::createDatabaseName_forTest(boost::none, "a"),
+ stats.databaseStats[2].dbname);
ASSERT_EQUALS(_clock.now(), stats.databaseStats[1].end);
ASSERT_EQUALS(_clock.now(), stats.databaseStats[2].start);
ASSERT_EQUALS(Date_t(), stats.databaseStats[2].end);
@@ -640,9 +646,11 @@ TEST_F(AllDatabaseClonerTest, DatabaseStats) {
stats = cloner->getStats();
ASSERT_EQUALS(3, stats.databasesCloned);
- ASSERT_EQUALS(DatabaseName(boost::none, "admin"), stats.databaseStats[0].dbname);
- ASSERT_EQUALS(DatabaseName(boost::none, "aab"), stats.databaseStats[1].dbname);
- ASSERT_EQUALS(DatabaseName(boost::none, "a"), stats.databaseStats[2].dbname);
+ ASSERT_EQUALS(DatabaseName::kAdmin, stats.databaseStats[0].dbname);
+ ASSERT_EQUALS(DatabaseName::createDatabaseName_forTest(boost::none, "aab"),
+ stats.databaseStats[1].dbname);
+ ASSERT_EQUALS(DatabaseName::createDatabaseName_forTest(boost::none, "a"),
+ stats.databaseStats[2].dbname);
ASSERT_EQUALS(_clock.now(), stats.databaseStats[2].end);
}
@@ -701,9 +709,9 @@ TEST_F(AllDatabaseClonerTest,
auto databases = getDatabasesFromCloner(cloner.get());
// Expect 4 dbs, since "local" should be removed
- DatabaseName adminWithTenantId = DatabaseName(tid, "admin");
- DatabaseName aWithTenantId = DatabaseName(tid, "a");
- DatabaseName aabWithTenantId = DatabaseName(tid, "aab");
+ DatabaseName adminWithTenantId = DatabaseName::createDatabaseName_forTest(tid, "admin");
+ DatabaseName aWithTenantId = DatabaseName::createDatabaseName_forTest(tid, "a");
+ DatabaseName aabWithTenantId = DatabaseName::createDatabaseName_forTest(tid, "aab");
// Checks admin is first db.
ASSERT_EQUALS(4u, databases.size());
ASSERT_EQUALS("admin", databases[0].db());
@@ -714,7 +722,7 @@ TEST_F(AllDatabaseClonerTest,
auto stats = cloner->getStats();
ASSERT_EQUALS(0, stats.databasesCloned);
ASSERT_EQUALS(4, stats.databaseStats.size());
- ASSERT_EQUALS(DatabaseName(boost::none, "admin"), stats.databaseStats[0].dbname);
+ ASSERT_EQUALS(DatabaseName::kAdmin, stats.databaseStats[0].dbname);
ASSERT_EQUALS(adminWithTenantId, stats.databaseStats[1].dbname);
ASSERT_EQUALS(aabWithTenantId, stats.databaseStats[2].dbname);
ASSERT_EQUALS(aWithTenantId, stats.databaseStats[3].dbname);
@@ -746,7 +754,7 @@ TEST_F(AllDatabaseClonerTest,
stats = cloner->getStats();
ASSERT_EQUALS(1, stats.databasesCloned);
ASSERT_EQUALS(4, stats.databaseStats.size());
- ASSERT_EQUALS(DatabaseName(boost::none, "admin"), stats.databaseStats[0].dbname);
+ ASSERT_EQUALS(DatabaseName::kAdmin, stats.databaseStats[0].dbname);
ASSERT_EQUALS(adminWithTenantId, stats.databaseStats[1].dbname);
ASSERT_EQUALS(aabWithTenantId, stats.databaseStats[2].dbname);
ASSERT_EQUALS(aWithTenantId, stats.databaseStats[3].dbname);
@@ -776,7 +784,7 @@ TEST_F(AllDatabaseClonerTest,
stats = cloner->getStats();
ASSERT_EQUALS(2, stats.databasesCloned);
ASSERT_EQUALS(4, stats.databaseStats.size());
- ASSERT_EQUALS(DatabaseName(boost::none, "admin"), stats.databaseStats[0].dbname);
+ ASSERT_EQUALS(DatabaseName::kAdmin, stats.databaseStats[0].dbname);
ASSERT_EQUALS(adminWithTenantId, stats.databaseStats[1].dbname);
ASSERT_EQUALS(aabWithTenantId, stats.databaseStats[2].dbname);
ASSERT_EQUALS(aWithTenantId, stats.databaseStats[3].dbname);
@@ -805,7 +813,7 @@ TEST_F(AllDatabaseClonerTest,
stats = cloner->getStats();
ASSERT_EQUALS(3, stats.databasesCloned);
ASSERT_EQUALS(4, stats.databaseStats.size());
- ASSERT_EQUALS(DatabaseName(boost::none, "admin"), stats.databaseStats[0].dbname);
+ ASSERT_EQUALS(DatabaseName::kAdmin, stats.databaseStats[0].dbname);
ASSERT_EQUALS(adminWithTenantId, stats.databaseStats[1].dbname);
ASSERT_EQUALS(aabWithTenantId, stats.databaseStats[2].dbname);
ASSERT_EQUALS(aWithTenantId, stats.databaseStats[3].dbname);
@@ -821,7 +829,7 @@ TEST_F(AllDatabaseClonerTest,
stats = cloner->getStats();
ASSERT_EQUALS(4, stats.databasesCloned);
- ASSERT_EQUALS(DatabaseName(boost::none, "admin"), stats.databaseStats[0].dbname);
+ ASSERT_EQUALS(DatabaseName::kAdmin, stats.databaseStats[0].dbname);
ASSERT_EQUALS(adminWithTenantId, stats.databaseStats[1].dbname);
ASSERT_EQUALS(aabWithTenantId, stats.databaseStats[2].dbname);
ASSERT_EQUALS(aWithTenantId, stats.databaseStats[3].dbname);
diff --git a/src/mongo/db/repl/database_cloner_test.cpp b/src/mongo/db/repl/database_cloner_test.cpp
index 3f1a6cec95d..5a82e24f9e1 100644
--- a/src/mongo/db/repl/database_cloner_test.cpp
+++ b/src/mongo/db/repl/database_cloner_test.cpp
@@ -53,7 +53,8 @@ const std::string dbNameStr = "testDb";
class DatabaseClonerTest : public InitialSyncClonerTestFixture {
public:
- DatabaseClonerTest() : _dbName(boost::none, dbNameStr) {}
+ DatabaseClonerTest()
+ : _dbName(DatabaseName::createDatabaseName_forTest(boost::none, dbNameStr)) {}
protected:
void setUp() override {
@@ -513,7 +514,8 @@ TEST_F(DatabaseClonerTest, DatabaseAndCollectionStats) {
class DatabaseClonerMultitenancyTest : public DatabaseClonerTest {
public:
- DatabaseClonerMultitenancyTest() : _dbName(TenantId(OID::gen()), dbNameStr) {}
+ DatabaseClonerMultitenancyTest()
+ : _dbName(DatabaseName::createDatabaseName_forTest(TenantId(OID::gen()), dbNameStr)) {}
protected:
void setUp() override {
diff --git a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
index 0d2856fdd9a..b4a6fb905e2 100644
--- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
+++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
@@ -522,7 +522,7 @@ void createDatabase(OperationContext* opCtx, StringData dbName) {
Lock::GlobalWrite globalLock(opCtx);
bool justCreated;
auto databaseHolder = DatabaseHolder::get(opCtx);
- const DatabaseName tenantDbName(boost::none, dbName);
+ const DatabaseName tenantDbName = DatabaseName::createDatabaseName_forTest(boost::none, dbName);
auto db = databaseHolder->openDb(opCtx, tenantDbName, &justCreated);
ASSERT_TRUE(db);
ASSERT_TRUE(justCreated);
diff --git a/src/mongo/db/repl/storage_timestamp_test.cpp b/src/mongo/db/repl/storage_timestamp_test.cpp
index 8bc7b9b0223..eee7e9987fa 100644
--- a/src/mongo/db/repl/storage_timestamp_test.cpp
+++ b/src/mongo/db/repl/storage_timestamp_test.cpp
@@ -1135,7 +1135,7 @@ TEST_F(StorageTimestampTest, SecondaryCreateTwoCollections) {
BSONObjBuilder resultBuilder;
auto swResult =
- doApplyOps(DatabaseName(dbName),
+ doApplyOps(DatabaseName::createDatabaseName_forTest(boost::none, dbName),
{
BSON("ts" << _presentTs << "t" << 1LL << "op"
<< "c"
@@ -2211,7 +2211,7 @@ TEST_F(StorageTimestampTest, TimestampMultiIndexBuildsDuringRename) {
// Rename collection.
BSONObj renameResult;
ASSERT(client.runCommand(
- DatabaseName(boost::none, "admin"),
+ DatabaseName::kAdmin,
BSON("renameCollection" << nss.ns() << "to" << renamedNss.ns() << "dropTarget" << true),
renameResult))
<< renameResult;
@@ -2957,8 +2957,8 @@ TEST_F(StorageTimestampTest, ViewCreationSeparateTransaction) {
const NamespaceString viewNss =
NamespaceString::createNamespaceString_forTest("unittests.view");
- const NamespaceString systemViewsNss =
- NamespaceString::makeSystemDotViewsNamespace({boost::none, "unittests"});
+ const NamespaceString systemViewsNss = NamespaceString::makeSystemDotViewsNamespace(
+ DatabaseName::createDatabaseName_forTest(boost::none, "unittests"));
ASSERT_OK(createCollection(_opCtx,
viewNss.dbName(),
diff --git a/src/mongo/db/repl/tenant_migration_access_blocker_registry_test.cpp b/src/mongo/db/repl/tenant_migration_access_blocker_registry_test.cpp
index 0e5fd37c5fc..964bbbdcb43 100644
--- a/src/mongo/db/repl/tenant_migration_access_blocker_registry_test.cpp
+++ b/src/mongo/db/repl/tenant_migration_access_blocker_registry_test.cpp
@@ -139,13 +139,14 @@ TEST_F(TenantMigrationAccessBlockerRegistryTest, GetAccessBlockerForDbName) {
const auto tenant = TenantId{OID::gen()};
const auto uuid = UUID::gen();
- ASSERT_FALSE(
- registry.getAccessBlockersForDbName(DatabaseName{boost::none, tenant.toString() + "_foo"}));
+ ASSERT_FALSE(registry.getAccessBlockersForDbName(
+ DatabaseName::createDatabaseName_forTest(boost::none, tenant.toString() + "_foo")));
// If the MTAB registry is empty (such as in non-serverless deployments) using an invalid
// tenantId simply returns boost::none. This is required as the underscore can be present in db
// names for non-serverless deployments.
- ASSERT_FALSE(registry.getAccessBlockersForDbName(DatabaseName{boost::none, "tenant_foo"}));
+ ASSERT_FALSE(registry.getAccessBlockersForDbName(
+ DatabaseName::createDatabaseName_forTest(boost::none, "tenant_foo")));
auto globalAccessBlocker =
std::make_shared<TenantMigrationDonorAccessBlocker>(getServiceContext(), UUID::gen());
@@ -153,46 +154,53 @@ TEST_F(TenantMigrationAccessBlockerRegistryTest, GetAccessBlockerForDbName) {
// If the MTAB registry is not empty, it implies we have a serverless deployment. In that case
// anything before the underscore should be a valid TenantId.
- ASSERT_THROWS_CODE(registry.getAccessBlockersForDbName(DatabaseName{boost::none, "tenant_foo"}),
+ ASSERT_THROWS_CODE(registry.getAccessBlockersForDbName(
+ DatabaseName::createDatabaseName_forTest(boost::none, "tenant_foo")),
DBException,
ErrorCodes::BadValue);
- ASSERT_EQ(
- registry.getAccessBlockersForDbName(DatabaseName{boost::none, tenant.toString() + "_foo"})
- ->getDonorAccessBlocker(),
- globalAccessBlocker);
- ASSERT_FALSE(registry.getAccessBlockersForDbName(DatabaseName{boost::none, "admin"}));
+ ASSERT_EQ(registry
+ .getAccessBlockersForDbName(DatabaseName::createDatabaseName_forTest(
+ boost::none, tenant.toString() + "_foo"))
+ ->getDonorAccessBlocker(),
+ globalAccessBlocker);
+ ASSERT_FALSE(registry.getAccessBlockersForDbName(DatabaseName::kAdmin));
auto recipientBlocker =
std::make_shared<TenantMigrationRecipientAccessBlocker>(getServiceContext(), uuid);
registry.add(tenant, recipientBlocker);
- ASSERT_EQ(
- registry.getAccessBlockersForDbName(DatabaseName{boost::none, tenant.toString() + "_foo"})
- ->getDonorAccessBlocker(),
- globalAccessBlocker);
- ASSERT_EQ(
- registry.getAccessBlockersForDbName(DatabaseName{boost::none, tenant.toString() + "_foo"})
- ->getRecipientAccessBlocker(),
- recipientBlocker);
+ ASSERT_EQ(registry
+ .getAccessBlockersForDbName(DatabaseName::createDatabaseName_forTest(
+ boost::none, tenant.toString() + "_foo"))
+ ->getDonorAccessBlocker(),
+ globalAccessBlocker);
+ ASSERT_EQ(registry
+ .getAccessBlockersForDbName(DatabaseName::createDatabaseName_forTest(
+ boost::none, tenant.toString() + "_foo"))
+ ->getRecipientAccessBlocker(),
+ recipientBlocker);
auto donorBlocker =
std::make_shared<TenantMigrationDonorAccessBlocker>(getServiceContext(), uuid);
registry.add(tenant, donorBlocker);
- ASSERT_EQ(
- registry.getAccessBlockersForDbName(DatabaseName{boost::none, tenant.toString() + "_foo"})
- ->getDonorAccessBlocker(),
- donorBlocker);
- ASSERT_EQ(
- registry.getAccessBlockersForDbName(DatabaseName{boost::none, tenant.toString() + "_foo"})
- ->getRecipientAccessBlocker(),
- recipientBlocker);
+ ASSERT_EQ(registry
+ .getAccessBlockersForDbName(DatabaseName::createDatabaseName_forTest(
+ boost::none, tenant.toString() + "_foo"))
+ ->getDonorAccessBlocker(),
+ donorBlocker);
+ ASSERT_EQ(registry
+ .getAccessBlockersForDbName(DatabaseName::createDatabaseName_forTest(
+ boost::none, tenant.toString() + "_foo"))
+ ->getRecipientAccessBlocker(),
+ recipientBlocker);
{
RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true);
// since we enabled multitenancySupport, having underscore in the dbName won't throw because
// we have constructed a DatabaseName with a TenantId. Therefore `my` won't be identified as
// the tenantId.
- const DatabaseName validUnderscoreDbName = DatabaseName(tenant, "my_Db");
+ const DatabaseName validUnderscoreDbName =
+ DatabaseName::createDatabaseName_forTest(tenant, "my_Db");
ASSERT(registry.getAccessBlockersForDbName(validUnderscoreDbName) != boost::none);
}
}
diff --git a/src/mongo/db/repl/tenant_oplog_applier_test.cpp b/src/mongo/db/repl/tenant_oplog_applier_test.cpp
index 78c67b21be0..166d9ccdcd5 100644
--- a/src/mongo/db/repl/tenant_oplog_applier_test.cpp
+++ b/src/mongo/db/repl/tenant_oplog_applier_test.cpp
@@ -197,7 +197,8 @@ protected:
executor::NetworkInterfaceMock* _net;
std::shared_ptr<executor::ThreadPoolTaskExecutor> _executor;
std::string _tenantId = OID::gen().toString();
- DatabaseName _dbName = DatabaseName(TenantId(OID(_tenantId)), "test");
+ DatabaseName _dbName =
+ DatabaseName::createDatabaseName_forTest(TenantId(OID(_tenantId)), "test");
UUID _migrationUuid = UUID::gen();
ServiceContext::UniqueOperationContext _opCtx;
TenantOplogApplierTestOpObserver* _opObserver; // Owned by service context opObserverRegistry
@@ -1358,7 +1359,7 @@ TEST_F(TenantOplogApplierTest, ApplyCRUD_WrongNSS_Merge) {
// Should not be able to apply a CRUD operation to a namespace not belonging to us.
NamespaceString nss =
- NamespaceString::createNamespaceString_forTest(DatabaseName(invalidTenant, "test"), "bar");
+ NamespaceString::createNamespaceString_forTest(invalidTenant, "test", "bar");
auto uuid = createCollectionWithUuid(_opCtx.get(), nss);
auto entry = makeInsertOplogEntry(1, nss, uuid);
bool onInsertsCalled = false;
diff --git a/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp
index bc446b2a279..d551549a0e5 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager_add_shard_test.cpp
@@ -228,7 +228,8 @@ protected:
std::vector<std::string> dbnamesOnTarget;
for (const auto& tenantId : tenantsOnTarget) {
dbnamesOnTarget.push_back(
- DatabaseName(tenantId, DatabaseName::kConfig.db()).toStringWithTenantId());
+ DatabaseName::createDatabaseName_forTest(tenantId, DatabaseName::kConfig.db())
+ .toStringWithTenantId());
}
if (gMultitenancySupport) {
@@ -258,7 +259,8 @@ protected:
ASSERT_EQ(results.size(), 1);
ASSERT_EQ(results[0]["_id"].String(), "testStrClusterParameter");
ASSERT_EQ(results[0]["strData"].String(),
- DatabaseName(tenantId, DatabaseName::kConfig.db()).toStringWithTenantId());
+ DatabaseName::createDatabaseName_forTest(tenantId, DatabaseName::kConfig.db())
+ .toStringWithTenantId());
}
}
@@ -313,7 +315,7 @@ protected:
for (auto& param : params) {
SetClusterParameter setClusterParameterRequest(param);
setClusterParameterRequest.setDbName(
- DatabaseName(tenantId, DatabaseName::kAdmin.db()));
+ DatabaseName::createDatabaseName_forTest(tenantId, DatabaseName::kAdmin.db()));
DBDirectClient client(operationContext());
ClusterParameterDBClientService dbService(client);
std::unique_ptr<ServerParameterService> parameterService =
@@ -378,13 +380,13 @@ protected:
<< BSON("level"
<< "majority")));
auto cursorRes =
- CursorResponse(NamespaceString::createNamespaceString_forTest(
- DatabaseName(request.dbname),
- NamespaceString::kClusterParametersNamespace.coll()),
- 0,
- {BSON("_id"
- << "testStrClusterParameter"
- << "strData" << request.dbname)});
+ CursorResponse(
+ NamespaceString::createNamespaceString_forTest(
+ request.dbname, NamespaceString::kClusterParametersNamespace.coll()),
+ 0,
+ {BSON("_id"
+ << "testStrClusterParameter"
+ << "strData" << request.dbname)});
return cursorRes.toBSON(CursorResponse::ResponseType::InitialResponse);
});
}
diff --git a/src/mongo/db/s/database_sharding_state_test.cpp b/src/mongo/db/s/database_sharding_state_test.cpp
index b37f16c4212..0b0d53785b6 100644
--- a/src/mongo/db/s/database_sharding_state_test.cpp
+++ b/src/mongo/db/s/database_sharding_state_test.cpp
@@ -135,9 +135,10 @@ TEST_F(DatabaseShardingStateTestWithMockedLoader, OnDbVersionMismatch) {
auto opCtx = operationContext();
auto getActiveDbVersion = [&] {
- AutoGetDb autoDb(opCtx, DatabaseName(boost::none, kDbName), MODE_IS);
+ AutoGetDb autoDb(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, kDbName), MODE_IS);
const auto scopedDss = DatabaseShardingState::assertDbLockedAndAcquireShared(
- opCtx, DatabaseName(boost::none, kDbName));
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, kDbName));
return scopedDss->getDbVersion(opCtx);
};
@@ -170,9 +171,10 @@ TEST_F(DatabaseShardingStateTestWithMockedLoader, ForceDatabaseRefresh) {
ASSERT_OK(onDbVersionMismatchNoExcept(opCtx, kDbName, boost::none));
boost::optional<DatabaseVersion> activeDbVersion = [&] {
- AutoGetDb autoDb(opCtx, DatabaseName(boost::none, kDbName), MODE_IS);
+ AutoGetDb autoDb(
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, kDbName), MODE_IS);
const auto scopedDss = DatabaseShardingState::assertDbLockedAndAcquireShared(
- opCtx, DatabaseName(boost::none, kDbName));
+ opCtx, DatabaseName::createDatabaseName_forTest(boost::none, kDbName));
return scopedDss->getDbVersion(opCtx);
}();
ASSERT_TRUE(activeDbVersion);
diff --git a/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp b/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp
index f85acd5834a..feaa9f30d57 100644
--- a/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp
+++ b/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp
@@ -310,7 +310,7 @@ public:
createGlobalIndex.setDbName(DatabaseName::kAdmin);
BSONObj cmdResult;
auto success =
- client.runCommand({boost::none, "admin"}, createGlobalIndex.toBSON({}), cmdResult);
+ client.runCommand(DatabaseName::kAdmin, createGlobalIndex.toBSON({}), cmdResult);
ASSERT(success) << "createGlobalIndex cmd failed with result: " << cmdResult;
}
diff --git a/src/mongo/db/s/global_index/global_index_inserter_test.cpp b/src/mongo/db/s/global_index/global_index_inserter_test.cpp
index ee70e6edb67..a01cc09f055 100644
--- a/src/mongo/db/s/global_index/global_index_inserter_test.cpp
+++ b/src/mongo/db/s/global_index/global_index_inserter_test.cpp
@@ -79,7 +79,7 @@ public:
createGlobalIndex.setDbName(DatabaseName::kAdmin);
BSONObj cmdResult;
auto success =
- client.runCommand({boost::none, "admin"}, createGlobalIndex.toBSON({}), cmdResult);
+ client.runCommand(DatabaseName::kAdmin, createGlobalIndex.toBSON({}), cmdResult);
ASSERT(success) << "createGlobalIndex cmd failed with result: " << cmdResult;
}
diff --git a/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp
index 455bad8a526..b58b296f2a0 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp
@@ -248,7 +248,10 @@ public:
onCommand([&](const executor::RemoteCommandRequest& request) -> StatusWith<BSONObj> {
DBDirectClient client(cc().getOperationContext());
BSONObj result;
- bool res = client.runCommand({boost::none, request.dbname}, request.cmdObj, result);
+ bool res = client.runCommand(
+ DatabaseName::createDatabaseName_forTest(boost::none, request.dbname),
+ request.cmdObj,
+ result);
if (res == false || result.hasField("cursorsKilled") ||
result["cursor"]["id"].Long() == 0) {
hasMore = false;
diff --git a/src/mongo/db/shard_role_test.cpp b/src/mongo/db/shard_role_test.cpp
index f630827261c..a53eafa60f3 100644
--- a/src/mongo/db/shard_role_test.cpp
+++ b/src/mongo/db/shard_role_test.cpp
@@ -1023,7 +1023,7 @@ void ShardRoleTest::testRestoreFailsIfCollectionRenamed(
DBDirectClient client(opCtx());
BSONObj info;
ASSERT_TRUE(client.runCommand(
- DatabaseName(boost::none, dbNameTestDb.db()),
+ DatabaseName::createDatabaseName_forTest(boost::none, dbNameTestDb.db()),
BSON("renameCollection"
<< nss.ns() << "to"
<< NamespaceString::createNamespaceString_forTest(dbNameTestDb, "foo2").ns()),
diff --git a/src/mongo/db/stats/fill_locker_info_test.cpp b/src/mongo/db/stats/fill_locker_info_test.cpp
index 2ab5714f6e3..022b5feac50 100644
--- a/src/mongo/db/stats/fill_locker_info_test.cpp
+++ b/src/mongo/db/stats/fill_locker_info_test.cpp
@@ -84,7 +84,9 @@ DEATH_TEST(FillLockerInfo, ShouldFailIfLocksAreNotSortedAppropriately, "Invarian
LockerInfo info;
// The global lock is supposed to come before the database lock.
info.locks = {
- OneLock{ResourceId(RESOURCE_DATABASE, DatabaseName(boost::none, "TestDB")), MODE_X},
+ OneLock{ResourceId(RESOURCE_DATABASE,
+ DatabaseName::createDatabaseName_forTest(boost::none, "TestDB")),
+ MODE_X},
OneLock{resourceIdGlobal, MODE_IX}};
BSONObjBuilder infoBuilder;
diff --git a/src/mongo/db/storage/storage_repair_observer_test.cpp b/src/mongo/db/storage/storage_repair_observer_test.cpp
index 780a3518b9a..268dcebf993 100644
--- a/src/mongo/db/storage/storage_repair_observer_test.cpp
+++ b/src/mongo/db/storage/storage_repair_observer_test.cpp
@@ -72,7 +72,7 @@ public:
void createMockReplConfig(OperationContext* opCtx) {
BSONObj replConfig;
- Lock::DBLock dbLock(opCtx, DatabaseName(boost::none, "local"), MODE_X);
+ Lock::DBLock dbLock(opCtx, DatabaseName::kLocal, MODE_X);
Helpers::putSingleton(
opCtx,
NamespaceString::createNamespaceString_forTest(boost::none, "local.system.replset"),
@@ -94,7 +94,7 @@ public:
bool hasReplConfig(OperationContext* opCtx) {
BSONObj replConfig;
- Lock::DBLock dbLock(opCtx, DatabaseName(boost::none, "local"), MODE_IS);
+ Lock::DBLock dbLock(opCtx, DatabaseName::kLocal, MODE_IS);
return Helpers::getSingleton(
opCtx,
NamespaceString::createNamespaceString_forTest(boost::none, "local.system.replset"),
diff --git a/src/mongo/db/transaction/transaction_api_test.cpp b/src/mongo/db/transaction/transaction_api_test.cpp
index af21988333a..d1bd94b067d 100644
--- a/src/mongo/db/transaction/transaction_api_test.cpp
+++ b/src/mongo/db/transaction/transaction_api_test.cpp
@@ -527,12 +527,13 @@ TEST_F(TxnAPITest, OwnSession_AttachesTxnMetadata) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(
mockClient()->getLastSentRequest(), 0 /* txnNumber */, true /* startTransaction */);
@@ -540,12 +541,13 @@ TEST_F(TxnAPITest, OwnSession_AttachesTxnMetadata) {
assertAPIParameters(mockClient()->getLastSentRequest(), boost::none);
mockClient()->setNextCommandResponse(kOKInsertResponse);
- insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(mockClient()->getLastSentRequest(),
0 /* txnNumber */,
@@ -585,12 +587,13 @@ TEST_F(TxnAPITest, AttachesAPIVersion) {
attempt += 1;
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(mockClient()->getLastSentRequest(),
attempt + 1 /* txnNumber */,
@@ -599,12 +602,13 @@ TEST_F(TxnAPITest, AttachesAPIVersion) {
assertAPIParameters(mockClient()->getLastSentRequest(), params);
mockClient()->setNextCommandResponse(kOKInsertResponse);
- insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(mockClient()->getLastSentRequest(),
attempt + 1 /* txnNumber */,
@@ -658,7 +662,8 @@ TEST_F(TxnAPITest, OwnSession_AttachesWriteConcernOnCommit) {
// No write concern on requests prior to commit/abort.
mockClient()->setNextCommandResponse(kOKInsertResponse);
auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(
+ boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -676,7 +681,8 @@ TEST_F(TxnAPITest, OwnSession_AttachesWriteConcernOnCommit) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none,
+ "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -738,7 +744,8 @@ TEST_F(TxnAPITest, OwnSession_AttachesWriteConcernOnAbort) {
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(
+ boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -780,7 +787,8 @@ TEST_F(TxnAPITest, OwnSession_AttachesReadConcernOnStartTransaction) {
attempt += 1;
mockClient()->setNextCommandResponse(kOKInsertResponse);
auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(
+ boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -799,7 +807,8 @@ TEST_F(TxnAPITest, OwnSession_AttachesReadConcernOnStartTransaction) {
// Subsequent requests shouldn't have a read concern.
mockClient()->setNextCommandResponse(kOKInsertResponse);
insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none,
+ "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -843,12 +852,13 @@ TEST_F(TxnAPITest, OwnSession_AbortsOnError) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
// The best effort abort response, the client should ignore this.
@@ -909,12 +919,13 @@ TEST_F(TxnAPITest, OwnSession_RetriesOnTransientError) {
mockClient()->setNextCommandResponse(attempt == 0 ? kNoSuchTransactionResponse
: kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
// The commit or implicit abort response.
mockClient()->setNextCommandResponse(kOKCommandResponse);
@@ -961,12 +972,13 @@ TEST_F(TxnAPITest, OwnSession_RetriesOnTransientClientError) {
}
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_OK(getStatusFromWriteCommandReply(insertRes));
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
@@ -1003,12 +1015,13 @@ TEST_F(TxnAPITest, OwnSession_CommitError) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_OK(getStatusFromWriteCommandReply(insertRes));
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
@@ -1047,12 +1060,13 @@ TEST_F(TxnAPITest, OwnSession_TransientCommitError) {
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
attempt += 1;
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_OK(getStatusFromWriteCommandReply(insertRes));
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
@@ -1092,12 +1106,13 @@ TEST_F(TxnAPITest, OwnSession_RetryableCommitError) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_OK(getStatusFromWriteCommandReply(insertRes));
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
@@ -1134,12 +1149,13 @@ TEST_F(TxnAPITest, OwnSession_NonRetryableCommitWCError) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(
mockClient()->getLastSentRequest(), 0 /* txnNumber */, true /* startTransaction */);
@@ -1174,12 +1190,13 @@ TEST_F(TxnAPITest, OwnSession_RetryableCommitWCError) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_OK(getStatusFromWriteCommandReply(insertRes));
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
@@ -1230,47 +1247,51 @@ TEST_F(TxnAPITest, RunThrowsOnBodyError) {
TEST_F(TxnAPITest, RunThrowsOnCommitCmdError) {
ASSERT_THROWS_CODE(
- txnWithRetries().run(
- opCtx(),
- [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
- mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ txnWithRetries().run(opCtx(),
+ [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
+ mockClient()->setNextCommandResponse(kOKInsertResponse);
+ auto insertRes =
+ txnClient
+ .runCommand(
+ DatabaseName::createDatabaseName_forTest(boost::none,
+ "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
- // The commit response.
- mockClient()->setNextCommandResponse(
- BSON("ok" << 0 << "code" << ErrorCodes::InternalError));
- mockClient()->setNextCommandResponse(
- kOKCommandResponse); // Best effort abort response.
- return SemiFuture<void>::makeReady();
- }),
+ // The commit response.
+ mockClient()->setNextCommandResponse(
+ BSON("ok" << 0 << "code" << ErrorCodes::InternalError));
+ mockClient()->setNextCommandResponse(
+ kOKCommandResponse); // Best effort abort response.
+ return SemiFuture<void>::makeReady();
+ }),
DBException,
ErrorCodes::InternalError);
}
TEST_F(TxnAPITest, RunThrowsOnCommitWCError) {
ASSERT_THROWS_CODE(
- txnWithRetries().run(
- opCtx(),
- [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
- mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ txnWithRetries().run(opCtx(),
+ [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
+ mockClient()->setNextCommandResponse(kOKInsertResponse);
+ auto insertRes =
+ txnClient
+ .runCommand(
+ DatabaseName::createDatabaseName_forTest(boost::none,
+ "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
- // The commit response.
- mockClient()->setNextCommandResponse(kResWithWriteConcernError);
- mockClient()->setNextCommandResponse(
- kOKCommandResponse); // Best effort abort response.
- return SemiFuture<void>::makeReady();
- }),
+ // The commit response.
+ mockClient()->setNextCommandResponse(kResWithWriteConcernError);
+ mockClient()->setNextCommandResponse(
+ kOKCommandResponse); // Best effort abort response.
+ return SemiFuture<void>::makeReady();
+ }),
DBException,
ErrorCodes::WriteConcernFailed);
}
@@ -1280,12 +1301,13 @@ TEST_F(TxnAPITest, UnyieldsAfterBodyError) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
uasserted(ErrorCodes::InternalError, "Simulated body error");
return SemiFuture<void>::makeReady();
});
@@ -1301,12 +1323,13 @@ TEST_F(TxnAPITest, HandlesExceptionWhileYielding) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
return SemiFuture<void>::makeReady();
});
ASSERT_EQ(swResult.getStatus(), ErrorCodes::Interrupted);
@@ -1321,12 +1344,13 @@ TEST_F(TxnAPITest, HandlesExceptionWhileUnyielding) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
return SemiFuture<void>::makeReady();
});
ASSERT_EQ(swResult.getStatus(), ErrorCodes::Interrupted);
@@ -1353,7 +1377,7 @@ TEST_F(TxnAPITest, UnyieldsAfterCancellation) {
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -1389,12 +1413,13 @@ TEST_F(TxnAPITest, ClientSession_UsesNonRetryableInternalSession) {
attempt += 1;
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(mockClient()->getLastSentRequest(),
attempt /* txnNumber */,
@@ -1440,16 +1465,17 @@ TEST_F(TxnAPITest, ClientRetryableWrite_UsesRetryableInternalSession) {
attempt += 1;
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents"
- << BSON_ARRAY(BSON("x" << 1))
- // Retryable transactions must include stmtIds for
- // retryable write commands.
- << "stmtIds" << BSON_ARRAY(1)))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents"
+ << BSON_ARRAY(BSON("x" << 1))
+ // Retryable transactions must include stmtIds for
+ // retryable write commands.
+ << "stmtIds" << BSON_ARRAY(1)))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(mockClient()->getLastSentRequest(),
attempt /* txnNumber */,
@@ -1461,18 +1487,19 @@ TEST_F(TxnAPITest, ClientRetryableWrite_UsesRetryableInternalSession) {
// Verify a non-retryable write command does not need to include stmtIds.
mockClient()->setNextCommandResponse(kOKCommandResponse);
- auto findRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("find"
- << "foo"))
- .get();
+ auto findRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("find"
+ << "foo"))
+ .get();
ASSERT(findRes["ok"]); // Verify the mocked response was returned.
// Verify the alternate format for stmtIds is allowed.
mockClient()->setNextCommandResponse(kOKInsertResponse);
insertRes =
txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1)) << "stmtId" << 1))
@@ -1516,12 +1543,13 @@ DEATH_TEST_F(TxnAPITest,
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
return SemiFuture<void>::makeReady();
});
@@ -1538,12 +1566,13 @@ TEST_F(TxnAPITest, ClientTransaction_UsesClientTransactionOptionsAndDoesNotCommi
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(mockClient()->getLastSentRequest(),
*opCtx()->getTxnNumber(),
@@ -1578,12 +1607,13 @@ TEST_F(TxnAPITest, ClientTransaction_DoesNotAppendStartTransactionFields) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(mockClient()->getLastSentRequest(),
*opCtx()->getTxnNumber(),
@@ -1612,12 +1642,13 @@ TEST_F(TxnAPITest, ClientTransaction_DoesNotBestEffortAbortOnFailure) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(mockClient()->getLastSentRequest(),
*opCtx()->getTxnNumber(),
@@ -1647,12 +1678,13 @@ TEST_F(TxnAPITest, ClientTransaction_DoesNotRetryOnTransientErrors) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(mockClient()->getLastSentRequest(),
*opCtx()->getTxnNumber(),
@@ -1677,12 +1709,13 @@ TEST_F(TxnAPITest, HandleErrorRetryCommitOnNetworkError) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(
@@ -1730,12 +1763,13 @@ TEST_F(TxnAPITest, RetryCommitMultipleTimesIncludesMajorityWriteConcern) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
return SemiFuture<void>::makeReady();
@@ -1788,12 +1822,13 @@ TEST_F(TxnAPITest, CommitAfterTransientErrorAfterRetryCommitUsesOriginalWriteCon
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
return SemiFuture<void>::makeReady();
@@ -1965,12 +2000,13 @@ TEST_F(TxnAPITest, OwnSession_StartTransactionRetryLimitOnTransientErrors) {
// Command response used for insert below and eventually abortTransaction.
mockClient()->setNextCommandResponse(kOKCommandResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
uasserted(ErrorCodes::HostUnreachable, "Host unreachable error");
return SemiFuture<void>::makeReady();
});
@@ -1994,12 +2030,13 @@ TEST_F(TxnAPITest, OwnSession_CommitTransactionRetryLimitOnTransientErrors) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(
mockClient()->getLastSentRequest(), 0 /* txnNumber */, true /* startTransaction */);
@@ -2045,12 +2082,13 @@ TEST_F(TxnAPITest, MaxTimeMSIsSetIfOperationContextHasDeadlineAndIgnoresDefaultR
attempt += 1;
mockClient()->setNextCommandResponse(kOKInsertResponse);
- auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
- BSON("insert"
- << "foo"
- << "documents" << BSON_ARRAY(BSON("x" << 1))))
- .get();
+ auto insertRes =
+ txnClient
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
+ BSON("insert"
+ << "foo"
+ << "documents" << BSON_ARRAY(BSON("x" << 1))))
+ .get();
ASSERT_EQ(insertRes["n"].Int(), 1); // Verify the mocked response was returned.
assertTxnMetadata(mockClient()->getLastSentRequest(),
attempt + 1 /* txnNumber */,
@@ -2149,7 +2187,8 @@ TEST_F(TxnAPITest, FailoverAndShutdownErrorsAreFatalForLocalTransactionBodyError
mockClient()->setNextCommandResponse(kOKInsertResponse);
auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(
+ boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -2198,7 +2237,8 @@ TEST_F(TxnAPITest, FailoverAndShutdownErrorsAreFatalForLocalTransactionCommandEr
mockClient()->setNextCommandResponse(kOKInsertResponse);
auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(
+ boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -2246,7 +2286,8 @@ TEST_F(TxnAPITest, FailoverAndShutdownErrorsAreFatalForLocalTransactionWCError)
mockClient()->setNextCommandResponse(kOKInsertResponse);
auto insertRes = txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(
+ boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -2297,7 +2338,7 @@ TEST_F(TxnAPITest, DoesNotWaitForBestEffortAbortIfCancelled) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -2349,7 +2390,7 @@ TEST_F(TxnAPITest, WaitsForBestEffortAbortOnNonTransientErrorIfNotCancelled) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
@@ -2415,7 +2456,7 @@ TEST_F(TxnAPITest, WaitsForBestEffortAbortOnTransientError) {
auto swResult = txnWithRetries().runNoThrow(
opCtx(), [&](const txn_api::TransactionClient& txnClient, ExecutorPtr txnExec) {
txnClient
- .runCommand(DatabaseName(boost::none, "user"_sd),
+ .runCommand(DatabaseName::createDatabaseName_forTest(boost::none, "user"_sd),
BSON("insert"
<< "foo"
<< "documents" << BSON_ARRAY(BSON("x" << 1))))
diff --git a/src/mongo/db/transaction/transaction_participant_test.cpp b/src/mongo/db/transaction/transaction_participant_test.cpp
index 1b38eba07e9..94cecec1608 100644
--- a/src/mongo/db/transaction/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction/transaction_participant_test.cpp
@@ -460,7 +460,10 @@ TEST_F(TxnParticipantTest, TransactionThrowsLockTimeoutIfLockIsUnavailable) {
auto txnParticipant = TransactionParticipant::get(opCtx());
txnParticipant.unstashTransactionResources(opCtx(), "insert");
- { Lock::DBLock dbXLock(opCtx(), DatabaseName(boost::none, dbName), MODE_X); }
+ {
+ Lock::DBLock dbXLock(
+ opCtx(), DatabaseName::createDatabaseName_forTest(boost::none, dbName), MODE_X);
+ }
txnParticipant.stashTransactionResources(opCtx());
auto clientWithDatabaseXLock = Client::releaseCurrent();
@@ -494,15 +497,23 @@ TEST_F(TxnParticipantTest, TransactionThrowsLockTimeoutIfLockIsUnavailable) {
newTxnParticipant.unstashTransactionResources(newOpCtx.get(), "insert");
Date_t t1 = Date_t::now();
- ASSERT_THROWS_CODE(Lock::DBLock(newOpCtx.get(), DatabaseName(boost::none, dbName), MODE_X),
- AssertionException,
- ErrorCodes::LockTimeout);
+ ASSERT_THROWS_CODE(
+ Lock::DBLock(newOpCtx.get(),
+ DatabaseName::createDatabaseName_forTest(boost::none, dbName),
+ MODE_X),
+ AssertionException,
+ ErrorCodes::LockTimeout);
Date_t t2 = Date_t::now();
int defaultMaxTransactionLockRequestTimeoutMillis = 5;
ASSERT_GTE(t2 - t1, Milliseconds(defaultMaxTransactionLockRequestTimeoutMillis));
// A non-conflicting lock acquisition should work just fine.
- { Lock::DBLock tempLock(newOpCtx.get(), DatabaseName(boost::none, "NewTestDB"), MODE_X); }
+ {
+ Lock::DBLock tempLock(
+ newOpCtx.get(),
+ DatabaseName::createDatabaseName_forTest(boost::none, "NewTestDB"),
+ MODE_X);
+ }
}
// Restore the original client so that teardown works.
Client::releaseCurrent();
@@ -1031,7 +1042,8 @@ TEST_F(TxnParticipantTest, UnstashFailsShouldLeaveTxnResourceStashUnchanged) {
// Simulate the locking of an insert.
{
- Lock::DBLock dbLock(opCtx(), DatabaseName(boost::none, "test"), MODE_IX);
+ Lock::DBLock dbLock(
+ opCtx(), DatabaseName::createDatabaseName_forTest(boost::none, "test"), MODE_IX);
Lock::CollectionLock collLock(
opCtx(), NamespaceString::createNamespaceString_forTest("test.foo"), MODE_IX);
}
@@ -1188,7 +1200,8 @@ TEST_F(TxnParticipantTest, StepDownDuringPreparedAbortReleasesRSTL) {
// Simulate the locking of an insert.
{
- Lock::DBLock dbLock(opCtx(), DatabaseName(boost::none, "test"), MODE_IX);
+ Lock::DBLock dbLock(
+ opCtx(), DatabaseName::createDatabaseName_forTest(boost::none, "test"), MODE_IX);
Lock::CollectionLock collLock(
opCtx(), NamespaceString::createNamespaceString_forTest("test.foo"), MODE_IX);
}
@@ -1242,7 +1255,8 @@ TEST_F(TxnParticipantTest, StepDownDuringPreparedCommitReleasesRSTL) {
// Simulate the locking of an insert.
{
- Lock::DBLock dbLock(opCtx(), DatabaseName(boost::none, "test"), MODE_IX);
+ Lock::DBLock dbLock(
+ opCtx(), DatabaseName::createDatabaseName_forTest(boost::none, "test"), MODE_IX);
Lock::CollectionLock collLock(
opCtx(), NamespaceString::createNamespaceString_forTest("test.foo"), MODE_IX);
}
@@ -1912,7 +1926,8 @@ TEST_F(TxnParticipantTest, ReacquireLocksForPreparedTransactionsOnStepUp) {
txnParticipant.unstashTransactionResources(opCtx(), "prepareTransaction");
// Simulate the locking of an insert.
{
- Lock::DBLock dbLock(opCtx(), DatabaseName(boost::none, "test"), MODE_IX);
+ Lock::DBLock dbLock(
+ opCtx(), DatabaseName::createDatabaseName_forTest(boost::none, "test"), MODE_IX);
Lock::CollectionLock collLock(
opCtx(), NamespaceString::createNamespaceString_forTest("test.foo"), MODE_IX);
}
diff --git a/src/mongo/db/views/view_catalog_test.cpp b/src/mongo/db/views/view_catalog_test.cpp
index 967e0dc98cd..09fad6db66a 100644
--- a/src/mongo/db/views/view_catalog_test.cpp
+++ b/src/mongo/db/views/view_catalog_test.cpp
@@ -78,7 +78,8 @@ const auto kTinyMatchStage = BSON("$match" << BSONObj());
class ViewCatalogFixture : public CatalogTestFixture {
public:
- ViewCatalogFixture() : ViewCatalogFixture(DatabaseName(boost::none, "db")) {}
+ ViewCatalogFixture()
+ : ViewCatalogFixture(DatabaseName::createDatabaseName_forTest(boost::none, "db")) {}
ViewCatalogFixture(DatabaseName dbName) : _dbName(std::move(dbName)) {}
@@ -86,8 +87,8 @@ public:
CatalogTestFixture::setUp();
_db = _createDatabase(_dbName);
- _createDatabase({_dbName.tenantId(), "db1"});
- _createDatabase({_dbName.tenantId(), "db2"});
+ _createDatabase(DatabaseName::createDatabaseName_forTest(_dbName.tenantId(), "db1"));
+ _createDatabase(DatabaseName::createDatabaseName_forTest(_dbName.tenantId(), "db2"));
}
void tearDown() override {
@@ -772,7 +773,9 @@ TEST_F(ViewCatalogFixture, ResolveViewCorrectlyExtractsDefaultCollation) {
class ServerlessViewCatalogFixture : public ViewCatalogFixture {
public:
- ServerlessViewCatalogFixture() : ViewCatalogFixture(DatabaseName(TenantId(OID::gen()), "db")) {}
+ ServerlessViewCatalogFixture()
+ : ViewCatalogFixture(DatabaseName::createDatabaseName_forTest(TenantId(OID::gen()), "db")) {
+ }
};
TEST_F(ServerlessViewCatalogFixture, LookupExistingViewBeforeAndAfterDropFeatureFlagOff) {
diff --git a/src/mongo/db/views/view_graph_test.cpp b/src/mongo/db/views/view_graph_test.cpp
index 5ca5fd716fb..fa8c865efd6 100644
--- a/src/mongo/db/views/view_graph_test.cpp
+++ b/src/mongo/db/views/view_graph_test.cpp
@@ -46,7 +46,7 @@
namespace mongo {
namespace {
constexpr auto kEmptyPipelineSize = 0;
-const auto kTestDb = DatabaseName(boost::none, "test");
+const auto kTestDb = DatabaseName::createDatabaseName_forTest(boost::none, "test");
constexpr auto kFooName = "foo"_sd;
constexpr auto kBarName = "bar"_sd;
constexpr auto kQuxName = "qux"_sd;
@@ -249,8 +249,8 @@ TEST_F(ViewGraphFixture, DroppingViewPreservesNodeInGraphIfDependedOnByOtherView
TEST_F(ViewGraphFixture, DifferentTenantsCanCreateViewWithConflictingNamespaces) {
RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true);
- DatabaseName db1(TenantId(OID::gen()), "test");
- DatabaseName db2(TenantId(OID::gen()), "test");
+ DatabaseName db1 = DatabaseName::createDatabaseName_forTest(TenantId(OID::gen()), "test");
+ DatabaseName db2 = DatabaseName::createDatabaseName_forTest(TenantId(OID::gen()), "test");
NamespaceString viewOn1 = NamespaceString::createNamespaceString_forTest(db1, kBarName);
NamespaceString viewOn2 = NamespaceString::createNamespaceString_forTest(db2, kBarName);