summaryrefslogtreecommitdiff
path: root/src/mongo/client
diff options
context:
space:
mode:
authorjannaerin <golden.janna@gmail.com>2023-02-01 20:54:39 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-08 02:46:14 +0000
commit567bcd0e4822d726aea15f0338c89c49de2a56b5 (patch)
treefa2a6ea1d3cbd4872fba26df3fdb44548544206f /src/mongo/client
parentf7afadd90f50662b2b3b3a45595b65b37a59bdc3 (diff)
downloadmongo-567bcd0e4822d726aea15f0338c89c49de2a56b5.tar.gz
SERVER-73112 Expose function to construct NamespaceString in unit tests
Diffstat (limited to 'src/mongo/client')
-rw-r--r--src/mongo/client/dbclient_cursor_test.cpp23
-rw-r--r--src/mongo/client/dbclient_rs_test.cpp66
2 files changed, 45 insertions, 44 deletions
diff --git a/src/mongo/client/dbclient_cursor_test.cpp b/src/mongo/client/dbclient_cursor_test.cpp
index 266307d6b70..e9b0adaf203 100644
--- a/src/mongo/client/dbclient_cursor_test.cpp
+++ b/src/mongo/client/dbclient_cursor_test.cpp
@@ -145,7 +145,7 @@ protected:
TEST_F(DBClientCursorTest, DBClientCursorCallsMetaDataReaderOncePerBatch) {
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
- const NamespaceString nss("test", "coll");
+ const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll");
FindCommandRequest findCmd{nss};
DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, false);
cursor.setBatchSize(2);
@@ -192,7 +192,8 @@ TEST_F(DBClientCursorTest, DBClientCursorGetMoreWithTenant) {
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
const TenantId tenantId(OID::gen());
- const NamespaceString nss(tenantId, "test", "coll");
+ const NamespaceString nss =
+ NamespaceString::createNamespaceString_forTest(tenantId, "test", "coll");
FindCommandRequest findCmd{nss};
RAIIServerParameterControllerForTest multitenancyController("multitenancySupport", true);
@@ -237,7 +238,7 @@ TEST_F(DBClientCursorTest, DBClientCursorHandlesOpMsgExhaustCorrectly) {
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
- const NamespaceString nss("test", "coll");
+ const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll");
FindCommandRequest findCmd{nss};
DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, true /*isExhaust*/);
cursor.setBatchSize(0);
@@ -301,7 +302,7 @@ TEST_F(DBClientCursorTest, DBClientCursorResendsGetMoreIfMoreToComeFlagIsOmitted
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
- const NamespaceString nss("test", "coll");
+ const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll");
FindCommandRequest findCmd{nss};
DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, true /*isExhaust*/);
cursor.setBatchSize(0);
@@ -385,7 +386,7 @@ TEST_F(DBClientCursorTest, DBClientCursorResendsGetMoreIfMoreToComeFlagIsOmitted
TEST_F(DBClientCursorTest, DBClientCursorMoreThrowsExceptionOnNonOKResponse) {
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
- const NamespaceString nss("test", "coll");
+ const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll");
FindCommandRequest findCmd{nss};
DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, true /*isExhaust*/);
cursor.setBatchSize(0);
@@ -416,7 +417,7 @@ TEST_F(DBClientCursorTest, DBClientCursorMoreThrowsExceptionOnNonOKResponse) {
TEST_F(DBClientCursorTest, DBClientCursorMoreThrowsExceptionWhenMoreToComeFlagSetWithZeroCursorId) {
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
- const NamespaceString nss("test", "coll");
+ const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll");
FindCommandRequest findCmd{nss};
DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, true /*isExhaust*/);
cursor.setBatchSize(0);
@@ -449,7 +450,7 @@ TEST_F(DBClientCursorTest, DBClientCursorMoreThrowsExceptionWhenMoreToComeFlagSe
TEST_F(DBClientCursorTest, DBClientCursorPassesReadOnceFlag) {
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
- const NamespaceString nss("test", "coll");
+ const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll");
FindCommandRequest findCmd{nss};
findCmd.setReadOnce(true);
DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, false);
@@ -476,7 +477,7 @@ TEST_F(DBClientCursorTest, DBClientCursorPassesReadOnceFlag) {
TEST_F(DBClientCursorTest, DBClientCursorPassesResumeFields) {
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
- const NamespaceString nss("test", "coll");
+ const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll");
FindCommandRequest findCmd{nss};
findCmd.setRequestResumeToken(true);
findCmd.setResumeAfter(BSON("$recordId" << 5LL));
@@ -512,7 +513,7 @@ TEST_F(DBClientCursorTest, DBClientCursorTailable) {
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
- const NamespaceString nss("test", "coll");
+ const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll");
FindCommandRequest findCmd{nss};
findCmd.setTailable(true);
DBClientCursor cursor(&conn, findCmd, ReadPreferenceSetting{}, false);
@@ -606,7 +607,7 @@ TEST_F(DBClientCursorTest, DBClientCursorTailableAwaitData) {
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
- const NamespaceString nss("test", "coll");
+ const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll");
FindCommandRequest findCmd{nss};
findCmd.setTailable(true);
findCmd.setAwaitData(true);
@@ -668,7 +669,7 @@ TEST_F(DBClientCursorTest, DBClientCursorTailableAwaitDataExhaust) {
// Set up the DBClientCursor and a mock client connection.
DBClientConnectionForTest conn;
- const NamespaceString nss("test", "coll");
+ const NamespaceString nss = NamespaceString::createNamespaceString_forTest("test", "coll");
FindCommandRequest findCmd{nss};
findCmd.setTailable(true);
findCmd.setAwaitData(true);
diff --git a/src/mongo/client/dbclient_rs_test.cpp b/src/mongo/client/dbclient_rs_test.cpp
index 7053d8fe623..27d572f498c 100644
--- a/src/mongo/client/dbclient_rs_test.cpp
+++ b/src/mongo/client/dbclient_rs_test.cpp
@@ -157,7 +157,7 @@ TEST_F(BasicRS, QueryPrimary) {
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
// Note: IdentityNS contains the name of the server.
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor =
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryOnly});
BSONObj doc = cursor->next();
@@ -173,7 +173,7 @@ TEST_F(BasicRS, QuerySecondaryOnly) {
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
// Note: IdentityNS contains the name of the server.
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor =
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryOnly});
BSONObj doc = cursor->next();
@@ -190,7 +190,7 @@ TEST_F(BasicRS, QueryPrimaryPreferred) {
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
// Note: IdentityNS contains the name of the server.
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor =
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
BSONObj doc = cursor->next();
@@ -206,7 +206,7 @@ TEST_F(BasicRS, QuerySecondaryPreferred) {
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
// Note: IdentityNS contains the name of the server.
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor = replConn.find(std::move(findCmd),
ReadPreferenceSetting{ReadPreference::SecondaryPreferred});
BSONObj doc = cursor->next();
@@ -270,7 +270,7 @@ TEST_F(AllNodesDown, QueryPrimary) {
MockReplicaSet* replSet = getReplSet();
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
ASSERT_THROWS(
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryOnly}),
AssertionException);
@@ -284,7 +284,7 @@ TEST_F(AllNodesDown, QuerySecondaryOnly) {
MockReplicaSet* replSet = getReplSet();
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
ASSERT_THROWS(
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryOnly}),
AssertionException);
@@ -298,7 +298,7 @@ TEST_F(AllNodesDown, QueryPrimaryPreferred) {
MockReplicaSet* replSet = getReplSet();
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
ASSERT_THROWS(
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryPreferred}),
AssertionException);
@@ -312,7 +312,7 @@ TEST_F(AllNodesDown, QuerySecondaryPreferred) {
MockReplicaSet* replSet = getReplSet();
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
ASSERT_THROWS(replConn.find(std::move(findCmd),
ReadPreferenceSetting{ReadPreference::SecondaryPreferred}),
AssertionException);
@@ -326,7 +326,7 @@ TEST_F(AllNodesDown, QueryNearest) {
MockReplicaSet* replSet = getReplSet();
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
ASSERT_THROWS(replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::Nearest}),
AssertionException);
}
@@ -372,7 +372,7 @@ TEST_F(PrimaryDown, QueryPrimary) {
MockReplicaSet* replSet = getReplSet();
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
ASSERT_THROWS(
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryOnly}),
AssertionException);
@@ -387,7 +387,7 @@ TEST_F(PrimaryDown, QuerySecondaryOnly) {
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
// Note: IdentityNS contains the name of the server.
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor =
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryOnly});
BSONObj doc = cursor->next();
@@ -404,7 +404,7 @@ TEST_F(PrimaryDown, QueryPrimaryPreferred) {
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
// Note: IdentityNS contains the name of the server.
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor =
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
BSONObj doc = cursor->next();
@@ -421,7 +421,7 @@ TEST_F(PrimaryDown, QuerySecondaryPreferred) {
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
// Note: IdentityNS contains the name of the server.
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor = replConn.find(std::move(findCmd),
ReadPreferenceSetting{ReadPreference::SecondaryPreferred});
BSONObj doc = cursor->next();
@@ -437,7 +437,7 @@ TEST_F(PrimaryDown, Nearest) {
MockReplicaSet* replSet = getReplSet();
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::Nearest});
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getSecondaries().front(), doc[HostField.name()].str());
@@ -482,7 +482,7 @@ TEST_F(SecondaryDown, QueryPrimary) {
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
// Note: IdentityNS contains the name of the server.
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor =
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryOnly});
BSONObj doc = cursor->next();
@@ -497,7 +497,7 @@ TEST_F(SecondaryDown, QuerySecondaryOnly) {
MockReplicaSet* replSet = getReplSet();
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
ASSERT_THROWS(
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::SecondaryOnly}),
AssertionException);
@@ -512,7 +512,7 @@ TEST_F(SecondaryDown, QueryPrimaryPreferred) {
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
// Note: IdentityNS contains the name of the server.
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor =
replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
BSONObj doc = cursor->next();
@@ -527,7 +527,7 @@ TEST_F(SecondaryDown, QuerySecondaryPreferred) {
MockReplicaSet* replSet = getReplSet();
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor = replConn.find(std::move(findCmd),
ReadPreferenceSetting{ReadPreference::SecondaryPreferred});
BSONObj doc = cursor->next();
@@ -542,7 +542,7 @@ TEST_F(SecondaryDown, QueryNearest) {
MockReplicaSet* replSet = getReplSet();
DBClientReplicaSet replConn(replSet->getSetName(), replSet->getHosts(), StringData());
- FindCommandRequest findCmd{NamespaceString{IdentityNS}};
+ FindCommandRequest findCmd{NamespaceString::createNamespaceString_forTest(IdentityNS)};
auto cursor = replConn.find(std::move(findCmd), ReadPreferenceSetting{ReadPreference::Nearest});
BSONObj doc = cursor->next();
ASSERT_EQUALS(replSet->getPrimary(), doc[HostField.name()].str());
@@ -691,17 +691,17 @@ TEST_F(TaggedFiveMemberRS, ConnShouldPinIfSameSettings) {
string dest;
{
// Note: IdentityNS contains the name of the server.
- std::unique_ptr<DBClientCursor> cursor =
- replConn.find(FindCommandRequest{NamespaceString{IdentityNS}},
- ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
+ std::unique_ptr<DBClientCursor> cursor = replConn.find(
+ FindCommandRequest{NamespaceString::createNamespaceString_forTest(IdentityNS)},
+ ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
BSONObj doc = cursor->next();
dest = doc[HostField.name()].str();
}
{
- std::unique_ptr<DBClientCursor> cursor =
- replConn.find(FindCommandRequest{NamespaceString{IdentityNS}},
- ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
+ std::unique_ptr<DBClientCursor> cursor = replConn.find(
+ FindCommandRequest{NamespaceString::createNamespaceString_forTest(IdentityNS)},
+ ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
BSONObj doc = cursor->next();
const string newDest = doc[HostField.name()].str();
ASSERT_EQUALS(dest, newDest);
@@ -718,9 +718,9 @@ TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfHostMarkedAsFailed) {
string dest;
{
// Note: IdentityNS contains the name of the server.
- std::unique_ptr<DBClientCursor> cursor =
- replConn.find(FindCommandRequest{NamespaceString{IdentityNS}},
- ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
+ std::unique_ptr<DBClientCursor> cursor = replConn.find(
+ FindCommandRequest{NamespaceString::createNamespaceString_forTest(IdentityNS)},
+ ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
BSONObj doc = cursor->next();
dest = doc[HostField.name()].str();
}
@@ -732,9 +732,9 @@ TEST_F(TaggedFiveMemberRS, ConnShouldNotPinIfHostMarkedAsFailed) {
getTopologyManager()->setTopologyDescription(getReplSet()->getTopologyDescription(clock()));
{
- std::unique_ptr<DBClientCursor> cursor =
- replConn.find(FindCommandRequest{NamespaceString{IdentityNS}},
- ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
+ std::unique_ptr<DBClientCursor> cursor = replConn.find(
+ FindCommandRequest{NamespaceString::createNamespaceString_forTest(IdentityNS)},
+ ReadPreferenceSetting{ReadPreference::PrimaryPreferred});
BSONObj doc = cursor->next();
const string newDest = doc[HostField.name()].str();
ASSERT_NOT_EQUALS(dest, newDest);
@@ -752,8 +752,8 @@ TEST_F(TaggedFiveMemberRS, SecondaryConnReturnsSecConn) {
mongo::DBClientConnection& secConn = replConn.secondaryConn();
// Note: IdentityNS contains the name of the server.
- std::unique_ptr<DBClientCursor> cursor =
- secConn.find(FindCommandRequest{NamespaceString{IdentityNS}});
+ std::unique_ptr<DBClientCursor> cursor = secConn.find(
+ FindCommandRequest{NamespaceString::createNamespaceString_forTest(IdentityNS)});
BSONObj doc = cursor->next();
std::string dest = doc[HostField.name()].str();
ASSERT_NOT_EQUALS(dest, replSet->getPrimary());