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


C++ LockManager类代码示例

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


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

示例1: TEST

TEST(LockManager, GrantMultipleFIFOOrder) {
    LockManager lockMgr;
    const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection"));

    std::unique_ptr<MMAPV1LockerImpl> locker[6];
    for (int i = 0; i < 6; i++) {
        locker[i].reset(new MMAPV1LockerImpl());
    }

    TrackingLockGrantNotification notify[6];

    LockRequest request[6];
    for (int i = 0; i < 6; i++) {
        request[i].initNew(locker[i].get(), &notify[i]);
        lockMgr.lock(resId, &request[i], MODE_X);

        ASSERT(request[i].mode == MODE_X);
        ASSERT(request[i].recursiveCount == 1);
    }

    // Release the last held lock and ensure the next one, based on time is granted
    for (int i = 0; i < 5; i++) {
        lockMgr.unlock(&request[i]);

        ASSERT(notify[i + 1].numNotifies == 1);
        ASSERT(notify[i + 1].lastResId == resId);
        ASSERT(notify[i + 1].lastResult == LOCK_OK);
    }

    // Release the last one
    lockMgr.unlock(&request[5]);
}
开发者ID:AshishSanju,项目名称:mongo,代码行数:32,代码来源:lock_manager_test.cpp

示例2: TEST

    TEST(LockManager, GrantRecursiveNonCompatibleConvertDown) {
        LockManager lockMgr;
        const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection"));

        LockState locker;
        TrackingLockGrantNotification notify;

        LockRequest request;
        request.initNew(&locker, &notify);

        ASSERT(LOCK_OK == lockMgr.lock(resId, &request, MODE_X));
        ASSERT(request.mode == MODE_X);
        ASSERT(request.recursiveCount == 1);
        ASSERT(notify.numNotifies == 0);

        // Acquire again, in *non-compatible*, but less strict mode
        ASSERT(LOCK_OK == lockMgr.lock(resId, &request, MODE_S));
        ASSERT(request.mode == MODE_X);
        ASSERT(request.recursiveCount == 2);
        ASSERT(notify.numNotifies == 0);

        // Release first acquire
        lockMgr.unlock(&request);
        ASSERT(request.mode == MODE_X);
        ASSERT(request.recursiveCount == 1);

        // Release second acquire
        lockMgr.unlock(&request);
        ASSERT(request.recursiveCount == 0);
    }
开发者ID:ANTco,项目名称:mongo,代码行数:30,代码来源:lock_mgr_new_test.cpp

示例3: checkConflict

// Lock conflict matrix tests
static void checkConflict(LockMode existingMode, LockMode newMode, bool hasConflict) {
    LockManager lockMgr;
    const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection"));

    MMAPV1LockerImpl lockerExisting;
    TrackingLockGrantNotification notifyExisting;
    LockRequest requestExisting;
    requestExisting.initNew(&lockerExisting, &notifyExisting);

    ASSERT(LOCK_OK == lockMgr.lock(resId, &requestExisting, existingMode));

    MMAPV1LockerImpl lockerNew;
    TrackingLockGrantNotification notifyNew;
    LockRequest requestNew;
    requestNew.initNew(&lockerNew, &notifyNew);

    LockResult result = lockMgr.lock(resId, &requestNew, newMode);
    if (hasConflict) {
        ASSERT_EQUALS(LOCK_WAITING, result);
    } else {
        ASSERT_EQUALS(LOCK_OK, result);
    }

    lockMgr.unlock(&requestNew);
    lockMgr.unlock(&requestExisting);
}
开发者ID:AshishSanju,项目名称:mongo,代码行数:27,代码来源:lock_manager_test.cpp

示例4: ActualTestImportDocument

void TestOnMappedNetworkDrives::ActualTestImportDocument()
{
	DocProviderWorker	objWorker;
	WSDocNonCom			wsDoc;
	LockManager			lockMgr;

	CStdString sMappedDriveLetter = m_NetDriveHelper.GetMapNetworkDriveLetter();
	assertMessage(!sMappedDriveLetter.IsEmpty(), _T("Cannot map network drive - used to just skip test"));
	CStdString sOrigFile = sMappedDriveLetter + _T("\\Original.doc");

	DocumentID docImportID(DocumentID::GenerateIdFromFilePath(sOrigFile));
	CStdString csLocalFile = docImportID.CreateLocalFile();
	objWorker.PopulateDocumentProperties(docImportID, wsDoc, false);
	CStdString sOldDocID = wsDoc.GetDocId();
	HRESULT hrImport = objWorker.ImportDocument(wsDoc, false);

	assertMessage(SUCCEEDED(hrImport),_T("Failure code returned from ImportDocument()"));

	if(sOldDocID.CompareNoCase( CStdString(wsDoc.GetDocId()))==0)
	{
		assertMessage(false,_T("The in and out DocID's are the same after import"));
	}


	// check lock=false
	CStdString sLockedBy;
	if(lockMgr.IsDocIDLocked(wsDoc.GetDocId(), sLockedBy) )
	{
		assertMessage(false, _T("Imported file is locked when it was requested not to be"));
	}

	if(docImportID.GetDescription() != wsDoc.GetDescription())
	{
		assertMessage(false, _T("The document Description does not match the original file used for the import."));
	}
	
	assertTest((wsDoc.GetFlags() & DOCUMENT_LOCKED_BY_US)==0);

	LFSDMSHelper dmsHelp;

	DocumentID docID(wsDoc.GetDocId());
	CStdString	sLocalName(docID.GetWorkingFile());
	int iFileNameStartsAt = sLocalName.ReverseFind('\\');
	if ((iFileNameStartsAt != CStdString::npos) && (dmsHelp.DoesFileExist(sLocalName)))
	{
		sLocalName.resize(iFileNameStartsAt);
		assertTest(dmsHelp.DeleteDirectoryAndContents(sLocalName));
	}
	::DeleteFile(csLocalFile.c_str());
}
开发者ID:killbug2004,项目名称:WSProf,代码行数:50,代码来源:TestOnMappedNetworkDrives.cpp

示例5: docTarget

void TestCloseDocument::TestUnlocksFileOnClose()
{
	DocProviderWorker	objWorker;
	WSDocNonCom			wsDoc;
	DocumentID			docTarget(DocumentID::GenerateIdFromFilePath(sTestOriginalFileName));
	
	wsDoc.SetDescription(docTarget.GetDescription());
	wsDoc.SetLocalFile(docTarget.GetWorkingFile());
	assertTest(objWorker.ImportDocument(wsDoc, true) == S_OK);
	m_wsImportedDoc = wsDoc;
	assertTest(objWorker.CloseDocument(wsDoc,0) == S_OK);

	LockManager lckMngr;
	CStdString sLockedBy;
	assertTest(lckMngr.IsDocIDLocked(wsDoc.GetDocId(),sLockedBy) == false);
}
开发者ID:killbug2004,项目名称:WSProf,代码行数:16,代码来源:TestCloseDocument.cpp

示例6: TEST

TEST(LockManagerTest, TxShutdown) {
    LockManager lm;
    ClientTransaction t1(&lm, 1);
    ClientTransaction t2(&lm, 2);

    t1.acquire(kShared, 1, ACQUIRED);
    lm.shutdown(3000);

    // t1 can still do work while quiescing
    t1.release(kShared, 1);
    t1.acquire(kShared, 2, ACQUIRED);
#ifdef TRANSACTION_REGISTRATION
    // t2 is new and should be refused
    t2.acquire(kShared, 3, ABORTED);
#else
    t2.quit();
#endif
    // after the quiescing period, t1's request should be refused
    sleepsecs(3);
    t1.acquire(kShared, 4, ABORTED);
}
开发者ID:Benguang,项目名称:mongo,代码行数:21,代码来源:lock_mgr_test.cpp

示例7: TestLockAttachment

void TestLockDocument::TestLockAttachment()
{
	DocProviderWorker	objWorker;
	LockManager			docLock;
	CStdString			sDocID(DocumentID::GetDocProviderId() + TEST_DIRECTORY + TEST_DOC + _T(".doc"));
	DocumentID			docID(sDocID);
	CStdString			szDummyUser(_T("HighHouseShadow"));
	CStdString			sLockFileName(docID.GetLockFileName(szDummyUser, false));
	WSDocNonCom			wsDoc;

	objWorker.GetDocument(sDocID,NULL,wsDoc);
		
	HRESULT hrLock = docLock.CreateLock(sDocID, szDummyUser);

	if(FAILED(hrLock))
	{
		CStdString szErr;
		szErr.Format(_T("CreateLock returned a Failure Error code - %08x"),hrLock);
		assertMessage(false, szErr);
	}
	
	if (_taccess(sLockFileName, 0) == -1)
	{
		assertMessage(false, _T("We didn't create a lock file as HighHouseShadow"));
	}

	HRESULT hrUnlock = docLock.RemoveLock(sDocID,szDummyUser);
	
	if(FAILED(hrUnlock))
	{
		CStdString szErr;
		szErr.Format(_T("CreateLock returned a Failure Error code - %08x"),hrUnlock);
		assertMessage(false,szErr);
	}

	if (_taccess(sLockFileName, 0) != -1)
	{
		assertMessage(false, _T("We didn't remove the HighHouseShadow lock"));
	}
}
开发者ID:killbug2004,项目名称:WSProf,代码行数:40,代码来源:TestLockDocument.cpp

示例8: sDocID

void TestLockDocument::TestAlreadyLockedByOther()
{
	DocProviderWorker	objWorker;
	CStdString			sDocID(DocumentID::GetDocProviderId() + TEST_DIRECTORY + TEST_DOC + _T(".doc"));
	DocumentID			docID(sDocID);
	CStdString			sLockFileName(docID.GetLockFileName(_T("apple"), false));
	WSDocNonCom			wsDoc;
	LockManager			docLock;
	
	objWorker.GetDocument(sDocID, 0, wsDoc);

	docLock.CreateLock(sDocID, _T("apple"));

	if (_taccess(sLockFileName, 0) == -1)
	{
		assertMessage(false, _T("Unable to create lock file"));
	}
	
	assertTest(objWorker.LockDocument(sDocID, LOCK_DOCUMENT) == E_DOCUMENT_LOCKED_BY_ANOTHER);

	assertMessage(docLock.RemoveLock(docID, _T("apple")) == S_OK, _T("Failed to unlock document at end of test"));	
}
开发者ID:killbug2004,项目名称:WSProf,代码行数:22,代码来源:TestLockDocument.cpp


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