96 |
|
private static final boolean useSecurityManager = |
97 |
|
Boolean.getBoolean("jsr166.useSecurityManager"); |
98 |
|
|
99 |
+ |
protected static final boolean expensiveTests = |
100 |
+ |
Boolean.getBoolean("jsr166.expensiveTests"); |
101 |
+ |
|
102 |
+ |
/** |
103 |
+ |
* If true, report on stdout all "slow" tests, that is, ones that |
104 |
+ |
* take more than profileThreshold milliseconds to execute. |
105 |
+ |
*/ |
106 |
+ |
private static final boolean profileTests = |
107 |
+ |
Boolean.getBoolean("jsr166.profileTests"); |
108 |
+ |
|
109 |
+ |
/** |
110 |
+ |
* The number of milliseconds that tests are permitted for |
111 |
+ |
* execution without being reported, when profileTests is set. |
112 |
+ |
*/ |
113 |
+ |
private static final long profileThreshold = |
114 |
+ |
Long.getLong("jsr166.profileThreshold", 100); |
115 |
+ |
|
116 |
+ |
protected void runTest() throws Throwable { |
117 |
+ |
if (profileTests) |
118 |
+ |
runTestProfiled(); |
119 |
+ |
else |
120 |
+ |
super.runTest(); |
121 |
+ |
} |
122 |
+ |
|
123 |
+ |
protected void runTestProfiled() throws Throwable { |
124 |
+ |
long t0 = System.nanoTime(); |
125 |
+ |
try { |
126 |
+ |
super.runTest(); |
127 |
+ |
} finally { |
128 |
+ |
long elapsedMillis = |
129 |
+ |
(System.nanoTime() - t0) / (1000L * 1000L); |
130 |
+ |
if (elapsedMillis >= profileThreshold) |
131 |
+ |
System.out.printf("%n%s: %d%n", toString(), elapsedMillis); |
132 |
+ |
} |
133 |
+ |
} |
134 |
+ |
|
135 |
|
/** |
136 |
|
* Runs all JSR166 unit tests using junit.textui.TestRunner |
137 |
|
*/ |
152 |
|
System.exit(0); |
153 |
|
} |
154 |
|
|
155 |
+ |
public static TestSuite newTestSuite(Object... suiteOrClasses) { |
156 |
+ |
TestSuite suite = new TestSuite(); |
157 |
+ |
for (Object suiteOrClass : suiteOrClasses) { |
158 |
+ |
if (suiteOrClass instanceof TestSuite) |
159 |
+ |
suite.addTest((TestSuite) suiteOrClass); |
160 |
+ |
else if (suiteOrClass instanceof Class) |
161 |
+ |
suite.addTest(new TestSuite((Class<?>) suiteOrClass)); |
162 |
+ |
else |
163 |
+ |
throw new ClassCastException("not a test suite or class"); |
164 |
+ |
} |
165 |
+ |
return suite; |
166 |
+ |
} |
167 |
+ |
|
168 |
|
/** |
169 |
< |
* Collects all JSR166 unit tests as one suite |
169 |
> |
* Collects all JSR166 unit tests as one suite. |
170 |
|
*/ |
171 |
|
public static Test suite() { |
172 |
< |
TestSuite suite = new TestSuite("JSR166 Unit Tests"); |
173 |
< |
|
174 |
< |
suite.addTest(ForkJoinPoolTest.suite()); |
175 |
< |
suite.addTest(ForkJoinTaskTest.suite()); |
176 |
< |
suite.addTest(RecursiveActionTest.suite()); |
177 |
< |
suite.addTest(RecursiveTaskTest.suite()); |
178 |
< |
suite.addTest(LinkedTransferQueueTest.suite()); |
179 |
< |
suite.addTest(PhaserTest.suite()); |
180 |
< |
suite.addTest(ThreadLocalRandomTest.suite()); |
181 |
< |
suite.addTest(AbstractExecutorServiceTest.suite()); |
182 |
< |
suite.addTest(AbstractQueueTest.suite()); |
183 |
< |
suite.addTest(AbstractQueuedSynchronizerTest.suite()); |
184 |
< |
suite.addTest(AbstractQueuedLongSynchronizerTest.suite()); |
185 |
< |
suite.addTest(ArrayBlockingQueueTest.suite()); |
186 |
< |
suite.addTest(ArrayDequeTest.suite()); |
187 |
< |
suite.addTest(AtomicBooleanTest.suite()); |
188 |
< |
suite.addTest(AtomicIntegerArrayTest.suite()); |
189 |
< |
suite.addTest(AtomicIntegerFieldUpdaterTest.suite()); |
190 |
< |
suite.addTest(AtomicIntegerTest.suite()); |
191 |
< |
suite.addTest(AtomicLongArrayTest.suite()); |
192 |
< |
suite.addTest(AtomicLongFieldUpdaterTest.suite()); |
193 |
< |
suite.addTest(AtomicLongTest.suite()); |
194 |
< |
suite.addTest(AtomicMarkableReferenceTest.suite()); |
195 |
< |
suite.addTest(AtomicReferenceArrayTest.suite()); |
196 |
< |
suite.addTest(AtomicReferenceFieldUpdaterTest.suite()); |
197 |
< |
suite.addTest(AtomicReferenceTest.suite()); |
198 |
< |
suite.addTest(AtomicStampedReferenceTest.suite()); |
199 |
< |
suite.addTest(ConcurrentHashMapTest.suite()); |
200 |
< |
suite.addTest(ConcurrentLinkedDequeTest.suite()); |
201 |
< |
suite.addTest(ConcurrentLinkedQueueTest.suite()); |
202 |
< |
suite.addTest(ConcurrentSkipListMapTest.suite()); |
203 |
< |
suite.addTest(ConcurrentSkipListSubMapTest.suite()); |
204 |
< |
suite.addTest(ConcurrentSkipListSetTest.suite()); |
205 |
< |
suite.addTest(ConcurrentSkipListSubSetTest.suite()); |
206 |
< |
suite.addTest(CopyOnWriteArrayListTest.suite()); |
207 |
< |
suite.addTest(CopyOnWriteArraySetTest.suite()); |
208 |
< |
suite.addTest(CountDownLatchTest.suite()); |
209 |
< |
suite.addTest(CyclicBarrierTest.suite()); |
210 |
< |
suite.addTest(DelayQueueTest.suite()); |
211 |
< |
suite.addTest(EntryTest.suite()); |
212 |
< |
suite.addTest(ExchangerTest.suite()); |
213 |
< |
suite.addTest(ExecutorsTest.suite()); |
214 |
< |
suite.addTest(ExecutorCompletionServiceTest.suite()); |
215 |
< |
suite.addTest(FutureTaskTest.suite()); |
216 |
< |
suite.addTest(LinkedBlockingDequeTest.suite()); |
217 |
< |
suite.addTest(LinkedBlockingQueueTest.suite()); |
218 |
< |
suite.addTest(LinkedListTest.suite()); |
219 |
< |
suite.addTest(LockSupportTest.suite()); |
220 |
< |
suite.addTest(PriorityBlockingQueueTest.suite()); |
221 |
< |
suite.addTest(PriorityQueueTest.suite()); |
222 |
< |
suite.addTest(ReentrantLockTest.suite()); |
223 |
< |
suite.addTest(ReentrantReadWriteLockTest.suite()); |
224 |
< |
suite.addTest(ScheduledExecutorTest.suite()); |
225 |
< |
suite.addTest(ScheduledExecutorSubclassTest.suite()); |
226 |
< |
suite.addTest(SemaphoreTest.suite()); |
227 |
< |
suite.addTest(SynchronousQueueTest.suite()); |
228 |
< |
suite.addTest(SystemTest.suite()); |
229 |
< |
suite.addTest(ThreadLocalTest.suite()); |
230 |
< |
suite.addTest(ThreadPoolExecutorTest.suite()); |
231 |
< |
suite.addTest(ThreadPoolExecutorSubclassTest.suite()); |
232 |
< |
suite.addTest(ThreadTest.suite()); |
233 |
< |
suite.addTest(TimeUnitTest.suite()); |
234 |
< |
suite.addTest(TreeMapTest.suite()); |
235 |
< |
suite.addTest(TreeSetTest.suite()); |
236 |
< |
suite.addTest(TreeSubMapTest.suite()); |
188 |
< |
suite.addTest(TreeSubSetTest.suite()); |
189 |
< |
|
190 |
< |
return suite; |
172 |
> |
return newTestSuite( |
173 |
> |
ForkJoinPoolTest.suite(), |
174 |
> |
ForkJoinTaskTest.suite(), |
175 |
> |
RecursiveActionTest.suite(), |
176 |
> |
RecursiveTaskTest.suite(), |
177 |
> |
LinkedTransferQueueTest.suite(), |
178 |
> |
PhaserTest.suite(), |
179 |
> |
ThreadLocalRandomTest.suite(), |
180 |
> |
AbstractExecutorServiceTest.suite(), |
181 |
> |
AbstractQueueTest.suite(), |
182 |
> |
AbstractQueuedSynchronizerTest.suite(), |
183 |
> |
AbstractQueuedLongSynchronizerTest.suite(), |
184 |
> |
ArrayBlockingQueueTest.suite(), |
185 |
> |
ArrayDequeTest.suite(), |
186 |
> |
AtomicBooleanTest.suite(), |
187 |
> |
AtomicIntegerArrayTest.suite(), |
188 |
> |
AtomicIntegerFieldUpdaterTest.suite(), |
189 |
> |
AtomicIntegerTest.suite(), |
190 |
> |
AtomicLongArrayTest.suite(), |
191 |
> |
AtomicLongFieldUpdaterTest.suite(), |
192 |
> |
AtomicLongTest.suite(), |
193 |
> |
AtomicMarkableReferenceTest.suite(), |
194 |
> |
AtomicReferenceArrayTest.suite(), |
195 |
> |
AtomicReferenceFieldUpdaterTest.suite(), |
196 |
> |
AtomicReferenceTest.suite(), |
197 |
> |
AtomicStampedReferenceTest.suite(), |
198 |
> |
ConcurrentHashMapTest.suite(), |
199 |
> |
ConcurrentLinkedDequeTest.suite(), |
200 |
> |
ConcurrentLinkedQueueTest.suite(), |
201 |
> |
ConcurrentSkipListMapTest.suite(), |
202 |
> |
ConcurrentSkipListSubMapTest.suite(), |
203 |
> |
ConcurrentSkipListSetTest.suite(), |
204 |
> |
ConcurrentSkipListSubSetTest.suite(), |
205 |
> |
CopyOnWriteArrayListTest.suite(), |
206 |
> |
CopyOnWriteArraySetTest.suite(), |
207 |
> |
CountDownLatchTest.suite(), |
208 |
> |
CyclicBarrierTest.suite(), |
209 |
> |
DelayQueueTest.suite(), |
210 |
> |
EntryTest.suite(), |
211 |
> |
ExchangerTest.suite(), |
212 |
> |
ExecutorsTest.suite(), |
213 |
> |
ExecutorCompletionServiceTest.suite(), |
214 |
> |
FutureTaskTest.suite(), |
215 |
> |
LinkedBlockingDequeTest.suite(), |
216 |
> |
LinkedBlockingQueueTest.suite(), |
217 |
> |
LinkedListTest.suite(), |
218 |
> |
LockSupportTest.suite(), |
219 |
> |
PriorityBlockingQueueTest.suite(), |
220 |
> |
PriorityQueueTest.suite(), |
221 |
> |
ReentrantLockTest.suite(), |
222 |
> |
ReentrantReadWriteLockTest.suite(), |
223 |
> |
ScheduledExecutorTest.suite(), |
224 |
> |
ScheduledExecutorSubclassTest.suite(), |
225 |
> |
SemaphoreTest.suite(), |
226 |
> |
SynchronousQueueTest.suite(), |
227 |
> |
SystemTest.suite(), |
228 |
> |
ThreadLocalTest.suite(), |
229 |
> |
ThreadPoolExecutorTest.suite(), |
230 |
> |
ThreadPoolExecutorSubclassTest.suite(), |
231 |
> |
ThreadTest.suite(), |
232 |
> |
TimeUnitTest.suite(), |
233 |
> |
TreeMapTest.suite(), |
234 |
> |
TreeSetTest.suite(), |
235 |
> |
TreeSubMapTest.suite(), |
236 |
> |
TreeSubSetTest.suite()); |
237 |
|
} |
238 |
|
|
239 |
|
|
296 |
|
throw (RuntimeException) t; |
297 |
|
else if (t instanceof Exception) |
298 |
|
throw (Exception) t; |
299 |
< |
else |
300 |
< |
throw new AssertionError(t); |
299 |
> |
else { |
300 |
> |
AssertionFailedError afe = |
301 |
> |
new AssertionFailedError(t.toString()); |
302 |
> |
afe.initCause(t); |
303 |
> |
throw afe; |
304 |
> |
} |
305 |
|
} |
306 |
|
} |
307 |
|
|
308 |
|
/** |
309 |
|
* Just like fail(reason), but additionally recording (using |
310 |
< |
* threadRecordFailure) any AssertionError thrown, so that the current |
311 |
< |
* testcase will fail. |
310 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
311 |
> |
* the current testcase will fail. |
312 |
|
*/ |
313 |
|
public void threadFail(String reason) { |
314 |
|
try { |
315 |
|
fail(reason); |
316 |
< |
} catch (Throwable t) { |
316 |
> |
} catch (AssertionFailedError t) { |
317 |
|
threadRecordFailure(t); |
318 |
|
fail(reason); |
319 |
|
} |
321 |
|
|
322 |
|
/** |
323 |
|
* Just like assertTrue(b), but additionally recording (using |
324 |
< |
* threadRecordFailure) any AssertionError thrown, so that the current |
325 |
< |
* testcase will fail. |
324 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
325 |
> |
* the current testcase will fail. |
326 |
|
*/ |
327 |
|
public void threadAssertTrue(boolean b) { |
328 |
|
try { |
329 |
|
assertTrue(b); |
330 |
< |
} catch (AssertionError t) { |
330 |
> |
} catch (AssertionFailedError t) { |
331 |
|
threadRecordFailure(t); |
332 |
|
throw t; |
333 |
|
} |
335 |
|
|
336 |
|
/** |
337 |
|
* Just like assertFalse(b), but additionally recording (using |
338 |
< |
* threadRecordFailure) any AssertionError thrown, so that the |
339 |
< |
* current testcase will fail. |
338 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
339 |
> |
* the current testcase will fail. |
340 |
|
*/ |
341 |
|
public void threadAssertFalse(boolean b) { |
342 |
|
try { |
343 |
|
assertFalse(b); |
344 |
< |
} catch (AssertionError t) { |
344 |
> |
} catch (AssertionFailedError t) { |
345 |
|
threadRecordFailure(t); |
346 |
|
throw t; |
347 |
|
} |
349 |
|
|
350 |
|
/** |
351 |
|
* Just like assertNull(x), but additionally recording (using |
352 |
< |
* threadRecordFailure) any AssertionError thrown, so that the |
353 |
< |
* current testcase will fail. |
352 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
353 |
> |
* the current testcase will fail. |
354 |
|
*/ |
355 |
|
public void threadAssertNull(Object x) { |
356 |
|
try { |
357 |
|
assertNull(x); |
358 |
< |
} catch (AssertionError t) { |
358 |
> |
} catch (AssertionFailedError t) { |
359 |
|
threadRecordFailure(t); |
360 |
|
throw t; |
361 |
|
} |
363 |
|
|
364 |
|
/** |
365 |
|
* Just like assertEquals(x, y), but additionally recording (using |
366 |
< |
* threadRecordFailure) any AssertionError thrown, so that the |
367 |
< |
* current testcase will fail. |
366 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
367 |
> |
* the current testcase will fail. |
368 |
|
*/ |
369 |
|
public void threadAssertEquals(long x, long y) { |
370 |
|
try { |
371 |
|
assertEquals(x, y); |
372 |
< |
} catch (AssertionError t) { |
372 |
> |
} catch (AssertionFailedError t) { |
373 |
|
threadRecordFailure(t); |
374 |
|
throw t; |
375 |
|
} |
377 |
|
|
378 |
|
/** |
379 |
|
* Just like assertEquals(x, y), but additionally recording (using |
380 |
< |
* threadRecordFailure) any AssertionError thrown, so that the |
381 |
< |
* current testcase will fail. |
380 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
381 |
> |
* the current testcase will fail. |
382 |
|
*/ |
383 |
|
public void threadAssertEquals(Object x, Object y) { |
384 |
|
try { |
385 |
|
assertEquals(x, y); |
386 |
< |
} catch (AssertionError t) { |
386 |
> |
} catch (AssertionFailedError t) { |
387 |
|
threadRecordFailure(t); |
388 |
|
throw t; |
389 |
+ |
} catch (Throwable t) { |
390 |
+ |
threadUnexpectedException(t); |
391 |
|
} |
392 |
|
} |
393 |
|
|
394 |
|
/** |
395 |
|
* Just like assertSame(x, y), but additionally recording (using |
396 |
< |
* threadRecordFailure) any AssertionError thrown, so that the |
397 |
< |
* current testcase will fail. |
396 |
> |
* threadRecordFailure) any AssertionFailedError thrown, so that |
397 |
> |
* the current testcase will fail. |
398 |
|
*/ |
399 |
|
public void threadAssertSame(Object x, Object y) { |
400 |
|
try { |
401 |
|
assertSame(x, y); |
402 |
< |
} catch (AssertionError t) { |
402 |
> |
} catch (AssertionFailedError t) { |
403 |
|
threadRecordFailure(t); |
404 |
|
throw t; |
405 |
|
} |
420 |
|
} |
421 |
|
|
422 |
|
/** |
423 |
< |
* Calls threadFail with message "Unexpected exception" + ex. |
423 |
> |
* Records the given exception using {@link #threadRecordFailure}, |
424 |
> |
* then rethrows the exception, wrapping it in an |
425 |
> |
* AssertionFailedError if necessary. |
426 |
|
*/ |
427 |
|
public void threadUnexpectedException(Throwable t) { |
428 |
|
threadRecordFailure(t); |
429 |
|
t.printStackTrace(); |
376 |
– |
// Rethrow, wrapping in an AssertionError if necessary |
430 |
|
if (t instanceof RuntimeException) |
431 |
|
throw (RuntimeException) t; |
432 |
|
else if (t instanceof Error) |
433 |
|
throw (Error) t; |
434 |
|
else { |
435 |
< |
AssertionError ae = new AssertionError("unexpected exception: " + t); |
435 |
> |
AssertionFailedError afe = |
436 |
> |
new AssertionFailedError("unexpected exception: " + t); |
437 |
|
t.initCause(t); |
438 |
< |
throw ae; |
438 |
> |
throw afe; |
439 |
|
} |
440 |
|
} |
441 |
|
|
470 |
|
} |
471 |
|
|
472 |
|
/** |
419 |
– |
* Fails with message "Unexpected exception: " + ex. |
420 |
– |
*/ |
421 |
– |
public void unexpectedException(Throwable ex) { |
422 |
– |
ex.printStackTrace(); |
423 |
– |
fail("Unexpected exception: " + ex); |
424 |
– |
} |
425 |
– |
|
426 |
– |
|
427 |
– |
/** |
473 |
|
* The number of elements to place in collections, arrays, etc. |
474 |
|
*/ |
475 |
|
public static final int SIZE = 20; |
580 |
|
} |
581 |
|
|
582 |
|
/** |
583 |
< |
* Sleep until the timeout has elapsed, or interrupted. |
583 |
> |
* Sleeps until the given time has elapsed. |
584 |
> |
* Throws AssertionFailedError if interrupted. |
585 |
> |
*/ |
586 |
> |
void sleep(long millis) { |
587 |
> |
try { |
588 |
> |
Thread.sleep(millis); |
589 |
> |
} catch (InterruptedException ie) { |
590 |
> |
AssertionFailedError afe = |
591 |
> |
new AssertionFailedError("Unexpected InterruptedException"); |
592 |
> |
afe.initCause(ie); |
593 |
> |
throw afe; |
594 |
> |
} |
595 |
> |
} |
596 |
> |
|
597 |
> |
/** |
598 |
> |
* Sleeps until the timeout has elapsed, or interrupted. |
599 |
|
* Does <em>NOT</em> throw InterruptedException. |
600 |
|
*/ |
601 |
|
void sleepTillInterrupted(long timeoutMillis) { |
605 |
|
} |
606 |
|
|
607 |
|
/** |
608 |
< |
* Returns a new started Thread running the given runnable. |
608 |
> |
* Waits up to the specified number of milliseconds for the given |
609 |
> |
* thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING. |
610 |
> |
*/ |
611 |
> |
void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) { |
612 |
> |
long timeoutNanos = timeoutMillis * 1000L * 1000L; |
613 |
> |
long t0 = System.nanoTime(); |
614 |
> |
for (;;) { |
615 |
> |
Thread.State s = thread.getState(); |
616 |
> |
if (s == Thread.State.BLOCKED || |
617 |
> |
s == Thread.State.WAITING || |
618 |
> |
s == Thread.State.TIMED_WAITING || |
619 |
> |
System.nanoTime() - t0 > timeoutNanos) |
620 |
> |
return; |
621 |
> |
Thread.yield(); |
622 |
> |
} |
623 |
> |
} |
624 |
> |
|
625 |
> |
/** |
626 |
> |
* Returns a new started daemon Thread running the given runnable. |
627 |
|
*/ |
628 |
|
Thread newStartedThread(Runnable runnable) { |
629 |
|
Thread t = new Thread(runnable); |
630 |
+ |
t.setDaemon(true); |
631 |
|
t.start(); |
632 |
|
return t; |
633 |
|
} |
634 |
|
|
635 |
+ |
/** |
636 |
+ |
* Waits for the specified time (in milliseconds) for the thread |
637 |
+ |
* to terminate (using {@link Thread#join(long)}), else interrupts |
638 |
+ |
* the thread (in the hope that it may terminate later) and fails. |
639 |
+ |
*/ |
640 |
+ |
void awaitTermination(Thread t, long timeoutMillis) { |
641 |
+ |
try { |
642 |
+ |
t.join(timeoutMillis); |
643 |
+ |
} catch (InterruptedException ie) { |
644 |
+ |
threadUnexpectedException(ie); |
645 |
+ |
} finally { |
646 |
+ |
if (t.isAlive()) { |
647 |
+ |
t.interrupt(); |
648 |
+ |
fail("Test timed out"); |
649 |
+ |
} |
650 |
+ |
} |
651 |
+ |
} |
652 |
+ |
|
653 |
|
// Some convenient Runnable classes |
654 |
|
|
655 |
|
public abstract class CheckedRunnable implements Runnable { |
764 |
|
|
765 |
|
public Callable<String> latchAwaitingStringTask(final CountDownLatch latch) { |
766 |
|
return new CheckedCallable<String>() { |
767 |
< |
public String realCall() { |
767 |
> |
protected String realCall() { |
768 |
|
try { |
769 |
|
latch.await(); |
770 |
|
} catch (InterruptedException quittingTime) {} |
813 |
|
} |
814 |
|
} |
815 |
|
|
719 |
– |
public class SmallInterruptedRunnable extends CheckedInterruptedRunnable { |
720 |
– |
protected void realRun() throws InterruptedException { |
721 |
– |
Thread.sleep(SMALL_DELAY_MS); |
722 |
– |
} |
723 |
– |
} |
724 |
– |
|
816 |
|
public class MediumRunnable extends CheckedRunnable { |
817 |
|
protected void realRun() throws Throwable { |
818 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
825 |
|
} |
826 |
|
} |
827 |
|
|
828 |
+ |
public Runnable possiblyInterruptedRunnable(final long timeoutMillis) { |
829 |
+ |
return new CheckedRunnable() { |
830 |
+ |
protected void realRun() { |
831 |
+ |
try { |
832 |
+ |
Thread.sleep(timeoutMillis); |
833 |
+ |
} catch (InterruptedException ok) {} |
834 |
+ |
}}; |
835 |
+ |
} |
836 |
+ |
|
837 |
|
public class MediumPossiblyInterruptedRunnable extends CheckedRunnable { |
838 |
|
protected void realRun() { |
839 |
|
try { |
859 |
|
} |
860 |
|
} |
861 |
|
|
862 |
+ |
public interface TrackedRunnable extends Runnable { |
863 |
+ |
boolean isDone(); |
864 |
+ |
} |
865 |
+ |
|
866 |
+ |
public static TrackedRunnable trackedRunnable(final long timeoutMillis) { |
867 |
+ |
return new TrackedRunnable() { |
868 |
+ |
private volatile boolean done = false; |
869 |
+ |
public boolean isDone() { return done; } |
870 |
+ |
public void run() { |
871 |
+ |
try { |
872 |
+ |
Thread.sleep(timeoutMillis); |
873 |
+ |
done = true; |
874 |
+ |
} catch (InterruptedException ok) {} |
875 |
+ |
} |
876 |
+ |
}; |
877 |
+ |
} |
878 |
+ |
|
879 |
|
public static class TrackedShortRunnable implements Runnable { |
880 |
|
public volatile boolean done = false; |
881 |
|
public void run() { |
882 |
|
try { |
883 |
+ |
Thread.sleep(SHORT_DELAY_MS); |
884 |
+ |
done = true; |
885 |
+ |
} catch (InterruptedException ok) {} |
886 |
+ |
} |
887 |
+ |
} |
888 |
+ |
|
889 |
+ |
public static class TrackedSmallRunnable implements Runnable { |
890 |
+ |
public volatile boolean done = false; |
891 |
+ |
public void run() { |
892 |
+ |
try { |
893 |
|
Thread.sleep(SMALL_DELAY_MS); |
894 |
|
done = true; |
895 |
|
} catch (InterruptedException ok) {} |
973 |
|
ThreadPoolExecutor executor) {} |
974 |
|
} |
975 |
|
|
976 |
+ |
/** |
977 |
+ |
* A CyclicBarrier that fails with AssertionFailedErrors instead |
978 |
+ |
* of throwing checked exceptions. |
979 |
+ |
*/ |
980 |
+ |
public class CheckedBarrier extends CyclicBarrier { |
981 |
+ |
public CheckedBarrier(int parties) { super(parties); } |
982 |
+ |
|
983 |
+ |
public int await() { |
984 |
+ |
try { |
985 |
+ |
return super.await(); |
986 |
+ |
} catch (Exception e) { |
987 |
+ |
AssertionFailedError afe = |
988 |
+ |
new AssertionFailedError("Unexpected exception: " + e); |
989 |
+ |
afe.initCause(e); |
990 |
+ |
throw afe; |
991 |
+ |
} |
992 |
+ |
} |
993 |
+ |
} |
994 |
+ |
|
995 |
|
} |