From b569f3769de0d771dc29adaa4a3d0f79010eddc7 Mon Sep 17 00:00:00 2001 From: Eric Daniels Date: Thu, 23 Jan 2020 22:35:28 -0500 Subject: SERVER-45699 - Set LogicalClock on Stitch support library ServiceContext --- .../embedded/stitch_support/stitch_support.cpp | 6 ++++- .../stitch_support/stitch_support_test.cpp | 29 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/mongo/embedded/stitch_support/stitch_support.cpp b/src/mongo/embedded/stitch_support/stitch_support.cpp index 8a2c1133777..9bd13132808 100644 --- a/src/mongo/embedded/stitch_support/stitch_support.cpp +++ b/src/mongo/embedded/stitch_support/stitch_support.cpp @@ -37,6 +37,7 @@ #include "mongo/db/client.h" #include "mongo/db/exec/projection_executor.h" #include "mongo/db/exec/projection_executor_builder.h" +#include "mongo/db/logical_clock.h" #include "mongo/db/matcher/matcher.h" #include "mongo/db/ops/parsed_update.h" #include "mongo/db/query/collation/collator_factory_interface.h" @@ -123,8 +124,11 @@ ServiceContext* initialize() { mongo::runGlobalInitializers(0 /* argc */, nullptr /* argv */, nullptr /* envp */); uassertStatusOKWithContext(status, "Global initialization failed"); setGlobalServiceContext(ServiceContext::make()); + auto serviceContext = getGlobalServiceContext(); + auto logicalClock = std::make_unique(serviceContext); + LogicalClock::set(serviceContext, std::move(logicalClock)); - return getGlobalServiceContext(); + return serviceContext; } struct ServiceContextDestructor { diff --git a/src/mongo/embedded/stitch_support/stitch_support_test.cpp b/src/mongo/embedded/stitch_support/stitch_support_test.cpp index 1bd360601f4..d46ba1b3281 100644 --- a/src/mongo/embedded/stitch_support/stitch_support_test.cpp +++ b/src/mongo/embedded/stitch_support/stitch_support_test.cpp @@ -478,6 +478,35 @@ TEST_F(StitchSupportTest, TestReplacementStyleUpdatePreservesId) { ASSERT_EQ("{ \"_id\" : 123, \"b\" : 789 }", checkUpdate("{b: 789}", "{_id: 123, a: 456}")); } +TEST_F(StitchSupportTest, TestReplacementZeroTimestamp) { + auto result = + mongo::fromjson(checkUpdate("{b: Timestamp(0, 0)}", "{_id: 123, a: 456}").c_str()); + auto elemB = result["b"]; + ASSERT_TRUE(elemB.ok()); + ASSERT_EQUALS(elemB.type(), mongo::BSONType::bsonTimestamp); + auto ts = elemB.timestamp(); + ASSERT_NOT_EQUALS(0U, ts.getSecs()); + ASSERT_NOT_EQUALS(0U, ts.getInc()); +} + +TEST_F(StitchSupportTest, TestUpdateCurrentDateTimestamp) { + auto result = mongo::fromjson( + checkUpdate("{$currentDate: {b: {$type: 'timestamp'}}}", "{_id: 123, a: 456}").c_str()); + auto elemB = result["b"]; + ASSERT_TRUE(elemB.ok()); + ASSERT_EQUALS(elemB.type(), mongo::BSONType::bsonTimestamp); + auto ts = elemB.timestamp(); + ASSERT_NOT_EQUALS(0U, ts.getSecs()); + ASSERT_NOT_EQUALS(0U, ts.getInc()); +} + +TEST_F(StitchSupportTest, TestUpdatePipelineClusterTime) { + auto result = mongo::fromjson( + checkUpdate("[{$set: {b: '$$CLUSTER_TIME'}}]", "{_id: 123, a: 456}").c_str()); + auto elemB = result["b"]; + ASSERT_FALSE(elemB.ok()); +} + TEST_F(StitchSupportTest, TestUpdateArrayElement) { ASSERT_EQ("{ \"a\" : [ 2, 2 ] }", checkUpdate("{$set: {'a.0': 2}}", "{a: [1, 2]}")); ASSERT_EQ("[a.0]", getModifiedPaths()); -- cgit v1.2.1