diff options
author | Randolph Tan <randolph@10gen.com> | 2018-06-29 10:19:48 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2018-08-08 16:00:20 -0400 |
commit | 52b2cc0886cdb992e2491067bdc029301d5bb6af (patch) | |
tree | c414da256a84890af3fb084ab699b572b49dab4f /src/mongo/db/session_catalog_test.cpp | |
parent | 210bb5d91cb3c77bb3ed169114f8b85cd1062fb3 (diff) | |
download | mongo-52b2cc0886cdb992e2491067bdc029301d5bb6af.tar.gz |
SERVER-35900 Refactor transaction machinery out from Session class
Diffstat (limited to 'src/mongo/db/session_catalog_test.cpp')
-rw-r--r-- | src/mongo/db/session_catalog_test.cpp | 95 |
1 files changed, 5 insertions, 90 deletions
diff --git a/src/mongo/db/session_catalog_test.cpp b/src/mongo/db/session_catalog_test.cpp index 1d4ba8ec87d..c55c2c780db 100644 --- a/src/mongo/db/session_catalog_test.cpp +++ b/src/mongo/db/session_catalog_test.cpp @@ -90,7 +90,7 @@ TEST_F(SessionCatalogTest, OperationContextCheckedOutSession) { const TxnNumber txnNum = 20; opCtx()->setTxnNumber(txnNum); - OperationContextSession ocs(opCtx(), true, boost::none, boost::none, "testDB", "insert"); + OperationContextSession ocs(opCtx(), true); auto session = OperationContextSession::get(opCtx()); ASSERT(session); ASSERT_EQ(*opCtx()->getLogicalSessionId(), session->getSessionId()); @@ -99,7 +99,7 @@ TEST_F(SessionCatalogTest, OperationContextCheckedOutSession) { TEST_F(SessionCatalogTest, OperationContextNonCheckedOutSession) { opCtx()->setLogicalSessionId(makeLogicalSessionIdForTest()); - OperationContextSession ocs(opCtx(), false, boost::none, boost::none, "testDB", "insert"); + OperationContextSession ocs(opCtx(), false); auto session = OperationContextSession::get(opCtx()); ASSERT(!session); @@ -118,7 +118,7 @@ TEST_F(SessionCatalogTest, GetOrCreateSessionAfterCheckOutSession) { opCtx()->setLogicalSessionId(lsid); boost::optional<OperationContextSession> ocs; - ocs.emplace(opCtx(), true, boost::none, false, "testDB", "insert"); + ocs.emplace(opCtx(), true); stdx::async(stdx::launch::async, [&] { ON_BLOCK_EXIT([&] { Client::destroy(); }); @@ -149,13 +149,11 @@ TEST_F(SessionCatalogTest, NestedOperationContextSession) { opCtx()->setLogicalSessionId(makeLogicalSessionIdForTest()); { - OperationContextSession outerScopedSession( - opCtx(), true, boost::none, boost::none, "testDB", "insert"); + OperationContextSession outerScopedSession(opCtx(), true); { DirectClientSetter inDirectClient(opCtx()); - OperationContextSession innerScopedSession( - opCtx(), true, boost::none, boost::none, "testDB", "insert"); + OperationContextSession innerScopedSession(opCtx(), true); auto session = OperationContextSession::get(opCtx()); ASSERT(session); @@ -173,89 +171,6 @@ TEST_F(SessionCatalogTest, NestedOperationContextSession) { ASSERT(!OperationContextSession::get(opCtx())); } -TEST_F(SessionCatalogTest, StashInNestedSessionIsANoop) { - opCtx()->setLogicalSessionId(makeLogicalSessionIdForTest()); - opCtx()->setTxnNumber(1); - - { - OperationContextSession outerScopedSession( - opCtx(), true, /* autocommit */ false, /* startTransaction */ true, "testDB", "find"); - - Locker* originalLocker = opCtx()->lockState(); - RecoveryUnit* originalRecoveryUnit = opCtx()->recoveryUnit(); - ASSERT(originalLocker); - ASSERT(originalRecoveryUnit); - - // Set the readConcern on the OperationContext. - repl::ReadConcernArgs readConcernArgs; - ASSERT_OK(readConcernArgs.initialize(BSON("find" - << "test" - << repl::ReadConcernArgs::kReadConcernFieldName - << BSON(repl::ReadConcernArgs::kLevelFieldName - << "snapshot")))); - repl::ReadConcernArgs::get(opCtx()) = readConcernArgs; - - // Perform initial unstash, which sets up a WriteUnitOfWork. - OperationContextSession::get(opCtx())->unstashTransactionResources(opCtx(), "find"); - ASSERT_EQUALS(originalLocker, opCtx()->lockState()); - ASSERT_EQUALS(originalRecoveryUnit, opCtx()->recoveryUnit()); - ASSERT(opCtx()->getWriteUnitOfWork()); - - { - // Make it look like we're in a DBDirectClient running a nested operation. - DirectClientSetter inDirectClient(opCtx()); - OperationContextSession innerScopedSession( - opCtx(), true, boost::none, boost::none, "testDB", "find"); - - OperationContextSession::get(opCtx())->stashTransactionResources(opCtx()); - - // The stash was a noop, so the locker, RecoveryUnit, and WriteUnitOfWork on the - // OperationContext are unaffected. - ASSERT_EQUALS(originalLocker, opCtx()->lockState()); - ASSERT_EQUALS(originalRecoveryUnit, opCtx()->recoveryUnit()); - ASSERT(opCtx()->getWriteUnitOfWork()); - } - } -} - -TEST_F(SessionCatalogTest, UnstashInNestedSessionIsANoop) { - opCtx()->setLogicalSessionId(makeLogicalSessionIdForTest()); - opCtx()->setTxnNumber(1); - - { - OperationContextSession outerScopedSession( - opCtx(), true, /* autocommit */ false, /* startTransaction */ true, "testDB", "find"); - - Locker* originalLocker = opCtx()->lockState(); - RecoveryUnit* originalRecoveryUnit = opCtx()->recoveryUnit(); - ASSERT(originalLocker); - ASSERT(originalRecoveryUnit); - - // Set the readConcern on the OperationContext. - repl::ReadConcernArgs readConcernArgs; - ASSERT_OK(readConcernArgs.initialize(BSON("find" - << "test" - << repl::ReadConcernArgs::kReadConcernFieldName - << BSON(repl::ReadConcernArgs::kLevelFieldName - << "snapshot")))); - repl::ReadConcernArgs::get(opCtx()) = readConcernArgs; - - { - // Make it look like we're in a DBDirectClient running a nested operation. - DirectClientSetter inDirectClient(opCtx()); - OperationContextSession innerScopedSession( - opCtx(), true, boost::none, boost::none, "testDB", "find"); - - OperationContextSession::get(opCtx())->unstashTransactionResources(opCtx(), "find"); - - // The unstash was a noop, so the OperationContext did not get a WriteUnitOfWork. - ASSERT_EQUALS(originalLocker, opCtx()->lockState()); - ASSERT_EQUALS(originalRecoveryUnit, opCtx()->recoveryUnit()); - ASSERT_FALSE(opCtx()->getWriteUnitOfWork()); - } - } -} - TEST_F(SessionCatalogTest, ScanSessions) { std::vector<LogicalSessionId> lsids; auto workerFn = [&](OperationContext* opCtx, Session* session) { |