ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ForkJoinTaskTest.java
Revision: 1.27
Committed: Mon Nov 22 07:50:50 2010 UTC (13 years, 5 months ago) by jsr166
Branch: MAIN
Changes since 1.26: +1 -0 lines
Log Message:
small improvement to testSetRawResult

File Contents

# Content
1 /*
2 * Written by Doug Lea with assistance from members of JCP JSR-166
3 * Expert Group and released to the public domain, as explained at
4 * http://creativecommons.org/licenses/publicdomain
5 */
6 import java.util.concurrent.ExecutionException;
7 import java.util.concurrent.CancellationException;
8 import java.util.concurrent.ForkJoinPool;
9 import java.util.concurrent.ForkJoinTask;
10 import java.util.concurrent.ForkJoinWorkerThread;
11 import java.util.concurrent.RecursiveAction;
12 import java.util.concurrent.TimeUnit;
13 import java.util.concurrent.TimeoutException;
14 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
15 import static java.util.concurrent.TimeUnit.MILLISECONDS;
16 import static java.util.concurrent.TimeUnit.SECONDS;
17 import java.util.HashSet;
18 import junit.framework.*;
19
20 public class ForkJoinTaskTest extends JSR166TestCase {
21
22 public static void main(String[] args) {
23 junit.textui.TestRunner.run(suite());
24 }
25
26 public static Test suite() {
27 return new TestSuite(ForkJoinTaskTest.class);
28 }
29
30 // Runs with "mainPool" use > 1 thread. singletonPool tests use 1
31 static final int mainPoolSize =
32 Math.max(2, Runtime.getRuntime().availableProcessors());
33
34 private static ForkJoinPool mainPool() {
35 return new ForkJoinPool(mainPoolSize);
36 }
37
38 private static ForkJoinPool singletonPool() {
39 return new ForkJoinPool(1);
40 }
41
42 private static ForkJoinPool asyncSingletonPool() {
43 return new ForkJoinPool(1,
44 ForkJoinPool.defaultForkJoinWorkerThreadFactory,
45 null, true);
46 }
47
48 private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
49 try {
50 assertFalse(a.isDone());
51 assertFalse(a.isCompletedNormally());
52 assertFalse(a.isCompletedAbnormally());
53 assertFalse(a.isCancelled());
54 assertNull(a.getException());
55 assertNull(a.getRawResult());
56
57 assertNull(pool.invoke(a));
58
59 assertTrue(a.isDone());
60 assertTrue(a.isCompletedNormally());
61 assertFalse(a.isCompletedAbnormally());
62 assertFalse(a.isCancelled());
63 assertNull(a.getException());
64 assertNull(a.getRawResult());
65 } finally {
66 joinPool(pool);
67 }
68 }
69
70 void checkNotDone(ForkJoinTask a) {
71 assertFalse(a.isDone());
72 assertFalse(a.isCompletedNormally());
73 assertFalse(a.isCompletedAbnormally());
74 assertFalse(a.isCancelled());
75 assertNull(a.getException());
76 assertNull(a.getRawResult());
77
78 try {
79 a.get(0L, SECONDS);
80 shouldThrow();
81 } catch (TimeoutException success) {
82 } catch (Throwable fail) { threadUnexpectedException(fail); }
83 }
84
85 <T> void checkCompletedNormally(ForkJoinTask<T> a) {
86 checkCompletedNormally(a, null);
87 }
88
89 <T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
90 assertTrue(a.isDone());
91 assertFalse(a.isCancelled());
92 assertTrue(a.isCompletedNormally());
93 assertFalse(a.isCompletedAbnormally());
94 assertNull(a.getException());
95 assertSame(expected, a.getRawResult());
96 assertSame(expected, a.join());
97 assertFalse(a.cancel(false));
98 assertFalse(a.cancel(true));
99 try {
100 assertSame(expected, a.get());
101 } catch (Throwable fail) { threadUnexpectedException(fail); }
102 try {
103 assertSame(expected, a.get(5L, SECONDS));
104 } catch (Throwable fail) { threadUnexpectedException(fail); }
105 }
106
107 void checkCancelled(ForkJoinTask a) {
108 assertTrue(a.isDone());
109 assertTrue(a.isCancelled());
110 assertFalse(a.isCompletedNormally());
111 assertTrue(a.isCompletedAbnormally());
112 assertTrue(a.getException() instanceof CancellationException);
113 assertNull(a.getRawResult());
114 assertTrue(a.cancel(false));
115 assertTrue(a.cancel(true));
116
117 try {
118 a.join();
119 shouldThrow();
120 } catch (CancellationException success) {
121 } catch (Throwable fail) { threadUnexpectedException(fail); }
122
123 try {
124 a.get();
125 shouldThrow();
126 } catch (CancellationException success) {
127 } catch (Throwable fail) { threadUnexpectedException(fail); }
128
129 try {
130 a.get(5L, SECONDS);
131 shouldThrow();
132 } catch (CancellationException success) {
133 } catch (Throwable fail) { threadUnexpectedException(fail); }
134 }
135
136 void checkCompletedAbnormally(ForkJoinTask a, Throwable t) {
137 assertTrue(a.isDone());
138 assertFalse(a.isCancelled());
139 assertFalse(a.isCompletedNormally());
140 assertTrue(a.isCompletedAbnormally());
141 assertSame(t, a.getException());
142 assertNull(a.getRawResult());
143 assertFalse(a.cancel(false));
144 assertFalse(a.cancel(true));
145
146 try {
147 a.join();
148 shouldThrow();
149 } catch (Throwable expected) {
150 assertSame(t, expected);
151 }
152
153 try {
154 a.get();
155 shouldThrow();
156 } catch (ExecutionException success) {
157 assertSame(t, success.getCause());
158 } catch (Throwable fail) { threadUnexpectedException(fail); }
159
160 try {
161 a.get(5L, SECONDS);
162 shouldThrow();
163 } catch (ExecutionException success) {
164 assertSame(t, success.getCause());
165 } catch (Throwable fail) { threadUnexpectedException(fail); }
166 }
167
168 /*
169 * Testing coverage notes:
170 *
171 * To test extension methods and overrides, most tests use
172 * BinaryAsyncAction extension class that processes joins
173 * differently than supplied Recursive forms.
174 */
175
176 static final class FJException extends RuntimeException {
177 FJException() { super(); }
178 }
179
180 abstract static class BinaryAsyncAction extends ForkJoinTask<Void> {
181 private volatile int controlState;
182
183 static final AtomicIntegerFieldUpdater<BinaryAsyncAction> controlStateUpdater =
184 AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
185 "controlState");
186
187 private BinaryAsyncAction parent;
188
189 private BinaryAsyncAction sibling;
190
191 protected BinaryAsyncAction() {
192 }
193
194 public final Void getRawResult() { return null; }
195 protected final void setRawResult(Void mustBeNull) { }
196
197 public final void linkSubtasks(BinaryAsyncAction x, BinaryAsyncAction y) {
198 x.parent = y.parent = this;
199 x.sibling = y;
200 y.sibling = x;
201 }
202
203 protected void onComplete(BinaryAsyncAction x, BinaryAsyncAction y) {
204 }
205
206 protected boolean onException() {
207 return true;
208 }
209
210 public void linkAndForkSubtasks(BinaryAsyncAction x, BinaryAsyncAction y) {
211 linkSubtasks(x, y);
212 y.fork();
213 x.fork();
214 }
215
216 private void completeThis() {
217 super.complete(null);
218 }
219
220 private void completeThisExceptionally(Throwable ex) {
221 super.completeExceptionally(ex);
222 }
223
224 public final void complete() {
225 BinaryAsyncAction a = this;
226 for (;;) {
227 BinaryAsyncAction s = a.sibling;
228 BinaryAsyncAction p = a.parent;
229 a.sibling = null;
230 a.parent = null;
231 a.completeThis();
232 if (p == null || p.compareAndSetControlState(0, 1))
233 break;
234 try {
235 p.onComplete(a, s);
236 } catch (Throwable rex) {
237 p.completeExceptionally(rex);
238 return;
239 }
240 a = p;
241 }
242 }
243
244 public final void completeExceptionally(Throwable ex) {
245 BinaryAsyncAction a = this;
246 while (!a.isCompletedAbnormally()) {
247 a.completeThisExceptionally(ex);
248 BinaryAsyncAction s = a.sibling;
249 if (s != null)
250 s.cancel(false);
251 if (!a.onException() || (a = a.parent) == null)
252 break;
253 }
254 }
255
256 public final BinaryAsyncAction getParent() {
257 return parent;
258 }
259
260 public BinaryAsyncAction getSibling() {
261 return sibling;
262 }
263
264 public void reinitialize() {
265 parent = sibling = null;
266 super.reinitialize();
267 }
268
269 protected final int getControlState() {
270 return controlState;
271 }
272
273 protected final boolean compareAndSetControlState(int expect,
274 int update) {
275 return controlStateUpdater.compareAndSet(this, expect, update);
276 }
277
278 protected final void setControlState(int value) {
279 controlState = value;
280 }
281
282 protected final void incrementControlState() {
283 controlStateUpdater.incrementAndGet(this);
284 }
285
286 protected final void decrementControlState() {
287 controlStateUpdater.decrementAndGet(this);
288 }
289
290 }
291
292 static final class AsyncFib extends BinaryAsyncAction {
293 int number;
294 public AsyncFib(int n) {
295 this.number = n;
296 }
297
298 public final boolean exec() {
299 AsyncFib f = this;
300 int n = f.number;
301 if (n > 1) {
302 while (n > 1) {
303 AsyncFib p = f;
304 AsyncFib r = new AsyncFib(n - 2);
305 f = new AsyncFib(--n);
306 p.linkSubtasks(r, f);
307 r.fork();
308 }
309 f.number = n;
310 }
311 f.complete();
312 return false;
313 }
314
315 protected void onComplete(BinaryAsyncAction x, BinaryAsyncAction y) {
316 number = ((AsyncFib)x).number + ((AsyncFib)y).number;
317 }
318 }
319
320
321 static final class FailingAsyncFib extends BinaryAsyncAction {
322 int number;
323 public FailingAsyncFib(int n) {
324 this.number = n;
325 }
326
327 public final boolean exec() {
328 FailingAsyncFib f = this;
329 int n = f.number;
330 if (n > 1) {
331 while (n > 1) {
332 FailingAsyncFib p = f;
333 FailingAsyncFib r = new FailingAsyncFib(n - 2);
334 f = new FailingAsyncFib(--n);
335 p.linkSubtasks(r, f);
336 r.fork();
337 }
338 f.number = n;
339 }
340 f.complete();
341 return false;
342 }
343
344 protected void onComplete(BinaryAsyncAction x, BinaryAsyncAction y) {
345 completeExceptionally(new FJException());
346 }
347 }
348
349 /**
350 * invoke returns when task completes normally.
351 * isCompletedAbnormally and isCancelled return false for normally
352 * completed tasks; getRawResult returns null.
353 */
354 public void testInvoke() {
355 RecursiveAction a = new CheckedRecursiveAction() {
356 public void realCompute() {
357 AsyncFib f = new AsyncFib(8);
358 assertNull(f.invoke());
359 assertEquals(21, f.number);
360 checkCompletedNormally(f);
361 }};
362 testInvokeOnPool(mainPool(), a);
363 }
364
365 /**
366 * quietlyInvoke task returns when task completes normally.
367 * isCompletedAbnormally and isCancelled return false for normally
368 * completed tasks
369 */
370 public void testQuietlyInvoke() {
371 RecursiveAction a = new CheckedRecursiveAction() {
372 public void realCompute() {
373 AsyncFib f = new AsyncFib(8);
374 f.quietlyInvoke();
375 assertEquals(21, f.number);
376 checkCompletedNormally(f);
377 }};
378 testInvokeOnPool(mainPool(), a);
379 }
380
381 /**
382 * join of a forked task returns when task completes
383 */
384 public void testForkJoin() {
385 RecursiveAction a = new CheckedRecursiveAction() {
386 public void realCompute() {
387 AsyncFib f = new AsyncFib(8);
388 assertSame(f, f.fork());
389 assertNull(f.join());
390 assertEquals(21, f.number);
391 checkCompletedNormally(f);
392 }};
393 testInvokeOnPool(mainPool(), a);
394 }
395
396 /**
397 * get of a forked task returns when task completes
398 */
399 public void testForkGet() {
400 RecursiveAction a = new CheckedRecursiveAction() {
401 public void realCompute() throws Exception {
402 AsyncFib f = new AsyncFib(8);
403 assertSame(f, f.fork());
404 assertNull(f.get());
405 assertEquals(21, f.number);
406 checkCompletedNormally(f);
407 }};
408 testInvokeOnPool(mainPool(), a);
409 }
410
411 /**
412 * timed get of a forked task returns when task completes
413 */
414 public void testForkTimedGet() {
415 RecursiveAction a = new CheckedRecursiveAction() {
416 public void realCompute() throws Exception {
417 AsyncFib f = new AsyncFib(8);
418 assertSame(f, f.fork());
419 assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
420 assertEquals(21, f.number);
421 checkCompletedNormally(f);
422 }};
423 testInvokeOnPool(mainPool(), a);
424 }
425
426 /**
427 * timed get with null time unit throws NPE
428 */
429 public void testForkTimedGetNPE() {
430 RecursiveAction a = new CheckedRecursiveAction() {
431 public void realCompute() throws Exception {
432 AsyncFib f = new AsyncFib(8);
433 assertSame(f, f.fork());
434 try {
435 f.get(5L, null);
436 shouldThrow();
437 } catch (NullPointerException success) {}
438 }};
439 testInvokeOnPool(mainPool(), a);
440 }
441
442 /**
443 * quietlyJoin of a forked task returns when task completes
444 */
445 public void testForkQuietlyJoin() {
446 RecursiveAction a = new CheckedRecursiveAction() {
447 public void realCompute() {
448 AsyncFib f = new AsyncFib(8);
449 assertSame(f, f.fork());
450 f.quietlyJoin();
451 assertEquals(21, f.number);
452 checkCompletedNormally(f);
453 }};
454 testInvokeOnPool(mainPool(), a);
455 }
456
457
458 /**
459 * helpQuiesce returns when tasks are complete.
460 * getQueuedTaskCount returns 0 when quiescent
461 */
462 public void testForkHelpQuiesce() {
463 RecursiveAction a = new CheckedRecursiveAction() {
464 public void realCompute() {
465 AsyncFib f = new AsyncFib(8);
466 assertSame(f, f.fork());
467 f.helpQuiesce();
468 assertEquals(21, f.number);
469 assertEquals(0, getQueuedTaskCount());
470 checkCompletedNormally(f);
471 }};
472 testInvokeOnPool(mainPool(), a);
473 }
474
475
476 /**
477 * invoke task throws exception when task completes abnormally
478 */
479 public void testAbnormalInvoke() {
480 RecursiveAction a = new CheckedRecursiveAction() {
481 public void realCompute() {
482 FailingAsyncFib f = new FailingAsyncFib(8);
483 try {
484 f.invoke();
485 shouldThrow();
486 } catch (FJException success) {
487 checkCompletedAbnormally(f, success);
488 }
489 }};
490 testInvokeOnPool(mainPool(), a);
491 }
492
493 /**
494 * quietlyInvoke task returns when task completes abnormally
495 */
496 public void testAbnormalQuietlyInvoke() {
497 RecursiveAction a = new CheckedRecursiveAction() {
498 public void realCompute() {
499 FailingAsyncFib f = new FailingAsyncFib(8);
500 f.quietlyInvoke();
501 assertTrue(f.getException() instanceof FJException);
502 checkCompletedAbnormally(f, f.getException());
503 }};
504 testInvokeOnPool(mainPool(), a);
505 }
506
507 /**
508 * join of a forked task throws exception when task completes abnormally
509 */
510 public void testAbnormalForkJoin() {
511 RecursiveAction a = new CheckedRecursiveAction() {
512 public void realCompute() {
513 FailingAsyncFib f = new FailingAsyncFib(8);
514 assertSame(f, f.fork());
515 try {
516 f.join();
517 shouldThrow();
518 } catch (FJException success) {
519 checkCompletedAbnormally(f, success);
520 }
521 }};
522 testInvokeOnPool(mainPool(), a);
523 }
524
525 /**
526 * get of a forked task throws exception when task completes abnormally
527 */
528 public void testAbnormalForkGet() {
529 RecursiveAction a = new CheckedRecursiveAction() {
530 public void realCompute() throws Exception {
531 FailingAsyncFib f = new FailingAsyncFib(8);
532 assertSame(f, f.fork());
533 try {
534 f.get();
535 shouldThrow();
536 } catch (ExecutionException success) {
537 Throwable cause = success.getCause();
538 assertTrue(cause instanceof FJException);
539 checkCompletedAbnormally(f, cause);
540 }
541 }};
542 testInvokeOnPool(mainPool(), a);
543 }
544
545 /**
546 * timed get of a forked task throws exception when task completes abnormally
547 */
548 public void testAbnormalForkTimedGet() {
549 RecursiveAction a = new CheckedRecursiveAction() {
550 public void realCompute() throws Exception {
551 FailingAsyncFib f = new FailingAsyncFib(8);
552 assertSame(f, f.fork());
553 try {
554 f.get(LONG_DELAY_MS, MILLISECONDS);
555 shouldThrow();
556 } catch (ExecutionException success) {
557 Throwable cause = success.getCause();
558 assertTrue(cause instanceof FJException);
559 checkCompletedAbnormally(f, cause);
560 }
561 }};
562 testInvokeOnPool(mainPool(), a);
563 }
564
565 /**
566 * quietlyJoin of a forked task returns when task completes abnormally
567 */
568 public void testAbnormalForkQuietlyJoin() {
569 RecursiveAction a = new CheckedRecursiveAction() {
570 public void realCompute() {
571 FailingAsyncFib f = new FailingAsyncFib(8);
572 assertSame(f, f.fork());
573 f.quietlyJoin();
574 assertTrue(f.getException() instanceof FJException);
575 checkCompletedAbnormally(f, f.getException());
576 }};
577 testInvokeOnPool(mainPool(), a);
578 }
579
580 /**
581 * invoke task throws exception when task cancelled
582 */
583 public void testCancelledInvoke() {
584 RecursiveAction a = new CheckedRecursiveAction() {
585 public void realCompute() {
586 AsyncFib f = new AsyncFib(8);
587 assertTrue(f.cancel(true));
588 try {
589 f.invoke();
590 shouldThrow();
591 } catch (CancellationException success) {
592 checkCancelled(f);
593 }
594 }};
595 testInvokeOnPool(mainPool(), a);
596 }
597
598 /**
599 * join of a forked task throws exception when task cancelled
600 */
601 public void testCancelledForkJoin() {
602 RecursiveAction a = new CheckedRecursiveAction() {
603 public void realCompute() {
604 AsyncFib f = new AsyncFib(8);
605 assertTrue(f.cancel(true));
606 assertSame(f, f.fork());
607 try {
608 f.join();
609 shouldThrow();
610 } catch (CancellationException success) {
611 checkCancelled(f);
612 }
613 }};
614 testInvokeOnPool(mainPool(), a);
615 }
616
617 /**
618 * get of a forked task throws exception when task cancelled
619 */
620 public void testCancelledForkGet() {
621 RecursiveAction a = new CheckedRecursiveAction() {
622 public void realCompute() throws Exception {
623 AsyncFib f = new AsyncFib(8);
624 assertTrue(f.cancel(true));
625 assertSame(f, f.fork());
626 try {
627 f.get();
628 shouldThrow();
629 } catch (CancellationException success) {
630 checkCancelled(f);
631 }
632 }};
633 testInvokeOnPool(mainPool(), a);
634 }
635
636 /**
637 * timed get of a forked task throws exception when task cancelled
638 */
639 public void testCancelledForkTimedGet() throws Exception {
640 RecursiveAction a = new CheckedRecursiveAction() {
641 public void realCompute() throws Exception {
642 AsyncFib f = new AsyncFib(8);
643 assertTrue(f.cancel(true));
644 assertSame(f, f.fork());
645 try {
646 f.get(LONG_DELAY_MS, MILLISECONDS);
647 shouldThrow();
648 } catch (CancellationException success) {
649 checkCancelled(f);
650 }
651 }};
652 testInvokeOnPool(mainPool(), a);
653 }
654
655 /**
656 * quietlyJoin of a forked task returns when task cancelled
657 */
658 public void testCancelledForkQuietlyJoin() {
659 RecursiveAction a = new CheckedRecursiveAction() {
660 public void realCompute() {
661 AsyncFib f = new AsyncFib(8);
662 assertTrue(f.cancel(true));
663 assertSame(f, f.fork());
664 f.quietlyJoin();
665 checkCancelled(f);
666 }};
667 testInvokeOnPool(mainPool(), a);
668 }
669
670 /**
671 * getPool of executing task returns its pool
672 */
673 public void testGetPool() {
674 final ForkJoinPool mainPool = mainPool();
675 RecursiveAction a = new CheckedRecursiveAction() {
676 public void realCompute() {
677 assertSame(mainPool, getPool());
678 }};
679 testInvokeOnPool(mainPool, a);
680 }
681
682 /**
683 * getPool of non-FJ task returns null
684 */
685 public void testGetPool2() {
686 RecursiveAction a = new CheckedRecursiveAction() {
687 public void realCompute() {
688 assertNull(getPool());
689 }};
690 assertNull(a.invoke());
691 }
692
693 /**
694 * inForkJoinPool of executing task returns true
695 */
696 public void testInForkJoinPool() {
697 RecursiveAction a = new CheckedRecursiveAction() {
698 public void realCompute() {
699 assertTrue(inForkJoinPool());
700 }};
701 testInvokeOnPool(mainPool(), a);
702 }
703
704 /**
705 * inForkJoinPool of non-FJ task returns false
706 */
707 public void testInForkJoinPool2() {
708 RecursiveAction a = new CheckedRecursiveAction() {
709 public void realCompute() {
710 assertFalse(inForkJoinPool());
711 }};
712 assertNull(a.invoke());
713 }
714
715 /**
716 * setRawResult(null) succeeds
717 */
718 public void testSetRawResult() {
719 RecursiveAction a = new CheckedRecursiveAction() {
720 public void realCompute() {
721 setRawResult(null);
722 assertNull(getRawResult());
723 }};
724 assertNull(a.invoke());
725 }
726
727 /**
728 * invoke task throws exception after invoking completeExceptionally
729 */
730 public void testCompleteExceptionally() {
731 RecursiveAction a = new CheckedRecursiveAction() {
732 public void realCompute() {
733 AsyncFib f = new AsyncFib(8);
734 f.completeExceptionally(new FJException());
735 try {
736 f.invoke();
737 shouldThrow();
738 } catch (FJException success) {
739 checkCompletedAbnormally(f, success);
740 }
741 }};
742 testInvokeOnPool(mainPool(), a);
743 }
744
745 /**
746 * invokeAll(t1, t2) invokes all task arguments
747 */
748 public void testInvokeAll2() {
749 RecursiveAction a = new CheckedRecursiveAction() {
750 public void realCompute() {
751 AsyncFib f = new AsyncFib(8);
752 AsyncFib g = new AsyncFib(9);
753 invokeAll(f, g);
754 assertEquals(21, f.number);
755 assertEquals(34, g.number);
756 checkCompletedNormally(f);
757 checkCompletedNormally(g);
758 }};
759 testInvokeOnPool(mainPool(), a);
760 }
761
762 /**
763 * invokeAll(tasks) with 1 argument invokes task
764 */
765 public void testInvokeAll1() {
766 RecursiveAction a = new CheckedRecursiveAction() {
767 public void realCompute() {
768 AsyncFib f = new AsyncFib(8);
769 invokeAll(f);
770 checkCompletedNormally(f);
771 assertEquals(21, f.number);
772 }};
773 testInvokeOnPool(mainPool(), a);
774 }
775
776 /**
777 * invokeAll(tasks) with > 2 argument invokes tasks
778 */
779 public void testInvokeAll3() {
780 RecursiveAction a = new CheckedRecursiveAction() {
781 public void realCompute() {
782 AsyncFib f = new AsyncFib(8);
783 AsyncFib g = new AsyncFib(9);
784 AsyncFib h = new AsyncFib(7);
785 invokeAll(f, g, h);
786 assertEquals(21, f.number);
787 assertEquals(34, g.number);
788 assertEquals(13, h.number);
789 checkCompletedNormally(f);
790 checkCompletedNormally(g);
791 checkCompletedNormally(h);
792 }};
793 testInvokeOnPool(mainPool(), a);
794 }
795
796 /**
797 * invokeAll(collection) invokes all tasks in the collection
798 */
799 public void testInvokeAllCollection() {
800 RecursiveAction a = new CheckedRecursiveAction() {
801 public void realCompute() {
802 AsyncFib f = new AsyncFib(8);
803 AsyncFib g = new AsyncFib(9);
804 AsyncFib h = new AsyncFib(7);
805 HashSet set = new HashSet();
806 set.add(f);
807 set.add(g);
808 set.add(h);
809 invokeAll(set);
810 assertEquals(21, f.number);
811 assertEquals(34, g.number);
812 assertEquals(13, h.number);
813 checkCompletedNormally(f);
814 checkCompletedNormally(g);
815 checkCompletedNormally(h);
816 }};
817 testInvokeOnPool(mainPool(), a);
818 }
819
820
821 /**
822 * invokeAll(tasks) with any null task throws NPE
823 */
824 public void testInvokeAllNPE() {
825 RecursiveAction a = new CheckedRecursiveAction() {
826 public void realCompute() {
827 AsyncFib f = new AsyncFib(8);
828 AsyncFib g = new AsyncFib(9);
829 AsyncFib h = null;
830 try {
831 invokeAll(f, g, h);
832 shouldThrow();
833 } catch (NullPointerException success) {}
834 }};
835 testInvokeOnPool(mainPool(), a);
836 }
837
838 /**
839 * invokeAll(t1, t2) throw exception if any task does
840 */
841 public void testAbnormalInvokeAll2() {
842 RecursiveAction a = new CheckedRecursiveAction() {
843 public void realCompute() {
844 AsyncFib f = new AsyncFib(8);
845 FailingAsyncFib g = new FailingAsyncFib(9);
846 try {
847 invokeAll(f, g);
848 shouldThrow();
849 } catch (FJException success) {
850 checkCompletedAbnormally(g, success);
851 }
852 }};
853 testInvokeOnPool(mainPool(), a);
854 }
855
856 /**
857 * invokeAll(tasks) with 1 argument throws exception if task does
858 */
859 public void testAbnormalInvokeAll1() {
860 RecursiveAction a = new CheckedRecursiveAction() {
861 public void realCompute() {
862 FailingAsyncFib g = new FailingAsyncFib(9);
863 try {
864 invokeAll(g);
865 shouldThrow();
866 } catch (FJException success) {
867 checkCompletedAbnormally(g, success);
868 }
869 }};
870 testInvokeOnPool(mainPool(), a);
871 }
872
873 /**
874 * invokeAll(tasks) with > 2 argument throws exception if any task does
875 */
876 public void testAbnormalInvokeAll3() {
877 RecursiveAction a = new CheckedRecursiveAction() {
878 public void realCompute() {
879 AsyncFib f = new AsyncFib(8);
880 FailingAsyncFib g = new FailingAsyncFib(9);
881 AsyncFib h = new AsyncFib(7);
882 try {
883 invokeAll(f, g, h);
884 shouldThrow();
885 } catch (FJException success) {
886 checkCompletedAbnormally(g, success);
887 }
888 }};
889 testInvokeOnPool(mainPool(), a);
890 }
891
892 /**
893 * invokeAll(collection) throws exception if any task does
894 */
895 public void testAbnormalInvokeAllCollection() {
896 RecursiveAction a = new CheckedRecursiveAction() {
897 public void realCompute() {
898 FailingAsyncFib f = new FailingAsyncFib(8);
899 AsyncFib g = new AsyncFib(9);
900 AsyncFib h = new AsyncFib(7);
901 HashSet set = new HashSet();
902 set.add(f);
903 set.add(g);
904 set.add(h);
905 try {
906 invokeAll(set);
907 shouldThrow();
908 } catch (FJException success) {
909 checkCompletedAbnormally(f, success);
910 }
911 }};
912 testInvokeOnPool(mainPool(), a);
913 }
914
915 /**
916 * tryUnfork returns true for most recent unexecuted task,
917 * and suppresses execution
918 */
919 public void testTryUnfork() {
920 RecursiveAction a = new CheckedRecursiveAction() {
921 public void realCompute() {
922 AsyncFib g = new AsyncFib(9);
923 assertSame(g, g.fork());
924 AsyncFib f = new AsyncFib(8);
925 assertSame(f, f.fork());
926 assertTrue(f.tryUnfork());
927 helpQuiesce();
928 checkNotDone(f);
929 checkCompletedNormally(g);
930 }};
931 testInvokeOnPool(singletonPool(), a);
932 }
933
934 /**
935 * getSurplusQueuedTaskCount returns > 0 when
936 * there are more tasks than threads
937 */
938 public void testGetSurplusQueuedTaskCount() {
939 RecursiveAction a = new CheckedRecursiveAction() {
940 public void realCompute() {
941 AsyncFib h = new AsyncFib(7);
942 assertSame(h, h.fork());
943 AsyncFib g = new AsyncFib(9);
944 assertSame(g, g.fork());
945 AsyncFib f = new AsyncFib(8);
946 assertSame(f, f.fork());
947 assertTrue(getSurplusQueuedTaskCount() > 0);
948 helpQuiesce();
949 assertEquals(0, getSurplusQueuedTaskCount());
950 checkCompletedNormally(f);
951 checkCompletedNormally(g);
952 checkCompletedNormally(h);
953 }};
954 testInvokeOnPool(singletonPool(), a);
955 }
956
957 /**
958 * peekNextLocalTask returns most recent unexecuted task.
959 */
960 public void testPeekNextLocalTask() {
961 RecursiveAction a = new CheckedRecursiveAction() {
962 public void realCompute() {
963 AsyncFib g = new AsyncFib(9);
964 assertSame(g, g.fork());
965 AsyncFib f = new AsyncFib(8);
966 assertSame(f, f.fork());
967 assertSame(f, peekNextLocalTask());
968 assertNull(f.join());
969 checkCompletedNormally(f);
970 helpQuiesce();
971 checkCompletedNormally(g);
972 }};
973 testInvokeOnPool(singletonPool(), a);
974 }
975
976 /**
977 * pollNextLocalTask returns most recent unexecuted task without
978 * executing it
979 */
980 public void testPollNextLocalTask() {
981 RecursiveAction a = new CheckedRecursiveAction() {
982 public void realCompute() {
983 AsyncFib g = new AsyncFib(9);
984 assertSame(g, g.fork());
985 AsyncFib f = new AsyncFib(8);
986 assertSame(f, f.fork());
987 assertSame(f, pollNextLocalTask());
988 helpQuiesce();
989 checkNotDone(f);
990 assertEquals(34, g.number);
991 checkCompletedNormally(g);
992 }};
993 testInvokeOnPool(singletonPool(), a);
994 }
995
996 /**
997 * pollTask returns an unexecuted task without executing it
998 */
999 public void testPollTask() {
1000 RecursiveAction a = new CheckedRecursiveAction() {
1001 public void realCompute() {
1002 AsyncFib g = new AsyncFib(9);
1003 assertSame(g, g.fork());
1004 AsyncFib f = new AsyncFib(8);
1005 assertSame(f, f.fork());
1006 assertSame(f, pollTask());
1007 helpQuiesce();
1008 checkNotDone(f);
1009 checkCompletedNormally(g);
1010 }};
1011 testInvokeOnPool(singletonPool(), a);
1012 }
1013
1014 /**
1015 * peekNextLocalTask returns least recent unexecuted task in async mode
1016 */
1017 public void testPeekNextLocalTaskAsync() {
1018 RecursiveAction a = new CheckedRecursiveAction() {
1019 public void realCompute() {
1020 AsyncFib g = new AsyncFib(9);
1021 assertSame(g, g.fork());
1022 AsyncFib f = new AsyncFib(8);
1023 assertSame(f, f.fork());
1024 assertSame(g, peekNextLocalTask());
1025 assertNull(f.join());
1026 helpQuiesce();
1027 checkCompletedNormally(f);
1028 assertEquals(34, g.number);
1029 checkCompletedNormally(g);
1030 }};
1031 testInvokeOnPool(asyncSingletonPool(), a);
1032 }
1033
1034 /**
1035 * pollNextLocalTask returns least recent unexecuted task without
1036 * executing it, in async mode
1037 */
1038 public void testPollNextLocalTaskAsync() {
1039 RecursiveAction a = new CheckedRecursiveAction() {
1040 public void realCompute() {
1041 AsyncFib g = new AsyncFib(9);
1042 assertSame(g, g.fork());
1043 AsyncFib f = new AsyncFib(8);
1044 assertSame(f, f.fork());
1045 assertSame(g, pollNextLocalTask());
1046 helpQuiesce();
1047 assertEquals(21, f.number);
1048 checkCompletedNormally(f);
1049 checkNotDone(g);
1050 }};
1051 testInvokeOnPool(asyncSingletonPool(), a);
1052 }
1053
1054 /**
1055 * pollTask returns an unexecuted task without executing it, in
1056 * async mode
1057 */
1058 public void testPollTaskAsync() {
1059 RecursiveAction a = new CheckedRecursiveAction() {
1060 public void realCompute() {
1061 AsyncFib g = new AsyncFib(9);
1062 assertSame(g, g.fork());
1063 AsyncFib f = new AsyncFib(8);
1064 assertSame(f, f.fork());
1065 assertSame(g, pollTask());
1066 helpQuiesce();
1067 assertEquals(21, f.number);
1068 checkCompletedNormally(f);
1069 checkNotDone(g);
1070 }};
1071 testInvokeOnPool(asyncSingletonPool(), a);
1072 }
1073
1074 // versions for singleton pools
1075
1076 /**
1077 * invoke returns when task completes normally.
1078 * isCompletedAbnormally and isCancelled return false for normally
1079 * completed tasks; getRawResult returns null.
1080 */
1081 public void testInvokeSingleton() {
1082 RecursiveAction a = new CheckedRecursiveAction() {
1083 public void realCompute() {
1084 AsyncFib f = new AsyncFib(8);
1085 assertNull(f.invoke());
1086 assertEquals(21, f.number);
1087 checkCompletedNormally(f);
1088 }};
1089 testInvokeOnPool(singletonPool(), a);
1090 }
1091
1092 /**
1093 * quietlyInvoke task returns when task completes normally.
1094 * isCompletedAbnormally and isCancelled return false for normally
1095 * completed tasks
1096 */
1097 public void testQuietlyInvokeSingleton() {
1098 RecursiveAction a = new CheckedRecursiveAction() {
1099 public void realCompute() {
1100 AsyncFib f = new AsyncFib(8);
1101 f.quietlyInvoke();
1102 assertEquals(21, f.number);
1103 checkCompletedNormally(f);
1104 }};
1105 testInvokeOnPool(singletonPool(), a);
1106 }
1107
1108 /**
1109 * join of a forked task returns when task completes
1110 */
1111 public void testForkJoinSingleton() {
1112 RecursiveAction a = new CheckedRecursiveAction() {
1113 public void realCompute() {
1114 AsyncFib f = new AsyncFib(8);
1115 assertSame(f, f.fork());
1116 assertNull(f.join());
1117 assertEquals(21, f.number);
1118 checkCompletedNormally(f);
1119 }};
1120 testInvokeOnPool(singletonPool(), a);
1121 }
1122
1123 /**
1124 * get of a forked task returns when task completes
1125 */
1126 public void testForkGetSingleton() {
1127 RecursiveAction a = new CheckedRecursiveAction() {
1128 public void realCompute() throws Exception {
1129 AsyncFib f = new AsyncFib(8);
1130 assertSame(f, f.fork());
1131 assertNull(f.get());
1132 assertEquals(21, f.number);
1133 checkCompletedNormally(f);
1134 }};
1135 testInvokeOnPool(singletonPool(), a);
1136 }
1137
1138 /**
1139 * timed get of a forked task returns when task completes
1140 */
1141 public void testForkTimedGetSingleton() {
1142 RecursiveAction a = new CheckedRecursiveAction() {
1143 public void realCompute() throws Exception {
1144 AsyncFib f = new AsyncFib(8);
1145 assertSame(f, f.fork());
1146 assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
1147 assertEquals(21, f.number);
1148 checkCompletedNormally(f);
1149 }};
1150 testInvokeOnPool(singletonPool(), a);
1151 }
1152
1153 /**
1154 * timed get with null time unit throws NPE
1155 */
1156 public void testForkTimedGetNPESingleton() {
1157 RecursiveAction a = new CheckedRecursiveAction() {
1158 public void realCompute() throws Exception {
1159 AsyncFib f = new AsyncFib(8);
1160 assertSame(f, f.fork());
1161 try {
1162 f.get(5L, null);
1163 shouldThrow();
1164 } catch (NullPointerException success) {}
1165 }};
1166 testInvokeOnPool(singletonPool(), a);
1167 }
1168
1169 /**
1170 * quietlyJoin of a forked task returns when task completes
1171 */
1172 public void testForkQuietlyJoinSingleton() {
1173 RecursiveAction a = new CheckedRecursiveAction() {
1174 public void realCompute() {
1175 AsyncFib f = new AsyncFib(8);
1176 assertSame(f, f.fork());
1177 f.quietlyJoin();
1178 assertEquals(21, f.number);
1179 checkCompletedNormally(f);
1180 }};
1181 testInvokeOnPool(singletonPool(), a);
1182 }
1183
1184
1185 /**
1186 * helpQuiesce returns when tasks are complete.
1187 * getQueuedTaskCount returns 0 when quiescent
1188 */
1189 public void testForkHelpQuiesceSingleton() {
1190 RecursiveAction a = new CheckedRecursiveAction() {
1191 public void realCompute() {
1192 AsyncFib f = new AsyncFib(8);
1193 assertSame(f, f.fork());
1194 f.helpQuiesce();
1195 assertEquals(0, getQueuedTaskCount());
1196 assertEquals(21, f.number);
1197 checkCompletedNormally(f);
1198 }};
1199 testInvokeOnPool(singletonPool(), a);
1200 }
1201
1202
1203 /**
1204 * invoke task throws exception when task completes abnormally
1205 */
1206 public void testAbnormalInvokeSingleton() {
1207 RecursiveAction a = new CheckedRecursiveAction() {
1208 public void realCompute() {
1209 FailingAsyncFib f = new FailingAsyncFib(8);
1210 try {
1211 f.invoke();
1212 shouldThrow();
1213 } catch (FJException success) {
1214 checkCompletedAbnormally(f, success);
1215 }
1216 }};
1217 testInvokeOnPool(singletonPool(), a);
1218 }
1219
1220 /**
1221 * quietlyInvoke task returns when task completes abnormally
1222 */
1223 public void testAbnormalQuietlyInvokeSingleton() {
1224 RecursiveAction a = new CheckedRecursiveAction() {
1225 public void realCompute() {
1226 FailingAsyncFib f = new FailingAsyncFib(8);
1227 f.quietlyInvoke();
1228 assertTrue(f.getException() instanceof FJException);
1229 checkCompletedAbnormally(f, f.getException());
1230 }};
1231 testInvokeOnPool(singletonPool(), a);
1232 }
1233
1234 /**
1235 * join of a forked task throws exception when task completes abnormally
1236 */
1237 public void testAbnormalForkJoinSingleton() {
1238 RecursiveAction a = new CheckedRecursiveAction() {
1239 public void realCompute() {
1240 FailingAsyncFib f = new FailingAsyncFib(8);
1241 assertSame(f, f.fork());
1242 try {
1243 f.join();
1244 shouldThrow();
1245 } catch (FJException success) {
1246 checkCompletedAbnormally(f, success);
1247 }
1248 }};
1249 testInvokeOnPool(singletonPool(), a);
1250 }
1251
1252 /**
1253 * get of a forked task throws exception when task completes abnormally
1254 */
1255 public void testAbnormalForkGetSingleton() {
1256 RecursiveAction a = new CheckedRecursiveAction() {
1257 public void realCompute() throws Exception {
1258 FailingAsyncFib f = new FailingAsyncFib(8);
1259 assertSame(f, f.fork());
1260 try {
1261 f.get();
1262 shouldThrow();
1263 } catch (ExecutionException success) {
1264 Throwable cause = success.getCause();
1265 assertTrue(cause instanceof FJException);
1266 checkCompletedAbnormally(f, cause);
1267 }
1268 }};
1269 testInvokeOnPool(singletonPool(), a);
1270 }
1271
1272 /**
1273 * timed get of a forked task throws exception when task completes abnormally
1274 */
1275 public void testAbnormalForkTimedGetSingleton() {
1276 RecursiveAction a = new CheckedRecursiveAction() {
1277 public void realCompute() throws Exception {
1278 FailingAsyncFib f = new FailingAsyncFib(8);
1279 assertSame(f, f.fork());
1280 try {
1281 f.get(LONG_DELAY_MS, MILLISECONDS);
1282 shouldThrow();
1283 } catch (ExecutionException success) {
1284 Throwable cause = success.getCause();
1285 assertTrue(cause instanceof FJException);
1286 checkCompletedAbnormally(f, cause);
1287 }
1288 }};
1289 testInvokeOnPool(singletonPool(), a);
1290 }
1291
1292 /**
1293 * quietlyJoin of a forked task returns when task completes abnormally
1294 */
1295 public void testAbnormalForkQuietlyJoinSingleton() {
1296 RecursiveAction a = new CheckedRecursiveAction() {
1297 public void realCompute() {
1298 FailingAsyncFib f = new FailingAsyncFib(8);
1299 assertSame(f, f.fork());
1300 f.quietlyJoin();
1301 assertTrue(f.getException() instanceof FJException);
1302 checkCompletedAbnormally(f, f.getException());
1303 }};
1304 testInvokeOnPool(singletonPool(), a);
1305 }
1306
1307 /**
1308 * invoke task throws exception when task cancelled
1309 */
1310 public void testCancelledInvokeSingleton() {
1311 RecursiveAction a = new CheckedRecursiveAction() {
1312 public void realCompute() {
1313 AsyncFib f = new AsyncFib(8);
1314 assertTrue(f.cancel(true));
1315 try {
1316 f.invoke();
1317 shouldThrow();
1318 } catch (CancellationException success) {
1319 checkCancelled(f);
1320 }
1321 }};
1322 testInvokeOnPool(singletonPool(), a);
1323 }
1324
1325 /**
1326 * join of a forked task throws exception when task cancelled
1327 */
1328 public void testCancelledForkJoinSingleton() {
1329 RecursiveAction a = new CheckedRecursiveAction() {
1330 public void realCompute() {
1331 AsyncFib f = new AsyncFib(8);
1332 assertTrue(f.cancel(true));
1333 assertSame(f, f.fork());
1334 try {
1335 f.join();
1336 shouldThrow();
1337 } catch (CancellationException success) {
1338 checkCancelled(f);
1339 }
1340 }};
1341 testInvokeOnPool(singletonPool(), a);
1342 }
1343
1344 /**
1345 * get of a forked task throws exception when task cancelled
1346 */
1347 public void testCancelledForkGetSingleton() {
1348 RecursiveAction a = new CheckedRecursiveAction() {
1349 public void realCompute() throws Exception {
1350 AsyncFib f = new AsyncFib(8);
1351 assertTrue(f.cancel(true));
1352 assertSame(f, f.fork());
1353 try {
1354 f.get();
1355 shouldThrow();
1356 } catch (CancellationException success) {
1357 checkCancelled(f);
1358 }
1359 }};
1360 testInvokeOnPool(singletonPool(), a);
1361 }
1362
1363 /**
1364 * timed get of a forked task throws exception when task cancelled
1365 */
1366 public void testCancelledForkTimedGetSingleton() throws Exception {
1367 RecursiveAction a = new CheckedRecursiveAction() {
1368 public void realCompute() throws Exception {
1369 AsyncFib f = new AsyncFib(8);
1370 assertTrue(f.cancel(true));
1371 assertSame(f, f.fork());
1372 try {
1373 f.get(LONG_DELAY_MS, MILLISECONDS);
1374 shouldThrow();
1375 } catch (CancellationException success) {
1376 checkCancelled(f);
1377 }
1378 }};
1379 testInvokeOnPool(singletonPool(), a);
1380 }
1381
1382 /**
1383 * quietlyJoin of a forked task returns when task cancelled
1384 */
1385 public void testCancelledForkQuietlyJoinSingleton() {
1386 RecursiveAction a = new CheckedRecursiveAction() {
1387 public void realCompute() {
1388 AsyncFib f = new AsyncFib(8);
1389 assertTrue(f.cancel(true));
1390 assertSame(f, f.fork());
1391 f.quietlyJoin();
1392 checkCancelled(f);
1393 }};
1394 testInvokeOnPool(singletonPool(), a);
1395 }
1396
1397 /**
1398 * invoke task throws exception after invoking completeExceptionally
1399 */
1400 public void testCompleteExceptionallySingleton() {
1401 RecursiveAction a = new CheckedRecursiveAction() {
1402 public void realCompute() {
1403 AsyncFib f = new AsyncFib(8);
1404 f.completeExceptionally(new FJException());
1405 try {
1406 f.invoke();
1407 shouldThrow();
1408 } catch (FJException success) {
1409 checkCompletedAbnormally(f, success);
1410 }
1411 }};
1412 testInvokeOnPool(singletonPool(), a);
1413 }
1414
1415 /**
1416 * invokeAll(t1, t2) invokes all task arguments
1417 */
1418 public void testInvokeAll2Singleton() {
1419 RecursiveAction a = new CheckedRecursiveAction() {
1420 public void realCompute() {
1421 AsyncFib f = new AsyncFib(8);
1422 AsyncFib g = new AsyncFib(9);
1423 invokeAll(f, g);
1424 assertEquals(21, f.number);
1425 assertEquals(34, g.number);
1426 checkCompletedNormally(f);
1427 checkCompletedNormally(g);
1428 }};
1429 testInvokeOnPool(singletonPool(), a);
1430 }
1431
1432 /**
1433 * invokeAll(tasks) with 1 argument invokes task
1434 */
1435 public void testInvokeAll1Singleton() {
1436 RecursiveAction a = new CheckedRecursiveAction() {
1437 public void realCompute() {
1438 AsyncFib f = new AsyncFib(8);
1439 invokeAll(f);
1440 checkCompletedNormally(f);
1441 assertEquals(21, f.number);
1442 }};
1443 testInvokeOnPool(singletonPool(), a);
1444 }
1445
1446 /**
1447 * invokeAll(tasks) with > 2 argument invokes tasks
1448 */
1449 public void testInvokeAll3Singleton() {
1450 RecursiveAction a = new CheckedRecursiveAction() {
1451 public void realCompute() {
1452 AsyncFib f = new AsyncFib(8);
1453 AsyncFib g = new AsyncFib(9);
1454 AsyncFib h = new AsyncFib(7);
1455 invokeAll(f, g, h);
1456 assertEquals(21, f.number);
1457 assertEquals(34, g.number);
1458 assertEquals(13, h.number);
1459 checkCompletedNormally(f);
1460 checkCompletedNormally(g);
1461 checkCompletedNormally(h);
1462 }};
1463 testInvokeOnPool(singletonPool(), a);
1464 }
1465
1466 /**
1467 * invokeAll(collection) invokes all tasks in the collection
1468 */
1469 public void testInvokeAllCollectionSingleton() {
1470 RecursiveAction a = new CheckedRecursiveAction() {
1471 public void realCompute() {
1472 AsyncFib f = new AsyncFib(8);
1473 AsyncFib g = new AsyncFib(9);
1474 AsyncFib h = new AsyncFib(7);
1475 HashSet set = new HashSet();
1476 set.add(f);
1477 set.add(g);
1478 set.add(h);
1479 invokeAll(set);
1480 assertEquals(21, f.number);
1481 assertEquals(34, g.number);
1482 assertEquals(13, h.number);
1483 checkCompletedNormally(f);
1484 checkCompletedNormally(g);
1485 checkCompletedNormally(h);
1486 }};
1487 testInvokeOnPool(singletonPool(), a);
1488 }
1489
1490
1491 /**
1492 * invokeAll(tasks) with any null task throws NPE
1493 */
1494 public void testInvokeAllNPESingleton() {
1495 RecursiveAction a = new CheckedRecursiveAction() {
1496 public void realCompute() {
1497 AsyncFib f = new AsyncFib(8);
1498 AsyncFib g = new AsyncFib(9);
1499 AsyncFib h = null;
1500 try {
1501 invokeAll(f, g, h);
1502 shouldThrow();
1503 } catch (NullPointerException success) {}
1504 }};
1505 testInvokeOnPool(singletonPool(), a);
1506 }
1507
1508 /**
1509 * invokeAll(t1, t2) throw exception if any task does
1510 */
1511 public void testAbnormalInvokeAll2Singleton() {
1512 RecursiveAction a = new CheckedRecursiveAction() {
1513 public void realCompute() {
1514 AsyncFib f = new AsyncFib(8);
1515 FailingAsyncFib g = new FailingAsyncFib(9);
1516 try {
1517 invokeAll(f, g);
1518 shouldThrow();
1519 } catch (FJException success) {
1520 checkCompletedAbnormally(g, success);
1521 }
1522 }};
1523 testInvokeOnPool(singletonPool(), a);
1524 }
1525
1526 /**
1527 * invokeAll(tasks) with 1 argument throws exception if task does
1528 */
1529 public void testAbnormalInvokeAll1Singleton() {
1530 RecursiveAction a = new CheckedRecursiveAction() {
1531 public void realCompute() {
1532 FailingAsyncFib g = new FailingAsyncFib(9);
1533 try {
1534 invokeAll(g);
1535 shouldThrow();
1536 } catch (FJException success) {
1537 checkCompletedAbnormally(g, success);
1538 }
1539 }};
1540 testInvokeOnPool(singletonPool(), a);
1541 }
1542
1543 /**
1544 * invokeAll(tasks) with > 2 argument throws exception if any task does
1545 */
1546 public void testAbnormalInvokeAll3Singleton() {
1547 RecursiveAction a = new CheckedRecursiveAction() {
1548 public void realCompute() {
1549 AsyncFib f = new AsyncFib(8);
1550 FailingAsyncFib g = new FailingAsyncFib(9);
1551 AsyncFib h = new AsyncFib(7);
1552 try {
1553 invokeAll(f, g, h);
1554 shouldThrow();
1555 } catch (FJException success) {
1556 checkCompletedAbnormally(g, success);
1557 }
1558 }};
1559 testInvokeOnPool(singletonPool(), a);
1560 }
1561
1562 /**
1563 * invokeAll(collection) throws exception if any task does
1564 */
1565 public void testAbnormalInvokeAllCollectionSingleton() {
1566 RecursiveAction a = new CheckedRecursiveAction() {
1567 public void realCompute() {
1568 FailingAsyncFib f = new FailingAsyncFib(8);
1569 AsyncFib g = new AsyncFib(9);
1570 AsyncFib h = new AsyncFib(7);
1571 HashSet set = new HashSet();
1572 set.add(f);
1573 set.add(g);
1574 set.add(h);
1575 try {
1576 invokeAll(set);
1577 shouldThrow();
1578 } catch (FJException success) {
1579 checkCompletedAbnormally(f, success);
1580 }
1581 }};
1582 testInvokeOnPool(singletonPool(), a);
1583 }
1584
1585 }