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 |
4 |
> |
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
< |
import java.util.concurrent.ExecutionException; |
6 |
> |
import java.util.HashSet; |
7 |
|
import java.util.concurrent.CancellationException; |
8 |
+ |
import java.util.concurrent.ExecutionException; |
9 |
|
import java.util.concurrent.ForkJoinPool; |
10 |
|
import java.util.concurrent.ForkJoinTask; |
10 |
– |
import java.util.concurrent.ForkJoinWorkerThread; |
11 |
|
import java.util.concurrent.RecursiveAction; |
12 |
< |
import java.util.concurrent.TimeUnit; |
12 |
> |
import java.util.concurrent.TimeoutException; |
13 |
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
14 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
15 |
< |
import java.util.HashSet; |
15 |
> |
import static java.util.concurrent.TimeUnit.SECONDS; |
16 |
|
import junit.framework.*; |
17 |
|
|
18 |
|
public class ForkJoinTaskTest extends JSR166TestCase { |
50 |
|
assertFalse(a.isCompletedAbnormally()); |
51 |
|
assertFalse(a.isCancelled()); |
52 |
|
assertNull(a.getException()); |
53 |
+ |
assertNull(a.getRawResult()); |
54 |
|
|
55 |
|
assertNull(pool.invoke(a)); |
56 |
|
|
59 |
|
assertFalse(a.isCompletedAbnormally()); |
60 |
|
assertFalse(a.isCancelled()); |
61 |
|
assertNull(a.getException()); |
62 |
+ |
assertNull(a.getRawResult()); |
63 |
|
} finally { |
64 |
|
joinPool(pool); |
65 |
|
} |
66 |
|
} |
67 |
|
|
68 |
+ |
void checkNotDone(ForkJoinTask a) { |
69 |
+ |
assertFalse(a.isDone()); |
70 |
+ |
assertFalse(a.isCompletedNormally()); |
71 |
+ |
assertFalse(a.isCompletedAbnormally()); |
72 |
+ |
assertFalse(a.isCancelled()); |
73 |
+ |
assertNull(a.getException()); |
74 |
+ |
assertNull(a.getRawResult()); |
75 |
+ |
|
76 |
+ |
try { |
77 |
+ |
a.get(0L, SECONDS); |
78 |
+ |
shouldThrow(); |
79 |
+ |
} catch (TimeoutException success) { |
80 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
81 |
+ |
} |
82 |
+ |
|
83 |
+ |
<T> void checkCompletedNormally(ForkJoinTask<T> a) { |
84 |
+ |
checkCompletedNormally(a, null); |
85 |
+ |
} |
86 |
+ |
|
87 |
+ |
<T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) { |
88 |
+ |
assertTrue(a.isDone()); |
89 |
+ |
assertFalse(a.isCancelled()); |
90 |
+ |
assertTrue(a.isCompletedNormally()); |
91 |
+ |
assertFalse(a.isCompletedAbnormally()); |
92 |
+ |
assertNull(a.getException()); |
93 |
+ |
assertSame(expected, a.getRawResult()); |
94 |
+ |
|
95 |
+ |
{ |
96 |
+ |
Thread.currentThread().interrupt(); |
97 |
+ |
long t0 = System.nanoTime(); |
98 |
+ |
assertSame(expected, a.join()); |
99 |
+ |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
100 |
+ |
Thread.interrupted(); |
101 |
+ |
} |
102 |
+ |
|
103 |
+ |
{ |
104 |
+ |
Thread.currentThread().interrupt(); |
105 |
+ |
long t0 = System.nanoTime(); |
106 |
+ |
a.quietlyJoin(); // should be no-op |
107 |
+ |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
108 |
+ |
Thread.interrupted(); |
109 |
+ |
} |
110 |
+ |
|
111 |
+ |
assertFalse(a.cancel(false)); |
112 |
+ |
assertFalse(a.cancel(true)); |
113 |
+ |
try { |
114 |
+ |
assertSame(expected, a.get()); |
115 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
116 |
+ |
try { |
117 |
+ |
assertSame(expected, a.get(5L, SECONDS)); |
118 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
119 |
+ |
} |
120 |
+ |
|
121 |
+ |
void checkCancelled(ForkJoinTask a) { |
122 |
+ |
assertTrue(a.isDone()); |
123 |
+ |
assertTrue(a.isCancelled()); |
124 |
+ |
assertFalse(a.isCompletedNormally()); |
125 |
+ |
assertTrue(a.isCompletedAbnormally()); |
126 |
+ |
assertTrue(a.getException() instanceof CancellationException); |
127 |
+ |
assertNull(a.getRawResult()); |
128 |
+ |
assertTrue(a.cancel(false)); |
129 |
+ |
assertTrue(a.cancel(true)); |
130 |
+ |
|
131 |
+ |
try { |
132 |
+ |
Thread.currentThread().interrupt(); |
133 |
+ |
a.join(); |
134 |
+ |
shouldThrow(); |
135 |
+ |
} catch (CancellationException success) { |
136 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
137 |
+ |
Thread.interrupted(); |
138 |
+ |
|
139 |
+ |
{ |
140 |
+ |
long t0 = System.nanoTime(); |
141 |
+ |
a.quietlyJoin(); // should be no-op |
142 |
+ |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
143 |
+ |
} |
144 |
+ |
|
145 |
+ |
try { |
146 |
+ |
a.get(); |
147 |
+ |
shouldThrow(); |
148 |
+ |
} catch (CancellationException success) { |
149 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
150 |
+ |
|
151 |
+ |
try { |
152 |
+ |
a.get(5L, SECONDS); |
153 |
+ |
shouldThrow(); |
154 |
+ |
} catch (CancellationException success) { |
155 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
156 |
+ |
} |
157 |
+ |
|
158 |
+ |
void checkCompletedAbnormally(ForkJoinTask a, Throwable t) { |
159 |
+ |
assertTrue(a.isDone()); |
160 |
+ |
assertFalse(a.isCancelled()); |
161 |
+ |
assertFalse(a.isCompletedNormally()); |
162 |
+ |
assertTrue(a.isCompletedAbnormally()); |
163 |
+ |
assertSame(t.getClass(), a.getException().getClass()); |
164 |
+ |
assertNull(a.getRawResult()); |
165 |
+ |
assertFalse(a.cancel(false)); |
166 |
+ |
assertFalse(a.cancel(true)); |
167 |
+ |
|
168 |
+ |
try { |
169 |
+ |
Thread.currentThread().interrupt(); |
170 |
+ |
a.join(); |
171 |
+ |
shouldThrow(); |
172 |
+ |
} catch (Throwable expected) { |
173 |
+ |
assertSame(t.getClass(), expected.getClass()); |
174 |
+ |
} |
175 |
+ |
Thread.interrupted(); |
176 |
+ |
|
177 |
+ |
{ |
178 |
+ |
long t0 = System.nanoTime(); |
179 |
+ |
a.quietlyJoin(); // should be no-op |
180 |
+ |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
181 |
+ |
} |
182 |
+ |
|
183 |
+ |
try { |
184 |
+ |
a.get(); |
185 |
+ |
shouldThrow(); |
186 |
+ |
} catch (ExecutionException success) { |
187 |
+ |
assertSame(t.getClass(), success.getCause().getClass()); |
188 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
189 |
+ |
|
190 |
+ |
try { |
191 |
+ |
a.get(5L, SECONDS); |
192 |
+ |
shouldThrow(); |
193 |
+ |
} catch (ExecutionException success) { |
194 |
+ |
assertSame(t.getClass(), success.getCause().getClass()); |
195 |
+ |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
196 |
+ |
} |
197 |
+ |
|
198 |
|
/* |
199 |
|
* Testing coverage notes: |
200 |
|
* |
203 |
|
* differently than supplied Recursive forms. |
204 |
|
*/ |
205 |
|
|
206 |
< |
static final class FJException extends RuntimeException { |
206 |
> |
public static final class FJException extends RuntimeException { |
207 |
|
FJException() { super(); } |
208 |
|
} |
209 |
|
|
347 |
|
} |
348 |
|
} |
349 |
|
|
218 |
– |
|
350 |
|
static final class FailingAsyncFib extends BinaryAsyncAction { |
351 |
|
int number; |
352 |
|
public FailingAsyncFib(int n) { |
378 |
|
/** |
379 |
|
* invoke returns when task completes normally. |
380 |
|
* isCompletedAbnormally and isCancelled return false for normally |
381 |
< |
* completed tasks. getRawResult of a RecursiveAction returns null; |
381 |
> |
* completed tasks; getRawResult returns null. |
382 |
|
*/ |
383 |
|
public void testInvoke() { |
384 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
385 |
< |
public void realCompute() { |
385 |
> |
protected void realCompute() { |
386 |
|
AsyncFib f = new AsyncFib(8); |
387 |
|
assertNull(f.invoke()); |
388 |
|
assertEquals(21, f.number); |
389 |
< |
assertTrue(f.isDone()); |
259 |
< |
assertFalse(f.isCancelled()); |
260 |
< |
assertFalse(f.isCompletedAbnormally()); |
261 |
< |
assertNull(f.getRawResult()); |
389 |
> |
checkCompletedNormally(f); |
390 |
|
}}; |
391 |
|
testInvokeOnPool(mainPool(), a); |
392 |
|
} |
398 |
|
*/ |
399 |
|
public void testQuietlyInvoke() { |
400 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
401 |
< |
public void realCompute() { |
401 |
> |
protected void realCompute() { |
402 |
|
AsyncFib f = new AsyncFib(8); |
403 |
|
f.quietlyInvoke(); |
404 |
|
assertEquals(21, f.number); |
405 |
< |
assertTrue(f.isDone()); |
278 |
< |
assertFalse(f.isCancelled()); |
279 |
< |
assertFalse(f.isCompletedAbnormally()); |
280 |
< |
assertNull(f.getRawResult()); |
405 |
> |
checkCompletedNormally(f); |
406 |
|
}}; |
407 |
|
testInvokeOnPool(mainPool(), a); |
408 |
|
} |
412 |
|
*/ |
413 |
|
public void testForkJoin() { |
414 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
415 |
< |
public void realCompute() { |
415 |
> |
protected void realCompute() { |
416 |
|
AsyncFib f = new AsyncFib(8); |
417 |
|
assertSame(f, f.fork()); |
418 |
|
assertNull(f.join()); |
419 |
|
assertEquals(21, f.number); |
420 |
< |
assertTrue(f.isDone()); |
296 |
< |
assertNull(f.getRawResult()); |
420 |
> |
checkCompletedNormally(f); |
421 |
|
}}; |
422 |
|
testInvokeOnPool(mainPool(), a); |
423 |
|
} |
427 |
|
*/ |
428 |
|
public void testForkGet() { |
429 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
430 |
< |
public void realCompute() throws Exception { |
430 |
> |
protected void realCompute() throws Exception { |
431 |
|
AsyncFib f = new AsyncFib(8); |
432 |
|
assertSame(f, f.fork()); |
433 |
|
assertNull(f.get()); |
434 |
|
assertEquals(21, f.number); |
435 |
< |
assertTrue(f.isDone()); |
435 |
> |
checkCompletedNormally(f); |
436 |
|
}}; |
437 |
|
testInvokeOnPool(mainPool(), a); |
438 |
|
} |
442 |
|
*/ |
443 |
|
public void testForkTimedGet() { |
444 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
445 |
< |
public void realCompute() throws Exception { |
445 |
> |
protected void realCompute() throws Exception { |
446 |
|
AsyncFib f = new AsyncFib(8); |
447 |
|
assertSame(f, f.fork()); |
448 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
449 |
|
assertEquals(21, f.number); |
450 |
< |
assertTrue(f.isDone()); |
450 |
> |
checkCompletedNormally(f); |
451 |
|
}}; |
452 |
|
testInvokeOnPool(mainPool(), a); |
453 |
|
} |
457 |
|
*/ |
458 |
|
public void testForkTimedGetNPE() { |
459 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
460 |
< |
public void realCompute() throws Exception { |
460 |
> |
protected void realCompute() throws Exception { |
461 |
|
AsyncFib f = new AsyncFib(8); |
462 |
|
assertSame(f, f.fork()); |
463 |
|
try { |
473 |
|
*/ |
474 |
|
public void testForkQuietlyJoin() { |
475 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
476 |
< |
public void realCompute() { |
476 |
> |
protected void realCompute() { |
477 |
|
AsyncFib f = new AsyncFib(8); |
478 |
|
assertSame(f, f.fork()); |
479 |
|
f.quietlyJoin(); |
480 |
|
assertEquals(21, f.number); |
481 |
< |
assertTrue(f.isDone()); |
481 |
> |
checkCompletedNormally(f); |
482 |
|
}}; |
483 |
|
testInvokeOnPool(mainPool(), a); |
484 |
|
} |
485 |
|
|
362 |
– |
|
486 |
|
/** |
487 |
|
* helpQuiesce returns when tasks are complete. |
488 |
|
* getQueuedTaskCount returns 0 when quiescent |
489 |
|
*/ |
490 |
|
public void testForkHelpQuiesce() { |
491 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
492 |
< |
public void realCompute() { |
492 |
> |
protected void realCompute() { |
493 |
|
AsyncFib f = new AsyncFib(8); |
494 |
|
assertSame(f, f.fork()); |
495 |
< |
f.helpQuiesce(); |
495 |
> |
helpQuiesce(); |
496 |
|
assertEquals(21, f.number); |
374 |
– |
assertTrue(f.isDone()); |
497 |
|
assertEquals(0, getQueuedTaskCount()); |
498 |
+ |
checkCompletedNormally(f); |
499 |
|
}}; |
500 |
|
testInvokeOnPool(mainPool(), a); |
501 |
|
} |
502 |
|
|
380 |
– |
|
503 |
|
/** |
504 |
|
* invoke task throws exception when task completes abnormally |
505 |
|
*/ |
506 |
|
public void testAbnormalInvoke() { |
507 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
508 |
< |
public void realCompute() { |
508 |
> |
protected void realCompute() { |
509 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
510 |
|
try { |
511 |
|
f.invoke(); |
512 |
|
shouldThrow(); |
513 |
< |
} catch (FJException success) {} |
513 |
> |
} catch (FJException success) { |
514 |
> |
checkCompletedAbnormally(f, success); |
515 |
> |
} |
516 |
|
}}; |
517 |
|
testInvokeOnPool(mainPool(), a); |
518 |
|
} |
522 |
|
*/ |
523 |
|
public void testAbnormalQuietlyInvoke() { |
524 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
525 |
< |
public void realCompute() { |
525 |
> |
protected void realCompute() { |
526 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
527 |
|
f.quietlyInvoke(); |
528 |
< |
assertTrue(f.isDone()); |
528 |
> |
assertTrue(f.getException() instanceof FJException); |
529 |
> |
checkCompletedAbnormally(f, f.getException()); |
530 |
|
}}; |
531 |
|
testInvokeOnPool(mainPool(), a); |
532 |
|
} |
536 |
|
*/ |
537 |
|
public void testAbnormalForkJoin() { |
538 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
539 |
< |
public void realCompute() { |
539 |
> |
protected void realCompute() { |
540 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
541 |
|
assertSame(f, f.fork()); |
542 |
|
try { |
543 |
|
f.join(); |
544 |
|
shouldThrow(); |
545 |
< |
} catch (FJException success) {} |
545 |
> |
} catch (FJException success) { |
546 |
> |
checkCompletedAbnormally(f, success); |
547 |
> |
} |
548 |
|
}}; |
549 |
|
testInvokeOnPool(mainPool(), a); |
550 |
|
} |
554 |
|
*/ |
555 |
|
public void testAbnormalForkGet() { |
556 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
557 |
< |
public void realCompute() throws Exception { |
557 |
> |
protected void realCompute() throws Exception { |
558 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
559 |
|
assertSame(f, f.fork()); |
560 |
|
try { |
563 |
|
} catch (ExecutionException success) { |
564 |
|
Throwable cause = success.getCause(); |
565 |
|
assertTrue(cause instanceof FJException); |
566 |
< |
assertTrue(f.isDone()); |
440 |
< |
assertTrue(f.isCompletedAbnormally()); |
441 |
< |
assertSame(cause, f.getException()); |
566 |
> |
checkCompletedAbnormally(f, cause); |
567 |
|
} |
568 |
|
}}; |
569 |
|
testInvokeOnPool(mainPool(), a); |
574 |
|
*/ |
575 |
|
public void testAbnormalForkTimedGet() { |
576 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
577 |
< |
public void realCompute() throws Exception { |
577 |
> |
protected void realCompute() throws Exception { |
578 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
579 |
|
assertSame(f, f.fork()); |
580 |
|
try { |
583 |
|
} catch (ExecutionException success) { |
584 |
|
Throwable cause = success.getCause(); |
585 |
|
assertTrue(cause instanceof FJException); |
586 |
< |
assertTrue(f.isDone()); |
462 |
< |
assertTrue(f.isCompletedAbnormally()); |
463 |
< |
assertSame(cause, f.getException()); |
586 |
> |
checkCompletedAbnormally(f, cause); |
587 |
|
} |
588 |
|
}}; |
589 |
|
testInvokeOnPool(mainPool(), a); |
594 |
|
*/ |
595 |
|
public void testAbnormalForkQuietlyJoin() { |
596 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
597 |
< |
public void realCompute() { |
597 |
> |
protected void realCompute() { |
598 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
599 |
|
assertSame(f, f.fork()); |
600 |
|
f.quietlyJoin(); |
478 |
– |
assertTrue(f.isDone()); |
479 |
– |
assertTrue(f.isCompletedAbnormally()); |
601 |
|
assertTrue(f.getException() instanceof FJException); |
602 |
+ |
checkCompletedAbnormally(f, f.getException()); |
603 |
|
}}; |
604 |
|
testInvokeOnPool(mainPool(), a); |
605 |
|
} |
609 |
|
*/ |
610 |
|
public void testCancelledInvoke() { |
611 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
612 |
< |
public void realCompute() { |
612 |
> |
protected void realCompute() { |
613 |
|
AsyncFib f = new AsyncFib(8); |
614 |
|
assertTrue(f.cancel(true)); |
615 |
|
try { |
616 |
|
f.invoke(); |
617 |
|
shouldThrow(); |
618 |
|
} catch (CancellationException success) { |
619 |
< |
assertTrue(f.isDone()); |
498 |
< |
assertTrue(f.isCancelled()); |
499 |
< |
assertTrue(f.isCompletedAbnormally()); |
500 |
< |
assertTrue(f.getException() instanceof CancellationException); |
619 |
> |
checkCancelled(f); |
620 |
|
} |
621 |
|
}}; |
622 |
|
testInvokeOnPool(mainPool(), a); |
627 |
|
*/ |
628 |
|
public void testCancelledForkJoin() { |
629 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
630 |
< |
public void realCompute() { |
630 |
> |
protected void realCompute() { |
631 |
|
AsyncFib f = new AsyncFib(8); |
632 |
|
assertTrue(f.cancel(true)); |
633 |
|
assertSame(f, f.fork()); |
635 |
|
f.join(); |
636 |
|
shouldThrow(); |
637 |
|
} catch (CancellationException success) { |
638 |
< |
assertTrue(f.isDone()); |
520 |
< |
assertTrue(f.isCancelled()); |
521 |
< |
assertTrue(f.isCompletedAbnormally()); |
522 |
< |
assertTrue(f.getException() instanceof CancellationException); |
638 |
> |
checkCancelled(f); |
639 |
|
} |
640 |
|
}}; |
641 |
|
testInvokeOnPool(mainPool(), a); |
646 |
|
*/ |
647 |
|
public void testCancelledForkGet() { |
648 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
649 |
< |
public void realCompute() throws Exception { |
649 |
> |
protected void realCompute() throws Exception { |
650 |
|
AsyncFib f = new AsyncFib(8); |
651 |
|
assertTrue(f.cancel(true)); |
652 |
|
assertSame(f, f.fork()); |
654 |
|
f.get(); |
655 |
|
shouldThrow(); |
656 |
|
} catch (CancellationException success) { |
657 |
< |
assertTrue(f.isDone()); |
542 |
< |
assertTrue(f.isCancelled()); |
543 |
< |
assertTrue(f.isCompletedAbnormally()); |
544 |
< |
assertTrue(f.getException() instanceof CancellationException); |
657 |
> |
checkCancelled(f); |
658 |
|
} |
659 |
|
}}; |
660 |
|
testInvokeOnPool(mainPool(), a); |
665 |
|
*/ |
666 |
|
public void testCancelledForkTimedGet() throws Exception { |
667 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
668 |
< |
public void realCompute() throws Exception { |
668 |
> |
protected void realCompute() throws Exception { |
669 |
|
AsyncFib f = new AsyncFib(8); |
670 |
|
assertTrue(f.cancel(true)); |
671 |
|
assertSame(f, f.fork()); |
673 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
674 |
|
shouldThrow(); |
675 |
|
} catch (CancellationException success) { |
676 |
< |
assertTrue(f.isDone()); |
564 |
< |
assertTrue(f.isCancelled()); |
565 |
< |
assertTrue(f.isCompletedAbnormally()); |
566 |
< |
assertTrue(f.getException() instanceof CancellationException); |
676 |
> |
checkCancelled(f); |
677 |
|
} |
678 |
|
}}; |
679 |
|
testInvokeOnPool(mainPool(), a); |
684 |
|
*/ |
685 |
|
public void testCancelledForkQuietlyJoin() { |
686 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
687 |
< |
public void realCompute() { |
687 |
> |
protected void realCompute() { |
688 |
|
AsyncFib f = new AsyncFib(8); |
689 |
|
assertTrue(f.cancel(true)); |
690 |
|
assertSame(f, f.fork()); |
691 |
|
f.quietlyJoin(); |
692 |
< |
assertTrue(f.isDone()); |
583 |
< |
assertTrue(f.isCompletedAbnormally()); |
584 |
< |
assertTrue(f.isCancelled()); |
585 |
< |
assertTrue(f.getException() instanceof CancellationException); |
692 |
> |
checkCancelled(f); |
693 |
|
}}; |
694 |
|
testInvokeOnPool(mainPool(), a); |
695 |
|
} |
700 |
|
public void testGetPool() { |
701 |
|
final ForkJoinPool mainPool = mainPool(); |
702 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
703 |
< |
public void realCompute() { |
703 |
> |
protected void realCompute() { |
704 |
|
assertSame(mainPool, getPool()); |
705 |
|
}}; |
706 |
|
testInvokeOnPool(mainPool, a); |
711 |
|
*/ |
712 |
|
public void testGetPool2() { |
713 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
714 |
< |
public void realCompute() { |
714 |
> |
protected void realCompute() { |
715 |
|
assertNull(getPool()); |
716 |
|
}}; |
717 |
|
assertNull(a.invoke()); |
722 |
|
*/ |
723 |
|
public void testInForkJoinPool() { |
724 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
725 |
< |
public void realCompute() { |
725 |
> |
protected void realCompute() { |
726 |
|
assertTrue(inForkJoinPool()); |
727 |
|
}}; |
728 |
|
testInvokeOnPool(mainPool(), a); |
733 |
|
*/ |
734 |
|
public void testInForkJoinPool2() { |
735 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
736 |
< |
public void realCompute() { |
737 |
< |
assertTrue(!inForkJoinPool()); |
736 |
> |
protected void realCompute() { |
737 |
> |
assertFalse(inForkJoinPool()); |
738 |
|
}}; |
739 |
|
assertNull(a.invoke()); |
740 |
|
} |
744 |
|
*/ |
745 |
|
public void testSetRawResult() { |
746 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
747 |
< |
public void realCompute() { |
747 |
> |
protected void realCompute() { |
748 |
|
setRawResult(null); |
749 |
+ |
assertNull(getRawResult()); |
750 |
|
}}; |
751 |
|
assertNull(a.invoke()); |
752 |
|
} |
756 |
|
*/ |
757 |
|
public void testCompleteExceptionally() { |
758 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
759 |
< |
public void realCompute() { |
759 |
> |
protected void realCompute() { |
760 |
|
AsyncFib f = new AsyncFib(8); |
761 |
|
f.completeExceptionally(new FJException()); |
762 |
|
try { |
763 |
|
f.invoke(); |
764 |
|
shouldThrow(); |
765 |
< |
} catch (FJException success) {} |
765 |
> |
} catch (FJException success) { |
766 |
> |
checkCompletedAbnormally(f, success); |
767 |
> |
} |
768 |
|
}}; |
769 |
|
testInvokeOnPool(mainPool(), a); |
770 |
|
} |
774 |
|
*/ |
775 |
|
public void testInvokeAll2() { |
776 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
777 |
< |
public void realCompute() { |
777 |
> |
protected void realCompute() { |
778 |
|
AsyncFib f = new AsyncFib(8); |
779 |
|
AsyncFib g = new AsyncFib(9); |
780 |
|
invokeAll(f, g); |
671 |
– |
assertTrue(f.isDone()); |
781 |
|
assertEquals(21, f.number); |
673 |
– |
assertTrue(g.isDone()); |
782 |
|
assertEquals(34, g.number); |
783 |
+ |
checkCompletedNormally(f); |
784 |
+ |
checkCompletedNormally(g); |
785 |
|
}}; |
786 |
|
testInvokeOnPool(mainPool(), a); |
787 |
|
} |
791 |
|
*/ |
792 |
|
public void testInvokeAll1() { |
793 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
794 |
< |
public void realCompute() { |
794 |
> |
protected void realCompute() { |
795 |
|
AsyncFib f = new AsyncFib(8); |
796 |
|
invokeAll(f); |
797 |
< |
assertTrue(f.isDone()); |
797 |
> |
checkCompletedNormally(f); |
798 |
|
assertEquals(21, f.number); |
799 |
|
}}; |
800 |
|
testInvokeOnPool(mainPool(), a); |
805 |
|
*/ |
806 |
|
public void testInvokeAll3() { |
807 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
808 |
< |
public void realCompute() { |
808 |
> |
protected void realCompute() { |
809 |
|
AsyncFib f = new AsyncFib(8); |
810 |
|
AsyncFib g = new AsyncFib(9); |
811 |
|
AsyncFib h = new AsyncFib(7); |
812 |
|
invokeAll(f, g, h); |
703 |
– |
assertTrue(f.isDone()); |
813 |
|
assertEquals(21, f.number); |
705 |
– |
assertTrue(g.isDone()); |
814 |
|
assertEquals(34, g.number); |
707 |
– |
assertTrue(h.isDone()); |
815 |
|
assertEquals(13, h.number); |
816 |
+ |
checkCompletedNormally(f); |
817 |
+ |
checkCompletedNormally(g); |
818 |
+ |
checkCompletedNormally(h); |
819 |
|
}}; |
820 |
|
testInvokeOnPool(mainPool(), a); |
821 |
|
} |
825 |
|
*/ |
826 |
|
public void testInvokeAllCollection() { |
827 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
828 |
< |
public void realCompute() { |
828 |
> |
protected void realCompute() { |
829 |
|
AsyncFib f = new AsyncFib(8); |
830 |
|
AsyncFib g = new AsyncFib(9); |
831 |
|
AsyncFib h = new AsyncFib(7); |
834 |
|
set.add(g); |
835 |
|
set.add(h); |
836 |
|
invokeAll(set); |
727 |
– |
assertTrue(f.isDone()); |
837 |
|
assertEquals(21, f.number); |
729 |
– |
assertTrue(g.isDone()); |
838 |
|
assertEquals(34, g.number); |
731 |
– |
assertTrue(h.isDone()); |
839 |
|
assertEquals(13, h.number); |
840 |
+ |
checkCompletedNormally(f); |
841 |
+ |
checkCompletedNormally(g); |
842 |
+ |
checkCompletedNormally(h); |
843 |
|
}}; |
844 |
|
testInvokeOnPool(mainPool(), a); |
845 |
|
} |
846 |
|
|
737 |
– |
|
847 |
|
/** |
848 |
|
* invokeAll(tasks) with any null task throws NPE |
849 |
|
*/ |
850 |
|
public void testInvokeAllNPE() { |
851 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
852 |
< |
public void realCompute() { |
852 |
> |
protected void realCompute() { |
853 |
|
AsyncFib f = new AsyncFib(8); |
854 |
|
AsyncFib g = new AsyncFib(9); |
855 |
|
AsyncFib h = null; |
866 |
|
*/ |
867 |
|
public void testAbnormalInvokeAll2() { |
868 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
869 |
< |
public void realCompute() { |
869 |
> |
protected void realCompute() { |
870 |
|
AsyncFib f = new AsyncFib(8); |
871 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
872 |
|
try { |
873 |
|
invokeAll(f, g); |
874 |
|
shouldThrow(); |
875 |
< |
} catch (FJException success) {} |
875 |
> |
} catch (FJException success) { |
876 |
> |
checkCompletedAbnormally(g, success); |
877 |
> |
} |
878 |
|
}}; |
879 |
|
testInvokeOnPool(mainPool(), a); |
880 |
|
} |
884 |
|
*/ |
885 |
|
public void testAbnormalInvokeAll1() { |
886 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
887 |
< |
public void realCompute() { |
887 |
> |
protected void realCompute() { |
888 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
889 |
|
try { |
890 |
|
invokeAll(g); |
891 |
|
shouldThrow(); |
892 |
< |
} catch (FJException success) {} |
892 |
> |
} catch (FJException success) { |
893 |
> |
checkCompletedAbnormally(g, success); |
894 |
> |
} |
895 |
|
}}; |
896 |
|
testInvokeOnPool(mainPool(), a); |
897 |
|
} |
901 |
|
*/ |
902 |
|
public void testAbnormalInvokeAll3() { |
903 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
904 |
< |
public void realCompute() { |
904 |
> |
protected void realCompute() { |
905 |
|
AsyncFib f = new AsyncFib(8); |
906 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
907 |
|
AsyncFib h = new AsyncFib(7); |
908 |
|
try { |
909 |
|
invokeAll(f, g, h); |
910 |
|
shouldThrow(); |
911 |
< |
} catch (FJException success) {} |
911 |
> |
} catch (FJException success) { |
912 |
> |
checkCompletedAbnormally(g, success); |
913 |
> |
} |
914 |
|
}}; |
915 |
|
testInvokeOnPool(mainPool(), a); |
916 |
|
} |
917 |
|
|
918 |
|
/** |
919 |
< |
* invokeAll(collection) throws exception if any task does |
919 |
> |
* invokeAll(collection) throws exception if any task does |
920 |
|
*/ |
921 |
|
public void testAbnormalInvokeAllCollection() { |
922 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
923 |
< |
public void realCompute() { |
923 |
> |
protected void realCompute() { |
924 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
925 |
|
AsyncFib g = new AsyncFib(9); |
926 |
|
AsyncFib h = new AsyncFib(7); |
931 |
|
try { |
932 |
|
invokeAll(set); |
933 |
|
shouldThrow(); |
934 |
< |
} catch (FJException success) {} |
934 |
> |
} catch (FJException success) { |
935 |
> |
checkCompletedAbnormally(f, success); |
936 |
> |
} |
937 |
|
}}; |
938 |
|
testInvokeOnPool(mainPool(), a); |
939 |
|
} |
944 |
|
*/ |
945 |
|
public void testTryUnfork() { |
946 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
947 |
< |
public void realCompute() { |
947 |
> |
protected void realCompute() { |
948 |
|
AsyncFib g = new AsyncFib(9); |
949 |
|
assertSame(g, g.fork()); |
950 |
|
AsyncFib f = new AsyncFib(8); |
951 |
|
assertSame(f, f.fork()); |
952 |
|
assertTrue(f.tryUnfork()); |
953 |
|
helpQuiesce(); |
954 |
< |
assertFalse(f.isDone()); |
955 |
< |
assertTrue(g.isDone()); |
954 |
> |
checkNotDone(f); |
955 |
> |
checkCompletedNormally(g); |
956 |
|
}}; |
957 |
|
testInvokeOnPool(singletonPool(), a); |
958 |
|
} |
963 |
|
*/ |
964 |
|
public void testGetSurplusQueuedTaskCount() { |
965 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
966 |
< |
public void realCompute() { |
966 |
> |
protected void realCompute() { |
967 |
|
AsyncFib h = new AsyncFib(7); |
968 |
|
assertSame(h, h.fork()); |
969 |
|
AsyncFib g = new AsyncFib(9); |
972 |
|
assertSame(f, f.fork()); |
973 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
974 |
|
helpQuiesce(); |
975 |
+ |
assertEquals(0, getSurplusQueuedTaskCount()); |
976 |
+ |
checkCompletedNormally(f); |
977 |
+ |
checkCompletedNormally(g); |
978 |
+ |
checkCompletedNormally(h); |
979 |
|
}}; |
980 |
|
testInvokeOnPool(singletonPool(), a); |
981 |
|
} |
985 |
|
*/ |
986 |
|
public void testPeekNextLocalTask() { |
987 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
988 |
< |
public void realCompute() { |
988 |
> |
protected void realCompute() { |
989 |
|
AsyncFib g = new AsyncFib(9); |
990 |
|
assertSame(g, g.fork()); |
991 |
|
AsyncFib f = new AsyncFib(8); |
992 |
|
assertSame(f, f.fork()); |
993 |
|
assertSame(f, peekNextLocalTask()); |
994 |
|
assertNull(f.join()); |
995 |
< |
assertTrue(f.isDone()); |
995 |
> |
checkCompletedNormally(f); |
996 |
|
helpQuiesce(); |
997 |
+ |
checkCompletedNormally(g); |
998 |
|
}}; |
999 |
|
testInvokeOnPool(singletonPool(), a); |
1000 |
|
} |
1001 |
|
|
1002 |
|
/** |
1003 |
< |
* pollNextLocalTask returns most recent unexecuted task |
1004 |
< |
* without executing it |
1003 |
> |
* pollNextLocalTask returns most recent unexecuted task without |
1004 |
> |
* executing it |
1005 |
|
*/ |
1006 |
|
public void testPollNextLocalTask() { |
1007 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1008 |
< |
public void realCompute() { |
1008 |
> |
protected void realCompute() { |
1009 |
|
AsyncFib g = new AsyncFib(9); |
1010 |
|
assertSame(g, g.fork()); |
1011 |
|
AsyncFib f = new AsyncFib(8); |
1012 |
|
assertSame(f, f.fork()); |
1013 |
|
assertSame(f, pollNextLocalTask()); |
1014 |
|
helpQuiesce(); |
1015 |
< |
assertFalse(f.isDone()); |
1015 |
> |
checkNotDone(f); |
1016 |
> |
assertEquals(34, g.number); |
1017 |
> |
checkCompletedNormally(g); |
1018 |
|
}}; |
1019 |
|
testInvokeOnPool(singletonPool(), a); |
1020 |
|
} |
1021 |
|
|
1022 |
|
/** |
1023 |
< |
* pollTask returns an unexecuted task |
900 |
< |
* without executing it |
1023 |
> |
* pollTask returns an unexecuted task without executing it |
1024 |
|
*/ |
1025 |
|
public void testPollTask() { |
1026 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1027 |
< |
public void realCompute() { |
1027 |
> |
protected void realCompute() { |
1028 |
|
AsyncFib g = new AsyncFib(9); |
1029 |
|
assertSame(g, g.fork()); |
1030 |
|
AsyncFib f = new AsyncFib(8); |
1031 |
|
assertSame(f, f.fork()); |
1032 |
|
assertSame(f, pollTask()); |
1033 |
|
helpQuiesce(); |
1034 |
< |
assertFalse(f.isDone()); |
1035 |
< |
assertTrue(g.isDone()); |
1034 |
> |
checkNotDone(f); |
1035 |
> |
checkCompletedNormally(g); |
1036 |
|
}}; |
1037 |
|
testInvokeOnPool(singletonPool(), a); |
1038 |
|
} |
1042 |
|
*/ |
1043 |
|
public void testPeekNextLocalTaskAsync() { |
1044 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1045 |
< |
public void realCompute() { |
1045 |
> |
protected void realCompute() { |
1046 |
|
AsyncFib g = new AsyncFib(9); |
1047 |
|
assertSame(g, g.fork()); |
1048 |
|
AsyncFib f = new AsyncFib(8); |
1050 |
|
assertSame(g, peekNextLocalTask()); |
1051 |
|
assertNull(f.join()); |
1052 |
|
helpQuiesce(); |
1053 |
< |
assertTrue(f.isDone()); |
1053 |
> |
checkCompletedNormally(f); |
1054 |
> |
assertEquals(34, g.number); |
1055 |
> |
checkCompletedNormally(g); |
1056 |
|
}}; |
1057 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1058 |
|
} |
1059 |
|
|
1060 |
|
/** |
1061 |
< |
* pollNextLocalTask returns least recent unexecuted task |
1062 |
< |
* without executing it, in async mode |
1061 |
> |
* pollNextLocalTask returns least recent unexecuted task without |
1062 |
> |
* executing it, in async mode |
1063 |
|
*/ |
1064 |
|
public void testPollNextLocalTaskAsync() { |
1065 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1066 |
< |
public void realCompute() { |
1066 |
> |
protected void realCompute() { |
1067 |
|
AsyncFib g = new AsyncFib(9); |
1068 |
|
assertSame(g, g.fork()); |
1069 |
|
AsyncFib f = new AsyncFib(8); |
1070 |
|
assertSame(f, f.fork()); |
1071 |
|
assertSame(g, pollNextLocalTask()); |
1072 |
|
helpQuiesce(); |
1073 |
< |
assertTrue(f.isDone()); |
1074 |
< |
assertFalse(g.isDone()); |
1073 |
> |
assertEquals(21, f.number); |
1074 |
> |
checkCompletedNormally(f); |
1075 |
> |
checkNotDone(g); |
1076 |
|
}}; |
1077 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1078 |
|
} |
1079 |
|
|
1080 |
|
/** |
1081 |
< |
* pollTask returns an unexecuted task |
1082 |
< |
* without executing it, in async mode |
1081 |
> |
* pollTask returns an unexecuted task without executing it, in |
1082 |
> |
* async mode |
1083 |
|
*/ |
1084 |
|
public void testPollTaskAsync() { |
1085 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1086 |
< |
public void realCompute() { |
1086 |
> |
protected void realCompute() { |
1087 |
|
AsyncFib g = new AsyncFib(9); |
1088 |
|
assertSame(g, g.fork()); |
1089 |
|
AsyncFib f = new AsyncFib(8); |
1090 |
|
assertSame(f, f.fork()); |
1091 |
|
assertSame(g, pollTask()); |
1092 |
|
helpQuiesce(); |
1093 |
< |
assertTrue(f.isDone()); |
1094 |
< |
assertFalse(g.isDone()); |
1093 |
> |
assertEquals(21, f.number); |
1094 |
> |
checkCompletedNormally(f); |
1095 |
> |
checkNotDone(g); |
1096 |
|
}}; |
1097 |
|
testInvokeOnPool(asyncSingletonPool(), a); |
1098 |
|
} |
1102 |
|
/** |
1103 |
|
* invoke returns when task completes normally. |
1104 |
|
* isCompletedAbnormally and isCancelled return false for normally |
1105 |
< |
* completed tasks. getRawResult of a RecursiveAction returns null; |
1105 |
> |
* completed tasks; getRawResult returns null. |
1106 |
|
*/ |
1107 |
|
public void testInvokeSingleton() { |
1108 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1109 |
< |
public void realCompute() { |
1109 |
> |
protected void realCompute() { |
1110 |
|
AsyncFib f = new AsyncFib(8); |
1111 |
|
assertNull(f.invoke()); |
1112 |
|
assertEquals(21, f.number); |
1113 |
< |
assertTrue(f.isDone()); |
987 |
< |
assertFalse(f.isCancelled()); |
988 |
< |
assertFalse(f.isCompletedAbnormally()); |
989 |
< |
assertNull(f.getRawResult()); |
1113 |
> |
checkCompletedNormally(f); |
1114 |
|
}}; |
1115 |
|
testInvokeOnPool(singletonPool(), a); |
1116 |
|
} |
1122 |
|
*/ |
1123 |
|
public void testQuietlyInvokeSingleton() { |
1124 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1125 |
< |
public void realCompute() { |
1125 |
> |
protected void realCompute() { |
1126 |
|
AsyncFib f = new AsyncFib(8); |
1127 |
|
f.quietlyInvoke(); |
1128 |
|
assertEquals(21, f.number); |
1129 |
< |
assertTrue(f.isDone()); |
1006 |
< |
assertFalse(f.isCancelled()); |
1007 |
< |
assertFalse(f.isCompletedAbnormally()); |
1008 |
< |
assertNull(f.getRawResult()); |
1129 |
> |
checkCompletedNormally(f); |
1130 |
|
}}; |
1131 |
|
testInvokeOnPool(singletonPool(), a); |
1132 |
|
} |
1136 |
|
*/ |
1137 |
|
public void testForkJoinSingleton() { |
1138 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1139 |
< |
public void realCompute() { |
1139 |
> |
protected void realCompute() { |
1140 |
|
AsyncFib f = new AsyncFib(8); |
1141 |
|
assertSame(f, f.fork()); |
1142 |
|
assertNull(f.join()); |
1143 |
|
assertEquals(21, f.number); |
1144 |
< |
assertTrue(f.isDone()); |
1024 |
< |
assertNull(f.getRawResult()); |
1144 |
> |
checkCompletedNormally(f); |
1145 |
|
}}; |
1146 |
|
testInvokeOnPool(singletonPool(), a); |
1147 |
|
} |
1151 |
|
*/ |
1152 |
|
public void testForkGetSingleton() { |
1153 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1154 |
< |
public void realCompute() throws Exception { |
1154 |
> |
protected void realCompute() throws Exception { |
1155 |
|
AsyncFib f = new AsyncFib(8); |
1156 |
|
assertSame(f, f.fork()); |
1157 |
|
assertNull(f.get()); |
1158 |
|
assertEquals(21, f.number); |
1159 |
< |
assertTrue(f.isDone()); |
1159 |
> |
checkCompletedNormally(f); |
1160 |
|
}}; |
1161 |
|
testInvokeOnPool(singletonPool(), a); |
1162 |
|
} |
1166 |
|
*/ |
1167 |
|
public void testForkTimedGetSingleton() { |
1168 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1169 |
< |
public void realCompute() throws Exception { |
1169 |
> |
protected void realCompute() throws Exception { |
1170 |
|
AsyncFib f = new AsyncFib(8); |
1171 |
|
assertSame(f, f.fork()); |
1172 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1173 |
|
assertEquals(21, f.number); |
1174 |
< |
assertTrue(f.isDone()); |
1174 |
> |
checkCompletedNormally(f); |
1175 |
|
}}; |
1176 |
|
testInvokeOnPool(singletonPool(), a); |
1177 |
|
} |
1181 |
|
*/ |
1182 |
|
public void testForkTimedGetNPESingleton() { |
1183 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1184 |
< |
public void realCompute() throws Exception { |
1184 |
> |
protected void realCompute() throws Exception { |
1185 |
|
AsyncFib f = new AsyncFib(8); |
1186 |
|
assertSame(f, f.fork()); |
1187 |
|
try { |
1197 |
|
*/ |
1198 |
|
public void testForkQuietlyJoinSingleton() { |
1199 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1200 |
< |
public void realCompute() { |
1200 |
> |
protected void realCompute() { |
1201 |
|
AsyncFib f = new AsyncFib(8); |
1202 |
|
assertSame(f, f.fork()); |
1203 |
|
f.quietlyJoin(); |
1204 |
|
assertEquals(21, f.number); |
1205 |
< |
assertTrue(f.isDone()); |
1205 |
> |
checkCompletedNormally(f); |
1206 |
|
}}; |
1207 |
|
testInvokeOnPool(singletonPool(), a); |
1208 |
|
} |
1209 |
|
|
1090 |
– |
|
1210 |
|
/** |
1211 |
|
* helpQuiesce returns when tasks are complete. |
1212 |
|
* getQueuedTaskCount returns 0 when quiescent |
1213 |
|
*/ |
1214 |
|
public void testForkHelpQuiesceSingleton() { |
1215 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1216 |
< |
public void realCompute() { |
1216 |
> |
protected void realCompute() { |
1217 |
|
AsyncFib f = new AsyncFib(8); |
1218 |
|
assertSame(f, f.fork()); |
1219 |
< |
f.helpQuiesce(); |
1101 |
< |
assertEquals(21, f.number); |
1102 |
< |
assertTrue(f.isDone()); |
1219 |
> |
helpQuiesce(); |
1220 |
|
assertEquals(0, getQueuedTaskCount()); |
1221 |
+ |
assertEquals(21, f.number); |
1222 |
+ |
checkCompletedNormally(f); |
1223 |
|
}}; |
1224 |
|
testInvokeOnPool(singletonPool(), a); |
1225 |
|
} |
1226 |
|
|
1108 |
– |
|
1227 |
|
/** |
1228 |
|
* invoke task throws exception when task completes abnormally |
1229 |
|
*/ |
1230 |
|
public void testAbnormalInvokeSingleton() { |
1231 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1232 |
< |
public void realCompute() { |
1232 |
> |
protected void realCompute() { |
1233 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1234 |
|
try { |
1235 |
|
f.invoke(); |
1236 |
|
shouldThrow(); |
1237 |
< |
} catch (FJException success) {} |
1237 |
> |
} catch (FJException success) { |
1238 |
> |
checkCompletedAbnormally(f, success); |
1239 |
> |
} |
1240 |
|
}}; |
1241 |
|
testInvokeOnPool(singletonPool(), a); |
1242 |
|
} |
1246 |
|
*/ |
1247 |
|
public void testAbnormalQuietlyInvokeSingleton() { |
1248 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1249 |
< |
public void realCompute() { |
1249 |
> |
protected void realCompute() { |
1250 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1251 |
|
f.quietlyInvoke(); |
1252 |
< |
assertTrue(f.isDone()); |
1252 |
> |
assertTrue(f.getException() instanceof FJException); |
1253 |
> |
checkCompletedAbnormally(f, f.getException()); |
1254 |
|
}}; |
1255 |
|
testInvokeOnPool(singletonPool(), a); |
1256 |
|
} |
1260 |
|
*/ |
1261 |
|
public void testAbnormalForkJoinSingleton() { |
1262 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1263 |
< |
public void realCompute() { |
1263 |
> |
protected void realCompute() { |
1264 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1265 |
|
assertSame(f, f.fork()); |
1266 |
|
try { |
1267 |
|
f.join(); |
1268 |
|
shouldThrow(); |
1269 |
< |
} catch (FJException success) {} |
1269 |
> |
} catch (FJException success) { |
1270 |
> |
checkCompletedAbnormally(f, success); |
1271 |
> |
} |
1272 |
|
}}; |
1273 |
|
testInvokeOnPool(singletonPool(), a); |
1274 |
|
} |
1278 |
|
*/ |
1279 |
|
public void testAbnormalForkGetSingleton() { |
1280 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1281 |
< |
public void realCompute() throws Exception { |
1281 |
> |
protected void realCompute() throws Exception { |
1282 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1283 |
|
assertSame(f, f.fork()); |
1284 |
|
try { |
1287 |
|
} catch (ExecutionException success) { |
1288 |
|
Throwable cause = success.getCause(); |
1289 |
|
assertTrue(cause instanceof FJException); |
1290 |
< |
assertTrue(f.isDone()); |
1168 |
< |
assertTrue(f.isCompletedAbnormally()); |
1169 |
< |
assertSame(cause, f.getException()); |
1290 |
> |
checkCompletedAbnormally(f, cause); |
1291 |
|
} |
1292 |
|
}}; |
1293 |
|
testInvokeOnPool(singletonPool(), a); |
1298 |
|
*/ |
1299 |
|
public void testAbnormalForkTimedGetSingleton() { |
1300 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1301 |
< |
public void realCompute() throws Exception { |
1301 |
> |
protected void realCompute() throws Exception { |
1302 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1303 |
|
assertSame(f, f.fork()); |
1304 |
|
try { |
1307 |
|
} catch (ExecutionException success) { |
1308 |
|
Throwable cause = success.getCause(); |
1309 |
|
assertTrue(cause instanceof FJException); |
1310 |
< |
assertTrue(f.isDone()); |
1190 |
< |
assertTrue(f.isCompletedAbnormally()); |
1191 |
< |
assertSame(cause, f.getException()); |
1310 |
> |
checkCompletedAbnormally(f, cause); |
1311 |
|
} |
1312 |
|
}}; |
1313 |
|
testInvokeOnPool(singletonPool(), a); |
1318 |
|
*/ |
1319 |
|
public void testAbnormalForkQuietlyJoinSingleton() { |
1320 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1321 |
< |
public void realCompute() { |
1321 |
> |
protected void realCompute() { |
1322 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1323 |
|
assertSame(f, f.fork()); |
1324 |
|
f.quietlyJoin(); |
1206 |
– |
assertTrue(f.isDone()); |
1207 |
– |
assertTrue(f.isCompletedAbnormally()); |
1325 |
|
assertTrue(f.getException() instanceof FJException); |
1326 |
+ |
checkCompletedAbnormally(f, f.getException()); |
1327 |
|
}}; |
1328 |
|
testInvokeOnPool(singletonPool(), a); |
1329 |
|
} |
1333 |
|
*/ |
1334 |
|
public void testCancelledInvokeSingleton() { |
1335 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1336 |
< |
public void realCompute() { |
1336 |
> |
protected void realCompute() { |
1337 |
|
AsyncFib f = new AsyncFib(8); |
1338 |
|
assertTrue(f.cancel(true)); |
1339 |
|
try { |
1340 |
|
f.invoke(); |
1341 |
|
shouldThrow(); |
1342 |
|
} catch (CancellationException success) { |
1343 |
< |
assertTrue(f.isDone()); |
1226 |
< |
assertTrue(f.isCancelled()); |
1227 |
< |
assertTrue(f.isCompletedAbnormally()); |
1228 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1343 |
> |
checkCancelled(f); |
1344 |
|
} |
1345 |
|
}}; |
1346 |
|
testInvokeOnPool(singletonPool(), a); |
1351 |
|
*/ |
1352 |
|
public void testCancelledForkJoinSingleton() { |
1353 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1354 |
< |
public void realCompute() { |
1354 |
> |
protected void realCompute() { |
1355 |
|
AsyncFib f = new AsyncFib(8); |
1356 |
|
assertTrue(f.cancel(true)); |
1357 |
|
assertSame(f, f.fork()); |
1359 |
|
f.join(); |
1360 |
|
shouldThrow(); |
1361 |
|
} catch (CancellationException success) { |
1362 |
< |
assertTrue(f.isDone()); |
1248 |
< |
assertTrue(f.isCancelled()); |
1249 |
< |
assertTrue(f.isCompletedAbnormally()); |
1250 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1362 |
> |
checkCancelled(f); |
1363 |
|
} |
1364 |
|
}}; |
1365 |
|
testInvokeOnPool(singletonPool(), a); |
1370 |
|
*/ |
1371 |
|
public void testCancelledForkGetSingleton() { |
1372 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1373 |
< |
public void realCompute() throws Exception { |
1373 |
> |
protected void realCompute() throws Exception { |
1374 |
|
AsyncFib f = new AsyncFib(8); |
1375 |
|
assertTrue(f.cancel(true)); |
1376 |
|
assertSame(f, f.fork()); |
1378 |
|
f.get(); |
1379 |
|
shouldThrow(); |
1380 |
|
} catch (CancellationException success) { |
1381 |
< |
assertTrue(f.isDone()); |
1270 |
< |
assertTrue(f.isCancelled()); |
1271 |
< |
assertTrue(f.isCompletedAbnormally()); |
1272 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1381 |
> |
checkCancelled(f); |
1382 |
|
} |
1383 |
|
}}; |
1384 |
|
testInvokeOnPool(singletonPool(), a); |
1389 |
|
*/ |
1390 |
|
public void testCancelledForkTimedGetSingleton() throws Exception { |
1391 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1392 |
< |
public void realCompute() throws Exception { |
1392 |
> |
protected void realCompute() throws Exception { |
1393 |
|
AsyncFib f = new AsyncFib(8); |
1394 |
|
assertTrue(f.cancel(true)); |
1395 |
|
assertSame(f, f.fork()); |
1397 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
1398 |
|
shouldThrow(); |
1399 |
|
} catch (CancellationException success) { |
1400 |
< |
assertTrue(f.isDone()); |
1292 |
< |
assertTrue(f.isCancelled()); |
1293 |
< |
assertTrue(f.isCompletedAbnormally()); |
1294 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1400 |
> |
checkCancelled(f); |
1401 |
|
} |
1402 |
|
}}; |
1403 |
|
testInvokeOnPool(singletonPool(), a); |
1408 |
|
*/ |
1409 |
|
public void testCancelledForkQuietlyJoinSingleton() { |
1410 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1411 |
< |
public void realCompute() { |
1411 |
> |
protected void realCompute() { |
1412 |
|
AsyncFib f = new AsyncFib(8); |
1413 |
|
assertTrue(f.cancel(true)); |
1414 |
|
assertSame(f, f.fork()); |
1415 |
|
f.quietlyJoin(); |
1416 |
< |
assertTrue(f.isDone()); |
1311 |
< |
assertTrue(f.isCompletedAbnormally()); |
1312 |
< |
assertTrue(f.isCancelled()); |
1313 |
< |
assertTrue(f.getException() instanceof CancellationException); |
1416 |
> |
checkCancelled(f); |
1417 |
|
}}; |
1418 |
|
testInvokeOnPool(singletonPool(), a); |
1419 |
|
} |
1423 |
|
*/ |
1424 |
|
public void testCompleteExceptionallySingleton() { |
1425 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1426 |
< |
public void realCompute() { |
1426 |
> |
protected void realCompute() { |
1427 |
|
AsyncFib f = new AsyncFib(8); |
1428 |
|
f.completeExceptionally(new FJException()); |
1429 |
|
try { |
1430 |
|
f.invoke(); |
1431 |
|
shouldThrow(); |
1432 |
< |
} catch (FJException success) {} |
1432 |
> |
} catch (FJException success) { |
1433 |
> |
checkCompletedAbnormally(f, success); |
1434 |
> |
} |
1435 |
|
}}; |
1436 |
|
testInvokeOnPool(singletonPool(), a); |
1437 |
|
} |
1441 |
|
*/ |
1442 |
|
public void testInvokeAll2Singleton() { |
1443 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1444 |
< |
public void realCompute() { |
1444 |
> |
protected void realCompute() { |
1445 |
|
AsyncFib f = new AsyncFib(8); |
1446 |
|
AsyncFib g = new AsyncFib(9); |
1447 |
|
invokeAll(f, g); |
1343 |
– |
assertTrue(f.isDone()); |
1448 |
|
assertEquals(21, f.number); |
1345 |
– |
assertTrue(g.isDone()); |
1449 |
|
assertEquals(34, g.number); |
1450 |
+ |
checkCompletedNormally(f); |
1451 |
+ |
checkCompletedNormally(g); |
1452 |
|
}}; |
1453 |
|
testInvokeOnPool(singletonPool(), a); |
1454 |
|
} |
1458 |
|
*/ |
1459 |
|
public void testInvokeAll1Singleton() { |
1460 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1461 |
< |
public void realCompute() { |
1461 |
> |
protected void realCompute() { |
1462 |
|
AsyncFib f = new AsyncFib(8); |
1463 |
|
invokeAll(f); |
1464 |
< |
assertTrue(f.isDone()); |
1464 |
> |
checkCompletedNormally(f); |
1465 |
|
assertEquals(21, f.number); |
1466 |
|
}}; |
1467 |
|
testInvokeOnPool(singletonPool(), a); |
1472 |
|
*/ |
1473 |
|
public void testInvokeAll3Singleton() { |
1474 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1475 |
< |
public void realCompute() { |
1475 |
> |
protected void realCompute() { |
1476 |
|
AsyncFib f = new AsyncFib(8); |
1477 |
|
AsyncFib g = new AsyncFib(9); |
1478 |
|
AsyncFib h = new AsyncFib(7); |
1479 |
|
invokeAll(f, g, h); |
1375 |
– |
assertTrue(f.isDone()); |
1480 |
|
assertEquals(21, f.number); |
1377 |
– |
assertTrue(g.isDone()); |
1481 |
|
assertEquals(34, g.number); |
1379 |
– |
assertTrue(h.isDone()); |
1482 |
|
assertEquals(13, h.number); |
1483 |
+ |
checkCompletedNormally(f); |
1484 |
+ |
checkCompletedNormally(g); |
1485 |
+ |
checkCompletedNormally(h); |
1486 |
|
}}; |
1487 |
|
testInvokeOnPool(singletonPool(), a); |
1488 |
|
} |
1492 |
|
*/ |
1493 |
|
public void testInvokeAllCollectionSingleton() { |
1494 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1495 |
< |
public void realCompute() { |
1495 |
> |
protected void realCompute() { |
1496 |
|
AsyncFib f = new AsyncFib(8); |
1497 |
|
AsyncFib g = new AsyncFib(9); |
1498 |
|
AsyncFib h = new AsyncFib(7); |
1501 |
|
set.add(g); |
1502 |
|
set.add(h); |
1503 |
|
invokeAll(set); |
1399 |
– |
assertTrue(f.isDone()); |
1504 |
|
assertEquals(21, f.number); |
1401 |
– |
assertTrue(g.isDone()); |
1505 |
|
assertEquals(34, g.number); |
1403 |
– |
assertTrue(h.isDone()); |
1506 |
|
assertEquals(13, h.number); |
1507 |
+ |
checkCompletedNormally(f); |
1508 |
+ |
checkCompletedNormally(g); |
1509 |
+ |
checkCompletedNormally(h); |
1510 |
|
}}; |
1511 |
|
testInvokeOnPool(singletonPool(), a); |
1512 |
|
} |
1513 |
|
|
1409 |
– |
|
1514 |
|
/** |
1515 |
|
* invokeAll(tasks) with any null task throws NPE |
1516 |
|
*/ |
1517 |
|
public void testInvokeAllNPESingleton() { |
1518 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1519 |
< |
public void realCompute() { |
1519 |
> |
protected void realCompute() { |
1520 |
|
AsyncFib f = new AsyncFib(8); |
1521 |
|
AsyncFib g = new AsyncFib(9); |
1522 |
|
AsyncFib h = null; |
1533 |
|
*/ |
1534 |
|
public void testAbnormalInvokeAll2Singleton() { |
1535 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1536 |
< |
public void realCompute() { |
1536 |
> |
protected void realCompute() { |
1537 |
|
AsyncFib f = new AsyncFib(8); |
1538 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1539 |
|
try { |
1540 |
|
invokeAll(f, g); |
1541 |
|
shouldThrow(); |
1542 |
< |
} catch (FJException success) {} |
1542 |
> |
} catch (FJException success) { |
1543 |
> |
checkCompletedAbnormally(g, success); |
1544 |
> |
} |
1545 |
|
}}; |
1546 |
|
testInvokeOnPool(singletonPool(), a); |
1547 |
|
} |
1551 |
|
*/ |
1552 |
|
public void testAbnormalInvokeAll1Singleton() { |
1553 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1554 |
< |
public void realCompute() { |
1554 |
> |
protected void realCompute() { |
1555 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1556 |
|
try { |
1557 |
|
invokeAll(g); |
1558 |
|
shouldThrow(); |
1559 |
< |
} catch (FJException success) {} |
1559 |
> |
} catch (FJException success) { |
1560 |
> |
checkCompletedAbnormally(g, success); |
1561 |
> |
} |
1562 |
|
}}; |
1563 |
|
testInvokeOnPool(singletonPool(), a); |
1564 |
|
} |
1568 |
|
*/ |
1569 |
|
public void testAbnormalInvokeAll3Singleton() { |
1570 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1571 |
< |
public void realCompute() { |
1571 |
> |
protected void realCompute() { |
1572 |
|
AsyncFib f = new AsyncFib(8); |
1573 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1574 |
|
AsyncFib h = new AsyncFib(7); |
1575 |
|
try { |
1576 |
|
invokeAll(f, g, h); |
1577 |
|
shouldThrow(); |
1578 |
< |
} catch (FJException success) {} |
1578 |
> |
} catch (FJException success) { |
1579 |
> |
checkCompletedAbnormally(g, success); |
1580 |
> |
} |
1581 |
|
}}; |
1582 |
|
testInvokeOnPool(singletonPool(), a); |
1583 |
|
} |
1584 |
|
|
1585 |
|
/** |
1586 |
< |
* invokeAll(collection) throws exception if any task does |
1586 |
> |
* invokeAll(collection) throws exception if any task does |
1587 |
|
*/ |
1588 |
|
public void testAbnormalInvokeAllCollectionSingleton() { |
1589 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1590 |
< |
public void realCompute() { |
1590 |
> |
protected void realCompute() { |
1591 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1592 |
|
AsyncFib g = new AsyncFib(9); |
1593 |
|
AsyncFib h = new AsyncFib(7); |
1598 |
|
try { |
1599 |
|
invokeAll(set); |
1600 |
|
shouldThrow(); |
1601 |
< |
} catch (FJException success) {} |
1601 |
> |
} catch (FJException success) { |
1602 |
> |
checkCompletedAbnormally(f, success); |
1603 |
> |
} |
1604 |
|
}}; |
1605 |
|
testInvokeOnPool(singletonPool(), a); |
1606 |
|
} |
1607 |
|
|
1608 |
+ |
/** |
1609 |
+ |
* ForkJoinTask.quietlyComplete returns when task completes |
1610 |
+ |
* normally without setting a value. The most recent value |
1611 |
+ |
* established by setRawResult(V) (or null by default) is returned |
1612 |
+ |
* from invoke. |
1613 |
+ |
*/ |
1614 |
+ |
public void testQuietlyComplete() { |
1615 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1616 |
+ |
protected void realCompute() { |
1617 |
+ |
AsyncFib f = new AsyncFib(8); |
1618 |
+ |
f.quietlyComplete(); |
1619 |
+ |
assertEquals(8, f.number); |
1620 |
+ |
checkCompletedNormally(f); |
1621 |
+ |
}}; |
1622 |
+ |
testInvokeOnPool(mainPool(), a); |
1623 |
+ |
} |
1624 |
+ |
|
1625 |
|
} |