4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
< |
import static java.util.concurrent.TimeUnit.SECONDS; |
7 |
> |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
|
|
9 |
|
import java.util.Arrays; |
10 |
|
import java.util.HashSet; |
73 |
|
|
74 |
|
Thread.currentThread().interrupt(); |
75 |
|
try { |
76 |
< |
a.get(5L, SECONDS); |
76 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
77 |
|
shouldThrow(); |
78 |
|
} catch (InterruptedException success) { |
79 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
80 |
|
} |
81 |
|
|
82 |
|
try { |
83 |
< |
a.get(0L, SECONDS); |
83 |
> |
a.get(randomExpiredTimeout(), randomTimeUnit()); |
84 |
|
shouldThrow(); |
85 |
|
} catch (TimeoutException success) { |
86 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
96 |
|
assertNull(a.join()); |
97 |
|
assertFalse(a.cancel(false)); |
98 |
|
assertFalse(a.cancel(true)); |
99 |
+ |
|
100 |
+ |
Object v1 = null, v2 = null; |
101 |
|
try { |
102 |
< |
assertNull(a.get()); |
103 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
102 |
< |
try { |
103 |
< |
assertNull(a.get(5L, SECONDS)); |
102 |
> |
v1 = a.get(); |
103 |
> |
v2 = a.get(randomTimeout(), randomTimeUnit()); |
104 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
105 |
+ |
assertNull(v1); |
106 |
+ |
assertNull(v2); |
107 |
|
} |
108 |
|
|
109 |
|
void checkCancelled(RecursiveAction a) { |
127 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
128 |
|
|
129 |
|
try { |
130 |
< |
a.get(5L, SECONDS); |
130 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
131 |
|
shouldThrow(); |
132 |
|
} catch (CancellationException success) { |
133 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
158 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
159 |
|
|
160 |
|
try { |
161 |
< |
a.get(5L, SECONDS); |
161 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
162 |
|
shouldThrow(); |
163 |
|
} catch (ExecutionException success) { |
164 |
|
assertSame(t.getClass(), success.getCause().getClass()); |
329 |
|
* succeeds in the presence of interrupts |
330 |
|
*/ |
331 |
|
public void testJoinIgnoresInterruptsOutsideForkJoinPool() { |
332 |
< |
final SynchronousQueue<FibAction[]> sq = |
331 |
< |
new SynchronousQueue<FibAction[]>(); |
332 |
> |
final SynchronousQueue<FibAction[]> sq = new SynchronousQueue<>(); |
333 |
|
RecursiveAction a = new CheckedRecursiveAction() { |
334 |
|
protected void realCompute() throws InterruptedException { |
335 |
|
FibAction[] fibActions = new FibAction[6]; |
341 |
|
fibActions[4].cancel(true); |
342 |
|
fibActions[5].completeExceptionally(new FJException()); |
343 |
|
|
344 |
< |
for (int i = 0; i < fibActions.length; i++) |
345 |
< |
fibActions[i].fork(); |
344 |
> |
for (FibAction fibAction : fibActions) |
345 |
> |
fibAction.fork(); |
346 |
|
|
347 |
|
sq.put(fibActions); |
348 |
|
|
443 |
|
protected void realCompute() throws Exception { |
444 |
|
FibAction f = new FibAction(8); |
445 |
|
assertSame(f, f.fork()); |
446 |
< |
assertNull(f.get(5L, SECONDS)); |
446 |
> |
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
447 |
|
assertEquals(21, f.result); |
448 |
|
checkCompletedNormally(f); |
449 |
|
}}; |
459 |
|
FibAction f = new FibAction(8); |
460 |
|
assertSame(f, f.fork()); |
461 |
|
try { |
462 |
< |
f.get(5L, null); |
462 |
> |
f.get(randomTimeout(), null); |
463 |
|
shouldThrow(); |
464 |
|
} catch (NullPointerException success) {} |
465 |
|
}}; |
578 |
|
FailingFibAction f = new FailingFibAction(8); |
579 |
|
assertSame(f, f.fork()); |
580 |
|
try { |
581 |
< |
f.get(5L, SECONDS); |
581 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
582 |
|
shouldThrow(); |
583 |
|
} catch (ExecutionException success) { |
584 |
|
Throwable cause = success.getCause(); |
670 |
|
assertTrue(f.cancel(true)); |
671 |
|
assertSame(f, f.fork()); |
672 |
|
try { |
673 |
< |
f.get(5L, SECONDS); |
673 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
674 |
|
shouldThrow(); |
675 |
|
} catch (CancellationException success) { |
676 |
|
checkCancelled(f); |
920 |
|
FibAction f = new FibAction(8); |
921 |
|
FibAction g = new FibAction(9); |
922 |
|
FibAction h = new FibAction(7); |
923 |
< |
HashSet set = new HashSet(); |
923 |
> |
HashSet<ForkJoinTask<?>> set = new HashSet<ForkJoinTask<?>>(); |
924 |
|
set.add(f); |
925 |
|
set.add(g); |
926 |
|
set.add(h); |
1018 |
|
FailingFibAction f = new FailingFibAction(8); |
1019 |
|
FibAction g = new FibAction(9); |
1020 |
|
FibAction h = new FibAction(7); |
1021 |
< |
HashSet set = new HashSet(); |
1021 |
> |
HashSet<ForkJoinTask<?>> set = new HashSet<ForkJoinTask<?>>(); |
1022 |
|
set.add(f); |
1023 |
|
set.add(g); |
1024 |
|
set.add(h); |