3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
< |
import java.util.concurrent.ExecutionException; |
6 |
> |
|
7 |
> |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
> |
|
9 |
> |
import java.util.Arrays; |
10 |
> |
import java.util.HashSet; |
11 |
> |
import java.util.concurrent.Callable; |
12 |
|
import java.util.concurrent.CancellationException; |
13 |
+ |
import java.util.concurrent.ExecutionException; |
14 |
|
import java.util.concurrent.ForkJoinPool; |
15 |
|
import java.util.concurrent.ForkJoinTask; |
10 |
– |
import java.util.concurrent.ForkJoinWorkerThread; |
16 |
|
import java.util.concurrent.RecursiveAction; |
12 |
– |
import java.util.concurrent.TimeUnit; |
17 |
|
import java.util.concurrent.TimeoutException; |
18 |
|
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
19 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
20 |
< |
import static java.util.concurrent.TimeUnit.SECONDS; |
21 |
< |
import java.util.HashSet; |
18 |
< |
import junit.framework.*; |
19 |
> |
|
20 |
> |
import junit.framework.Test; |
21 |
> |
import junit.framework.TestSuite; |
22 |
|
|
23 |
|
public class ForkJoinTaskTest extends JSR166TestCase { |
24 |
|
|
25 |
|
public static void main(String[] args) { |
26 |
< |
junit.textui.TestRunner.run(suite()); |
26 |
> |
main(suite(), args); |
27 |
|
} |
28 |
|
|
29 |
|
public static Test suite() { |
49 |
|
} |
50 |
|
|
51 |
|
private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) { |
52 |
< |
try { |
52 |
> |
try (PoolCleaner cleaner = cleaner(pool)) { |
53 |
|
assertFalse(a.isDone()); |
54 |
|
assertFalse(a.isCompletedNormally()); |
55 |
|
assertFalse(a.isCompletedAbnormally()); |
65 |
|
assertFalse(a.isCancelled()); |
66 |
|
assertNull(a.getException()); |
67 |
|
assertNull(a.getRawResult()); |
65 |
– |
} finally { |
66 |
– |
joinPool(pool); |
68 |
|
} |
69 |
|
} |
70 |
|
|
71 |
< |
void checkNotDone(ForkJoinTask a) { |
71 |
> |
void checkNotDone(ForkJoinTask<?> a) { |
72 |
|
assertFalse(a.isDone()); |
73 |
|
assertFalse(a.isCompletedNormally()); |
74 |
|
assertFalse(a.isCompletedAbnormally()); |
77 |
|
assertNull(a.getRawResult()); |
78 |
|
|
79 |
|
try { |
80 |
< |
a.get(0L, SECONDS); |
80 |
> |
a.get(randomExpiredTimeout(), randomTimeUnit()); |
81 |
|
shouldThrow(); |
82 |
|
} catch (TimeoutException success) { |
83 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
87 |
|
checkCompletedNormally(a, null); |
88 |
|
} |
89 |
|
|
90 |
< |
<T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) { |
90 |
> |
<T> void checkCompletedNormally(ForkJoinTask<T> a, T expectedValue) { |
91 |
|
assertTrue(a.isDone()); |
92 |
|
assertFalse(a.isCancelled()); |
93 |
|
assertTrue(a.isCompletedNormally()); |
94 |
|
assertFalse(a.isCompletedAbnormally()); |
95 |
|
assertNull(a.getException()); |
96 |
< |
assertSame(expected, a.getRawResult()); |
96 |
> |
assertSame(expectedValue, a.getRawResult()); |
97 |
|
|
98 |
|
{ |
99 |
|
Thread.currentThread().interrupt(); |
100 |
< |
long t0 = System.nanoTime(); |
101 |
< |
assertSame(expected, a.join()); |
102 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
100 |
> |
long startTime = System.nanoTime(); |
101 |
> |
assertSame(expectedValue, a.join()); |
102 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
103 |
|
Thread.interrupted(); |
104 |
|
} |
105 |
|
|
106 |
|
{ |
107 |
|
Thread.currentThread().interrupt(); |
108 |
< |
long t0 = System.nanoTime(); |
108 |
> |
long startTime = System.nanoTime(); |
109 |
|
a.quietlyJoin(); // should be no-op |
110 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
110 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
111 |
|
Thread.interrupted(); |
112 |
|
} |
113 |
|
|
114 |
|
assertFalse(a.cancel(false)); |
115 |
|
assertFalse(a.cancel(true)); |
116 |
+ |
|
117 |
+ |
T v1 = null, v2 = null; |
118 |
|
try { |
119 |
< |
assertSame(expected, a.get()); |
120 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
118 |
< |
try { |
119 |
< |
assertSame(expected, a.get(5L, SECONDS)); |
119 |
> |
v1 = a.get(); |
120 |
> |
v2 = a.get(randomTimeout(), randomTimeUnit()); |
121 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
122 |
+ |
assertSame(expectedValue, v1); |
123 |
+ |
assertSame(expectedValue, v2); |
124 |
|
} |
125 |
|
|
126 |
< |
void checkCancelled(ForkJoinTask a) { |
126 |
> |
void checkCancelled(ForkJoinTask<?> a) { |
127 |
|
assertTrue(a.isDone()); |
128 |
|
assertTrue(a.isCancelled()); |
129 |
|
assertFalse(a.isCompletedNormally()); |
142 |
|
Thread.interrupted(); |
143 |
|
|
144 |
|
{ |
145 |
< |
long t0 = System.nanoTime(); |
145 |
> |
long startTime = System.nanoTime(); |
146 |
|
a.quietlyJoin(); // should be no-op |
147 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
147 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
148 |
|
} |
149 |
|
|
150 |
|
try { |
154 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
155 |
|
|
156 |
|
try { |
157 |
< |
a.get(5L, SECONDS); |
157 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
158 |
|
shouldThrow(); |
159 |
|
} catch (CancellationException success) { |
160 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
161 |
|
} |
162 |
|
|
163 |
< |
void checkCompletedAbnormally(ForkJoinTask a, Throwable t) { |
163 |
> |
void checkCompletedAbnormally(ForkJoinTask<?> a, Throwable t) { |
164 |
|
assertTrue(a.isDone()); |
165 |
|
assertFalse(a.isCancelled()); |
166 |
|
assertFalse(a.isCompletedNormally()); |
180 |
|
Thread.interrupted(); |
181 |
|
|
182 |
|
{ |
183 |
< |
long t0 = System.nanoTime(); |
183 |
> |
long startTime = System.nanoTime(); |
184 |
|
a.quietlyJoin(); // should be no-op |
185 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
185 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
186 |
|
} |
187 |
|
|
188 |
|
try { |
193 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
194 |
|
|
195 |
|
try { |
196 |
< |
a.get(5L, SECONDS); |
196 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
197 |
|
shouldThrow(); |
198 |
|
} catch (ExecutionException success) { |
199 |
|
assertSame(t.getClass(), success.getCause().getClass()); |
219 |
|
AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class, |
220 |
|
"controlState"); |
221 |
|
|
222 |
< |
private BinaryAsyncAction parent; |
222 |
> |
private volatile BinaryAsyncAction parent; |
223 |
|
|
224 |
< |
private BinaryAsyncAction sibling; |
224 |
> |
private volatile BinaryAsyncAction sibling; |
225 |
|
|
226 |
|
protected BinaryAsyncAction() { |
227 |
|
} |
256 |
|
super.completeExceptionally(ex); |
257 |
|
} |
258 |
|
|
259 |
+ |
public boolean cancel(boolean mayInterruptIfRunning) { |
260 |
+ |
if (super.cancel(mayInterruptIfRunning)) { |
261 |
+ |
completeExceptionally(new FJException()); |
262 |
+ |
return true; |
263 |
+ |
} |
264 |
+ |
return false; |
265 |
+ |
} |
266 |
+ |
|
267 |
|
public final void complete() { |
268 |
|
BinaryAsyncAction a = this; |
269 |
|
for (;;) { |
285 |
|
} |
286 |
|
|
287 |
|
public final void completeExceptionally(Throwable ex) { |
288 |
< |
BinaryAsyncAction a = this; |
278 |
< |
while (!a.isCompletedAbnormally()) { |
288 |
> |
for (BinaryAsyncAction a = this;;) { |
289 |
|
a.completeThisExceptionally(ex); |
290 |
|
BinaryAsyncAction s = a.sibling; |
291 |
< |
if (s != null) |
292 |
< |
s.cancel(false); |
293 |
< |
if (!a.onException() || (a = a.parent) == null) |
291 |
> |
if (s != null && !s.isDone()) |
292 |
> |
s.completeExceptionally(ex); |
293 |
> |
if ((a = a.parent) == null) |
294 |
|
break; |
295 |
|
} |
296 |
|
} |
340 |
|
public final boolean exec() { |
341 |
|
AsyncFib f = this; |
342 |
|
int n = f.number; |
343 |
< |
if (n > 1) { |
344 |
< |
while (n > 1) { |
345 |
< |
AsyncFib p = f; |
346 |
< |
AsyncFib r = new AsyncFib(n - 2); |
347 |
< |
f = new AsyncFib(--n); |
348 |
< |
p.linkSubtasks(r, f); |
339 |
< |
r.fork(); |
340 |
< |
} |
341 |
< |
f.number = n; |
343 |
> |
while (n > 1) { |
344 |
> |
AsyncFib p = f; |
345 |
> |
AsyncFib r = new AsyncFib(n - 2); |
346 |
> |
f = new AsyncFib(--n); |
347 |
> |
p.linkSubtasks(r, f); |
348 |
> |
r.fork(); |
349 |
|
} |
350 |
|
f.complete(); |
351 |
|
return false; |
365 |
|
public final boolean exec() { |
366 |
|
FailingAsyncFib f = this; |
367 |
|
int n = f.number; |
368 |
< |
if (n > 1) { |
369 |
< |
while (n > 1) { |
370 |
< |
FailingAsyncFib p = f; |
371 |
< |
FailingAsyncFib r = new FailingAsyncFib(n - 2); |
372 |
< |
f = new FailingAsyncFib(--n); |
373 |
< |
p.linkSubtasks(r, f); |
367 |
< |
r.fork(); |
368 |
< |
} |
369 |
< |
f.number = n; |
368 |
> |
while (n > 1) { |
369 |
> |
FailingAsyncFib p = f; |
370 |
> |
FailingAsyncFib r = new FailingAsyncFib(n - 2); |
371 |
> |
f = new FailingAsyncFib(--n); |
372 |
> |
p.linkSubtasks(r, f); |
373 |
> |
r.fork(); |
374 |
|
} |
375 |
|
f.complete(); |
376 |
|
return false; |
388 |
|
*/ |
389 |
|
public void testInvoke() { |
390 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
391 |
< |
public void realCompute() { |
391 |
> |
protected void realCompute() { |
392 |
|
AsyncFib f = new AsyncFib(8); |
393 |
|
assertNull(f.invoke()); |
394 |
|
assertEquals(21, f.number); |
404 |
|
*/ |
405 |
|
public void testQuietlyInvoke() { |
406 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
407 |
< |
public void realCompute() { |
407 |
> |
protected void realCompute() { |
408 |
|
AsyncFib f = new AsyncFib(8); |
409 |
|
f.quietlyInvoke(); |
410 |
|
assertEquals(21, f.number); |
418 |
|
*/ |
419 |
|
public void testForkJoin() { |
420 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
421 |
< |
public void realCompute() { |
421 |
> |
protected void realCompute() { |
422 |
|
AsyncFib f = new AsyncFib(8); |
423 |
|
assertSame(f, f.fork()); |
424 |
|
assertNull(f.join()); |
433 |
|
*/ |
434 |
|
public void testForkGet() { |
435 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
436 |
< |
public void realCompute() throws Exception { |
436 |
> |
protected void realCompute() throws Exception { |
437 |
|
AsyncFib f = new AsyncFib(8); |
438 |
|
assertSame(f, f.fork()); |
439 |
|
assertNull(f.get()); |
448 |
|
*/ |
449 |
|
public void testForkTimedGet() { |
450 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
451 |
< |
public void realCompute() throws Exception { |
451 |
> |
protected void realCompute() throws Exception { |
452 |
|
AsyncFib f = new AsyncFib(8); |
453 |
|
assertSame(f, f.fork()); |
454 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
463 |
|
*/ |
464 |
|
public void testForkTimedGetNPE() { |
465 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
466 |
< |
public void realCompute() throws Exception { |
466 |
> |
protected void realCompute() throws Exception { |
467 |
|
AsyncFib f = new AsyncFib(8); |
468 |
|
assertSame(f, f.fork()); |
469 |
|
try { |
470 |
< |
f.get(5L, null); |
470 |
> |
f.get(randomTimeout(), null); |
471 |
|
shouldThrow(); |
472 |
|
} catch (NullPointerException success) {} |
473 |
|
}}; |
479 |
|
*/ |
480 |
|
public void testForkQuietlyJoin() { |
481 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
482 |
< |
public void realCompute() { |
482 |
> |
protected void realCompute() { |
483 |
|
AsyncFib f = new AsyncFib(8); |
484 |
|
assertSame(f, f.fork()); |
485 |
|
f.quietlyJoin(); |
495 |
|
*/ |
496 |
|
public void testForkHelpQuiesce() { |
497 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
498 |
< |
public void realCompute() { |
498 |
> |
protected void realCompute() { |
499 |
|
AsyncFib f = new AsyncFib(8); |
500 |
|
assertSame(f, f.fork()); |
501 |
|
helpQuiesce(); |
502 |
+ |
while (!f.isDone()) // wait out race |
503 |
+ |
; |
504 |
|
assertEquals(21, f.number); |
505 |
|
assertEquals(0, getQueuedTaskCount()); |
506 |
|
checkCompletedNormally(f); |
513 |
|
*/ |
514 |
|
public void testAbnormalInvoke() { |
515 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
516 |
< |
public void realCompute() { |
516 |
> |
protected void realCompute() { |
517 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
518 |
|
try { |
519 |
|
f.invoke(); |
530 |
|
*/ |
531 |
|
public void testAbnormalQuietlyInvoke() { |
532 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
533 |
< |
public void realCompute() { |
533 |
> |
protected void realCompute() { |
534 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
535 |
|
f.quietlyInvoke(); |
536 |
|
assertTrue(f.getException() instanceof FJException); |
544 |
|
*/ |
545 |
|
public void testAbnormalForkJoin() { |
546 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
547 |
< |
public void realCompute() { |
547 |
> |
protected void realCompute() { |
548 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
549 |
|
assertSame(f, f.fork()); |
550 |
|
try { |
562 |
|
*/ |
563 |
|
public void testAbnormalForkGet() { |
564 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
565 |
< |
public void realCompute() throws Exception { |
565 |
> |
protected void realCompute() throws Exception { |
566 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
567 |
|
assertSame(f, f.fork()); |
568 |
|
try { |
582 |
|
*/ |
583 |
|
public void testAbnormalForkTimedGet() { |
584 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
585 |
< |
public void realCompute() throws Exception { |
585 |
> |
protected void realCompute() throws Exception { |
586 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
587 |
|
assertSame(f, f.fork()); |
588 |
|
try { |
602 |
|
*/ |
603 |
|
public void testAbnormalForkQuietlyJoin() { |
604 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
605 |
< |
public void realCompute() { |
605 |
> |
protected void realCompute() { |
606 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
607 |
|
assertSame(f, f.fork()); |
608 |
|
f.quietlyJoin(); |
617 |
|
*/ |
618 |
|
public void testCancelledInvoke() { |
619 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
620 |
< |
public void realCompute() { |
620 |
> |
protected void realCompute() { |
621 |
|
AsyncFib f = new AsyncFib(8); |
622 |
|
assertTrue(f.cancel(true)); |
623 |
|
try { |
635 |
|
*/ |
636 |
|
public void testCancelledForkJoin() { |
637 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
638 |
< |
public void realCompute() { |
638 |
> |
protected void realCompute() { |
639 |
|
AsyncFib f = new AsyncFib(8); |
640 |
|
assertTrue(f.cancel(true)); |
641 |
|
assertSame(f, f.fork()); |
654 |
|
*/ |
655 |
|
public void testCancelledForkGet() { |
656 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
657 |
< |
public void realCompute() throws Exception { |
657 |
> |
protected void realCompute() throws Exception { |
658 |
|
AsyncFib f = new AsyncFib(8); |
659 |
|
assertTrue(f.cancel(true)); |
660 |
|
assertSame(f, f.fork()); |
673 |
|
*/ |
674 |
|
public void testCancelledForkTimedGet() throws Exception { |
675 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
676 |
< |
public void realCompute() throws Exception { |
676 |
> |
protected void realCompute() throws Exception { |
677 |
|
AsyncFib f = new AsyncFib(8); |
678 |
|
assertTrue(f.cancel(true)); |
679 |
|
assertSame(f, f.fork()); |
692 |
|
*/ |
693 |
|
public void testCancelledForkQuietlyJoin() { |
694 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
695 |
< |
public void realCompute() { |
695 |
> |
protected void realCompute() { |
696 |
|
AsyncFib f = new AsyncFib(8); |
697 |
|
assertTrue(f.cancel(true)); |
698 |
|
assertSame(f, f.fork()); |
708 |
|
public void testGetPool() { |
709 |
|
final ForkJoinPool mainPool = mainPool(); |
710 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
711 |
< |
public void realCompute() { |
711 |
> |
protected void realCompute() { |
712 |
|
assertSame(mainPool, getPool()); |
713 |
|
}}; |
714 |
|
testInvokeOnPool(mainPool, a); |
719 |
|
*/ |
720 |
|
public void testGetPool2() { |
721 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
722 |
< |
public void realCompute() { |
722 |
> |
protected void realCompute() { |
723 |
|
assertNull(getPool()); |
724 |
|
}}; |
725 |
|
assertNull(a.invoke()); |
730 |
|
*/ |
731 |
|
public void testInForkJoinPool() { |
732 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
733 |
< |
public void realCompute() { |
733 |
> |
protected void realCompute() { |
734 |
|
assertTrue(inForkJoinPool()); |
735 |
|
}}; |
736 |
|
testInvokeOnPool(mainPool(), a); |
741 |
|
*/ |
742 |
|
public void testInForkJoinPool2() { |
743 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
744 |
< |
public void realCompute() { |
744 |
> |
protected void realCompute() { |
745 |
|
assertFalse(inForkJoinPool()); |
746 |
|
}}; |
747 |
|
assertNull(a.invoke()); |
752 |
|
*/ |
753 |
|
public void testSetRawResult() { |
754 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
755 |
< |
public void realCompute() { |
755 |
> |
protected void realCompute() { |
756 |
|
setRawResult(null); |
757 |
|
assertNull(getRawResult()); |
758 |
|
}}; |
764 |
|
*/ |
765 |
|
public void testCompleteExceptionally() { |
766 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
767 |
< |
public void realCompute() { |
767 |
> |
protected void realCompute() { |
768 |
|
AsyncFib f = new AsyncFib(8); |
769 |
|
f.completeExceptionally(new FJException()); |
770 |
|
try { |
778 |
|
} |
779 |
|
|
780 |
|
/** |
781 |
+ |
* completeExceptionally(null) surprisingly has the same effect as |
782 |
+ |
* completeExceptionally(new RuntimeException()) |
783 |
+ |
*/ |
784 |
+ |
public void testCompleteExceptionally_null() { |
785 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
786 |
+ |
protected void realCompute() { |
787 |
+ |
AsyncFib f = new AsyncFib(8); |
788 |
+ |
f.completeExceptionally(null); |
789 |
+ |
try { |
790 |
+ |
f.invoke(); |
791 |
+ |
shouldThrow(); |
792 |
+ |
} catch (RuntimeException success) { |
793 |
+ |
assertSame(success.getClass(), RuntimeException.class); |
794 |
+ |
assertNull(success.getCause()); |
795 |
+ |
checkCompletedAbnormally(f, success); |
796 |
+ |
} |
797 |
+ |
}}; |
798 |
+ |
testInvokeOnPool(mainPool(), a); |
799 |
+ |
} |
800 |
+ |
|
801 |
+ |
/** |
802 |
|
* invokeAll(t1, t2) invokes all task arguments |
803 |
|
*/ |
804 |
|
public void testInvokeAll2() { |
805 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
806 |
< |
public void realCompute() { |
806 |
> |
protected void realCompute() { |
807 |
|
AsyncFib f = new AsyncFib(8); |
808 |
|
AsyncFib g = new AsyncFib(9); |
809 |
|
invokeAll(f, g); |
820 |
|
*/ |
821 |
|
public void testInvokeAll1() { |
822 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
823 |
< |
public void realCompute() { |
823 |
> |
protected void realCompute() { |
824 |
|
AsyncFib f = new AsyncFib(8); |
825 |
|
invokeAll(f); |
826 |
|
checkCompletedNormally(f); |
834 |
|
*/ |
835 |
|
public void testInvokeAll3() { |
836 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
837 |
< |
public void realCompute() { |
837 |
> |
protected void realCompute() { |
838 |
|
AsyncFib f = new AsyncFib(8); |
839 |
|
AsyncFib g = new AsyncFib(9); |
840 |
|
AsyncFib h = new AsyncFib(7); |
854 |
|
*/ |
855 |
|
public void testInvokeAllCollection() { |
856 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
857 |
< |
public void realCompute() { |
857 |
> |
protected void realCompute() { |
858 |
|
AsyncFib f = new AsyncFib(8); |
859 |
|
AsyncFib g = new AsyncFib(9); |
860 |
|
AsyncFib h = new AsyncFib(7); |
861 |
< |
HashSet set = new HashSet(); |
861 |
> |
HashSet<ForkJoinTask<?>> set = new HashSet<ForkJoinTask<?>>(); |
862 |
|
set.add(f); |
863 |
|
set.add(g); |
864 |
|
set.add(h); |
878 |
|
*/ |
879 |
|
public void testInvokeAllNPE() { |
880 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
881 |
< |
public void realCompute() { |
881 |
> |
protected void realCompute() { |
882 |
|
AsyncFib f = new AsyncFib(8); |
883 |
|
AsyncFib g = new AsyncFib(9); |
884 |
|
AsyncFib h = null; |
895 |
|
*/ |
896 |
|
public void testAbnormalInvokeAll2() { |
897 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
898 |
< |
public void realCompute() { |
898 |
> |
protected void realCompute() { |
899 |
|
AsyncFib f = new AsyncFib(8); |
900 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
901 |
+ |
ForkJoinTask<?>[] tasks = { f, g }; |
902 |
+ |
shuffle(tasks); |
903 |
|
try { |
904 |
< |
invokeAll(f, g); |
904 |
> |
invokeAll(tasks); |
905 |
|
shouldThrow(); |
906 |
|
} catch (FJException success) { |
907 |
|
checkCompletedAbnormally(g, success); |
915 |
|
*/ |
916 |
|
public void testAbnormalInvokeAll1() { |
917 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
918 |
< |
public void realCompute() { |
918 |
> |
protected void realCompute() { |
919 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
920 |
|
try { |
921 |
|
invokeAll(g); |
932 |
|
*/ |
933 |
|
public void testAbnormalInvokeAll3() { |
934 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
935 |
< |
public void realCompute() { |
935 |
> |
protected void realCompute() { |
936 |
|
AsyncFib f = new AsyncFib(8); |
937 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
938 |
|
AsyncFib h = new AsyncFib(7); |
939 |
+ |
ForkJoinTask<?>[] tasks = { f, g, h }; |
940 |
+ |
shuffle(tasks); |
941 |
|
try { |
942 |
< |
invokeAll(f, g, h); |
942 |
> |
invokeAll(tasks); |
943 |
|
shouldThrow(); |
944 |
|
} catch (FJException success) { |
945 |
|
checkCompletedAbnormally(g, success); |
949 |
|
} |
950 |
|
|
951 |
|
/** |
952 |
< |
* invokeAll(collection) throws exception if any task does |
952 |
> |
* invokeAll(collection) throws exception if any task does |
953 |
|
*/ |
954 |
|
public void testAbnormalInvokeAllCollection() { |
955 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
956 |
< |
public void realCompute() { |
956 |
> |
protected void realCompute() { |
957 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
958 |
|
AsyncFib g = new AsyncFib(9); |
959 |
|
AsyncFib h = new AsyncFib(7); |
960 |
< |
HashSet set = new HashSet(); |
961 |
< |
set.add(f); |
931 |
< |
set.add(g); |
932 |
< |
set.add(h); |
960 |
> |
ForkJoinTask<?>[] tasks = { f, g, h }; |
961 |
> |
shuffle(tasks); |
962 |
|
try { |
963 |
< |
invokeAll(set); |
963 |
> |
invokeAll(Arrays.asList(tasks)); |
964 |
|
shouldThrow(); |
965 |
|
} catch (FJException success) { |
966 |
|
checkCompletedAbnormally(f, success); |
975 |
|
*/ |
976 |
|
public void testTryUnfork() { |
977 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
978 |
< |
public void realCompute() { |
978 |
> |
protected void realCompute() { |
979 |
|
AsyncFib g = new AsyncFib(9); |
980 |
|
assertSame(g, g.fork()); |
981 |
|
AsyncFib f = new AsyncFib(8); |
994 |
|
*/ |
995 |
|
public void testGetSurplusQueuedTaskCount() { |
996 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
997 |
< |
public void realCompute() { |
997 |
> |
protected void realCompute() { |
998 |
|
AsyncFib h = new AsyncFib(7); |
999 |
|
assertSame(h, h.fork()); |
1000 |
|
AsyncFib g = new AsyncFib(9); |
1016 |
|
*/ |
1017 |
|
public void testPeekNextLocalTask() { |
1018 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1019 |
< |
public void realCompute() { |
1019 |
> |
protected void realCompute() { |
1020 |
|
AsyncFib g = new AsyncFib(9); |
1021 |
|
assertSame(g, g.fork()); |
1022 |
|
AsyncFib f = new AsyncFib(8); |
1036 |
|
*/ |
1037 |
|
public void testPollNextLocalTask() { |
1038 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1039 |
< |
public void realCompute() { |
1039 |
> |
protected void realCompute() { |
1040 |
|
AsyncFib g = new AsyncFib(9); |
1041 |
|
assertSame(g, g.fork()); |
1042 |
|
AsyncFib f = new AsyncFib(8); |
1055 |
|
*/ |
1056 |
|
public void testPollTask() { |
1057 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1058 |
< |
public void realCompute() { |
1058 |
> |
protected void realCompute() { |
1059 |
|
AsyncFib g = new AsyncFib(9); |
1060 |
|
assertSame(g, g.fork()); |
1061 |
|
AsyncFib f = new AsyncFib(8); |
1073 |
|
*/ |
1074 |
|
public void testPeekNextLocalTaskAsync() { |
1075 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1076 |
< |
public void realCompute() { |
1076 |
> |
protected void realCompute() { |
1077 |
|
AsyncFib g = new AsyncFib(9); |
1078 |
|
assertSame(g, g.fork()); |
1079 |
|
AsyncFib f = new AsyncFib(8); |
1094 |
|
*/ |
1095 |
|
public void testPollNextLocalTaskAsync() { |
1096 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1097 |
< |
public void realCompute() { |
1097 |
> |
protected void realCompute() { |
1098 |
|
AsyncFib g = new AsyncFib(9); |
1099 |
|
assertSame(g, g.fork()); |
1100 |
|
AsyncFib f = new AsyncFib(8); |
1114 |
|
*/ |
1115 |
|
public void testPollTaskAsync() { |
1116 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1117 |
< |
public void realCompute() { |
1117 |
> |
protected void realCompute() { |
1118 |
|
AsyncFib g = new AsyncFib(9); |
1119 |
|
assertSame(g, g.fork()); |
1120 |
|
AsyncFib f = new AsyncFib(8); |
1137 |
|
*/ |
1138 |
|
public void testInvokeSingleton() { |
1139 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1140 |
< |
public void realCompute() { |
1140 |
> |
protected void realCompute() { |
1141 |
|
AsyncFib f = new AsyncFib(8); |
1142 |
|
assertNull(f.invoke()); |
1143 |
|
assertEquals(21, f.number); |
1153 |
|
*/ |
1154 |
|
public void testQuietlyInvokeSingleton() { |
1155 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1156 |
< |
public void realCompute() { |
1156 |
> |
protected void realCompute() { |
1157 |
|
AsyncFib f = new AsyncFib(8); |
1158 |
|
f.quietlyInvoke(); |
1159 |
|
assertEquals(21, f.number); |
1167 |
|
*/ |
1168 |
|
public void testForkJoinSingleton() { |
1169 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1170 |
< |
public void realCompute() { |
1170 |
> |
protected void realCompute() { |
1171 |
|
AsyncFib f = new AsyncFib(8); |
1172 |
|
assertSame(f, f.fork()); |
1173 |
|
assertNull(f.join()); |
1182 |
|
*/ |
1183 |
|
public void testForkGetSingleton() { |
1184 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1185 |
< |
public void realCompute() throws Exception { |
1185 |
> |
protected void realCompute() throws Exception { |
1186 |
|
AsyncFib f = new AsyncFib(8); |
1187 |
|
assertSame(f, f.fork()); |
1188 |
|
assertNull(f.get()); |
1197 |
|
*/ |
1198 |
|
public void testForkTimedGetSingleton() { |
1199 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1200 |
< |
public void realCompute() throws Exception { |
1200 |
> |
protected void realCompute() throws Exception { |
1201 |
|
AsyncFib f = new AsyncFib(8); |
1202 |
|
assertSame(f, f.fork()); |
1203 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1212 |
|
*/ |
1213 |
|
public void testForkTimedGetNPESingleton() { |
1214 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1215 |
< |
public void realCompute() throws Exception { |
1215 |
> |
protected void realCompute() throws Exception { |
1216 |
|
AsyncFib f = new AsyncFib(8); |
1217 |
|
assertSame(f, f.fork()); |
1218 |
|
try { |
1219 |
< |
f.get(5L, null); |
1219 |
> |
f.get(randomTimeout(), null); |
1220 |
|
shouldThrow(); |
1221 |
|
} catch (NullPointerException success) {} |
1222 |
|
}}; |
1228 |
|
*/ |
1229 |
|
public void testForkQuietlyJoinSingleton() { |
1230 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1231 |
< |
public void realCompute() { |
1231 |
> |
protected void realCompute() { |
1232 |
|
AsyncFib f = new AsyncFib(8); |
1233 |
|
assertSame(f, f.fork()); |
1234 |
|
f.quietlyJoin(); |
1244 |
|
*/ |
1245 |
|
public void testForkHelpQuiesceSingleton() { |
1246 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1247 |
< |
public void realCompute() { |
1247 |
> |
protected void realCompute() { |
1248 |
|
AsyncFib f = new AsyncFib(8); |
1249 |
|
assertSame(f, f.fork()); |
1250 |
|
helpQuiesce(); |
1260 |
|
*/ |
1261 |
|
public void testAbnormalInvokeSingleton() { |
1262 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1263 |
< |
public void realCompute() { |
1263 |
> |
protected void realCompute() { |
1264 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1265 |
|
try { |
1266 |
|
f.invoke(); |
1277 |
|
*/ |
1278 |
|
public void testAbnormalQuietlyInvokeSingleton() { |
1279 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1280 |
< |
public void realCompute() { |
1280 |
> |
protected void realCompute() { |
1281 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1282 |
|
f.quietlyInvoke(); |
1283 |
|
assertTrue(f.getException() instanceof FJException); |
1291 |
|
*/ |
1292 |
|
public void testAbnormalForkJoinSingleton() { |
1293 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1294 |
< |
public void realCompute() { |
1294 |
> |
protected void realCompute() { |
1295 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1296 |
|
assertSame(f, f.fork()); |
1297 |
|
try { |
1309 |
|
*/ |
1310 |
|
public void testAbnormalForkGetSingleton() { |
1311 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1312 |
< |
public void realCompute() throws Exception { |
1312 |
> |
protected void realCompute() throws Exception { |
1313 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1314 |
|
assertSame(f, f.fork()); |
1315 |
|
try { |
1329 |
|
*/ |
1330 |
|
public void testAbnormalForkTimedGetSingleton() { |
1331 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1332 |
< |
public void realCompute() throws Exception { |
1332 |
> |
protected void realCompute() throws Exception { |
1333 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1334 |
|
assertSame(f, f.fork()); |
1335 |
|
try { |
1349 |
|
*/ |
1350 |
|
public void testAbnormalForkQuietlyJoinSingleton() { |
1351 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1352 |
< |
public void realCompute() { |
1352 |
> |
protected void realCompute() { |
1353 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1354 |
|
assertSame(f, f.fork()); |
1355 |
|
f.quietlyJoin(); |
1364 |
|
*/ |
1365 |
|
public void testCancelledInvokeSingleton() { |
1366 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1367 |
< |
public void realCompute() { |
1367 |
> |
protected void realCompute() { |
1368 |
|
AsyncFib f = new AsyncFib(8); |
1369 |
|
assertTrue(f.cancel(true)); |
1370 |
|
try { |
1382 |
|
*/ |
1383 |
|
public void testCancelledForkJoinSingleton() { |
1384 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1385 |
< |
public void realCompute() { |
1385 |
> |
protected void realCompute() { |
1386 |
|
AsyncFib f = new AsyncFib(8); |
1387 |
|
assertTrue(f.cancel(true)); |
1388 |
|
assertSame(f, f.fork()); |
1401 |
|
*/ |
1402 |
|
public void testCancelledForkGetSingleton() { |
1403 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1404 |
< |
public void realCompute() throws Exception { |
1404 |
> |
protected void realCompute() throws Exception { |
1405 |
|
AsyncFib f = new AsyncFib(8); |
1406 |
|
assertTrue(f.cancel(true)); |
1407 |
|
assertSame(f, f.fork()); |
1420 |
|
*/ |
1421 |
|
public void testCancelledForkTimedGetSingleton() throws Exception { |
1422 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1423 |
< |
public void realCompute() throws Exception { |
1423 |
> |
protected void realCompute() throws Exception { |
1424 |
|
AsyncFib f = new AsyncFib(8); |
1425 |
|
assertTrue(f.cancel(true)); |
1426 |
|
assertSame(f, f.fork()); |
1439 |
|
*/ |
1440 |
|
public void testCancelledForkQuietlyJoinSingleton() { |
1441 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1442 |
< |
public void realCompute() { |
1442 |
> |
protected void realCompute() { |
1443 |
|
AsyncFib f = new AsyncFib(8); |
1444 |
|
assertTrue(f.cancel(true)); |
1445 |
|
assertSame(f, f.fork()); |
1454 |
|
*/ |
1455 |
|
public void testCompleteExceptionallySingleton() { |
1456 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1457 |
< |
public void realCompute() { |
1457 |
> |
protected void realCompute() { |
1458 |
|
AsyncFib f = new AsyncFib(8); |
1459 |
|
f.completeExceptionally(new FJException()); |
1460 |
|
try { |
1472 |
|
*/ |
1473 |
|
public void testInvokeAll2Singleton() { |
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 |
|
invokeAll(f, g); |
1489 |
|
*/ |
1490 |
|
public void testInvokeAll1Singleton() { |
1491 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1492 |
< |
public void realCompute() { |
1492 |
> |
protected void realCompute() { |
1493 |
|
AsyncFib f = new AsyncFib(8); |
1494 |
|
invokeAll(f); |
1495 |
|
checkCompletedNormally(f); |
1503 |
|
*/ |
1504 |
|
public void testInvokeAll3Singleton() { |
1505 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1506 |
< |
public void realCompute() { |
1506 |
> |
protected void realCompute() { |
1507 |
|
AsyncFib f = new AsyncFib(8); |
1508 |
|
AsyncFib g = new AsyncFib(9); |
1509 |
|
AsyncFib h = new AsyncFib(7); |
1523 |
|
*/ |
1524 |
|
public void testInvokeAllCollectionSingleton() { |
1525 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1526 |
< |
public void realCompute() { |
1526 |
> |
protected void realCompute() { |
1527 |
|
AsyncFib f = new AsyncFib(8); |
1528 |
|
AsyncFib g = new AsyncFib(9); |
1529 |
|
AsyncFib h = new AsyncFib(7); |
1530 |
< |
HashSet set = new HashSet(); |
1530 |
> |
HashSet<ForkJoinTask<?>> set = new HashSet<ForkJoinTask<?>>(); |
1531 |
|
set.add(f); |
1532 |
|
set.add(g); |
1533 |
|
set.add(h); |
1547 |
|
*/ |
1548 |
|
public void testInvokeAllNPESingleton() { |
1549 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1550 |
< |
public void realCompute() { |
1550 |
> |
protected void realCompute() { |
1551 |
|
AsyncFib f = new AsyncFib(8); |
1552 |
|
AsyncFib g = new AsyncFib(9); |
1553 |
|
AsyncFib h = null; |
1564 |
|
*/ |
1565 |
|
public void testAbnormalInvokeAll2Singleton() { |
1566 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1567 |
< |
public void realCompute() { |
1567 |
> |
protected void realCompute() { |
1568 |
|
AsyncFib f = new AsyncFib(8); |
1569 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1570 |
+ |
ForkJoinTask<?>[] tasks = { f, g }; |
1571 |
+ |
shuffle(tasks); |
1572 |
|
try { |
1573 |
< |
invokeAll(f, g); |
1573 |
> |
invokeAll(tasks); |
1574 |
|
shouldThrow(); |
1575 |
|
} catch (FJException success) { |
1576 |
|
checkCompletedAbnormally(g, success); |
1584 |
|
*/ |
1585 |
|
public void testAbnormalInvokeAll1Singleton() { |
1586 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1587 |
< |
public void realCompute() { |
1587 |
> |
protected void realCompute() { |
1588 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1589 |
|
try { |
1590 |
|
invokeAll(g); |
1601 |
|
*/ |
1602 |
|
public void testAbnormalInvokeAll3Singleton() { |
1603 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1604 |
< |
public void realCompute() { |
1604 |
> |
protected void realCompute() { |
1605 |
|
AsyncFib f = new AsyncFib(8); |
1606 |
|
FailingAsyncFib g = new FailingAsyncFib(9); |
1607 |
|
AsyncFib h = new AsyncFib(7); |
1608 |
+ |
ForkJoinTask<?>[] tasks = { f, g, h }; |
1609 |
+ |
shuffle(tasks); |
1610 |
|
try { |
1611 |
< |
invokeAll(f, g, h); |
1611 |
> |
invokeAll(tasks); |
1612 |
|
shouldThrow(); |
1613 |
|
} catch (FJException success) { |
1614 |
|
checkCompletedAbnormally(g, success); |
1618 |
|
} |
1619 |
|
|
1620 |
|
/** |
1621 |
< |
* invokeAll(collection) throws exception if any task does |
1621 |
> |
* invokeAll(collection) throws exception if any task does |
1622 |
|
*/ |
1623 |
|
public void testAbnormalInvokeAllCollectionSingleton() { |
1624 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
1625 |
< |
public void realCompute() { |
1625 |
> |
protected void realCompute() { |
1626 |
|
FailingAsyncFib f = new FailingAsyncFib(8); |
1627 |
|
AsyncFib g = new AsyncFib(9); |
1628 |
|
AsyncFib h = new AsyncFib(7); |
1629 |
< |
HashSet set = new HashSet(); |
1630 |
< |
set.add(f); |
1598 |
< |
set.add(g); |
1599 |
< |
set.add(h); |
1629 |
> |
ForkJoinTask<?>[] tasks = { f, g, h }; |
1630 |
> |
shuffle(tasks); |
1631 |
|
try { |
1632 |
< |
invokeAll(set); |
1632 |
> |
invokeAll(Arrays.asList(tasks)); |
1633 |
|
shouldThrow(); |
1634 |
|
} catch (FJException success) { |
1635 |
|
checkCompletedAbnormally(f, success); |
1638 |
|
testInvokeOnPool(singletonPool(), a); |
1639 |
|
} |
1640 |
|
|
1641 |
+ |
/** |
1642 |
+ |
* ForkJoinTask.quietlyComplete returns when task completes |
1643 |
+ |
* normally without setting a value. The most recent value |
1644 |
+ |
* established by setRawResult(V) (or null by default) is returned |
1645 |
+ |
* from invoke. |
1646 |
+ |
*/ |
1647 |
+ |
public void testQuietlyComplete() { |
1648 |
+ |
RecursiveAction a = new CheckedRecursiveAction() { |
1649 |
+ |
protected void realCompute() { |
1650 |
+ |
AsyncFib f = new AsyncFib(8); |
1651 |
+ |
f.quietlyComplete(); |
1652 |
+ |
assertEquals(8, f.number); |
1653 |
+ |
checkCompletedNormally(f); |
1654 |
+ |
}}; |
1655 |
+ |
testInvokeOnPool(mainPool(), a); |
1656 |
+ |
} |
1657 |
+ |
|
1658 |
+ |
/** |
1659 |
+ |
* adapt(runnable).toString() contains toString of wrapped task |
1660 |
+ |
*/ |
1661 |
+ |
public void testAdapt_Runnable_toString() { |
1662 |
+ |
if (testImplementationDetails) { |
1663 |
+ |
Runnable r = () -> {}; |
1664 |
+ |
ForkJoinTask<?> task = ForkJoinTask.adapt(r); |
1665 |
+ |
assertEquals( |
1666 |
+ |
identityString(task) + "[Wrapped task = " + r.toString() + "]", |
1667 |
+ |
task.toString()); |
1668 |
+ |
} |
1669 |
+ |
} |
1670 |
+ |
|
1671 |
+ |
/** |
1672 |
+ |
* adapt(runnable, x).toString() contains toString of wrapped task |
1673 |
+ |
*/ |
1674 |
+ |
public void testAdapt_Runnable_withResult_toString() { |
1675 |
+ |
if (testImplementationDetails) { |
1676 |
+ |
Runnable r = () -> {}; |
1677 |
+ |
ForkJoinTask<String> task = ForkJoinTask.adapt(r, ""); |
1678 |
+ |
assertEquals( |
1679 |
+ |
identityString(task) + "[Wrapped task = " + r.toString() + "]", |
1680 |
+ |
task.toString()); |
1681 |
+ |
} |
1682 |
+ |
} |
1683 |
+ |
|
1684 |
+ |
/** |
1685 |
+ |
* adapt(callable).toString() contains toString of wrapped task |
1686 |
+ |
*/ |
1687 |
+ |
public void testAdapt_Callable_toString() { |
1688 |
+ |
if (testImplementationDetails) { |
1689 |
+ |
Callable<String> c = () -> ""; |
1690 |
+ |
ForkJoinTask<String> task = ForkJoinTask.adapt(c); |
1691 |
+ |
assertEquals( |
1692 |
+ |
identityString(task) + "[Wrapped task = " + c.toString() + "]", |
1693 |
+ |
task.toString()); |
1694 |
+ |
} |
1695 |
+ |
} |
1696 |
+ |
|
1697 |
+ |
// adaptInterruptible deferred to its own independent change |
1698 |
+ |
// https://bugs.openjdk.java.net/browse/JDK-8246587 |
1699 |
+ |
|
1700 |
+ |
// /** |
1701 |
+ |
// * adaptInterruptible(callable).toString() contains toString of wrapped task |
1702 |
+ |
// */ |
1703 |
+ |
// public void testAdaptInterruptible_Callable_toString() { |
1704 |
+ |
// if (testImplementationDetails) { |
1705 |
+ |
// Callable<String> c = () -> ""; |
1706 |
+ |
// ForkJoinTask<String> task = ForkJoinTask.adaptInterruptible(c); |
1707 |
+ |
// assertEquals( |
1708 |
+ |
// identityString(task) + "[Wrapped task = " + c.toString() + "]", |
1709 |
+ |
// task.toString()); |
1710 |
+ |
// } |
1711 |
+ |
// } |
1712 |
|
} |