90 |
|
/** |
91 |
|
* Runs all JSR166 unit tests using junit.textui.TestRunner |
92 |
|
*/ |
93 |
< |
public static void main (String[] args) { |
93 |
> |
public static void main(String[] args) { |
94 |
|
int iters = 1; |
95 |
|
if (args.length > 0) |
96 |
|
iters = Integer.parseInt(args[0]); |
97 |
|
Test s = suite(); |
98 |
|
for (int i = 0; i < iters; ++i) { |
99 |
< |
junit.textui.TestRunner.run (s); |
99 |
> |
junit.textui.TestRunner.run(s); |
100 |
|
System.gc(); |
101 |
|
System.runFinalization(); |
102 |
|
} |
106 |
|
/** |
107 |
|
* Collects all JSR166 unit tests as one suite |
108 |
|
*/ |
109 |
< |
public static Test suite ( ) { |
109 |
> |
public static Test suite() { |
110 |
|
TestSuite suite = new TestSuite("JSR166 Unit Tests"); |
111 |
|
|
112 |
|
suite.addTest(new TestSuite(ForkJoinPoolTest.class)); |
195 |
|
/** |
196 |
|
* Sets delays as multiples of SHORT_DELAY. |
197 |
|
*/ |
198 |
< |
protected void setDelays() { |
198 |
> |
protected void setDelays() { |
199 |
|
SHORT_DELAY_MS = getShortDelay(); |
200 |
|
SMALL_DELAY_MS = SHORT_DELAY_MS * 5; |
201 |
|
MEDIUM_DELAY_MS = SHORT_DELAY_MS * 10; |
328 |
|
} catch (SecurityException ok) { |
329 |
|
// Allowed in case test doesn't have privs |
330 |
|
} catch (InterruptedException ie) { |
331 |
< |
fail("Unexpected exception"); |
331 |
> |
fail("Unexpected InterruptedException"); |
332 |
|
} |
333 |
|
} |
334 |
|
|
366 |
|
/** |
367 |
|
* The number of elements to place in collections, arrays, etc. |
368 |
|
*/ |
369 |
< |
static final int SIZE = 20; |
369 |
> |
public static final int SIZE = 20; |
370 |
|
|
371 |
|
// Some convenient Integer constants |
372 |
|
|
373 |
< |
static final Integer zero = new Integer(0); |
374 |
< |
static final Integer one = new Integer(1); |
375 |
< |
static final Integer two = new Integer(2); |
376 |
< |
static final Integer three = new Integer(3); |
377 |
< |
static final Integer four = new Integer(4); |
378 |
< |
static final Integer five = new Integer(5); |
379 |
< |
static final Integer six = new Integer(6); |
380 |
< |
static final Integer seven = new Integer(7); |
381 |
< |
static final Integer eight = new Integer(8); |
382 |
< |
static final Integer nine = new Integer(9); |
383 |
< |
static final Integer m1 = new Integer(-1); |
384 |
< |
static final Integer m2 = new Integer(-2); |
385 |
< |
static final Integer m3 = new Integer(-3); |
386 |
< |
static final Integer m4 = new Integer(-4); |
387 |
< |
static final Integer m5 = new Integer(-5); |
388 |
< |
static final Integer m6 = new Integer(-6); |
389 |
< |
static final Integer m10 = new Integer(-10); |
373 |
> |
public static final Integer zero = new Integer(0); |
374 |
> |
public static final Integer one = new Integer(1); |
375 |
> |
public static final Integer two = new Integer(2); |
376 |
> |
public static final Integer three = new Integer(3); |
377 |
> |
public static final Integer four = new Integer(4); |
378 |
> |
public static final Integer five = new Integer(5); |
379 |
> |
public static final Integer six = new Integer(6); |
380 |
> |
public static final Integer seven = new Integer(7); |
381 |
> |
public static final Integer eight = new Integer(8); |
382 |
> |
public static final Integer nine = new Integer(9); |
383 |
> |
public static final Integer m1 = new Integer(-1); |
384 |
> |
public static final Integer m2 = new Integer(-2); |
385 |
> |
public static final Integer m3 = new Integer(-3); |
386 |
> |
public static final Integer m4 = new Integer(-4); |
387 |
> |
public static final Integer m5 = new Integer(-5); |
388 |
> |
public static final Integer m6 = new Integer(-6); |
389 |
> |
public static final Integer m10 = new Integer(-10); |
390 |
|
|
391 |
|
|
392 |
|
/** |
393 |
|
* A security policy where new permissions can be dynamically added |
394 |
|
* or all cleared. |
395 |
|
*/ |
396 |
< |
static class AdjustablePolicy extends java.security.Policy { |
396 |
> |
public static class AdjustablePolicy extends java.security.Policy { |
397 |
|
Permissions perms = new Permissions(); |
398 |
|
AdjustablePolicy() { } |
399 |
|
void addPermission(Permission perm) { perms.add(perm); } |
400 |
|
void clearPermissions() { perms = new Permissions(); } |
401 |
< |
public PermissionCollection getPermissions(CodeSource cs) { |
402 |
< |
return perms; |
403 |
< |
} |
404 |
< |
public PermissionCollection getPermissions(ProtectionDomain pd) { |
405 |
< |
return perms; |
406 |
< |
} |
407 |
< |
public boolean implies(ProtectionDomain pd, Permission p) { |
408 |
< |
return perms.implies(p); |
409 |
< |
} |
410 |
< |
public void refresh() {} |
401 |
> |
public PermissionCollection getPermissions(CodeSource cs) { |
402 |
> |
return perms; |
403 |
> |
} |
404 |
> |
public PermissionCollection getPermissions(ProtectionDomain pd) { |
405 |
> |
return perms; |
406 |
> |
} |
407 |
> |
public boolean implies(ProtectionDomain pd, Permission p) { |
408 |
> |
return perms.implies(p); |
409 |
> |
} |
410 |
> |
public void refresh() {} |
411 |
|
} |
412 |
|
|
413 |
|
/** |
417 |
|
void sleepTillInterrupted(long timeoutMillis) { |
418 |
|
try { |
419 |
|
Thread.sleep(timeoutMillis); |
420 |
< |
} catch (InterruptedException wakeup) { |
421 |
< |
} |
420 |
> |
} catch (InterruptedException wakeup) {} |
421 |
|
} |
422 |
|
|
423 |
|
/** |
431 |
|
|
432 |
|
// Some convenient Runnable classes |
433 |
|
|
434 |
< |
abstract class CheckedRunnable implements Runnable { |
435 |
< |
abstract void realRun() throws Throwable; |
434 |
> |
public abstract class CheckedRunnable implements Runnable { |
435 |
> |
protected abstract void realRun() throws Throwable; |
436 |
|
|
437 |
|
public final void run() { |
438 |
|
try { |
443 |
|
} |
444 |
|
} |
445 |
|
|
446 |
< |
abstract class RunnableShouldThrow implements Runnable { |
447 |
< |
abstract void realRun() throws Throwable; |
446 |
> |
public abstract class RunnableShouldThrow implements Runnable { |
447 |
> |
protected abstract void realRun() throws Throwable; |
448 |
|
|
449 |
|
final Class<?> exceptionClass; |
450 |
|
|
464 |
|
} |
465 |
|
} |
466 |
|
|
467 |
< |
abstract class ThreadShouldThrow extends Thread { |
468 |
< |
abstract void realRun() throws Throwable; |
467 |
> |
public abstract class ThreadShouldThrow extends Thread { |
468 |
> |
protected abstract void realRun() throws Throwable; |
469 |
|
|
470 |
|
final Class<?> exceptionClass; |
471 |
|
|
485 |
|
} |
486 |
|
} |
487 |
|
|
488 |
< |
abstract class CheckedInterruptedRunnable implements Runnable { |
489 |
< |
abstract void realRun() throws Throwable; |
488 |
> |
public abstract class CheckedInterruptedRunnable implements Runnable { |
489 |
> |
protected abstract void realRun() throws Throwable; |
490 |
|
|
491 |
|
public final void run() { |
492 |
|
try { |
499 |
|
} |
500 |
|
} |
501 |
|
|
502 |
< |
abstract class CheckedCallable<T> implements Callable<T> { |
503 |
< |
abstract T realCall() throws Throwable; |
502 |
> |
public abstract class CheckedCallable<T> implements Callable<T> { |
503 |
> |
protected abstract T realCall() throws Throwable; |
504 |
|
|
505 |
|
public final T call() { |
506 |
|
try { |
512 |
|
} |
513 |
|
} |
514 |
|
|
515 |
< |
abstract class CheckedInterruptedCallable<T> implements Callable<T> { |
516 |
< |
abstract T realCall() throws Throwable; |
515 |
> |
public abstract class CheckedInterruptedCallable<T> implements Callable<T> { |
516 |
> |
protected abstract T realCall() throws Throwable; |
517 |
|
|
518 |
|
public final T call() { |
519 |
|
try { |
528 |
|
} |
529 |
|
} |
530 |
|
|
531 |
< |
static class NoOpRunnable implements Runnable { |
531 |
> |
public static class NoOpRunnable implements Runnable { |
532 |
|
public void run() {} |
533 |
|
} |
534 |
|
|
535 |
< |
static class NoOpCallable implements Callable { |
535 |
> |
public static class NoOpCallable implements Callable { |
536 |
|
public Object call() { return Boolean.TRUE; } |
537 |
|
} |
538 |
|
|
539 |
< |
static final String TEST_STRING = "a test string"; |
539 |
> |
public static final String TEST_STRING = "a test string"; |
540 |
|
|
541 |
< |
static class StringTask implements Callable<String> { |
541 |
> |
public static class StringTask implements Callable<String> { |
542 |
|
public String call() { return TEST_STRING; } |
543 |
|
} |
544 |
|
|
545 |
< |
static class NPETask implements Callable<String> { |
545 |
> |
public static class NPETask implements Callable<String> { |
546 |
|
public String call() { throw new NullPointerException(); } |
547 |
|
} |
548 |
|
|
549 |
< |
static class CallableOne implements Callable<Integer> { |
549 |
> |
public static class CallableOne implements Callable<Integer> { |
550 |
|
public Integer call() { return one; } |
551 |
|
} |
552 |
|
|
553 |
< |
class ShortRunnable extends CheckedRunnable { |
554 |
< |
void realRun() throws Throwable { |
553 |
> |
public class ShortRunnable extends CheckedRunnable { |
554 |
> |
protected void realRun() throws Throwable { |
555 |
|
Thread.sleep(SHORT_DELAY_MS); |
556 |
|
} |
557 |
|
} |
558 |
|
|
559 |
< |
class ShortInterruptedRunnable extends CheckedInterruptedRunnable { |
560 |
< |
void realRun() throws InterruptedException { |
559 |
> |
public class ShortInterruptedRunnable extends CheckedInterruptedRunnable { |
560 |
> |
protected void realRun() throws InterruptedException { |
561 |
|
Thread.sleep(SHORT_DELAY_MS); |
562 |
|
} |
563 |
|
} |
564 |
|
|
565 |
< |
class SmallRunnable extends CheckedRunnable { |
566 |
< |
void realRun() throws Throwable { |
565 |
> |
public class SmallRunnable extends CheckedRunnable { |
566 |
> |
protected void realRun() throws Throwable { |
567 |
|
Thread.sleep(SMALL_DELAY_MS); |
568 |
|
} |
569 |
|
} |
570 |
|
|
571 |
< |
class SmallPossiblyInterruptedRunnable extends CheckedRunnable { |
572 |
< |
void realRun() { |
571 |
> |
public class SmallPossiblyInterruptedRunnable extends CheckedRunnable { |
572 |
> |
protected void realRun() { |
573 |
|
try { |
574 |
|
Thread.sleep(SMALL_DELAY_MS); |
575 |
< |
} |
577 |
< |
catch (InterruptedException ok) { |
578 |
< |
} |
575 |
> |
} catch (InterruptedException ok) {} |
576 |
|
} |
577 |
|
} |
578 |
|
|
579 |
< |
class SmallCallable extends CheckedCallable { |
580 |
< |
Object realCall() throws Throwable { |
579 |
> |
public class SmallCallable extends CheckedCallable { |
580 |
> |
protected Object realCall() throws InterruptedException { |
581 |
|
Thread.sleep(SMALL_DELAY_MS); |
582 |
|
return Boolean.TRUE; |
583 |
|
} |
584 |
|
} |
585 |
|
|
586 |
< |
class SmallInterruptedRunnable extends CheckedInterruptedRunnable { |
587 |
< |
void realRun() throws InterruptedException { |
586 |
> |
public class SmallInterruptedRunnable extends CheckedInterruptedRunnable { |
587 |
> |
protected void realRun() throws InterruptedException { |
588 |
|
Thread.sleep(SMALL_DELAY_MS); |
589 |
|
} |
590 |
|
} |
591 |
|
|
592 |
< |
class MediumRunnable extends CheckedRunnable { |
593 |
< |
void realRun() throws Throwable { |
592 |
> |
public class MediumRunnable extends CheckedRunnable { |
593 |
> |
protected void realRun() throws Throwable { |
594 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
595 |
|
} |
596 |
|
} |
597 |
|
|
598 |
< |
class MediumInterruptedRunnable extends CheckedInterruptedRunnable { |
599 |
< |
void realRun() throws InterruptedException { |
598 |
> |
public class MediumInterruptedRunnable extends CheckedInterruptedRunnable { |
599 |
> |
protected void realRun() throws InterruptedException { |
600 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
601 |
|
} |
602 |
|
} |
603 |
|
|
604 |
< |
class MediumPossiblyInterruptedRunnable extends CheckedRunnable { |
605 |
< |
void realRun() { |
604 |
> |
public class MediumPossiblyInterruptedRunnable extends CheckedRunnable { |
605 |
> |
protected void realRun() { |
606 |
|
try { |
607 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
608 |
< |
} |
612 |
< |
catch (InterruptedException ok) { |
613 |
< |
} |
608 |
> |
} catch (InterruptedException ok) {} |
609 |
|
} |
610 |
|
} |
611 |
|
|
612 |
< |
class LongPossiblyInterruptedRunnable extends CheckedRunnable { |
613 |
< |
void realRun() { |
612 |
> |
public class LongPossiblyInterruptedRunnable extends CheckedRunnable { |
613 |
> |
protected void realRun() { |
614 |
|
try { |
615 |
|
Thread.sleep(LONG_DELAY_MS); |
616 |
< |
} |
622 |
< |
catch (InterruptedException ok) { |
623 |
< |
} |
616 |
> |
} catch (InterruptedException ok) {} |
617 |
|
} |
618 |
|
} |
619 |
|
|
620 |
|
/** |
621 |
|
* For use as ThreadFactory in constructors |
622 |
|
*/ |
623 |
< |
static class SimpleThreadFactory implements ThreadFactory { |
623 |
> |
public static class SimpleThreadFactory implements ThreadFactory { |
624 |
|
public Thread newThread(Runnable r) { |
625 |
|
return new Thread(r); |
626 |
|
} |
627 |
|
} |
628 |
|
|
629 |
< |
static class TrackedShortRunnable implements Runnable { |
630 |
< |
volatile boolean done = false; |
629 |
> |
public static class TrackedShortRunnable implements Runnable { |
630 |
> |
public volatile boolean done = false; |
631 |
|
public void run() { |
632 |
|
try { |
633 |
|
Thread.sleep(SMALL_DELAY_MS); |
634 |
|
done = true; |
635 |
< |
} catch (InterruptedException ok) { |
643 |
< |
} |
635 |
> |
} catch (InterruptedException ok) {} |
636 |
|
} |
637 |
|
} |
638 |
|
|
639 |
< |
static class TrackedMediumRunnable implements Runnable { |
640 |
< |
volatile boolean done = false; |
639 |
> |
public static class TrackedMediumRunnable implements Runnable { |
640 |
> |
public volatile boolean done = false; |
641 |
|
public void run() { |
642 |
|
try { |
643 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
644 |
|
done = true; |
645 |
< |
} catch (InterruptedException ok) { |
654 |
< |
} |
645 |
> |
} catch (InterruptedException ok) {} |
646 |
|
} |
647 |
|
} |
648 |
|
|
649 |
< |
static class TrackedLongRunnable implements Runnable { |
650 |
< |
volatile boolean done = false; |
649 |
> |
public static class TrackedLongRunnable implements Runnable { |
650 |
> |
public volatile boolean done = false; |
651 |
|
public void run() { |
652 |
|
try { |
653 |
|
Thread.sleep(LONG_DELAY_MS); |
654 |
|
done = true; |
655 |
< |
} catch (InterruptedException ok) { |
665 |
< |
} |
655 |
> |
} catch (InterruptedException ok) {} |
656 |
|
} |
657 |
|
} |
658 |
|
|
659 |
< |
static class TrackedNoOpRunnable implements Runnable { |
660 |
< |
volatile boolean done = false; |
659 |
> |
public static class TrackedNoOpRunnable implements Runnable { |
660 |
> |
public volatile boolean done = false; |
661 |
|
public void run() { |
662 |
|
done = true; |
663 |
|
} |
664 |
|
} |
665 |
|
|
666 |
< |
static class TrackedCallable implements Callable { |
667 |
< |
volatile boolean done = false; |
666 |
> |
public static class TrackedCallable implements Callable { |
667 |
> |
public volatile boolean done = false; |
668 |
|
public Object call() { |
669 |
|
try { |
670 |
|
Thread.sleep(SMALL_DELAY_MS); |
671 |
|
done = true; |
672 |
< |
} catch (InterruptedException ok) { |
683 |
< |
} |
672 |
> |
} catch (InterruptedException ok) {} |
673 |
|
return Boolean.TRUE; |
674 |
|
} |
675 |
|
} |
678 |
|
/** |
679 |
|
* For use as RejectedExecutionHandler in constructors |
680 |
|
*/ |
681 |
< |
static class NoOpREHandler implements RejectedExecutionHandler { |
681 |
> |
public static class NoOpREHandler implements RejectedExecutionHandler { |
682 |
|
public void rejectedExecution(Runnable r, |
683 |
|
ThreadPoolExecutor executor) {} |
684 |
|
} |