diff options
Diffstat (limited to 'src/mongo/s/catalog_cache_test_fixture.cpp')
-rw-r--r-- | src/mongo/s/catalog_cache_test_fixture.cpp | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/mongo/s/catalog_cache_test_fixture.cpp b/src/mongo/s/catalog_cache_test_fixture.cpp index 0bb9c38ce9c..5154f98d3ed 100644 --- a/src/mongo/s/catalog_cache_test_fixture.cpp +++ b/src/mongo/s/catalog_cache_test_fixture.cpp @@ -180,8 +180,16 @@ ChunkManager CatalogCacheTestFixture::makeChunkManager( auto future = scheduleRoutingInfoUnforcedRefresh(nss); expectFindSendBSONObjVector(kConfigHostAndPort, {databaseBSON}); - expectFindSendBSONObjVector(kConfigHostAndPort, {collectionBSON}); - expectFindSendBSONObjVector(kConfigHostAndPort, initialChunks); + expectFindSendBSONObjVector(kConfigHostAndPort, [&]() { + std::vector<BSONObj> aggResult; + std::transform(initialChunks.begin(), + initialChunks.end(), + std::back_inserter(aggResult), + [&collectionBSON](const auto& chunk) { + return collectionBSON.addFields(BSON("chunks" << chunk)); + }); + return aggResult; + }()); return *future.default_timed_get(); } @@ -205,6 +213,29 @@ void CatalogCacheTestFixture::expectGetCollection(NamespaceString nss, }()); } +void CatalogCacheTestFixture::expectCollectionAndChunksAggregation( + NamespaceString nss, + OID epoch, + UUID uuid, + const ShardKeyPattern& shardKeyPattern, + const std::vector<ChunkType>& chunks) { + expectFindSendBSONObjVector(kConfigHostAndPort, [&]() { + CollectionType collType(nss, epoch, Date_t::now(), uuid); + collType.setKeyPattern(shardKeyPattern.toBSON()); + collType.setUnique(false); + const auto collObj = collType.toBSON(); + + std::vector<BSONObj> aggResult; + std::transform(chunks.begin(), + chunks.end(), + std::back_inserter(aggResult), + [&collObj](const auto& chunk) { + return collObj.addFields(BSON("chunks" << chunk.toConfigBSON())); + }); + return aggResult; + }()); +} + ChunkManager CatalogCacheTestFixture::loadRoutingTableWithTwoChunksAndTwoShards( NamespaceString nss) { @@ -237,8 +268,11 @@ ChunkManager CatalogCacheTestFixture::loadRoutingTableWithTwoChunksAndTwoShardsI expectGetDatabase(nss); } } - expectGetCollection(nss, epoch, uuid, shardKeyPattern); expectFindSendBSONObjVector(kConfigHostAndPort, [&]() { + CollectionType collType(nss, epoch, Date_t::now(), uuid); + collType.setKeyPattern(shardKeyPattern.toBSON()); + collType.setUnique(false); + ChunkVersion version(1, 0, epoch, boost::none /* timestamp */); ChunkType chunk1( @@ -251,7 +285,10 @@ ChunkManager CatalogCacheTestFixture::loadRoutingTableWithTwoChunksAndTwoShardsI chunk2.setName(OID::gen()); version.incMinor(); - return std::vector<BSONObj>{chunk1.toConfigBSON(), chunk2.toConfigBSON()}; + const auto collObj = collType.toBSON(); + const auto chunk1Obj = collObj.addFields(BSON("chunks" << chunk1.toConfigBSON())); + const auto chunk2Obj = collObj.addFields(BSON("chunks" << chunk2.toConfigBSON())); + return std::vector<BSONObj>{chunk1Obj, chunk2Obj}; }()); return *future.default_timed_get(); |