当前位置: 首页>>代码示例>>C++>>正文


C++ CursorManager::hasTransactionCursorReference方法代码示例

本文整理汇总了C++中CursorManager::hasTransactionCursorReference方法的典型用法代码示例。如果您正苦于以下问题:C++ CursorManager::hasTransactionCursorReference方法的具体用法?C++ CursorManager::hasTransactionCursorReference怎么用?C++ CursorManager::hasTransactionCursorReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CursorManager的用法示例。


在下文中一共展示了CursorManager::hasTransactionCursorReference方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: makeLogicalSessionIdForTest

TEST_F(CursorManagerTestCustomOpCtx,
       KillAllCursorsForTransactionRemovesCorrectEntryFromTransactionMap) {
    CursorManager* cursorManager = CursorManager::getGlobalCursorManager();

    // Create 3 sets of cursors, each with a unique LogicalSessionId/TxnNumber pair, but each
    // sharing either LogicalSessionId or TxnNumber with another set.
    auto lsid1 = makeLogicalSessionIdForTest();
    TxnNumber txnNumber1 = 0;
    {
        auto opCtx = _queryServiceContext->makeOperationContext(lsid1, txnNumber1);
        auto pinned = cursorManager->registerCursor(opCtx.get(),
                                                    {makeFakePlanExecutor(),
                                                     NamespaceString{"test.collection"},
                                                     {},
                                                     repl::ReadConcernLevel::kLocalReadConcern,
                                                     BSONObj()});
        pinned.release();
    }

    auto lsid2 = lsid1;
    TxnNumber txnNumber2 = 1;
    {
        auto opCtx = _queryServiceContext->makeOperationContext(lsid2, txnNumber2);
        auto pinned = cursorManager->registerCursor(opCtx.get(),
                                                    {makeFakePlanExecutor(),
                                                     NamespaceString{"test.collection"},
                                                     {},
                                                     repl::ReadConcernLevel::kLocalReadConcern,
                                                     BSONObj()});
        pinned.release();
    }

    auto lsid3 = makeLogicalSessionIdForTest();
    TxnNumber txnNumber3 = txnNumber1;
    {
        auto opCtx = _queryServiceContext->makeOperationContext(lsid3, txnNumber3);
        // Create 2 cursors for the third set to confirm multiple cursor deregistration.
        auto pinned = cursorManager->registerCursor(opCtx.get(),
                                                    {makeFakePlanExecutor(),
                                                     NamespaceString{"test.collection"},
                                                     {},
                                                     repl::ReadConcernLevel::kLocalReadConcern,
                                                     BSONObj()});
        pinned.release();
        pinned = cursorManager->registerCursor(opCtx.get(),
                                               {makeFakePlanExecutor(),
                                                NamespaceString{"test.collection"},
                                                {},
                                                repl::ReadConcernLevel::kLocalReadConcern,
                                                BSONObj()});
        pinned.release();
    }

    auto opCtx = _queryServiceContext->makeOperationContext();

    // Transaction reference exists for all 3 sets.
    ASSERT_TRUE(cursorManager->hasTransactionCursorReference(lsid1, txnNumber1));
    ASSERT_TRUE(cursorManager->hasTransactionCursorReference(lsid2, txnNumber2));
    ASSERT_TRUE(cursorManager->hasTransactionCursorReference(lsid3, txnNumber3));

    // Transaction reference does not exist for LogicalSessionId/TxnNumber that has no cursors.
    ASSERT_FALSE(cursorManager->hasTransactionCursorReference(makeLogicalSessionIdForTest(), 99));

    // Kill cursors for set 1.
    ASSERT_EQ(1ul, cursorManager->killAllCursorsForTransaction(opCtx.get(), lsid1, txnNumber1));
    ASSERT_FALSE(cursorManager->hasTransactionCursorReference(lsid1, txnNumber1));
    ASSERT_TRUE(cursorManager->hasTransactionCursorReference(lsid2, txnNumber2));
    ASSERT_TRUE(cursorManager->hasTransactionCursorReference(lsid3, txnNumber3));

    // Kill cursors for set 2.
    ASSERT_EQ(1ul, cursorManager->killAllCursorsForTransaction(opCtx.get(), lsid2, txnNumber2));
    ASSERT_FALSE(cursorManager->hasTransactionCursorReference(lsid2, txnNumber2));
    ASSERT_TRUE(cursorManager->hasTransactionCursorReference(lsid3, txnNumber3));

    // Kill cursors for set 3.
    ASSERT_EQ(2ul, cursorManager->killAllCursorsForTransaction(opCtx.get(), lsid3, txnNumber3));
    ASSERT_FALSE(cursorManager->hasTransactionCursorReference(lsid3, txnNumber3));
}
开发者ID:,项目名称:,代码行数:78,代码来源:


注:本文中的CursorManager::hasTransactionCursorReference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。