File tree Expand file tree Collapse file tree 3 files changed +43
-30
lines changed
main/java/org/threadly/test/concurrent Expand file tree Collapse file tree 3 files changed +43
-30
lines changed Original file line number Diff line number Diff line change 1+ package org .threadly .test .concurrent ;
2+
3+ /**
4+ * An implementation of {@link TestRunnable} which will initially block the running thread with
5+ * {@link Object#wait()} when {@link #handleRunStart()} is invoked. The thread will remain blocked
6+ * until {@link #unblock()} is invoked.
7+ *
8+ * @since 1.0
9+ */
10+ public class BlockingTestRunnable extends TestRunnable {
11+ private volatile boolean unblocked = false ;
12+
13+ @ Override
14+ public void handleRunStart () throws InterruptedException {
15+ synchronized (this ) {
16+ while (! unblocked ) {
17+ this .wait ();
18+ }
19+ }
20+ }
21+
22+ /**
23+ * Check if the task has been unblocked yet.
24+ *
25+ * @return {@code true} if the thread has been unblocked.
26+ */
27+ public boolean isUnblocked () {
28+ return unblocked ;
29+ }
30+
31+ /**
32+ * Invoke to unblock any current or future executions for this {@link TestRunnable}. Once invoked
33+ * no future blocking will occur. In general this should be invoked at the end of every test
34+ * (fail or not) to avoid having left over blocked threads hanging around.
35+ */
36+ public void unblock () {
37+ synchronized (this ) {
38+ unblocked = true ;
39+
40+ this .notifyAll ();
41+ }
42+ }
43+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 55import org .junit .After ;
66import org .junit .Before ;
77import org .junit .Test ;
8- import org .threadly .BlockingTestRunnable ;
98import org .threadly .ThreadlyTester ;
109import org .threadly .test .concurrent .TestCondition .ConditionTimeoutException ;
1110import org .threadly .util .Clock ;
You can’t perform that action at this time.
0 commit comments