com.google.common.util.concurrent.CycleDetectingLockFactory.PotentialDeadlockException

Here are the examples of the java api class com.google.common.util.concurrent.CycleDetectingLockFactory.PotentialDeadlockException taken from open source projects.

1. CycleDetectingLockFactoryTest#testDeadlock_twoLocks()

View license
public void testDeadlock_twoLocks() {
    // Establish an acquisition order of lockA -> lockB.
    lockA.lock();
    lockB.lock();
    lockA.unlock();
    lockB.unlock();
    // The opposite order should fail (Policies.THROW).
    PotentialDeadlockException firstException = null;
    lockB.lock();
    try {
        lockA.lock();
        fail("Expected PotentialDeadlockException");
    } catch (PotentialDeadlockException expected) {
        checkMessage(expected, "LockB -> LockA", "LockA -> LockB");
        firstException = expected;
    }
    // Second time should also fail, with a cached causal chain.
    try {
        lockA.lock();
        fail("Expected PotentialDeadlockException");
    } catch (PotentialDeadlockException expected) {
        checkMessage(expected, "LockB -> LockA", "LockA -> LockB");
        assertSame(firstException.getCause(), expected.getCause());
    }
    // lockA should work after lockB is released.
    lockB.unlock();
    lockA.lock();
}