diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2018-11-01 17:35:26 -0400 |
---|---|---|
committer | Charlie Swanson <charlie.swanson@mongodb.com> | 2018-11-21 14:56:27 -0500 |
commit | cce280f98a8badf8aef4ed960e82e61e61d3fe5e (patch) | |
tree | 4ddfbd74d4acea1135c9ab15ecdd8803abb4ca6d /src/mongo/db/pipeline/document_source_out_test.cpp | |
parent | 756f8e070b5fbf6728ecefbd625601f3dd7e75a0 (diff) | |
download | mongo-cce280f98a8badf8aef4ed960e82e61e61d3fe5e.tar.gz |
SERVER-37871 Enforce agreement on shard key across cluster for $out
Diffstat (limited to 'src/mongo/db/pipeline/document_source_out_test.cpp')
-rw-r--r-- | src/mongo/db/pipeline/document_source_out_test.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/mongo/db/pipeline/document_source_out_test.cpp b/src/mongo/db/pipeline/document_source_out_test.cpp index 44256d1fb4b..60530547165 100644 --- a/src/mongo/db/pipeline/document_source_out_test.cpp +++ b/src/mongo/db/pipeline/document_source_out_test.cpp @@ -67,6 +67,12 @@ public: OperationContext* opCtx, const NamespaceString& nss) const override { return {"_id"}; } + + void checkRoutingInfoEpochOrThrow(const boost::intrusive_ptr<ExpressionContext>& expCtx, + const NamespaceString&, + ChunkVersion) const override { + return; // Pretend it always matches for our tests here. + } }; class DocumentSourceOutTest : public AggregationContextFixture { @@ -359,21 +365,38 @@ TEST_F(DocumentSourceOutTest, FailsToParseIfUniqueKeyHasDuplicateFields) { ASSERT_THROWS_CODE(createOutStage(spec), AssertionException, ErrorCodes::BadValue); } -TEST_F(DocumentSourceOutTest, FailsToParseIfTargetEpochIsSpecifiedOnMongos) { +TEST_F(DocumentSourceOutTest, FailsToParseIfTargetCollectionVersionIsSpecifiedOnMongos) { BSONObj spec = BSON("$out" << BSON("to" << "test" << "mode" << kDefaultMode << "uniqueKey" << BSON("_id" << 1) - << "epoch" - << OID::gen())); + << "targetCollectionVersion" + << ChunkVersion(0, 0, OID::gen()).toBSON())); getExpCtx()->inMongos = true; ASSERT_THROWS_CODE(createOutStage(spec), AssertionException, 50984); - // Test that 'targetEpoch' is accepted if not in mongos. + // Test that 'targetCollectionVersion' is accepted if _from_ mongos. getExpCtx()->inMongos = false; + getExpCtx()->fromMongos = true; ASSERT(createOutStage(spec) != nullptr); + + // Test that 'targetCollectionVersion' is not accepted if on mongod but not from mongos. + getExpCtx()->inMongos = false; + getExpCtx()->fromMongos = false; + ASSERT_THROWS_CODE(createOutStage(spec), AssertionException, 51018); +} + +TEST_F(DocumentSourceOutTest, FailsToParseifUniqueKeyIsNotSentFromMongos) { + BSONObj spec = BSON("$out" << BSON("to" + << "test" + << "mode" + << kDefaultMode + << "targetCollectionVersion" + << ChunkVersion(0, 0, OID::gen()).toBSON())); + getExpCtx()->fromMongos = true; + ASSERT_THROWS_CODE(createOutStage(spec), AssertionException, 51017); } TEST_F(DocumentSourceOutTest, CorrectlyUsesTargetDbThatMatchesAggregationDb) { |