summaryrefslogtreecommitdiff
path: root/src/mongo/db/operation_context_test.cpp
diff options
context:
space:
mode:
authorsamantharitter <samantha.ritter@10gen.com>2017-04-05 16:48:16 -0400
committersamantharitter <samantha.ritter@10gen.com>2017-04-12 13:17:21 -0400
commit7dc10fd9d845756bb983fe1637dece6f3d37b981 (patch)
treefdb3d1042f0cfa4c5f1eb5b5994615021d174f99 /src/mongo/db/operation_context_test.cpp
parent56b8f03ca7c0c6a315a30a7a41bd781540dedde8 (diff)
downloadmongo-7dc10fd9d845756bb983fe1637dece6f3d37b981.tar.gz
SERVER-28298 Allow OperationContext objects to be created with an optional LogicalSessionId
Diffstat (limited to 'src/mongo/db/operation_context_test.cpp')
-rw-r--r--src/mongo/db/operation_context_test.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/mongo/db/operation_context_test.cpp b/src/mongo/db/operation_context_test.cpp
index 95f53cf8053..33e23f45593 100644
--- a/src/mongo/db/operation_context_test.cpp
+++ b/src/mongo/db/operation_context_test.cpp
@@ -28,7 +28,10 @@
#include "mongo/platform/basic.h"
+#include <boost/optional.hpp>
+
#include "mongo/db/client.h"
+#include "mongo/db/logical_session_id.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_context_noop.h"
@@ -69,6 +72,40 @@ std::ostream& operator<<(std::ostream& os, stdx::future_status futureStatus) {
}
}
+TEST(OperationContextTest, CanHaveLogicalSessionId) {
+ // Test that we can create opCtx's with or without a logical session id
+ auto serviceCtx = stdx::make_unique<ServiceContextNoop>();
+ auto client = serviceCtx->makeClient("OperationContextTest");
+
+ // No session id
+ {
+ auto opCtx = client->makeOperationContext();
+ ASSERT(!opCtx->getLogicalSessionId());
+ }
+
+ {
+ auto opCtx = serviceCtx->makeOperationContext(client.get());
+ ASSERT(!opCtx->getLogicalSessionId());
+ }
+
+ // With a session id
+ auto res = LogicalSessionId::parse("00000000-abab-4000-8000-000000000000");
+ ASSERT(res.isOK());
+ auto lsid = res.getValue();
+
+ {
+ auto opCtx = client->makeOperationContext(lsid);
+ ASSERT(opCtx->getLogicalSessionId());
+ ASSERT_EQUALS(*(opCtx->getLogicalSessionId()), lsid);
+ }
+
+ {
+ auto opCtx = serviceCtx->makeOperationContext(client.get(), lsid);
+ ASSERT(opCtx->getLogicalSessionId());
+ ASSERT_EQUALS(*(opCtx->getLogicalSessionId()), lsid);
+ }
+}
+
class OperationDeadlineTests : public unittest::Test {
public:
void setUp() {