3232#include " mongo/db/s/balancer/scoped_migration_request.h"
3333
3434#include " mongo/db/s/balancer/type_migration.h"
35+ #include " mongo/db/s/config/sharding_catalog_manager.h"
3536#include " mongo/s/client/shard_registry.h"
3637#include " mongo/s/config_server_test_fixture.h"
3738#include " mongo/s/request_types/migration_secondary_throttle_options.h"
@@ -51,10 +52,10 @@ const ShardId kDifferentToShard("shard0002");
5152class ScopedMigrationRequestTest : public ConfigServerTestFixture {
5253public:
5354 /* *
54- * Queries config.migrations for a document with name (_id) "chunkName" and asserts that the
55+ * Queries config.migrations for the document pertaining to migrateInfo and asserts that the
5556 * number of documents returned equals "expectedNumberOfDocuments".
5657 */
57- void checkMigrationsCollectionForDocument (std::string chunkName ,
58+ void checkMigrationsCollectionForDocument (const MigrateInfo& migrateInfo ,
5859 const unsigned long expectedNumberOfDocuments);
5960
6061 /* *
@@ -63,16 +64,25 @@ class ScopedMigrationRequestTest : public ConfigServerTestFixture {
6364 * constructors.
6465 */
6566 ScopedMigrationRequest makeScopedMigrationRequest (const MigrateInfo& migrateInfo);
67+
68+ private:
69+ void setUp () override ;
6670};
6771
72+ void ScopedMigrationRequestTest::setUp () {
73+ ConfigServerTestFixture::setUp ();
74+ ASSERT_OK (ShardingCatalogManager::get (operationContext ())
75+ ->initializeConfigDatabaseIfNeeded (operationContext ()));
76+ }
77+
6878void ScopedMigrationRequestTest::checkMigrationsCollectionForDocument (
69- std::string chunkName , const unsigned long expectedNumberOfDocuments) {
79+ const MigrateInfo& migrateInfo , const unsigned long expectedNumberOfDocuments) {
7080 auto response = shardRegistry ()->getConfigShard ()->exhaustiveFindOnConfig (
7181 operationContext (),
7282 ReadPreferenceSetting{ReadPreference::PrimaryOnly},
7383 repl::ReadConcernLevel::kMajorityReadConcern ,
7484 MigrationType::ConfigNS,
75- BSON ( MigrationType::name (chunkName) ),
85+ migrateInfo. getMigrationTypeQuery ( ),
7686 BSONObj (),
7787 boost::none);
7888 Shard::QueryResponse queryResponse = unittest::assertGet (response);
@@ -85,7 +95,7 @@ ScopedMigrationRequest ScopedMigrationRequestTest::makeScopedMigrationRequest(
8595 ScopedMigrationRequest scopedMigrationRequest =
8696 assertGet (ScopedMigrationRequest::writeMigration (operationContext (), migrateInfo, false ));
8797
88- checkMigrationsCollectionForDocument (migrateInfo. getName () , 1 );
98+ checkMigrationsCollectionForDocument (migrateInfo, 1 );
8999
90100 return scopedMigrationRequest;
91101}
@@ -113,10 +123,10 @@ TEST_F(ScopedMigrationRequestTest, CreateScopedMigrationRequest) {
113123 ScopedMigrationRequest scopedMigrationRequest = assertGet (
114124 ScopedMigrationRequest::writeMigration (operationContext (), migrateInfo, false ));
115125
116- checkMigrationsCollectionForDocument (migrateInfo. getName () , 1 );
126+ checkMigrationsCollectionForDocument (migrateInfo, 1 );
117127 }
118128
119- checkMigrationsCollectionForDocument (migrateInfo. getName () , 0 );
129+ checkMigrationsCollectionForDocument (migrateInfo, 0 );
120130}
121131
122132/* *
@@ -134,12 +144,12 @@ TEST_F(ScopedMigrationRequestTest, CreateScopedMigrationRequestOnRecovery) {
134144 ScopedMigrationRequest scopedMigrationRequest = assertGet (
135145 ScopedMigrationRequest::writeMigration (operationContext (), migrateInfo, false ));
136146
137- checkMigrationsCollectionForDocument (migrateInfo. getName () , 1 );
147+ checkMigrationsCollectionForDocument (migrateInfo, 1 );
138148
139149 scopedMigrationRequest.keepDocumentOnDestruct ();
140150 }
141151
142- checkMigrationsCollectionForDocument (migrateInfo. getName () , 1 );
152+ checkMigrationsCollectionForDocument (migrateInfo, 1 );
143153
144154 // Fail to write a migration document if a migration document already exists for that chunk but
145155 // with a different destination shard. (the migration request must have identical parameters).
@@ -153,7 +163,7 @@ TEST_F(ScopedMigrationRequestTest, CreateScopedMigrationRequestOnRecovery) {
153163
154164 ASSERT_EQUALS (ErrorCodes::DuplicateKey, statusWithScopedMigrationRequest.getStatus ());
155165
156- checkMigrationsCollectionForDocument (migrateInfo. getName () , 1 );
166+ checkMigrationsCollectionForDocument (migrateInfo, 1 );
157167 }
158168
159169 // Create a new scoped object without inserting a document, and check that the destructor
@@ -162,10 +172,10 @@ TEST_F(ScopedMigrationRequestTest, CreateScopedMigrationRequestOnRecovery) {
162172 ScopedMigrationRequest scopedMigrationRequest = ScopedMigrationRequest::createForRecovery (
163173 operationContext (), migrateInfo.nss , migrateInfo.minKey );
164174
165- checkMigrationsCollectionForDocument (migrateInfo. getName () , 1 );
175+ checkMigrationsCollectionForDocument (migrateInfo, 1 );
166176 }
167177
168- checkMigrationsCollectionForDocument (migrateInfo. getName () , 0 );
178+ checkMigrationsCollectionForDocument (migrateInfo, 0 );
169179}
170180
171181TEST_F (ScopedMigrationRequestTest, CreateMultipleScopedMigrationRequestsForIdenticalMigration) {
@@ -176,22 +186,22 @@ TEST_F(ScopedMigrationRequestTest, CreateMultipleScopedMigrationRequestsForIdent
176186 ScopedMigrationRequest scopedMigrationRequest = assertGet (
177187 ScopedMigrationRequest::writeMigration (operationContext (), migrateInfo, false ));
178188
179- checkMigrationsCollectionForDocument (migrateInfo. getName () , 1 );
189+ checkMigrationsCollectionForDocument (migrateInfo, 1 );
180190
181191 {
182192 // Should be able to create another Scoped object if the request is identical.
183193 ScopedMigrationRequest identicalScopedMigrationRequest = assertGet (
184194 ScopedMigrationRequest::writeMigration (operationContext (), migrateInfo, false ));
185195
186- checkMigrationsCollectionForDocument (migrateInfo. getName () , 1 );
196+ checkMigrationsCollectionForDocument (migrateInfo, 1 );
187197 }
188198
189199 // If any scoped object goes out of scope, the migration should be over and the document
190200 // removed.
191- checkMigrationsCollectionForDocument (migrateInfo. getName () , 0 );
201+ checkMigrationsCollectionForDocument (migrateInfo, 0 );
192202 }
193203
194- checkMigrationsCollectionForDocument (migrateInfo. getName () , 0 );
204+ checkMigrationsCollectionForDocument (migrateInfo, 0 );
195205}
196206
197207TEST_F (ScopedMigrationRequestTest, TryToRemoveScopedMigrationRequestBeforeDestruct) {
@@ -201,11 +211,11 @@ TEST_F(ScopedMigrationRequestTest, TryToRemoveScopedMigrationRequestBeforeDestru
201211 ScopedMigrationRequest scopedMigrationRequest =
202212 assertGet (ScopedMigrationRequest::writeMigration (operationContext (), migrateInfo, false ));
203213
204- checkMigrationsCollectionForDocument (migrateInfo. getName () , 1 );
214+ checkMigrationsCollectionForDocument (migrateInfo, 1 );
205215
206216 ASSERT_OK (scopedMigrationRequest.tryToRemoveMigration ());
207217
208- checkMigrationsCollectionForDocument (migrateInfo. getName () , 0 );
218+ checkMigrationsCollectionForDocument (migrateInfo, 0 );
209219}
210220
211221TEST_F (ScopedMigrationRequestTest, MoveAndAssignmentConstructors) {
@@ -217,10 +227,10 @@ TEST_F(ScopedMigrationRequestTest, MoveAndAssignmentConstructors) {
217227 ScopedMigrationRequest anotherScopedMigrationRequest =
218228 makeScopedMigrationRequest (migrateInfo);
219229
220- checkMigrationsCollectionForDocument (migrateInfo. getName () , 1 );
230+ checkMigrationsCollectionForDocument (migrateInfo, 1 );
221231 }
222232
223- checkMigrationsCollectionForDocument (migrateInfo. getName () , 0 );
233+ checkMigrationsCollectionForDocument (migrateInfo, 0 );
224234}
225235
226236} // namespace
0 commit comments