108 |
|
public static Test suite ( ) { |
109 |
|
TestSuite suite = new TestSuite("JSR166 Unit Tests"); |
110 |
|
|
111 |
+ |
suite.addTest(new TestSuite(ForkJoinPoolTest.class)); |
112 |
+ |
suite.addTest(new TestSuite(ForkJoinTaskTest.class)); |
113 |
+ |
suite.addTest(new TestSuite(RecursiveActionTest.class)); |
114 |
+ |
suite.addTest(new TestSuite(RecursiveTaskTest.class)); |
115 |
+ |
suite.addTest(new TestSuite(LinkedTransferQueueTest.class)); |
116 |
+ |
suite.addTest(new TestSuite(PhaserTest.class)); |
117 |
+ |
suite.addTest(new TestSuite(ThreadLocalRandomTest.class)); |
118 |
|
suite.addTest(new TestSuite(AbstractExecutorServiceTest.class)); |
119 |
|
suite.addTest(new TestSuite(AbstractQueueTest.class)); |
120 |
|
suite.addTest(new TestSuite(AbstractQueuedSynchronizerTest.class)); |
144 |
|
suite.addTest(new TestSuite(CountDownLatchTest.class)); |
145 |
|
suite.addTest(new TestSuite(CyclicBarrierTest.class)); |
146 |
|
suite.addTest(new TestSuite(DelayQueueTest.class)); |
147 |
+ |
suite.addTest(new TestSuite(EntryTest.class)); |
148 |
|
suite.addTest(new TestSuite(ExchangerTest.class)); |
149 |
|
suite.addTest(new TestSuite(ExecutorsTest.class)); |
150 |
|
suite.addTest(new TestSuite(ExecutorCompletionServiceTest.class)); |
288 |
|
* threadFail with message "should throw exception" |
289 |
|
*/ |
290 |
|
public void threadShouldThrow() { |
291 |
< |
threadFailed = true; |
292 |
< |
fail("should throw exception"); |
291 |
> |
try { |
292 |
> |
threadFailed = true; |
293 |
> |
fail("should throw exception"); |
294 |
> |
} catch (AssertionFailedError e) { |
295 |
> |
e.printStackTrace(); |
296 |
> |
throw e; |
297 |
> |
} |
298 |
|
} |
299 |
|
|
300 |
|
/** |
305 |
|
fail("Unexpected exception"); |
306 |
|
} |
307 |
|
|
308 |
+ |
/** |
309 |
+ |
* threadFail with message "Unexpected exception", with argument |
310 |
+ |
*/ |
311 |
+ |
public void threadUnexpectedException(Throwable ex) { |
312 |
+ |
threadFailed = true; |
313 |
+ |
ex.printStackTrace(); |
314 |
+ |
fail("Unexpected exception: " + ex); |
315 |
+ |
} |
316 |
|
|
317 |
|
/** |
318 |
|
* Wait out termination of a thread pool or fail doing so |
321 |
|
try { |
322 |
|
exec.shutdown(); |
323 |
|
assertTrue(exec.awaitTermination(LONG_DELAY_MS, TimeUnit.MILLISECONDS)); |
324 |
< |
} catch(SecurityException ok) { |
324 |
> |
} catch (SecurityException ok) { |
325 |
|
// Allowed in case test doesn't have privs |
326 |
< |
} catch(InterruptedException ie) { |
326 |
> |
} catch (InterruptedException ie) { |
327 |
|
fail("Unexpected exception"); |
328 |
|
} |
329 |
|
} |
366 |
|
static final Integer m3 = new Integer(-3); |
367 |
|
static final Integer m4 = new Integer(-4); |
368 |
|
static final Integer m5 = new Integer(-5); |
369 |
+ |
static final Integer m6 = new Integer(-6); |
370 |
|
static final Integer m10 = new Integer(-10); |
371 |
|
|
372 |
|
|
394 |
|
|
395 |
|
// Some convenient Runnable classes |
396 |
|
|
397 |
+ |
abstract class CheckedRunnable implements Runnable { |
398 |
+ |
abstract void realRun() throws Throwable; |
399 |
+ |
|
400 |
+ |
public final void run() { |
401 |
+ |
try { |
402 |
+ |
realRun(); |
403 |
+ |
} catch (Throwable t) { |
404 |
+ |
threadUnexpectedException(t); |
405 |
+ |
} |
406 |
+ |
} |
407 |
+ |
} |
408 |
+ |
|
409 |
+ |
abstract class CheckedInterruptedRunnable implements Runnable { |
410 |
+ |
abstract void realRun() throws Throwable; |
411 |
+ |
|
412 |
+ |
public final void run() { |
413 |
+ |
try { |
414 |
+ |
realRun(); |
415 |
+ |
threadShouldThrow(); |
416 |
+ |
} catch (InterruptedException success) { |
417 |
+ |
} catch (Throwable t) { |
418 |
+ |
threadUnexpectedException(t); |
419 |
+ |
} |
420 |
+ |
} |
421 |
+ |
} |
422 |
+ |
|
423 |
+ |
abstract class CheckedCallable<T> implements Callable<T> { |
424 |
+ |
abstract T realCall() throws Throwable; |
425 |
+ |
|
426 |
+ |
public final T call() { |
427 |
+ |
try { |
428 |
+ |
return realCall(); |
429 |
+ |
} catch (Throwable t) { |
430 |
+ |
threadUnexpectedException(t); |
431 |
+ |
return null; |
432 |
+ |
} |
433 |
+ |
} |
434 |
+ |
} |
435 |
+ |
|
436 |
|
static class NoOpRunnable implements Runnable { |
437 |
|
public void run() {} |
438 |
|
} |
455 |
|
public Integer call() { return one; } |
456 |
|
} |
457 |
|
|
458 |
< |
class ShortRunnable implements Runnable { |
459 |
< |
public void run() { |
460 |
< |
try { |
400 |
< |
Thread.sleep(SHORT_DELAY_MS); |
401 |
< |
} |
402 |
< |
catch(Exception e) { |
403 |
< |
threadUnexpectedException(); |
404 |
< |
} |
458 |
> |
class ShortRunnable extends CheckedRunnable { |
459 |
> |
void realRun() throws Throwable { |
460 |
> |
Thread.sleep(SHORT_DELAY_MS); |
461 |
|
} |
462 |
|
} |
463 |
|
|
464 |
< |
class ShortInterruptedRunnable implements Runnable { |
465 |
< |
public void run() { |
466 |
< |
try { |
411 |
< |
Thread.sleep(SHORT_DELAY_MS); |
412 |
< |
threadShouldThrow(); |
413 |
< |
} |
414 |
< |
catch(InterruptedException success) { |
415 |
< |
} |
464 |
> |
class ShortInterruptedRunnable extends CheckedInterruptedRunnable { |
465 |
> |
void realRun() throws InterruptedException { |
466 |
> |
Thread.sleep(SHORT_DELAY_MS); |
467 |
|
} |
468 |
|
} |
469 |
|
|
470 |
< |
class SmallRunnable implements Runnable { |
471 |
< |
public void run() { |
472 |
< |
try { |
422 |
< |
Thread.sleep(SMALL_DELAY_MS); |
423 |
< |
} |
424 |
< |
catch(Exception e) { |
425 |
< |
threadUnexpectedException(); |
426 |
< |
} |
470 |
> |
class SmallRunnable extends CheckedRunnable { |
471 |
> |
void realRun() throws Throwable { |
472 |
> |
Thread.sleep(SMALL_DELAY_MS); |
473 |
|
} |
474 |
|
} |
475 |
|
|
476 |
< |
class SmallPossiblyInterruptedRunnable implements Runnable { |
477 |
< |
public void run() { |
476 |
> |
class SmallPossiblyInterruptedRunnable extends CheckedRunnable { |
477 |
> |
void realRun() { |
478 |
|
try { |
479 |
|
Thread.sleep(SMALL_DELAY_MS); |
480 |
|
} |
481 |
< |
catch(Exception e) { |
481 |
> |
catch (InterruptedException ok) { |
482 |
|
} |
483 |
|
} |
484 |
|
} |
485 |
|
|
486 |
< |
class SmallCallable implements Callable { |
487 |
< |
public Object call() { |
488 |
< |
try { |
443 |
< |
Thread.sleep(SMALL_DELAY_MS); |
444 |
< |
} |
445 |
< |
catch(Exception e) { |
446 |
< |
threadUnexpectedException(); |
447 |
< |
} |
486 |
> |
class SmallCallable extends CheckedCallable { |
487 |
> |
Object realCall() throws Throwable { |
488 |
> |
Thread.sleep(SMALL_DELAY_MS); |
489 |
|
return Boolean.TRUE; |
490 |
|
} |
491 |
|
} |
492 |
|
|
493 |
< |
class SmallInterruptedRunnable implements Runnable { |
494 |
< |
public void run() { |
495 |
< |
try { |
455 |
< |
Thread.sleep(SMALL_DELAY_MS); |
456 |
< |
threadShouldThrow(); |
457 |
< |
} |
458 |
< |
catch(InterruptedException success) { |
459 |
< |
} |
493 |
> |
class SmallInterruptedRunnable extends CheckedInterruptedRunnable { |
494 |
> |
void realRun() throws InterruptedException { |
495 |
> |
Thread.sleep(SMALL_DELAY_MS); |
496 |
|
} |
497 |
|
} |
498 |
|
|
499 |
< |
|
500 |
< |
class MediumRunnable implements Runnable { |
501 |
< |
public void run() { |
466 |
< |
try { |
467 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
468 |
< |
} |
469 |
< |
catch(Exception e) { |
470 |
< |
threadUnexpectedException(); |
471 |
< |
} |
499 |
> |
class MediumRunnable extends CheckedRunnable { |
500 |
> |
void realRun() throws Throwable { |
501 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
502 |
|
} |
503 |
|
} |
504 |
|
|
505 |
< |
class MediumInterruptedRunnable implements Runnable { |
506 |
< |
public void run() { |
507 |
< |
try { |
478 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
479 |
< |
threadShouldThrow(); |
480 |
< |
} |
481 |
< |
catch(InterruptedException success) { |
482 |
< |
} |
505 |
> |
class MediumInterruptedRunnable extends CheckedInterruptedRunnable { |
506 |
> |
void realRun() throws InterruptedException { |
507 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
508 |
|
} |
509 |
|
} |
510 |
|
|
511 |
< |
class MediumPossiblyInterruptedRunnable implements Runnable { |
512 |
< |
public void run() { |
511 |
> |
class MediumPossiblyInterruptedRunnable extends CheckedRunnable { |
512 |
> |
void realRun() { |
513 |
|
try { |
514 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
515 |
|
} |
516 |
< |
catch(InterruptedException success) { |
516 |
> |
catch (InterruptedException ok) { |
517 |
|
} |
518 |
|
} |
519 |
|
} |
520 |
|
|
521 |
< |
class LongPossiblyInterruptedRunnable implements Runnable { |
522 |
< |
public void run() { |
521 |
> |
class LongPossiblyInterruptedRunnable extends CheckedRunnable { |
522 |
> |
void realRun() { |
523 |
|
try { |
524 |
|
Thread.sleep(LONG_DELAY_MS); |
525 |
|
} |
526 |
< |
catch(InterruptedException success) { |
526 |
> |
catch (InterruptedException ok) { |
527 |
|
} |
528 |
|
} |
529 |
|
} |
531 |
|
/** |
532 |
|
* For use as ThreadFactory in constructors |
533 |
|
*/ |
534 |
< |
static class SimpleThreadFactory implements ThreadFactory{ |
535 |
< |
public Thread newThread(Runnable r){ |
534 |
> |
static class SimpleThreadFactory implements ThreadFactory { |
535 |
> |
public Thread newThread(Runnable r) { |
536 |
|
return new Thread(r); |
537 |
|
} |
538 |
|
} |
543 |
|
try { |
544 |
|
Thread.sleep(SMALL_DELAY_MS); |
545 |
|
done = true; |
546 |
< |
} catch(Exception e){ |
546 |
> |
} catch (Exception e) { |
547 |
|
} |
548 |
|
} |
549 |
|
} |
554 |
|
try { |
555 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
556 |
|
done = true; |
557 |
< |
} catch(Exception e){ |
557 |
> |
} catch (Exception e) { |
558 |
|
} |
559 |
|
} |
560 |
|
} |
565 |
|
try { |
566 |
|
Thread.sleep(LONG_DELAY_MS); |
567 |
|
done = true; |
568 |
< |
} catch(Exception e){ |
568 |
> |
} catch (Exception e) { |
569 |
|
} |
570 |
|
} |
571 |
|
} |
583 |
|
try { |
584 |
|
Thread.sleep(SMALL_DELAY_MS); |
585 |
|
done = true; |
586 |
< |
} catch(Exception e){ |
586 |
> |
} catch (Exception e) { |
587 |
|
} |
588 |
|
return Boolean.TRUE; |
589 |
|
} |
593 |
|
/** |
594 |
|
* For use as RejectedExecutionHandler in constructors |
595 |
|
*/ |
596 |
< |
static class NoOpREHandler implements RejectedExecutionHandler{ |
597 |
< |
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor){} |
596 |
> |
static class NoOpREHandler implements RejectedExecutionHandler { |
597 |
> |
public void rejectedExecution(Runnable r, |
598 |
> |
ThreadPoolExecutor executor) {} |
599 |
|
} |
600 |
|
|
575 |
– |
|
601 |
|
} |