コード例 #1
0
ファイル: lock_state_test.cpp プロジェクト: 3rf/mongo
    /**
     * Tests that restoreMMAPV1LockerImpl works by locking a db and collection and saving + restoring.
     */
    TEST(LockerImpl, saveAndRestoreDBAndCollection) {
        Locker::LockSnapshot lockInfo;

        MMAPV1LockerImpl locker;

        const ResourceId resIdDatabase(RESOURCE_DATABASE, std::string("TestDB"));
        const ResourceId resIdCollection(RESOURCE_COLLECTION, std::string("TestDB.collection"));

        // Lock some stuff.
        locker.lockGlobal(MODE_IX);
        ASSERT(LOCK_OK == locker.lock(resIdDatabase, MODE_IX));
        ASSERT(LOCK_OK == locker.lock(resIdCollection, MODE_X));
        locker.saveLockStateAndUnlock(&lockInfo);

        // Things shouldn't be locked anymore.
        ASSERT(locker.getLockMode(resIdDatabase) == MODE_NONE);
        ASSERT(locker.getLockMode(resIdCollection) == MODE_NONE);

        // Restore lock state.
        locker.restoreLockState(lockInfo);

        // Make sure things were re-locked.
        ASSERT(locker.getLockMode(resIdDatabase) == MODE_IX);
        ASSERT(locker.getLockMode(resIdCollection) == MODE_X);

        locker.unlockAll();
    }
コード例 #2
0
ファイル: lock_state_test.cpp プロジェクト: 3rf/mongo
    /**
     * Test that saveMMAPV1LockerImpl works by examining the output.
     */
    TEST(LockerImpl, saveAndRestoreGlobal) {
        Locker::LockSnapshot lockInfo;

        MMAPV1LockerImpl locker;

        // No lock requests made, no locks held.
        locker.saveLockStateAndUnlock(&lockInfo);
        ASSERT_EQUALS(0U, lockInfo.locks.size());

        // Lock the global lock, but just once.
        locker.lockGlobal(MODE_IX);

        // We've locked the global lock.  This should be reflected in the lockInfo.
        locker.saveLockStateAndUnlock(&lockInfo);
        ASSERT(!locker.isLocked());
        ASSERT_EQUALS(MODE_IX, lockInfo.globalMode);

        // Restore the lock(s) we had.
        locker.restoreLockState(lockInfo);

        ASSERT(locker.isLocked());
        ASSERT(locker.unlockAll());
    }