summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2017-08-30 23:58:30 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2017-09-15 17:20:22 -0400
commit7626535bbcc2f90b7815cbf1a8e6d2c0bef732f1 (patch)
tree8638e4aafe02c50a616e8f319f8ed0cae068210f /src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
parentc9e5bcbc0dacfa8031f3a2aaa1c6e369d0bc26c3 (diff)
downloadmongo-7626535bbcc2f90b7815cbf1a8e6d2c0bef732f1.tar.gz
SERVER-30591 Do changeStream lookups by UUID instead of namespace.
Diffstat (limited to 'src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp57
1 files changed, 45 insertions, 12 deletions
diff --git a/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp b/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
index fdeea5bffc6..66c408aa0d2 100644
--- a/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
+++ b/src/mongo/db/pipeline/document_source_lookup_change_post_image_test.cpp
@@ -52,7 +52,27 @@ using std::deque;
using std::vector;
// This provides access to getExpCtx(), but we'll use a different name for this test suite.
-using DocumentSourceLookupChangePostImageTest = AggregationContextFixture;
+class DocumentSourceLookupChangePostImageTest : public AggregationContextFixture {
+public:
+ /**
+ * This method is required to avoid a static initialization fiasco resulting from calling
+ * UUID::gen() in file static scope.
+ */
+ static const UUID& testUuid() {
+ static const UUID* uuid_gen = new UUID(UUID::gen());
+ return *uuid_gen;
+ }
+
+ Document makeResumeToken(ImplicitValue id = Value()) {
+ const Timestamp ts(100, 1);
+ if (id.missing()) {
+ return {{"clusterTime", Document{{"ts", ts}}}, {"uuid", testUuid()}};
+ }
+ return {{"clusterTime", Document{{"ts", ts}}},
+ {"uuid", testUuid()},
+ {"documentKey", Document{{"_id", id}}}};
+ }
+};
/**
* A mock MongodInterface which allows mocking a foreign pipeline.
@@ -92,7 +112,8 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfMissingDocumentKeyO
// Mock its input with a document without a "documentKey" field.
auto mockLocalSource = DocumentSourceMock::create(
- Document{{"operationType", "update"_sd},
+ Document{{"_id", makeResumeToken(0)},
+ {"operationType", "update"_sd},
{"fullDocument", Document{{"_id", 0}}},
{"ns", Document{{"db", expCtx->ns.db()}, {"coll", expCtx->ns.coll()}}}});
@@ -113,7 +134,8 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfMissingOperationTyp
// Mock its input with a document without a "ns" field.
auto mockLocalSource = DocumentSourceMock::create(
- Document{{"documentKey", Document{{"_id", 0}}},
+ Document{{"_id", makeResumeToken(0)},
+ {"documentKey", Document{{"_id", 0}}},
{"fullDocument", Document{{"_id", 0}}},
{"ns", Document{{"db", expCtx->ns.db()}, {"coll", expCtx->ns.coll()}}}});
@@ -134,7 +156,9 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfMissingNamespace) {
// Mock its input with a document without a "ns" field.
auto mockLocalSource = DocumentSourceMock::create(Document{
- {"documentKey", Document{{"_id", 0}}}, {"operationType", "update"_sd},
+ {"_id", makeResumeToken(0)},
+ {"documentKey", Document{{"_id", 0}}},
+ {"operationType", "update"_sd},
});
lookupChangeStage->setSource(mockLocalSource.get());
@@ -153,8 +177,11 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfNsFieldHasWrongType
auto lookupChangeStage = DocumentSourceLookupChangePostImage::create(expCtx);
// Mock its input with a document without a "ns" field.
- auto mockLocalSource = DocumentSourceMock::create(
- Document{{"documentKey", Document{{"_id", 0}}}, {"operationType", "update"_sd}, {"ns", 4}});
+ auto mockLocalSource =
+ DocumentSourceMock::create(Document{{"_id", makeResumeToken(0)},
+ {"documentKey", Document{{"_id", 0}}},
+ {"operationType", "update"_sd},
+ {"ns", 4}});
lookupChangeStage->setSource(mockLocalSource.get());
@@ -173,7 +200,8 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfNsFieldDoesNotMatch
// Mock its input with a document without a "ns" field.
auto mockLocalSource = DocumentSourceMock::create(
- Document{{"documentKey", Document{{"_id", 0}}},
+ Document{{"_id", makeResumeToken(0)},
+ {"documentKey", Document{{"_id", 0}}},
{"operationType", "update"_sd},
{"ns", Document{{"db", "DIFFERENT"_sd}, {"coll", expCtx->ns.coll()}}}});
@@ -194,7 +222,8 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldErrorIfDocumentKeyIsNotUni
// Mock its input with an update document.
auto mockLocalSource = DocumentSourceMock::create(
- Document{{"documentKey", Document{{"_id", 0}}},
+ Document{{"_id", makeResumeToken(0)},
+ {"documentKey", Document{{"_id", 0}}},
{"operationType", "update"_sd},
{"ns", Document{{"db", expCtx->ns.db()}, {"coll", expCtx->ns.coll()}}}});
@@ -217,12 +246,14 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldPropagatePauses) {
// Mock its input, pausing every other result.
auto mockLocalSource = DocumentSourceMock::create(
- {Document{{"documentKey", Document{{"_id", 0}}},
+ {Document{{"_id", makeResumeToken(0)},
+ {"documentKey", Document{{"_id", 0}}},
{"operationType", "insert"_sd},
{"ns", Document{{"db", expCtx->ns.db()}, {"coll", expCtx->ns.coll()}}},
{"fullDocument", Document{{"_id", 0}}}},
DocumentSource::GetNextResult::makePauseExecution(),
- Document{{"documentKey", Document{{"_id", 1}}},
+ Document{{"_id", makeResumeToken(1)},
+ {"documentKey", Document{{"_id", 1}}},
{"operationType", "update"_sd},
{"ns", Document{{"db", expCtx->ns.db()}, {"coll", expCtx->ns.coll()}}}},
DocumentSource::GetNextResult::makePauseExecution()});
@@ -239,7 +270,8 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldPropagatePauses) {
ASSERT_TRUE(next.isAdvanced());
ASSERT_DOCUMENT_EQ(
next.releaseDocument(),
- (Document{{"documentKey", Document{{"_id", 0}}},
+ (Document{{"_id", makeResumeToken(0)},
+ {"documentKey", Document{{"_id", 0}}},
{"operationType", "insert"_sd},
{"ns", Document{{"db", expCtx->ns.db()}, {"coll", expCtx->ns.coll()}}},
{"fullDocument", Document{{"_id", 0}}}}));
@@ -250,7 +282,8 @@ TEST_F(DocumentSourceLookupChangePostImageTest, ShouldPropagatePauses) {
ASSERT_TRUE(next.isAdvanced());
ASSERT_DOCUMENT_EQ(
next.releaseDocument(),
- (Document{{"documentKey", Document{{"_id", 1}}},
+ (Document{{"_id", makeResumeToken(1)},
+ {"documentKey", Document{{"_id", 1}}},
{"operationType", "update"_sd},
{"ns", Document{{"db", expCtx->ns.db()}, {"coll", expCtx->ns.coll()}}},
{"fullDocument", Document{{"_id", 1}}}}));