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); |
183 |
|
try { |
184 |
|
new ForkJoinPool(-1); |
185 |
|
shouldThrow(); |
186 |
< |
} |
174 |
< |
catch (IllegalArgumentException success) {} |
186 |
> |
} catch (IllegalArgumentException success) {} |
187 |
|
} |
188 |
|
|
189 |
|
/** |
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) { |
185 |
< |
} |
196 |
> |
} catch (NullPointerException success) {} |
197 |
|
} |
198 |
|
|
199 |
|
|
211 |
|
} |
212 |
|
|
213 |
|
/** |
203 |
– |
* setParallelism changes reported parallelism level. |
204 |
– |
*/ |
205 |
– |
public void testSetParallelism() { |
206 |
– |
ForkJoinPool p = null; |
207 |
– |
try { |
208 |
– |
p = new ForkJoinPool(1); |
209 |
– |
assertTrue(p.getParallelism() == 1); |
210 |
– |
p.setParallelism(2); |
211 |
– |
assertTrue(p.getParallelism() == 2); |
212 |
– |
} finally { |
213 |
– |
joinPool(p); |
214 |
– |
} |
215 |
– |
} |
216 |
– |
|
217 |
– |
/** |
218 |
– |
* setParallelism with argument <= 0 throws exception |
219 |
– |
*/ |
220 |
– |
public void testSetParallelism2() { |
221 |
– |
ForkJoinPool p = null; |
222 |
– |
try { |
223 |
– |
p = new ForkJoinPool(1); |
224 |
– |
assertTrue(p.getParallelism() == 1); |
225 |
– |
p.setParallelism(-2); |
226 |
– |
shouldThrow(); |
227 |
– |
} catch (IllegalArgumentException success) { |
228 |
– |
} finally { |
229 |
– |
joinPool(p); |
230 |
– |
} |
231 |
– |
} |
232 |
– |
|
233 |
– |
/** |
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 |
|
/** |
250 |
– |
* setMaximumPoolSize changes size reported by getMaximumPoolSize. |
251 |
– |
*/ |
252 |
– |
public void testSetMaximumPoolSize() { |
253 |
– |
ForkJoinPool p = null; |
254 |
– |
try { |
255 |
– |
p = new ForkJoinPool(1); |
256 |
– |
p.setMaximumPoolSize(2); |
257 |
– |
assertTrue(p.getMaximumPoolSize() == 2); |
258 |
– |
} finally { |
259 |
– |
joinPool(p); |
260 |
– |
} |
261 |
– |
} |
262 |
– |
|
263 |
– |
/** |
264 |
– |
* setMaximumPoolSize with argument <= 0 throws exception |
265 |
– |
*/ |
266 |
– |
public void testSetMaximumPoolSize2() { |
267 |
– |
ForkJoinPool p = null; |
268 |
– |
try { |
269 |
– |
p = new ForkJoinPool(1); |
270 |
– |
p.setMaximumPoolSize(-2); |
271 |
– |
shouldThrow(); |
272 |
– |
} catch (IllegalArgumentException success) { |
273 |
– |
} finally { |
274 |
– |
joinPool(p); |
275 |
– |
} |
276 |
– |
} |
277 |
– |
|
278 |
– |
/** |
279 |
– |
* setMaintainsParallelism changes policy reported by |
280 |
– |
* getMaintainsParallelism. |
281 |
– |
*/ |
282 |
– |
public void testSetMaintainsParallelism() { |
283 |
– |
ForkJoinPool p = null; |
284 |
– |
try { |
285 |
– |
p = new ForkJoinPool(1); |
286 |
– |
p.setMaintainsParallelism(false); |
287 |
– |
assertFalse(p.getMaintainsParallelism()); |
288 |
– |
} finally { |
289 |
– |
joinPool(p); |
290 |
– |
} |
291 |
– |
} |
292 |
– |
|
293 |
– |
/** |
294 |
– |
* setAsyncMode changes policy reported by |
295 |
– |
* getAsyncMode. |
296 |
– |
*/ |
297 |
– |
public void testSetAsyncMode() { |
298 |
– |
ForkJoinPool p = null; |
299 |
– |
try { |
300 |
– |
p = new ForkJoinPool(1); |
301 |
– |
p.setAsyncMode(true); |
302 |
– |
assertTrue(p.getAsyncMode()); |
303 |
– |
} finally { |
304 |
– |
joinPool(p); |
305 |
– |
} |
306 |
– |
} |
307 |
– |
|
308 |
– |
/** |
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 { |
317 |
– |
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 |
|
/** |
330 |
– |
* setUncaughtExceptionHandler of null removes handler |
331 |
– |
*/ |
332 |
– |
public void testSetUncaughtExceptionHandler2() { |
333 |
– |
ForkJoinPool p = null; |
334 |
– |
try { |
335 |
– |
p = new ForkJoinPool(1); |
336 |
– |
p.setUncaughtExceptionHandler(null); |
337 |
– |
assertNull(p.getUncaughtExceptionHandler()); |
338 |
– |
} finally { |
339 |
– |
joinPool(p); |
340 |
– |
} |
341 |
– |
} |
342 |
– |
|
343 |
– |
|
344 |
– |
/** |
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()); |
358 |
– |
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); |
415 |
– |
assertTrue(p.getPoolSize() >= 4); |
320 |
|
int r = f.get(); |
321 |
< |
assertTrue(r == 832040); |
321 |
> |
assertTrue(r == 832040); |
322 |
|
} finally { |
323 |
< |
joinPool(p); |
323 |
> |
p.shutdownNow(); // don't wait out shutdown |
324 |
|
} |
325 |
|
} |
326 |
|
|
496 |
|
Object result = future.get(); |
497 |
|
shouldThrow(); |
498 |
|
} catch (ExecutionException success) { |
499 |
+ |
assertTrue(success.getCause() instanceof IndexOutOfBoundsException); |
500 |
|
} finally { |
501 |
|
Policy.setPolicy(savedPolicy); |
502 |
|
} |
511 |
|
TrackedShortRunnable task = null; |
512 |
|
Future<?> future = e.submit(task); |
513 |
|
shouldThrow(); |
514 |
< |
} catch (NullPointerException success) { |
610 |
< |
} |
514 |
> |
} catch (NullPointerException success) {} |
515 |
|
} |
516 |
|
|
517 |
|
|
524 |
|
StringTask t = null; |
525 |
|
Future<String> future = e.submit(t); |
526 |
|
shouldThrow(); |
527 |
< |
} catch (NullPointerException success) { |
624 |
< |
} |
527 |
> |
} catch (NullPointerException success) {} |
528 |
|
} |
529 |
|
|
530 |
|
|
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 |
< |
Thread.sleep(MEDIUM_DELAY_MS); |
542 |
> |
try { |
543 |
> |
Thread.sleep(MEDIUM_DELAY_MS); |
544 |
> |
} catch (InterruptedException ok) { |
545 |
> |
} |
546 |
|
return null; |
547 |
|
}}).get(); |
548 |
|
}}); |
550 |
|
t.start(); |
551 |
|
Thread.sleep(SHORT_DELAY_MS); |
552 |
|
t.interrupt(); |
553 |
+ |
t.join(); |
554 |
+ |
p.shutdownNow(); |
555 |
|
joinPool(p); |
556 |
|
} |
557 |
|
|
561 |
|
*/ |
562 |
|
public void testSubmitEE() throws Throwable { |
563 |
|
ForkJoinPool p = new ForkJoinPool(1); |
656 |
– |
|
564 |
|
try { |
565 |
< |
Callable c = new Callable() { |
566 |
< |
public Object call() { |
567 |
< |
int i = 5/0; |
568 |
< |
return Boolean.TRUE; |
569 |
< |
} |
663 |
< |
}; |
664 |
< |
|
665 |
< |
for (int i = 0; i < 5; i++) { |
666 |
< |
p.submit(c).get(); |
667 |
< |
} |
565 |
> |
p.submit(new Callable() { |
566 |
> |
public Object call() { |
567 |
> |
int i = 5/0; |
568 |
> |
return Boolean.TRUE; |
569 |
> |
}}).get(); |
570 |
|
shouldThrow(); |
571 |
|
} catch (ExecutionException success) { |
572 |
+ |
assertTrue(success.getCause() instanceof ArithmeticException); |
573 |
|
} |
574 |
+ |
|
575 |
|
joinPool(p); |
576 |
|
} |
577 |
|
|
604 |
|
} |
605 |
|
|
606 |
|
/** |
607 |
< |
* invokeAny(c) throws NullPointerException if c has null elements |
607 |
> |
* invokeAny(c) throws NullPointerException if c has a single null element |
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 { |
708 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
709 |
– |
l.add(new StringTask()); |
710 |
– |
l.add(null); |
614 |
|
e.invokeAny(l); |
615 |
|
shouldThrow(); |
616 |
|
} catch (NullPointerException success) { |
620 |
|
} |
621 |
|
|
622 |
|
/** |
623 |
< |
* invokeAny(c) throws ExecutionException if no task in c completes |
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 { |
632 |
+ |
e.invokeAny(l); |
633 |
+ |
shouldThrow(); |
634 |
+ |
} catch (NullPointerException success) { |
635 |
+ |
} finally { |
636 |
+ |
latch.countDown(); |
637 |
+ |
joinPool(e); |
638 |
+ |
} |
639 |
+ |
} |
640 |
+ |
|
641 |
+ |
/** |
642 |
+ |
* invokeAny(c) throws ExecutionException if no task in c completes |
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 { |
725 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
726 |
– |
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 |
|
} |
658 |
|
/** |
659 |
|
* invokeAny(c) returns result of some task in c if at least one completes |
660 |
|
*/ |
661 |
< |
public void testInvokeAny5() throws Throwable { |
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 { |
785 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
786 |
– |
l.add(new StringTask()); |
787 |
– |
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>>(); |
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(); |
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 { |
855 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
856 |
– |
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>>(); |
887 |
< |
l.add(new StringTask()); |
888 |
< |
l.add(null); |
889 |
< |
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>>(); |
904 |
< |
l.add(new NPETask()); |
905 |
< |
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); |
834 |
|
} finally { |
835 |
|
joinPool(e); |
836 |
|
} |
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 { |
949 |
– |
ArrayList<Callable<String>> l = new ArrayList<Callable<String>>(); |
950 |
– |
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>>(); |
981 |
< |
l.add(new StringTask()); |
982 |
< |
l.add(null); |
983 |
< |
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>>(); |
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(); |
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); |