7 |
|
|
8 |
|
import junit.framework.*; |
9 |
|
import java.util.*; |
10 |
< |
import java.util.concurrent.*; |
11 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
10 |
> |
import java.util.concurrent.Executor; |
11 |
> |
import java.util.concurrent.Executors; |
12 |
> |
import java.util.concurrent.ExecutorService; |
13 |
> |
import java.util.concurrent.AbstractExecutorService; |
14 |
> |
import java.util.concurrent.CountDownLatch; |
15 |
> |
import java.util.concurrent.Callable; |
16 |
> |
import java.util.concurrent.Future; |
17 |
> |
import java.util.concurrent.ExecutionException; |
18 |
> |
import java.util.concurrent.CancellationException; |
19 |
> |
import java.util.concurrent.RejectedExecutionException; |
20 |
> |
import java.util.concurrent.ForkJoinPool; |
21 |
> |
import java.util.concurrent.ForkJoinTask; |
22 |
> |
import java.util.concurrent.ForkJoinWorkerThread; |
23 |
> |
import java.util.concurrent.RecursiveAction; |
24 |
> |
import java.util.concurrent.RecursiveTask; |
25 |
> |
import java.util.concurrent.TimeUnit; |
26 |
|
import java.util.concurrent.locks.*; |
27 |
|
import java.security.*; |
28 |
|
|
53 |
|
// Some classes to test extension and factory methods |
54 |
|
|
55 |
|
static class MyHandler implements Thread.UncaughtExceptionHandler { |
56 |
< |
int catches = 0; |
56 |
> |
volatile int catches = 0; |
57 |
|
public void uncaughtException(Thread t, Throwable e) { |
58 |
|
++catches; |
59 |
|
} |
62 |
|
// to test handlers |
63 |
|
static class FailingFJWSubclass extends ForkJoinWorkerThread { |
64 |
|
public FailingFJWSubclass(ForkJoinPool p) { super(p) ; } |
65 |
< |
protected void onStart() { throw new Error(); } |
65 |
> |
protected void onStart() { super.onStart(); throw new Error(); } |
66 |
|
} |
67 |
|
|
68 |
|
static class FailingThreadFactory |
69 |
|
implements ForkJoinPool.ForkJoinWorkerThreadFactory { |
70 |
< |
int calls = 0; |
70 |
> |
volatile int calls = 0; |
71 |
|
public ForkJoinWorkerThread newThread(ForkJoinPool p) { |
72 |
|
if (++calls > 1) return null; |
73 |
|
return new FailingFJWSubclass(p); |
162 |
|
assertTrue(p.getFactory() == |
163 |
|
ForkJoinPool.defaultForkJoinWorkerThreadFactory); |
164 |
|
assertTrue(p.isQuiescent()); |
151 |
– |
assertTrue(p.getMaintainsParallelism()); |
165 |
|
assertFalse(p.getAsyncMode()); |
166 |
|
assertTrue(p.getActiveThreadCount() == 0); |
167 |
|
assertTrue(p.getStealCount() == 0); |
191 |
|
*/ |
192 |
|
public void testConstructor2() { |
193 |
|
try { |
194 |
< |
new ForkJoinPool(1, null); |
194 |
> |
new ForkJoinPool(1, null, null, false); |
195 |
|
shouldThrow(); |
196 |
|
} catch (NullPointerException success) {} |
197 |
|
} |
211 |
|
} |
212 |
|
|
213 |
|
/** |
201 |
– |
* setParallelism changes reported parallelism level. |
202 |
– |
*/ |
203 |
– |
public void testSetParallelism() { |
204 |
– |
ForkJoinPool p = null; |
205 |
– |
try { |
206 |
– |
p = new ForkJoinPool(1); |
207 |
– |
assertTrue(p.getParallelism() == 1); |
208 |
– |
p.setParallelism(2); |
209 |
– |
assertTrue(p.getParallelism() == 2); |
210 |
– |
} finally { |
211 |
– |
joinPool(p); |
212 |
– |
} |
213 |
– |
} |
214 |
– |
|
215 |
– |
/** |
216 |
– |
* setParallelism with argument <= 0 throws exception |
217 |
– |
*/ |
218 |
– |
public void testSetParallelism2() { |
219 |
– |
ForkJoinPool p = null; |
220 |
– |
try { |
221 |
– |
p = new ForkJoinPool(1); |
222 |
– |
assertTrue(p.getParallelism() == 1); |
223 |
– |
p.setParallelism(-2); |
224 |
– |
shouldThrow(); |
225 |
– |
} catch (IllegalArgumentException success) { |
226 |
– |
} finally { |
227 |
– |
joinPool(p); |
228 |
– |
} |
229 |
– |
} |
230 |
– |
|
231 |
– |
/** |
214 |
|
* getPoolSize returns number of started workers. |
215 |
|
*/ |
216 |
|
public void testGetPoolSize() { |
217 |
|
ForkJoinPool p = null; |
218 |
|
try { |
219 |
|
p = new ForkJoinPool(1); |
220 |
< |
assertTrue(p.getPoolSize() == 0); |
220 |
> |
assertTrue(p.getActiveThreadCount() == 0); |
221 |
|
Future<String> future = p.submit(new StringTask()); |
222 |
|
assertTrue(p.getPoolSize() == 1); |
223 |
|
|
227 |
|
} |
228 |
|
|
229 |
|
/** |
248 |
– |
* setMaximumPoolSize changes size reported by getMaximumPoolSize. |
249 |
– |
*/ |
250 |
– |
public void testSetMaximumPoolSize() { |
251 |
– |
ForkJoinPool p = null; |
252 |
– |
try { |
253 |
– |
p = new ForkJoinPool(1); |
254 |
– |
p.setMaximumPoolSize(2); |
255 |
– |
assertTrue(p.getMaximumPoolSize() == 2); |
256 |
– |
} finally { |
257 |
– |
joinPool(p); |
258 |
– |
} |
259 |
– |
} |
260 |
– |
|
261 |
– |
/** |
262 |
– |
* setMaximumPoolSize with argument <= 0 throws exception |
263 |
– |
*/ |
264 |
– |
public void testSetMaximumPoolSize2() { |
265 |
– |
ForkJoinPool p = null; |
266 |
– |
try { |
267 |
– |
p = new ForkJoinPool(1); |
268 |
– |
p.setMaximumPoolSize(-2); |
269 |
– |
shouldThrow(); |
270 |
– |
} catch (IllegalArgumentException success) { |
271 |
– |
} finally { |
272 |
– |
joinPool(p); |
273 |
– |
} |
274 |
– |
} |
275 |
– |
|
276 |
– |
/** |
277 |
– |
* setMaintainsParallelism changes policy reported by |
278 |
– |
* getMaintainsParallelism. |
279 |
– |
*/ |
280 |
– |
public void testSetMaintainsParallelism() { |
281 |
– |
ForkJoinPool p = null; |
282 |
– |
try { |
283 |
– |
p = new ForkJoinPool(1); |
284 |
– |
p.setMaintainsParallelism(false); |
285 |
– |
assertFalse(p.getMaintainsParallelism()); |
286 |
– |
} finally { |
287 |
– |
joinPool(p); |
288 |
– |
} |
289 |
– |
} |
290 |
– |
|
291 |
– |
/** |
292 |
– |
* setAsyncMode changes policy reported by |
293 |
– |
* getAsyncMode. |
294 |
– |
*/ |
295 |
– |
public void testSetAsyncMode() { |
296 |
– |
ForkJoinPool p = null; |
297 |
– |
try { |
298 |
– |
p = new ForkJoinPool(1); |
299 |
– |
p.setAsyncMode(true); |
300 |
– |
assertTrue(p.getAsyncMode()); |
301 |
– |
} finally { |
302 |
– |
joinPool(p); |
303 |
– |
} |
304 |
– |
} |
305 |
– |
|
306 |
– |
/** |
230 |
|
* setUncaughtExceptionHandler changes handler for uncaught exceptions. |
231 |
|
* |
232 |
|
* Additionally tests: Overriding ForkJoinWorkerThread.onStart |
235 |
|
public void testSetUncaughtExceptionHandler() throws InterruptedException { |
236 |
|
ForkJoinPool p = null; |
237 |
|
try { |
315 |
– |
p = new ForkJoinPool(1, new FailingThreadFactory()); |
238 |
|
MyHandler eh = new MyHandler(); |
239 |
< |
p.setUncaughtExceptionHandler(eh); |
240 |
< |
assertEquals(eh, p.getUncaughtExceptionHandler()); |
239 |
> |
p = new ForkJoinPool(1, new FailingThreadFactory(), eh, false); |
240 |
> |
assert(eh == p.getUncaughtExceptionHandler()); |
241 |
|
p.execute(new FailingTask()); |
242 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
243 |
|
assertTrue(eh.catches > 0); |
244 |
|
} finally { |
245 |
+ |
p.shutdownNow(); |
246 |
|
joinPool(p); |
247 |
|
} |
248 |
|
} |
249 |
|
|
250 |
|
/** |
328 |
– |
* setUncaughtExceptionHandler of null removes handler |
329 |
– |
*/ |
330 |
– |
public void testSetUncaughtExceptionHandler2() { |
331 |
– |
ForkJoinPool p = null; |
332 |
– |
try { |
333 |
– |
p = new ForkJoinPool(1); |
334 |
– |
p.setUncaughtExceptionHandler(null); |
335 |
– |
assertNull(p.getUncaughtExceptionHandler()); |
336 |
– |
} finally { |
337 |
– |
joinPool(p); |
338 |
– |
} |
339 |
– |
} |
340 |
– |
|
341 |
– |
|
342 |
– |
/** |
251 |
|
* After invoking a single task, isQuiescent is true, |
252 |
|
* queues are empty, threads are not active, and |
253 |
|
* construction parameters continue to hold |
261 |
|
ForkJoinPool.defaultForkJoinWorkerThreadFactory); |
262 |
|
Thread.sleep(MEDIUM_DELAY_MS); |
263 |
|
assertTrue(p.isQuiescent()); |
356 |
– |
assertTrue(p.getMaintainsParallelism()); |
264 |
|
assertFalse(p.getAsyncMode()); |
265 |
|
assertTrue(p.getActiveThreadCount() == 0); |
266 |
|
assertTrue(p.getQueuedTaskCount() == 0); |
317 |
|
ManagedLocker locker = new ManagedLocker(lock); |
318 |
|
ForkJoinTask<Integer> f = new LockingFibTask(30, locker, lock); |
319 |
|
p.execute(f); |
413 |
– |
assertTrue(p.getPoolSize() >= 4); |
320 |
|
int r = f.get(); |
321 |
< |
assertTrue(r == 832040); |
321 |
> |
assertTrue(r == 832040); |
322 |
|
} finally { |
323 |
|
p.shutdownNow(); // don't wait out shutdown |
324 |
|
} |
496 |
|
Object result = future.get(); |
497 |
|
shouldThrow(); |
498 |
|
} catch (ExecutionException success) { |
499 |
+ |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
500 |
|
} finally { |
501 |
|
Policy.setPolicy(savedPolicy); |
502 |
|
} |
536 |
|
final ForkJoinPool p = new ForkJoinPool(1); |
537 |
|
|
538 |
|
Thread t = new Thread(new CheckedInterruptedRunnable() { |
539 |
< |
void realRun() throws Throwable { |
539 |
> |
public void realRun() throws Throwable { |
540 |
|
p.submit(new CheckedCallable<Object>() { |
541 |
|
public Object realCall() throws Throwable { |
542 |
|
try { |
568 |
|
return Boolean.TRUE; |
569 |
|
}}).get(); |
570 |
|
shouldThrow(); |
571 |
< |
} catch (ExecutionException success) {} |
572 |
< |
|
571 |
> |
} catch (ExecutionException success) { |
572 |
> |
assertTrue(success.getCause() instanceof ArithmeticException); |
573 |
> |
} |
574 |
> |
|
575 |
|
joinPool(p); |
576 |
|
} |
577 |
|
|
608 |
|
*/ |
609 |
|
public void testInvokeAny3() throws Throwable { |
610 |
|
ExecutorService e = new ForkJoinPool(1); |
611 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
612 |
+ |
l.add(null); |
613 |
|
try { |
703 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
704 |
– |
l.add(null); |
614 |
|
e.invokeAny(l); |
615 |
|
shouldThrow(); |
616 |
|
} catch (NullPointerException success) { |
623 |
|
* invokeAny(c) throws NullPointerException if c has null elements |
624 |
|
*/ |
625 |
|
public void testInvokeAny4() throws Throwable { |
626 |
+ |
CountDownLatch latch = new CountDownLatch(1); |
627 |
|
ExecutorService e = new ForkJoinPool(1); |
628 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
629 |
+ |
l.add(latchAwaitingStringTask(latch)); |
630 |
+ |
l.add(null); |
631 |
|
try { |
719 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
720 |
– |
l.add(new Callable<String>() { |
721 |
– |
public String call() { |
722 |
– |
// The delay gives the pool a chance to notice |
723 |
– |
// the null element. |
724 |
– |
sleepTillInterrupted(SMALL_DELAY_MS); |
725 |
– |
return "foo"; |
726 |
– |
}}); |
727 |
– |
l.add(null); |
632 |
|
e.invokeAny(l); |
633 |
|
shouldThrow(); |
634 |
|
} catch (NullPointerException success) { |
635 |
|
} finally { |
636 |
+ |
latch.countDown(); |
637 |
|
joinPool(e); |
638 |
|
} |
639 |
|
} |
643 |
|
*/ |
644 |
|
public void testInvokeAny5() throws Throwable { |
645 |
|
ExecutorService e = new ForkJoinPool(1); |
646 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
647 |
+ |
l.add(new NPETask()); |
648 |
|
try { |
742 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
743 |
– |
l.add(new NPETask()); |
649 |
|
e.invokeAny(l); |
650 |
|
shouldThrow(); |
651 |
|
} catch (ExecutionException success) { |
652 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
653 |
|
} finally { |
654 |
|
joinPool(e); |
655 |
|
} |
661 |
|
public void testInvokeAny6() throws Throwable { |
662 |
|
ExecutorService e = new ForkJoinPool(1); |
663 |
|
try { |
664 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
664 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
665 |
|
l.add(new StringTask()); |
666 |
|
l.add(new StringTask()); |
667 |
|
String result = e.invokeAny(l); |
704 |
|
*/ |
705 |
|
public void testInvokeAll3() throws InterruptedException { |
706 |
|
ExecutorService e = new ForkJoinPool(1); |
707 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
708 |
+ |
l.add(new StringTask()); |
709 |
+ |
l.add(null); |
710 |
|
try { |
802 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
803 |
– |
l.add(new StringTask()); |
804 |
– |
l.add(null); |
711 |
|
e.invokeAll(l); |
712 |
|
shouldThrow(); |
713 |
|
} catch (NullPointerException success) { |
722 |
|
*/ |
723 |
|
public void testInvokeAll4() throws Throwable { |
724 |
|
ExecutorService e = new ForkJoinPool(1); |
725 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
726 |
+ |
l.add(new NPETask()); |
727 |
+ |
List<Future<String>> futures = e.invokeAll(l); |
728 |
+ |
assertEquals(1, futures.size()); |
729 |
|
try { |
730 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
821 |
< |
l.add(new NPETask()); |
822 |
< |
List<Future<String>> result = e.invokeAll(l); |
823 |
< |
assertEquals(1, result.size()); |
824 |
< |
for (Future<String> future : result) |
825 |
< |
future.get(); |
730 |
> |
futures.get(0).get(); |
731 |
|
shouldThrow(); |
732 |
|
} catch (ExecutionException success) { |
733 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
734 |
|
} finally { |
735 |
|
joinPool(e); |
736 |
|
} |
742 |
|
public void testInvokeAll5() throws Throwable { |
743 |
|
ExecutorService e = new ForkJoinPool(1); |
744 |
|
try { |
745 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
745 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
746 |
|
l.add(new StringTask()); |
747 |
|
l.add(new StringTask()); |
748 |
< |
List<Future<String>> result = e.invokeAll(l); |
749 |
< |
assertEquals(2, result.size()); |
750 |
< |
for (Future<String> future : result) |
748 |
> |
List<Future<String>> futures = e.invokeAll(l); |
749 |
> |
assertEquals(2, futures.size()); |
750 |
> |
for (Future<String> future : futures) |
751 |
|
assertSame(TEST_STRING, future.get()); |
752 |
|
} finally { |
753 |
|
joinPool(e); |
761 |
|
public void testTimedInvokeAny1() throws Throwable { |
762 |
|
ExecutorService e = new ForkJoinPool(1); |
763 |
|
try { |
764 |
< |
e.invokeAny(null, MEDIUM_DELAY_MS, MILLISECONDS); |
764 |
> |
e.invokeAny(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
765 |
|
shouldThrow(); |
766 |
|
} catch (NullPointerException success) { |
767 |
|
} finally { |
774 |
|
*/ |
775 |
|
public void testTimedInvokeAnyNullTimeUnit() throws Throwable { |
776 |
|
ExecutorService e = new ForkJoinPool(1); |
777 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
778 |
+ |
l.add(new StringTask()); |
779 |
|
try { |
872 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
873 |
– |
l.add(new StringTask()); |
780 |
|
e.invokeAny(l, MEDIUM_DELAY_MS, null); |
781 |
|
shouldThrow(); |
782 |
|
} catch (NullPointerException success) { |
792 |
|
ExecutorService e = new ForkJoinPool(1); |
793 |
|
try { |
794 |
|
e.invokeAny(new ArrayList<Callable<String>>(), |
795 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
795 |
> |
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
796 |
|
shouldThrow(); |
797 |
|
} catch (IllegalArgumentException success) { |
798 |
|
} finally { |
804 |
|
* timed invokeAny(c) throws NullPointerException if c has null elements |
805 |
|
*/ |
806 |
|
public void testTimedInvokeAny3() throws Throwable { |
807 |
+ |
CountDownLatch latch = new CountDownLatch(1); |
808 |
|
ExecutorService e = new ForkJoinPool(1); |
809 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
810 |
+ |
l.add(latchAwaitingStringTask(latch)); |
811 |
+ |
l.add(null); |
812 |
|
try { |
813 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
904 |
< |
l.add(new StringTask()); |
905 |
< |
l.add(null); |
906 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
813 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
814 |
|
shouldThrow(); |
815 |
|
} catch (NullPointerException success) { |
816 |
|
} finally { |
817 |
+ |
latch.countDown(); |
818 |
|
joinPool(e); |
819 |
|
} |
820 |
|
} |
824 |
|
*/ |
825 |
|
public void testTimedInvokeAny4() throws Throwable { |
826 |
|
ExecutorService e = new ForkJoinPool(1); |
827 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
828 |
+ |
l.add(new NPETask()); |
829 |
|
try { |
830 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
921 |
< |
l.add(new NPETask()); |
922 |
< |
e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
830 |
> |
e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
831 |
|
shouldThrow(); |
832 |
|
} catch (ExecutionException success) { |
833 |
|
assertTrue(success.getCause() instanceof NullPointerException); |
842 |
|
public void testTimedInvokeAny5() throws Throwable { |
843 |
|
ExecutorService e = new ForkJoinPool(1); |
844 |
|
try { |
845 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
845 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
846 |
|
l.add(new StringTask()); |
847 |
|
l.add(new StringTask()); |
848 |
< |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, MILLISECONDS); |
848 |
> |
String result = e.invokeAny(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
849 |
|
assertSame(TEST_STRING, result); |
850 |
|
} finally { |
851 |
|
joinPool(e); |
858 |
|
public void testTimedInvokeAll1() throws Throwable { |
859 |
|
ExecutorService e = new ForkJoinPool(1); |
860 |
|
try { |
861 |
< |
e.invokeAll(null, MEDIUM_DELAY_MS, MILLISECONDS); |
861 |
> |
e.invokeAll(null, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
862 |
|
shouldThrow(); |
863 |
|
} catch (NullPointerException success) { |
864 |
|
} finally { |
871 |
|
*/ |
872 |
|
public void testTimedInvokeAllNullTimeUnit() throws Throwable { |
873 |
|
ExecutorService e = new ForkJoinPool(1); |
874 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
875 |
+ |
l.add(new StringTask()); |
876 |
|
try { |
967 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
968 |
– |
l.add(new StringTask()); |
877 |
|
e.invokeAll(l, MEDIUM_DELAY_MS, null); |
878 |
|
shouldThrow(); |
879 |
|
} catch (NullPointerException success) { |
890 |
|
try { |
891 |
|
List<Future<String>> r |
892 |
|
= e.invokeAll(new ArrayList<Callable<String>>(), |
893 |
< |
MEDIUM_DELAY_MS, MILLISECONDS); |
893 |
> |
MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
894 |
|
assertTrue(r.isEmpty()); |
895 |
|
} finally { |
896 |
|
joinPool(e); |
902 |
|
*/ |
903 |
|
public void testTimedInvokeAll3() throws InterruptedException { |
904 |
|
ExecutorService e = new ForkJoinPool(1); |
905 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
906 |
+ |
l.add(new StringTask()); |
907 |
+ |
l.add(null); |
908 |
|
try { |
909 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
999 |
< |
l.add(new StringTask()); |
1000 |
< |
l.add(null); |
1001 |
< |
e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
909 |
> |
e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
910 |
|
shouldThrow(); |
911 |
|
} catch (NullPointerException success) { |
912 |
|
} finally { |
919 |
|
*/ |
920 |
|
public void testTimedInvokeAll4() throws Throwable { |
921 |
|
ExecutorService e = new ForkJoinPool(1); |
922 |
+ |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
923 |
+ |
l.add(new NPETask()); |
924 |
+ |
List<Future<String>> futures |
925 |
+ |
= e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
926 |
+ |
assertEquals(1, futures.size()); |
927 |
|
try { |
928 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
1016 |
< |
l.add(new NPETask()); |
1017 |
< |
List<Future<String>> result |
1018 |
< |
= e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
1019 |
< |
assertEquals(1, result.size()); |
1020 |
< |
for (Future<String> future : result) |
1021 |
< |
future.get(); |
928 |
> |
futures.get(0).get(); |
929 |
|
shouldThrow(); |
930 |
|
} catch (ExecutionException success) { |
931 |
+ |
assertTrue(success.getCause() instanceof NullPointerException); |
932 |
|
} finally { |
933 |
|
joinPool(e); |
934 |
|
} |
940 |
|
public void testTimedInvokeAll5() throws Throwable { |
941 |
|
ExecutorService e = new ForkJoinPool(1); |
942 |
|
try { |
943 |
< |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
943 |
> |
List<Callable<String>> l = new ArrayList<Callable<String>>(); |
944 |
|
l.add(new StringTask()); |
945 |
|
l.add(new StringTask()); |
946 |
< |
List<Future<String>> result |
947 |
< |
= e.invokeAll(l, MEDIUM_DELAY_MS, MILLISECONDS); |
948 |
< |
assertEquals(2, result.size()); |
949 |
< |
for (Future<String> future : result) |
946 |
> |
List<Future<String>> futures |
947 |
> |
= e.invokeAll(l, MEDIUM_DELAY_MS, TimeUnit.MILLISECONDS); |
948 |
> |
assertEquals(2, futures.size()); |
949 |
> |
for (Future<String> future : futures) |
950 |
|
assertSame(TEST_STRING, future.get()); |
951 |
|
} finally { |
952 |
|
joinPool(e); |