178 |
|
} |
179 |
|
|
180 |
|
joinPool(se); |
181 |
– |
|
181 |
|
} |
182 |
|
|
183 |
|
/** |
658 |
|
* invokeAny(c) throws NPE if c has null elements |
659 |
|
*/ |
660 |
|
public void testInvokeAny3() throws Exception { |
661 |
< |
final CountDownLatch latch = new CountDownLatch(1); |
661 |
> |
CountDownLatch latch = new CountDownLatch(1); |
662 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
663 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
664 |
+ |
l.add(latchAwaitingStringTask(latch)); |
665 |
+ |
l.add(null); |
666 |
|
try { |
665 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
666 |
– |
l.add(new Callable<String>() { |
667 |
– |
public String call() { |
668 |
– |
try { |
669 |
– |
latch.await(); |
670 |
– |
} catch (InterruptedException ok) {} |
671 |
– |
return TEST_STRING; |
672 |
– |
}}); |
673 |
– |
l.add(null); |
667 |
|
e.invokeAny(l); |
668 |
|
shouldThrow(); |
669 |
|
} catch (NullPointerException success) { |
678 |
|
*/ |
679 |
|
public void testInvokeAny4() throws Exception { |
680 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
681 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
682 |
+ |
l.add(new NPETask()); |
683 |
|
try { |
689 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
690 |
– |
l.add(new NPETask()); |
684 |
|
e.invokeAny(l); |
685 |
|
shouldThrow(); |
686 |
|
} catch (ExecutionException success) { |
696 |
|
public void testInvokeAny5() throws Exception { |
697 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
698 |
|
try { |
699 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
699 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
700 |
|
l.add(new StringTask()); |
701 |
|
l.add(new StringTask()); |
702 |
|
String result = e.invokeAny(l); |
738 |
|
*/ |
739 |
|
public void testInvokeAll3() throws Exception { |
740 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
741 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
742 |
+ |
l.add(new StringTask()); |
743 |
+ |
l.add(null); |
744 |
|
try { |
749 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
750 |
– |
l.add(new StringTask()); |
751 |
– |
l.add(null); |
745 |
|
e.invokeAll(l); |
746 |
|
shouldThrow(); |
747 |
|
} catch (NullPointerException success) { |
755 |
|
*/ |
756 |
|
public void testInvokeAll4() throws Exception { |
757 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
758 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
759 |
+ |
l.add(new NPETask()); |
760 |
+ |
List<Future<String>> futures = e.invokeAll(l); |
761 |
+ |
assertEquals(1, futures.size()); |
762 |
|
try { |
763 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
767 |
< |
l.add(new NPETask()); |
768 |
< |
List<Future<String>> result = e.invokeAll(l); |
769 |
< |
assertEquals(1, result.size()); |
770 |
< |
for (Future<String> future : result) |
771 |
< |
future.get(); |
763 |
> |
futures.get(0).get(); |
764 |
|
shouldThrow(); |
765 |
|
} catch (ExecutionException success) { |
766 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
775 |
|
public void testInvokeAll5() throws Exception { |
776 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
777 |
|
try { |
778 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
778 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
779 |
|
l.add(new StringTask()); |
780 |
|
l.add(new StringTask()); |
781 |
< |
List<Future<String>> result = e.invokeAll(l); |
782 |
< |
assertEquals(2, result.size()); |
783 |
< |
for (Future<String> future : result) |
781 |
> |
List<Future<String>> futures = e.invokeAll(l); |
782 |
> |
assertEquals(2, futures.size()); |
783 |
> |
for (Future<String> future : futures) |
784 |
|
assertSame(TEST_STRING, future.get()); |
785 |
|
} finally { |
786 |
|
joinPool(e); |
806 |
|
*/ |
807 |
|
public void testTimedInvokeAnyNullTimeUnit() throws Exception { |
808 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
809 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
810 |
+ |
l.add(new StringTask()); |
811 |
|
try { |
818 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
819 |
– |
l.add(new StringTask()); |
812 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
813 |
|
shouldThrow(); |
814 |
|
} catch (NullPointerException success) { |
835 |
|
* timed invokeAny(c) throws NPE if c has null elements |
836 |
|
*/ |
837 |
|
public void testTimedInvokeAny3() throws Exception { |
838 |
< |
final CountDownLatch latch = new CountDownLatch(1); |
838 |
> |
CountDownLatch latch = new CountDownLatch(1); |
839 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
840 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
841 |
+ |
l.add(latchAwaitingStringTask(latch)); |
842 |
+ |
l.add(null); |
843 |
|
try { |
849 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
850 |
– |
l.add(new Callable<String>() { |
851 |
– |
public String call() { |
852 |
– |
try { |
853 |
– |
latch.await(); |
854 |
– |
} catch (InterruptedException ok) {} |
855 |
– |
return TEST_STRING; |
856 |
– |
}}); |
857 |
– |
l.add(null); |
844 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
845 |
|
shouldThrow(); |
846 |
|
} catch (NullPointerException success) { |
855 |
|
*/ |
856 |
|
public void testTimedInvokeAny4() throws Exception { |
857 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
858 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
859 |
+ |
l.add(new NPETask()); |
860 |
|
try { |
873 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
874 |
– |
l.add(new NPETask()); |
861 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
862 |
|
shouldThrow(); |
863 |
|
} catch (ExecutionException success) { |
873 |
|
public void testTimedInvokeAny5() throws Exception { |
874 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
875 |
|
try { |
876 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
876 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
877 |
|
l.add(new StringTask()); |
878 |
|
l.add(new StringTask()); |
879 |
|
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
902 |
|
*/ |
903 |
|
public void testTimedInvokeAllNullTimeUnit() throws Exception { |
904 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
905 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
906 |
+ |
l.add(new StringTask()); |
907 |
|
try { |
920 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
921 |
– |
l.add(new StringTask()); |
908 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
909 |
|
shouldThrow(); |
910 |
|
} catch (NullPointerException success) { |
931 |
|
*/ |
932 |
|
public void testTimedInvokeAll3() throws Exception { |
933 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
934 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
935 |
+ |
l.add(new StringTask()); |
936 |
+ |
l.add(null); |
937 |
|
try { |
949 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
950 |
– |
l.add(new StringTask()); |
951 |
– |
l.add(null); |
938 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
939 |
|
shouldThrow(); |
940 |
|
} catch (NullPointerException success) { |
948 |
|
*/ |
949 |
|
public void testTimedInvokeAll4() throws Exception { |
950 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
951 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
952 |
+ |
l.add(new NPETask()); |
953 |
+ |
List<Future<String>> futures = |
954 |
+ |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
955 |
+ |
assertEquals(1, futures.size()); |
956 |
|
try { |
957 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
967 |
< |
l.add(new NPETask()); |
968 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
969 |
< |
assertEquals(1, result.size()); |
970 |
< |
for (Future<String> future : result) |
971 |
< |
future.get(); |
957 |
> |
futures.get(0).get(); |
958 |
|
shouldThrow(); |
959 |
|
} catch (ExecutionException success) { |
960 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
969 |
|
public void testTimedInvokeAll5() throws Exception { |
970 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
971 |
|
try { |
972 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
972 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
973 |
|
l.add(new StringTask()); |
974 |
|
l.add(new StringTask()); |
975 |
< |
List<Future<String>> result = e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
976 |
< |
assertEquals(2, result.size()); |
977 |
< |
for (Future<String> future : result) |
975 |
> |
List<Future<String>> futures = |
976 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
977 |
> |
assertEquals(2, futures.size()); |
978 |
> |
for (Future<String> future : futures) |
979 |
|
assertSame(TEST_STRING, future.get()); |
980 |
|
} finally { |
981 |
|
joinPool(e); |
988 |
|
public void testTimedInvokeAll6() throws Exception { |
989 |
|
ExecutorService e = new ScheduledThreadPoolExecutor(2); |
990 |
|
try { |
991 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
991 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
992 |
|
l.add(new StringTask()); |
993 |
|
l.add(Executors.callable(new MediumPossiblyInterruptedRunnable(), TEST_STRING)); |
994 |
|
l.add(new StringTask()); |
995 |
< |
List<Future<String>> result = e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); |
996 |
< |
assertEquals(3, result.size()); |
997 |
< |
Iterator<Future<String>> it = result.iterator(); |
995 |
> |
List<Future<String>> futures = |
996 |
> |
e.invokeAll(l, SHORT_DELAY_MS, MILLISECONDS); |
997 |
> |
assertEquals(3, futures.size()); |
998 |
> |
Iterator<Future<String>> it = futures.iterator(); |
999 |
|
Future<String> f1 = it.next(); |
1000 |
|
Future<String> f2 = it.next(); |
1001 |
|
Future<String> f3 = it.next(); |