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 |
|
|
412 |
|
p.execute(f); |
413 |
|
assertTrue(p.getPoolSize() >= 4); |
414 |
|
int r = f.get(); |
415 |
< |
assertTrue(r == 832040); |
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 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
706 |
+ |
l.add(null); |
707 |
|
try { |
708 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
709 |
– |
l.add(new StringTask()); |
710 |
– |
l.add(null); |
708 |
|
e.invokeAny(l); |
709 |
|
shouldThrow(); |
710 |
|
} catch (NullPointerException success) { |
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 |
+ |
CountDownLatch latch = new CountDownLatch(1); |
721 |
|
ExecutorService e = new ForkJoinPool(1); |
722 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
723 |
+ |
l.add(latchAwaitingStringTask(latch)); |
724 |
+ |
l.add(null); |
725 |
+ |
try { |
726 |
+ |
e.invokeAny(l); |
727 |
+ |
shouldThrow(); |
728 |
+ |
} catch (NullPointerException success) { |
729 |
+ |
} finally { |
730 |
+ |
latch.countDown(); |
731 |
+ |
joinPool(e); |
732 |
+ |
} |
733 |
+ |
} |
734 |
+ |
|
735 |
+ |
/** |
736 |
+ |
* invokeAny(c) throws ExecutionException if no task in c completes |
737 |
+ |
*/ |
738 |
+ |
public void testInvokeAny5() throws Throwable { |
739 |
+ |
ExecutorService e = new ForkJoinPool(1); |
740 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
741 |
+ |
l.add(new NPETask()); |
742 |
|
try { |
725 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
726 |
– |
l.add(new NPETask()); |
743 |
|
e.invokeAny(l); |
744 |
|
shouldThrow(); |
745 |
|
} catch (ExecutionException success) { |
746 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
747 |
|
} finally { |
748 |
|
joinPool(e); |
749 |
|
} |
752 |
|
/** |
753 |
|
* invokeAny(c) returns result of some task in c if at least one completes |
754 |
|
*/ |
755 |
< |
public void testInvokeAny5() throws Throwable { |
755 |
> |
public void testInvokeAny6() throws Throwable { |
756 |
|
ExecutorService e = new ForkJoinPool(1); |
757 |
|
try { |
758 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
758 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
759 |
|
l.add(new StringTask()); |
760 |
|
l.add(new StringTask()); |
761 |
|
String result = e.invokeAny(l); |
798 |
|
*/ |
799 |
|
public void testInvokeAll3() throws InterruptedException { |
800 |
|
ExecutorService e = new ForkJoinPool(1); |
801 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
802 |
+ |
l.add(new StringTask()); |
803 |
+ |
l.add(null); |
804 |
|
try { |
785 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
786 |
– |
l.add(new StringTask()); |
787 |
– |
l.add(null); |
805 |
|
e.invokeAll(l); |
806 |
|
shouldThrow(); |
807 |
|
} catch (NullPointerException success) { |
816 |
|
*/ |
817 |
|
public void testInvokeAll4() throws Throwable { |
818 |
|
ExecutorService e = new ForkJoinPool(1); |
819 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
820 |
+ |
l.add(new NPETask()); |
821 |
+ |
List<Future<String>> futures = e.invokeAll(l); |
822 |
+ |
assertEquals(1, futures.size()); |
823 |
|
try { |
824 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
804 |
< |
l.add(new NPETask()); |
805 |
< |
List<Future<String>> result = e.invokeAll(l); |
806 |
< |
assertEquals(1, result.size()); |
807 |
< |
for (Future<String> future : result) |
808 |
< |
future.get(); |
824 |
> |
futures.get(0).get(); |
825 |
|
shouldThrow(); |
826 |
|
} catch (ExecutionException success) { |
827 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
828 |
|
} finally { |
829 |
|
joinPool(e); |
830 |
|
} |
836 |
|
public void testInvokeAll5() throws Throwable { |
837 |
|
ExecutorService e = new ForkJoinPool(1); |
838 |
|
try { |
839 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
839 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
840 |
|
l.add(new StringTask()); |
841 |
|
l.add(new StringTask()); |
842 |
< |
List<Future<String>> result = e.invokeAll(l); |
843 |
< |
assertEquals(2, result.size()); |
844 |
< |
for (Future<String> future : result) |
842 |
> |
List<Future<String>> futures = e.invokeAll(l); |
843 |
> |
assertEquals(2, futures.size()); |
844 |
> |
for (Future<String> future : futures) |
845 |
|
assertSame(TEST_STRING, future.get()); |
846 |
|
} finally { |
847 |
|
joinPool(e); |
868 |
|
*/ |
869 |
|
public void testTimedInvokeAnyNullTimeUnit() throws Throwable { |
870 |
|
ExecutorService e = new ForkJoinPool(1); |
871 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
872 |
+ |
l.add(new StringTask()); |
873 |
|
try { |
855 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
856 |
– |
l.add(new StringTask()); |
874 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
875 |
|
shouldThrow(); |
876 |
|
} catch (NullPointerException success) { |
898 |
|
* timed invokeAny(c) throws NullPointerException if c has null elements |
899 |
|
*/ |
900 |
|
public void testTimedInvokeAny3() throws Throwable { |
901 |
+ |
CountDownLatch latch = new CountDownLatch(1); |
902 |
|
ExecutorService e = new ForkJoinPool(1); |
903 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
904 |
+ |
l.add(latchAwaitingStringTask(latch)); |
905 |
+ |
l.add(null); |
906 |
|
try { |
886 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
887 |
– |
l.add(new StringTask()); |
888 |
– |
l.add(null); |
907 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
908 |
|
shouldThrow(); |
909 |
|
} catch (NullPointerException success) { |
910 |
|
} finally { |
911 |
+ |
latch.countDown(); |
912 |
|
joinPool(e); |
913 |
|
} |
914 |
|
} |
918 |
|
*/ |
919 |
|
public void testTimedInvokeAny4() throws Throwable { |
920 |
|
ExecutorService e = new ForkJoinPool(1); |
921 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
922 |
+ |
l.add(new NPETask()); |
923 |
|
try { |
903 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
904 |
– |
l.add(new NPETask()); |
924 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
925 |
|
shouldThrow(); |
926 |
|
} catch (ExecutionException success) { |
927 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
928 |
|
} finally { |
929 |
|
joinPool(e); |
930 |
|
} |
936 |
|
public void testTimedInvokeAny5() throws Throwable { |
937 |
|
ExecutorService e = new ForkJoinPool(1); |
938 |
|
try { |
939 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
939 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
940 |
|
l.add(new StringTask()); |
941 |
|
l.add(new StringTask()); |
942 |
|
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
965 |
|
*/ |
966 |
|
public void testTimedInvokeAllNullTimeUnit() throws Throwable { |
967 |
|
ExecutorService e = new ForkJoinPool(1); |
968 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
969 |
+ |
l.add(new StringTask()); |
970 |
|
try { |
949 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
950 |
– |
l.add(new StringTask()); |
971 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
972 |
|
shouldThrow(); |
973 |
|
} catch (NullPointerException success) { |
996 |
|
*/ |
997 |
|
public void testTimedInvokeAll3() throws InterruptedException { |
998 |
|
ExecutorService e = new ForkJoinPool(1); |
999 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1000 |
+ |
l.add(new StringTask()); |
1001 |
+ |
l.add(null); |
1002 |
|
try { |
980 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
981 |
– |
l.add(new StringTask()); |
982 |
– |
l.add(null); |
1003 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1004 |
|
shouldThrow(); |
1005 |
|
} catch (NullPointerException success) { |
1013 |
|
*/ |
1014 |
|
public void testTimedInvokeAll4() throws Throwable { |
1015 |
|
ExecutorService e = new ForkJoinPool(1); |
1016 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1017 |
+ |
l.add(new NPETask()); |
1018 |
+ |
List<Future<String>> futures |
1019 |
+ |
= e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1020 |
+ |
assertEquals(1, futures.size()); |
1021 |
|
try { |
1022 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
998 |
< |
l.add(new NPETask()); |
999 |
< |
List<Future<String>> result |
1000 |
< |
= e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1001 |
< |
assertEquals(1, result.size()); |
1002 |
< |
for (Future<String> future : result) |
1003 |
< |
future.get(); |
1022 |
> |
futures.get(0).get(); |
1023 |
|
shouldThrow(); |
1024 |
|
} catch (ExecutionException success) { |
1025 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
1026 |
|
} finally { |
1027 |
|
joinPool(e); |
1028 |
|
} |
1034 |
|
public void testTimedInvokeAll5() throws Throwable { |
1035 |
|
ExecutorService e = new ForkJoinPool(1); |
1036 |
|
try { |
1037 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1037 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
1038 |
|
l.add(new StringTask()); |
1039 |
|
l.add(new StringTask()); |
1040 |
< |
List<Future<String>> result |
1040 |
> |
List<Future<String>> futures |
1041 |
|
= e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1042 |
< |
assertEquals(2, result.size()); |
1043 |
< |
for (Future<String> future : result) |
1042 |
> |
assertEquals(2, futures.size()); |
1043 |
> |
for (Future<String> future : futures) |
1044 |
|
assertSame(TEST_STRING, future.get()); |
1045 |
|
} finally { |
1046 |
|
joinPool(e); |