170 |
|
try { |
171 |
|
new ForkJoinPool(-1); |
172 |
|
shouldThrow(); |
173 |
< |
} |
174 |
< |
catch (IllegalArgumentException success) {} |
173 |
> |
} catch (IllegalArgumentException success) {} |
174 |
|
} |
175 |
|
|
176 |
|
/** |
180 |
|
try { |
181 |
|
new ForkJoinPool(1, null); |
182 |
|
shouldThrow(); |
183 |
< |
} catch (NullPointerException success) { |
185 |
< |
} |
183 |
> |
} catch (NullPointerException success) {} |
184 |
|
} |
185 |
|
|
186 |
|
|
414 |
|
int r = f.get(); |
415 |
|
assertTrue(r == 832040); |
416 |
|
} finally { |
417 |
< |
joinPool(p); |
417 |
> |
p.shutdownNow(); // don't wait out shutdown |
418 |
|
} |
419 |
|
} |
420 |
|
|
590 |
|
Object result = future.get(); |
591 |
|
shouldThrow(); |
592 |
|
} catch (ExecutionException success) { |
593 |
+ |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
594 |
|
} finally { |
595 |
|
Policy.setPolicy(savedPolicy); |
596 |
|
} |
605 |
|
TrackedShortRunnable task = null; |
606 |
|
Future<?> future = e.submit(task); |
607 |
|
shouldThrow(); |
608 |
< |
} catch (NullPointerException success) { |
610 |
< |
} |
608 |
> |
} catch (NullPointerException success) {} |
609 |
|
} |
610 |
|
|
611 |
|
|
618 |
|
StringTask t = null; |
619 |
|
Future<String> future = e.submit(t); |
620 |
|
shouldThrow(); |
621 |
< |
} catch (NullPointerException success) { |
624 |
< |
} |
621 |
> |
} catch (NullPointerException success) {} |
622 |
|
} |
623 |
|
|
624 |
|
|
630 |
|
final ForkJoinPool p = new ForkJoinPool(1); |
631 |
|
|
632 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
633 |
< |
void realRun() throws Throwable { |
633 |
> |
public void realRun() throws Throwable { |
634 |
|
p.submit(new CheckedCallable<Object>() { |
635 |
|
public Object realCall() throws Throwable { |
636 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
636 |
> |
try { |
637 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
638 |
> |
} catch (InterruptedException ok) { |
639 |
> |
} |
640 |
|
return null; |
641 |
|
}}).get(); |
642 |
|
}}); |
644 |
|
t.start(); |
645 |
|
Thread.sleep(SHORT_DELAY_MS); |
646 |
|
t.interrupt(); |
647 |
+ |
t.join(); |
648 |
+ |
p.shutdownNow(); |
649 |
|
joinPool(p); |
650 |
|
} |
651 |
|
|
655 |
|
*/ |
656 |
|
public void testSubmitEE() throws Throwable { |
657 |
|
ForkJoinPool p = new ForkJoinPool(1); |
656 |
– |
|
658 |
|
try { |
659 |
< |
Callable c = new Callable() { |
660 |
< |
public Object call() { |
661 |
< |
int i = 5/0; |
662 |
< |
return Boolean.TRUE; |
663 |
< |
} |
663 |
< |
}; |
664 |
< |
|
665 |
< |
for (int i = 0; i < 5; i++) { |
666 |
< |
p.submit(c).get(); |
667 |
< |
} |
659 |
> |
p.submit(new Callable() { |
660 |
> |
public Object call() { |
661 |
> |
int i = 5/0; |
662 |
> |
return Boolean.TRUE; |
663 |
> |
}}).get(); |
664 |
|
shouldThrow(); |
665 |
|
} catch (ExecutionException success) { |
666 |
+ |
assertTrue(success.getCause() instanceof ArithmeticException); |
667 |
|
} |
668 |
+ |
|
669 |
|
joinPool(p); |
670 |
|
} |
671 |
|
|
698 |
|
} |
699 |
|
|
700 |
|
/** |
701 |
< |
* invokeAny(c) throws NullPointerException if c has null elements |
701 |
> |
* invokeAny(c) throws NullPointerException if c has a single null element |
702 |
|
*/ |
703 |
|
public void testInvokeAny3() throws Throwable { |
704 |
|
ExecutorService e = new ForkJoinPool(1); |
705 |
|
try { |
706 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
709 |
– |
l.add(new StringTask()); |
707 |
|
l.add(null); |
708 |
|
e.invokeAny(l); |
709 |
|
shouldThrow(); |
714 |
|
} |
715 |
|
|
716 |
|
/** |
717 |
< |
* invokeAny(c) throws ExecutionException if no task in c completes |
717 |
> |
* invokeAny(c) throws NullPointerException if c has null elements |
718 |
|
*/ |
719 |
|
public void testInvokeAny4() throws Throwable { |
720 |
|
ExecutorService e = new ForkJoinPool(1); |
721 |
|
try { |
722 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
723 |
+ |
l.add(new Callable<String>() { |
724 |
+ |
public String call() { |
725 |
+ |
// The delay gives the pool a chance to notice |
726 |
+ |
// the null element. |
727 |
+ |
sleepTillInterrupted(SMALL_DELAY_MS); |
728 |
+ |
return "foo"; |
729 |
+ |
}}); |
730 |
+ |
l.add(null); |
731 |
+ |
e.invokeAny(l); |
732 |
+ |
shouldThrow(); |
733 |
+ |
} catch (NullPointerException success) { |
734 |
+ |
} finally { |
735 |
+ |
joinPool(e); |
736 |
+ |
} |
737 |
+ |
} |
738 |
+ |
|
739 |
+ |
/** |
740 |
+ |
* invokeAny(c) throws ExecutionException if no task in c completes |
741 |
+ |
*/ |
742 |
+ |
public void testInvokeAny5() throws Throwable { |
743 |
+ |
ExecutorService e = new ForkJoinPool(1); |
744 |
+ |
try { |
745 |
+ |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
746 |
|
l.add(new NPETask()); |
747 |
|
e.invokeAny(l); |
748 |
|
shouldThrow(); |
749 |
|
} catch (ExecutionException success) { |
750 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
751 |
|
} finally { |
752 |
|
joinPool(e); |
753 |
|
} |
756 |
|
/** |
757 |
|
* invokeAny(c) returns result of some task in c if at least one completes |
758 |
|
*/ |
759 |
< |
public void testInvokeAny5() throws Throwable { |
759 |
> |
public void testInvokeAny6() throws Throwable { |
760 |
|
ExecutorService e = new ForkJoinPool(1); |
761 |
|
try { |
762 |
|
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
829 |
|
future.get(); |
830 |
|
shouldThrow(); |
831 |
|
} catch (ExecutionException success) { |
832 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
833 |
|
} finally { |
834 |
|
joinPool(e); |
835 |
|
} |
927 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
928 |
|
shouldThrow(); |
929 |
|
} catch (ExecutionException success) { |
930 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
931 |
|
} finally { |
932 |
|
joinPool(e); |
933 |
|
} |
1026 |
|
future.get(); |
1027 |
|
shouldThrow(); |
1028 |
|
} catch (ExecutionException success) { |
1029 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
1030 |
|
} finally { |
1031 |
|
joinPool(e); |
1032 |
|
} |