diff options
Diffstat (limited to 'src/mongo/db/s/resharding_util_test.cpp')
-rw-r--r-- | src/mongo/db/s/resharding_util_test.cpp | 236 |
1 files changed, 0 insertions, 236 deletions
diff --git a/src/mongo/db/s/resharding_util_test.cpp b/src/mongo/db/s/resharding_util_test.cpp index 93fefd8cb99..38b4dee5121 100644 --- a/src/mongo/db/s/resharding_util_test.cpp +++ b/src/mongo/db/s/resharding_util_test.cpp @@ -1203,241 +1203,5 @@ TEST_F(ReshardingTxnCloningPipelineTest, TxnPipelineAfterID) { ASSERT(pipelineMatchesDeque(pipeline, expectedTransactions)); } -class ReshardingCollectionCloneTest : public AggregationContextFixture { -protected: - const NamespaceString& sourceNss() { - return _sourceNss; - } - - boost::intrusive_ptr<ExpressionContextForTest> createExpressionContext( - NamespaceString sourceNss) { - _sourceNss = sourceNss; - NamespaceString foreignNss("config.cache.chunks." + sourceNss.toString()); - boost::intrusive_ptr<ExpressionContextForTest> expCtx( - new ExpressionContextForTest(getOpCtx(), sourceNss)); - expCtx->setResolvedNamespace(sourceNss, {sourceNss, {}}); - expCtx->setResolvedNamespace(foreignNss, {foreignNss, {}}); - return expCtx; - } - - - std::deque<DocumentSource::GetNextResult> makeForeignData(const ShardKeyPattern& pattern) { - const std::initializer_list<const char*> data{ - "{_id: { x : { $minKey : 1 } }, max: { x : 0.0 }, shard: 'shard1' }", - "{_id: { x : 0.0 }, max: { x : { $maxKey : 1 } }, shard: 'shard2' }"}; - std::deque<DocumentSource::GetNextResult> results; - for (auto&& json : data) { - results.emplace_back(Document(fromjson(json))); - } - return results; - } - - std::deque<DocumentSource::GetNextResult> makeForeignData(std::vector<BSONObj> data) { - std::deque<DocumentSource::GetNextResult> results; - for (auto&& obj : data) { - results.emplace_back(Document(obj)); - } - return results; - } - - std::deque<DocumentSource::GetNextResult> makeSourceData(const ShardKeyPattern& pattern) { - const std::initializer_list<const char*> data{ - "{_id: 1, x: { $minKey: 1} }", - "{_id: 2, x: -0.001}", - "{_id: 3, x: NumberLong(0)}", - "{_id: 4, x: 0.0}", - "{_id: 5, x: 0.001}", - "{_id: 6, x: { $maxKey: 1} }", - }; - std::deque<DocumentSource::GetNextResult> results; - for (auto&& json : data) { - results.emplace_back(Document(fromjson(json))); - } - return results; - } - - std::deque<DocumentSource::GetNextResult> makeSourceData(std::vector<BSONObj> data) { - std::deque<DocumentSource::GetNextResult> results; - for (auto&& obj : data) { - results.emplace_back(Document(obj)); - } - return results; - } - -private: - NamespaceString _sourceNss; -}; - -TEST_F(ReshardingCollectionCloneTest, CollectionClonePipelineBasicMinKey) { - NamespaceString fromNs("test", "system.resharding.coll"); - ShardKeyPattern pattern(BSON("x" << 1)); - - auto expCtx = createExpressionContext(fromNs); - - auto foreignData = makeForeignData(pattern); - expCtx->mongoProcessInterface = std::make_shared<MockMongoInterface>(std::move(foreignData)); - - auto sourceData = makeSourceData(pattern); - auto mockSource = DocumentSourceMock::createForTest(std::move(sourceData), expCtx); - - auto pipeline = createAggForCollectionCloning(expCtx, pattern, fromNs, ShardId("shard1")); - pipeline->addInitialSource(mockSource); - - auto next = pipeline->getNext(); - ASSERT(next); - BSONObj val = fromjson("{_id: 1, x: {$minKey : 1}}"); - ASSERT_BSONOBJ_BINARY_EQ(val, next->toBson()); - - next = pipeline->getNext(); - ASSERT(next); - ASSERT_BSONOBJ_BINARY_EQ(BSON("_id" << 2 << "x" << -0.001), next->toBson()); - - ASSERT(!pipeline->getNext()); -} - -TEST_F(ReshardingCollectionCloneTest, CollectionClonePipelineBasicMaxKey) { - NamespaceString fromNs("test", "system.resharding.coll"); - ShardKeyPattern pattern(BSON("x" << 1)); - - auto expCtx = createExpressionContext(fromNs); - - auto foreignData = makeForeignData(pattern); - expCtx->mongoProcessInterface = std::make_shared<MockMongoInterface>(std::move(foreignData)); - - auto sourceData = makeSourceData(pattern); - auto mockSource = DocumentSourceMock::createForTest(std::move(sourceData), expCtx); - - auto pipeline = createAggForCollectionCloning(expCtx, pattern, fromNs, ShardId("shard2")); - pipeline->addInitialSource(mockSource); - - auto next = pipeline->getNext(); - ASSERT(next); - BSONObj val = fromjson("{_id: 3, x: NumberLong(0)}"); - ASSERT_BSONOBJ_BINARY_EQ(val, next->toBson()); - - next = pipeline->getNext(); - ASSERT(next); - ASSERT_BSONOBJ_BINARY_EQ(BSON("_id" << 4 << "x" << 0.0), next->toBson()); - - next = pipeline->getNext(); - ASSERT(next); - ASSERT_BSONOBJ_BINARY_EQ(BSON("_id" << 5 << "x" << 0.001), next->toBson()); - - next = pipeline->getNext(); - ASSERT(next); - val = fromjson("{_id: 6, x: {$maxKey: 1}}"); - ASSERT_BSONOBJ_BINARY_EQ(val, next->toBson()); - - - ASSERT(!pipeline->getNext()); -} - -template <class T> -auto getHashedElementValue(T value) { - return BSONElementHasher::hash64(BSON("" << value).firstElement(), - BSONElementHasher::DEFAULT_HASH_SEED); -} - -TEST_F(ReshardingCollectionCloneTest, CollectionClonePipelineBasicHashedExactMatch) { - NamespaceString fromNs("test", "system.resharding.coll"); - ShardKeyPattern pattern(BSON("x" - << "hashed")); - - auto expCtx = createExpressionContext(fromNs); - - // Documents in a mock config.cache.chunks collection. Mocked collection boundaries: - // - [MinKey, hash(0)) : shard1 - // - [hash(0), hash(0) + 1) : shard2 - // - [hash(0) + 1, MaxKey] : shard3 - auto foreignData = - makeForeignData({BSON("_id" << BSON("x" << MINKEY) << "max" - << BSON("x" << getHashedElementValue(0)) << "shard" - << "shard1"), - BSON("_id" << BSON("x" << getHashedElementValue(0)) << "max" - << BSON("x" << getHashedElementValue(0) + 1) << "shard" - << "shard2"), - BSON("_id" << BSON("x" << getHashedElementValue(0) + 1) << "max" - << BSON("x" << MAXKEY) << "shard" - << "shard3")}); - expCtx->mongoProcessInterface = std::make_shared<MockMongoInterface>(std::move(foreignData)); - - // Documents in a mocked sharded collection. - auto sourceData = makeSourceData({fromjson("{_id: 1, x: {$minKey: 1}}"), - fromjson("{_id: 2, x: -1}"), - fromjson("{_id: 3, x: -0.123}"), - fromjson("{_id: 4, x: 0}"), - fromjson("{_id: 5, x: NumberLong(0)}"), - fromjson("{_id: 6, x: 0.123}"), - fromjson("{_id: 7, x: 1}"), - fromjson("{_id: 8, x: {$maxKey: 1}}")}); - auto mockSource = DocumentSourceMock::createForTest(std::move(sourceData), expCtx); - - auto pipeline = createAggForCollectionCloning(expCtx, pattern, fromNs, ShardId("shard2")); - pipeline->addInitialSource(mockSource); - - auto next = pipeline->getNext(); - ASSERT(next); - ASSERT_BSONOBJ_BINARY_EQ(fromjson("{_id: 3, x: -0.123}"), next->toBson()); - - next = pipeline->getNext(); - ASSERT(next); - ASSERT_BSONOBJ_BINARY_EQ(fromjson("{_id: 4, x: 0}"), next->toBson()); - - next = pipeline->getNext(); - ASSERT(next); - ASSERT_BSONOBJ_BINARY_EQ(fromjson("{_id: 5, x: NumberLong(0)}"), next->toBson()); - - next = pipeline->getNext(); - ASSERT(next); - ASSERT_BSONOBJ_BINARY_EQ(fromjson("{_id: 6, x: 0.123}"), next->toBson()); - - ASSERT_FALSE(pipeline->getNext()); -} - -TEST_F(ReshardingCollectionCloneTest, CollectionClonePipelineBasicHashedExactMatchCompoundKey) { - NamespaceString fromNs("test", "system.resharding.coll"); - ShardKeyPattern pattern(BSON("x" - << "hashed" - << "y" << 1)); - - auto expCtx = createExpressionContext(fromNs); - - // Documents in a mock config.cache.chunks collection. Mocked collection boundaries: - // - [{x: MinKey, y: MinKey}, {x: hash(0), y: 0}) : shard1 - // - [{x: hash(0), y: 0}, {x: hash(0), y: 1}) : shard2 - // - [{x: hash(0), y: 1}, {x: MaxKey, y: MaxKey}] : shard3 - auto foreignData = makeForeignData( - {BSON("_id" << BSON("x" << MINKEY << "y" << MINKEY) << "max" - << BSON("x" << getHashedElementValue(0) << "y" << 0) << "shard" - << "shard1"), - BSON("_id" << BSON("x" << getHashedElementValue(0) << "y" << 0) << "max" - << BSON("x" << (getHashedElementValue(0) + 0) << "y" << 1) << "shard" - << "shard2"), - BSON("_id" << BSON("x" << (getHashedElementValue(0) + 0) << "y" << 1) << "max" - << BSON("x" << MAXKEY << "y" << MAXKEY) << "shard" - << "shard3")}); - expCtx->mongoProcessInterface = std::make_shared<MockMongoInterface>(std::move(foreignData)); - - // Documents in a mocked sharded collection. - auto sourceData = makeSourceData({fromjson("{_id: 1, x: {$minKey: 1}}"), - fromjson("{_id: 2, x: -1}"), - fromjson("{_id: 3, x: -0.123, y: -1}"), - fromjson("{_id: 4, x: 0, y: 0}"), - fromjson("{_id: 5, x: NumberLong(0), y: 1}"), - fromjson("{_id: 6, x: 0.123}"), - fromjson("{_id: 7, x: 1}"), - fromjson("{_id: 8, x: {$maxKey: 1}}")}); - auto mockSource = DocumentSourceMock::createForTest(std::move(sourceData), expCtx); - - auto pipeline = createAggForCollectionCloning(expCtx, pattern, fromNs, ShardId("shard2")); - pipeline->addInitialSource(mockSource); - - auto next = pipeline->getNext(); - ASSERT(next); - ASSERT_BSONOBJ_BINARY_EQ(fromjson("{_id: 4, x: 0, y: 0}"), next->toBson()); - - ASSERT_FALSE(pipeline->getNext()); -} - } // namespace } // namespace mongo |