Esempio n. 1
0
    TEST(LockManager, Downgrade) {
        LockManager lockMgr;
        const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection"));

        LockState locker1;
        TrackingLockGrantNotification notify1;
        LockRequest request1;
        request1.initNew(&locker1, &notify1);
        ASSERT(LOCK_OK == lockMgr.lock(resId, &request1, MODE_X));

        LockState locker2;
        TrackingLockGrantNotification notify2;
        LockRequest request2;
        request2.initNew(&locker2, &notify2);
        ASSERT(LOCK_WAITING == lockMgr.lock(resId, &request2, MODE_S));
        ASSERT(request2.recursiveCount == 1);

        lockMgr.downgrade(&request1, MODE_S);
        ASSERT(notify2.numNotifies == 1);
        ASSERT(request2.recursiveCount == 1);

        lockMgr.unlock(&request1);
        ASSERT(request1.recursiveCount == 0);

        lockMgr.unlock(&request2);
        ASSERT(request2.recursiveCount == 0);
    }
Esempio n. 2
0
TEST(LockManager, Downgrade) {
    LockManager lockMgr;
    const ResourceId resId(RESOURCE_COLLECTION, std::string("TestDB.collection"));

    MMAPV1LockerImpl locker1;
    LockRequestCombo request1(&locker1);
    ASSERT(LOCK_OK == lockMgr.lock(resId, &request1, MODE_X));

    MMAPV1LockerImpl locker2;
    LockRequestCombo request2(&locker2);
    ASSERT(LOCK_WAITING == lockMgr.lock(resId, &request2, MODE_S));

    // Downgrade the X request to S
    lockMgr.downgrade(&request1, MODE_S);

    ASSERT(request2.numNotifies == 1);
    ASSERT(request2.lastResult == LOCK_OK);
    ASSERT(request2.recursiveCount == 1);

    ASSERT(lockMgr.unlock(&request1));
    ASSERT(lockMgr.unlock(&request2));
}