jayway/awaitility — pull request #12 by Turbo87 (2014-10-06 14:29:02+00:00)
Title: DeadlockDetectionTest: Cleanup threads after testrun

With the previous test code the threads would have stayed in deadlock forever until the JVM is killed. The new code uses Locks that can be interrupted instead, so thread cleanup after the test run is possible.

Due to the different locking semantics the exception output is now:

~~~
com.jayway.awaitility.core.ConditionTimeoutException: com.jayway.awaitility.core.ConditionFactory.untilAtomic Callable expected ( or ) but was within 200 milliseconds.
at com.jayway.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:96)
at com.jayway.awaitility.core.AbstractHamcrestCondition.await(AbstractHamcrestCondition.java:136)
at com.jayway.awaitility.core.ConditionFactory.until(ConditionFactory.java:590)
at com.jayway.awaitility.core.ConditionFactory.untilAtomic(ConditionFactory.java:505)
at com.jayway.awaitility.core.ConditionFactory.untilTrue(ConditionFactory.java:519)
at com.jayway.awaitility.DeadlockDetectionTest.deadlockTest(DeadlockDetectionTest.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62)
Caused by: com.jayway.awaitility.core.DeadlockException: Deadlocked threads detected:

"Thread-2" Id=11 WAITING on java.util.concurrent.locks.ReentrantLock$NonfairSync@35369763 owned by "Thread-1" Id=10
at sun.misc.Unsafe.park(Native Method)
- waiting on java.util.concurrent.locks.ReentrantLock$NonfairSync@35369763
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:834)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireInterruptibly(AbstractQueuedSynchronizer.java:894)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1221)
at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:340)
at com.jayway.awaitility.DeadlockDetectionTest$2.run(DeadlockDetectionTest.java:51)

Number of locked synchronizers = 1
- java.util.concurrent.locks.ReentrantLock$NonfairSync@4e19e97b

"Thread-1" Id=10 WAITING on java.util.concurrent.locks.ReentrantLock$NonfairSync@4e19e97b owned by "Thread-2" Id=11
at sun.misc.Unsafe.park(Native Method)
- waiting on java.util.concurrent.locks.ReentrantLock$NonfairSync@4e19e97b
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:834)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireInterruptibly(AbstractQueuedSynchronizer.java:894)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireInterruptibly(AbstractQueuedSynchronizer.java:1221)
at java.util.concurrent.locks.ReentrantLock.lockInterruptibly(ReentrantLock.java:340)
at com.jayway.awaitility.DeadlockDetectionTest$1.run(DeadlockDetectionTest.java:33)

Number of locked synchronizers = 1
- java.util.concurrent.locks.ReentrantLock$NonfairSync@35369763

at com.jayway.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:101)
... 14 more
~~~