Java 类com.google.common.util.concurrent.CycleDetectingLockFactory.PotentialDeadlockException 实例源码

项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testDeadlock_threeLocks() {
  // Establish an ordering from lockA -> lockB.
  lockA.lock();
  lockB.lock();
  lockB.unlock();
  lockA.unlock();

  // Establish an ordering from lockB -> lockC.
  lockB.lock();
  lockC.lock();
  lockB.unlock();

  // lockC -> lockA should fail.
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "LockC -> LockA", "LockB -> LockC", "LockA -> LockB");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_cycleWithUnorderedLock() {
  Lock myLock = CycleDetectingLockFactory.newInstance(Policies.THROW)
      .newReentrantLock("MyLock");
  lock03.lock();
  myLock.lock();
  lock03.unlock();

  try {
    lock01.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "MyLock -> OtherOrder.FIRST",
        "OtherOrder.THIRD -> MyLock",
        "OtherOrder.FIRST -> OtherOrder.THIRD");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testReadLock_transitive() {
  readLockA.lock();  // Establish an ordering from readLockA -> lockB.
  lockB.lock();
  lockB.unlock();
  readLockA.unlock();

  // Establish an ordering from lockB -> readLockC.
  lockB.lock();
  readLockC.lock();
  lockB.unlock();
  readLockC.unlock();

  // readLockC -> readLockA
  readLockC.lock();
  try {
    readLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "ReadWriteC -> ReadWriteA",
        "LockB -> ReadWriteC",
        "ReadWriteA -> LockB");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testWriteLock_threeLockDeadLock() {
  // Establish an ordering from writeLockA -> writeLockB.
  writeLockA.lock();
  writeLockB.lock();
  writeLockB.unlock();
  writeLockA.unlock();

  // Establish an ordering from writeLockB -> writeLockC.
  writeLockB.lock();
  writeLockC.lock();
  writeLockB.unlock();

  // writeLockC -> writeLockA should fail.
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "ReadWriteC -> ReadWriteA",
        "ReadWriteB -> ReadWriteC",
        "ReadWriteA -> ReadWriteB");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testWriteToReadLockDowngrading() {
  writeLockA.lock();  // writeLockA downgrades to readLockA
  readLockA.lock();
  writeLockA.unlock();

  lockB.lock();  // readLockA -> lockB
  readLockA.unlock();

  // lockB -> writeLockA should fail
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "LockB -> ReadWriteA", "ReadWriteA -> LockB");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock() {
  writeLockA.lock();  // Establish an ordering from writeLockA -> lockB
  lockB.lock();
  writeLockA.unlock();
  lockB.unlock();

  // lockB -> readLockA should fail.
  lockB.lock();
  try {
    readLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "LockB -> ReadWriteA", "ReadWriteA -> LockB");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock_transitive() {
  readLockA.lock();  // Establish an ordering from readLockA -> lockB
  lockB.lock();
  readLockA.unlock();
  lockB.unlock();

  // Establish an ordering from lockB -> lockC
  lockB.lock();
  lockC.lock();
  lockB.unlock();
  lockC.unlock();

  // lockC -> writeLockA should fail.
  lockC.lock();
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "LockC -> ReadWriteA",
        "LockB -> LockC",
        "ReadWriteA -> LockB");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock_treatedEquivalently() {
  readLockA.lock();  // readLockA -> writeLockB
  writeLockB.lock();
  readLockA.unlock();
  writeLockB.unlock();

  // readLockB -> writeLockA should fail.
  readLockB.lock();
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "ReadWriteB -> ReadWriteA", "ReadWriteA -> ReadWriteB");
  }
}
项目:guava-mock    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories() {
  CycleDetectingLockFactory otherFactory =
      CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockA -> lockD
  lockA.lock();
  lockD.lock();
  lockA.unlock();
  lockD.unlock();

  // lockD -> lockA should fail even though lockD is from a different factory.
  lockD.lock();
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockD -> LockA", "LockA -> LockD");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testDeadlock_threeLocks() {
  // Establish an ordering from lockA -> lockB.
  lockA.lock();
  lockB.lock();
  lockB.unlock();
  lockA.unlock();

  // Establish an ordering from lockB -> lockC.
  lockB.lock();
  lockC.lock();
  lockB.unlock();

  // lockC -> lockA should fail.
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "LockC -> LockA", "LockB -> LockC", "LockA -> LockB");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_cycleWithUnorderedLock() {
  Lock myLock = CycleDetectingLockFactory.newInstance(Policies.THROW)
      .newReentrantLock("MyLock");
  lock03.lock();
  myLock.lock();
  lock03.unlock();

  try {
    lock01.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "MyLock -> OtherOrder.FIRST",
        "OtherOrder.THIRD -> MyLock",
        "OtherOrder.FIRST -> OtherOrder.THIRD");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testReadLock_transitive() {
  readLockA.lock();  // Establish an ordering from readLockA -> lockB.
  lockB.lock();
  lockB.unlock();
  readLockA.unlock();

  // Establish an ordering from lockB -> readLockC.
  lockB.lock();
  readLockC.lock();
  lockB.unlock();
  readLockC.unlock();

  // readLockC -> readLockA
  readLockC.lock();
  try {
    readLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "ReadWriteC -> ReadWriteA",
        "LockB -> ReadWriteC",
        "ReadWriteA -> LockB");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testWriteLock_threeLockDeadLock() {
  // Establish an ordering from writeLockA -> writeLockB.
  writeLockA.lock();
  writeLockB.lock();
  writeLockB.unlock();
  writeLockA.unlock();

  // Establish an ordering from writeLockB -> writeLockC.
  writeLockB.lock();
  writeLockC.lock();
  writeLockB.unlock();

  // writeLockC -> writeLockA should fail.
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "ReadWriteC -> ReadWriteA",
        "ReadWriteB -> ReadWriteC",
        "ReadWriteA -> ReadWriteB");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testWriteToReadLockDowngrading() {
  writeLockA.lock();  // writeLockA downgrades to readLockA
  readLockA.lock();
  writeLockA.unlock();

  lockB.lock();  // readLockA -> lockB
  readLockA.unlock();

  // lockB -> writeLockA should fail
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "LockB -> ReadWriteA", "ReadWriteA -> LockB");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock() {
  writeLockA.lock();  // Establish an ordering from writeLockA -> lockB
  lockB.lock();
  writeLockA.unlock();
  lockB.unlock();

  // lockB -> readLockA should fail.
  lockB.lock();
  try {
    readLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "LockB -> ReadWriteA", "ReadWriteA -> LockB");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock_transitive() {
  readLockA.lock();  // Establish an ordering from readLockA -> lockB
  lockB.lock();
  readLockA.unlock();
  lockB.unlock();

  // Establish an ordering from lockB -> lockC
  lockB.lock();
  lockC.lock();
  lockB.unlock();
  lockC.unlock();

  // lockC -> writeLockA should fail.
  lockC.lock();
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "LockC -> ReadWriteA",
        "LockB -> LockC",
        "ReadWriteA -> LockB");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock_treatedEquivalently() {
  readLockA.lock();  // readLockA -> writeLockB
  writeLockB.lock();
  readLockA.unlock();
  writeLockB.unlock();

  // readLockB -> writeLockA should fail.
  readLockB.lock();
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "ReadWriteB -> ReadWriteA", "ReadWriteA -> ReadWriteB");
  }
}
项目:googles-monorepo-demo    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories() {
  CycleDetectingLockFactory otherFactory =
      CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockA -> lockD
  lockA.lock();
  lockD.lock();
  lockA.unlock();
  lockD.unlock();

  // lockD -> lockA should fail even though lockD is from a different factory.
  lockD.lock();
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockD -> LockA", "LockA -> LockD");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testDeadlock_threeLocks() {
  // Establish an ordering from lockA -> lockB.
  lockA.lock();
  lockB.lock();
  lockB.unlock();
  lockA.unlock();

  // Establish an ordering from lockB -> lockC.
  lockB.lock();
  lockC.lock();
  lockB.unlock();

  // lockC -> lockA should fail.
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "LockC -> LockA", "LockB -> LockC", "LockA -> LockB");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_cycleWithUnorderedLock() {
  Lock myLock = CycleDetectingLockFactory.newInstance(Policies.THROW)
      .newReentrantLock("MyLock");
  lock03.lock();
  myLock.lock();
  lock03.unlock();

  try {
    lock01.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "MyLock -> OtherOrder.FIRST",
        "OtherOrder.THIRD -> MyLock",
        "OtherOrder.FIRST -> OtherOrder.THIRD");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testReadLock_transitive() {
  readLockA.lock();  // Establish an ordering from readLockA -> lockB.
  lockB.lock();
  lockB.unlock();
  readLockA.unlock();

  // Establish an ordering from lockB -> readLockC.
  lockB.lock();
  readLockC.lock();
  lockB.unlock();
  readLockC.unlock();

  // readLockC -> readLockA
  readLockC.lock();
  try {
    readLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "ReadWriteC -> ReadWriteA",
        "LockB -> ReadWriteC",
        "ReadWriteA -> LockB");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testWriteLock_threeLockDeadLock() {
  // Establish an ordering from writeLockA -> writeLockB.
  writeLockA.lock();
  writeLockB.lock();
  writeLockB.unlock();
  writeLockA.unlock();

  // Establish an ordering from writeLockB -> writeLockC.
  writeLockB.lock();
  writeLockC.lock();
  writeLockB.unlock();

  // writeLockC -> writeLockA should fail.
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "ReadWriteC -> ReadWriteA",
        "ReadWriteB -> ReadWriteC",
        "ReadWriteA -> ReadWriteB");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testWriteToReadLockDowngrading() {
  writeLockA.lock();  // writeLockA downgrades to readLockA
  readLockA.lock();
  writeLockA.unlock();

  lockB.lock();  // readLockA -> lockB
  readLockA.unlock();

  // lockB -> writeLockA should fail
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "LockB -> ReadWriteA", "ReadWriteA -> LockB");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock() {
  writeLockA.lock();  // Establish an ordering from writeLockA -> lockB
  lockB.lock();
  writeLockA.unlock();
  lockB.unlock();

  // lockB -> readLockA should fail.
  lockB.lock();
  try {
    readLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "LockB -> ReadWriteA", "ReadWriteA -> LockB");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock_transitive() {
  readLockA.lock();  // Establish an ordering from readLockA -> lockB
  lockB.lock();
  readLockA.unlock();
  lockB.unlock();

  // Establish an ordering from lockB -> lockC
  lockB.lock();
  lockC.lock();
  lockB.unlock();
  lockC.unlock();

  // lockC -> writeLockA should fail.
  lockC.lock();
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "LockC -> ReadWriteA",
        "LockB -> LockC",
        "ReadWriteA -> LockB");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock_treatedEquivalently() {
  readLockA.lock();  // readLockA -> writeLockB
  writeLockB.lock();
  readLockA.unlock();
  writeLockB.unlock();

  // readLockB -> writeLockA should fail.
  readLockB.lock();
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "ReadWriteB -> ReadWriteA", "ReadWriteA -> ReadWriteB");
  }
}
项目:guava-libraries    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories() {
  CycleDetectingLockFactory otherFactory =
      CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockA -> lockD
  lockA.lock();
  lockD.lock();
  lockA.unlock();
  lockD.unlock();

  // lockD -> lockA should fail even though lockD is from a different factory.
  lockD.lock();
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockD -> LockA", "LockA -> LockD");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testDeadlock_threeLocks() {
  // Establish an ordering from lockA -> lockB.
  lockA.lock();
  lockB.lock();
  lockB.unlock();
  lockA.unlock();

  // Establish an ordering from lockB -> lockC.
  lockB.lock();
  lockC.lock();
  lockB.unlock();

  // lockC -> lockA should fail.
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockC -> LockA", "LockB -> LockC", "LockA -> LockB");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_cycleWithUnorderedLock() {
  Lock myLock = CycleDetectingLockFactory.newInstance(Policies.THROW).newReentrantLock("MyLock");
  lock03.lock();
  myLock.lock();
  lock03.unlock();

  try {
    lock01.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "MyLock -> OtherOrder.FIRST",
        "OtherOrder.THIRD -> MyLock",
        "OtherOrder.FIRST -> OtherOrder.THIRD");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testReadLock_transitive() {
  readLockA.lock(); // Establish an ordering from readLockA -> lockB.
  lockB.lock();
  lockB.unlock();
  readLockA.unlock();

  // Establish an ordering from lockB -> readLockC.
  lockB.lock();
  readLockC.lock();
  lockB.unlock();
  readLockC.unlock();

  // readLockC -> readLockA
  readLockC.lock();
  try {
    readLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "ReadWriteC -> ReadWriteA", "LockB -> ReadWriteC", "ReadWriteA -> LockB");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testWriteLock_threeLockDeadLock() {
  // Establish an ordering from writeLockA -> writeLockB.
  writeLockA.lock();
  writeLockB.lock();
  writeLockB.unlock();
  writeLockA.unlock();

  // Establish an ordering from writeLockB -> writeLockC.
  writeLockB.lock();
  writeLockC.lock();
  writeLockB.unlock();

  // writeLockC -> writeLockA should fail.
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "ReadWriteC -> ReadWriteA",
        "ReadWriteB -> ReadWriteC",
        "ReadWriteA -> ReadWriteB");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testWriteToReadLockDowngrading() {
  writeLockA.lock(); // writeLockA downgrades to readLockA
  readLockA.lock();
  writeLockA.unlock();

  lockB.lock(); // readLockA -> lockB
  readLockA.unlock();

  // lockB -> writeLockA should fail
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockB -> ReadWriteA", "ReadWriteA -> LockB");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock_transitive() {
  readLockA.lock(); // Establish an ordering from readLockA -> lockB
  lockB.lock();
  readLockA.unlock();
  lockB.unlock();

  // Establish an ordering from lockB -> lockC
  lockB.lock();
  lockC.lock();
  lockB.unlock();
  lockC.unlock();

  // lockC -> writeLockA should fail.
  lockC.lock();
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockC -> ReadWriteA", "LockB -> LockC", "ReadWriteA -> LockB");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testDifferentLockFactories() {
  CycleDetectingLockFactory otherFactory = CycleDetectingLockFactory.newInstance(Policies.WARN);
  ReentrantLock lockD = otherFactory.newReentrantLock("LockD");

  // lockA -> lockD
  lockA.lock();
  lockD.lock();
  lockA.unlock();
  lockD.unlock();

  // lockD -> lockA should fail even though lockD is from a different factory.
  lockD.lock();
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockD -> LockA", "LockA -> LockD");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testDeadlock_threeLocks() {
  // Establish an ordering from lockA -> lockB.
  lockA.lock();
  lockB.lock();
  lockB.unlock();
  lockA.unlock();

  // Establish an ordering from lockB -> lockC.
  lockB.lock();
  lockC.lock();
  lockB.unlock();

  // lockC -> lockA should fail.
  try {
    lockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockC -> LockA", "LockB -> LockC", "LockA -> LockB");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testExplicitOrdering_cycleWithUnorderedLock() {
  Lock myLock = CycleDetectingLockFactory.newInstance(Policies.THROW).newReentrantLock("MyLock");
  lock03.lock();
  myLock.lock();
  lock03.unlock();

  try {
    lock01.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "MyLock -> OtherOrder.FIRST",
        "OtherOrder.THIRD -> MyLock",
        "OtherOrder.FIRST -> OtherOrder.THIRD");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testReadLock_transitive() {
  readLockA.lock(); // Establish an ordering from readLockA -> lockB.
  lockB.lock();
  lockB.unlock();
  readLockA.unlock();

  // Establish an ordering from lockB -> readLockC.
  lockB.lock();
  readLockC.lock();
  lockB.unlock();
  readLockC.unlock();

  // readLockC -> readLockA
  readLockC.lock();
  try {
    readLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected, "ReadWriteC -> ReadWriteA", "LockB -> ReadWriteC", "ReadWriteA -> LockB");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testWriteLock_threeLockDeadLock() {
  // Establish an ordering from writeLockA -> writeLockB.
  writeLockA.lock();
  writeLockB.lock();
  writeLockB.unlock();
  writeLockA.unlock();

  // Establish an ordering from writeLockB -> writeLockC.
  writeLockB.lock();
  writeLockC.lock();
  writeLockB.unlock();

  // writeLockC -> writeLockA should fail.
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(
        expected,
        "ReadWriteC -> ReadWriteA",
        "ReadWriteB -> ReadWriteC",
        "ReadWriteA -> ReadWriteB");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testWriteToReadLockDowngrading() {
  writeLockA.lock(); // writeLockA downgrades to readLockA
  readLockA.lock();
  writeLockA.unlock();

  lockB.lock(); // readLockA -> lockB
  readLockA.unlock();

  // lockB -> writeLockA should fail
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockB -> ReadWriteA", "ReadWriteA -> LockB");
  }
}
项目:guava    文件:CycleDetectingLockFactoryTest.java   
public void testReadWriteLockDeadlock_transitive() {
  readLockA.lock(); // Establish an ordering from readLockA -> lockB
  lockB.lock();
  readLockA.unlock();
  lockB.unlock();

  // Establish an ordering from lockB -> lockC
  lockB.lock();
  lockC.lock();
  lockB.unlock();
  lockC.unlock();

  // lockC -> writeLockA should fail.
  lockC.lock();
  try {
    writeLockA.lock();
    fail("Expected PotentialDeadlockException");
  } catch (PotentialDeadlockException expected) {
    checkMessage(expected, "LockC -> ReadWriteA", "LockB -> LockC", "ReadWriteA -> LockB");
  }
}