summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Daniels <eric@erdaniels.com>2020-01-23 22:35:28 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-01-25 03:06:37 +0000
commitb569f3769de0d771dc29adaa4a3d0f79010eddc7 (patch)
tree06193826dd9c919cfbc5eacd6621d754ddc3976e
parente9aff0aa463d8a85a27e2ca254a6175eb23f2bf8 (diff)
downloadmongo-b569f3769de0d771dc29adaa4a3d0f79010eddc7.tar.gz
SERVER-45699 - Set LogicalClock on Stitch support library ServiceContext
-rw-r--r--src/mongo/embedded/stitch_support/stitch_support.cpp6
-rw-r--r--src/mongo/embedded/stitch_support/stitch_support_test.cpp29
2 files changed, 34 insertions, 1 deletions
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<LogicalClock>(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());