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); } |
98 |
|
assertFalse(a.cancel(true)); |
99 |
|
try { |
100 |
|
assertNull(a.get()); |
101 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
102 |
< |
try { |
103 |
< |
assertNull(a.get(5L, SECONDS)); |
101 |
> |
assertNull(a.get(randomTimeout(), randomTimeUnit())); |
102 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
103 |
|
} |
104 |
|
|
123 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
124 |
|
|
125 |
|
try { |
126 |
< |
a.get(5L, SECONDS); |
126 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
127 |
|
shouldThrow(); |
128 |
|
} catch (CancellationException success) { |
129 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
154 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
155 |
|
|
156 |
|
try { |
157 |
< |
a.get(5L, SECONDS); |
157 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
158 |
|
shouldThrow(); |
159 |
|
} catch (ExecutionException success) { |
160 |
|
assertSame(t.getClass(), success.getCause().getClass()); |
166 |
|
public FJException(Throwable cause) { super(cause); } |
167 |
|
} |
168 |
|
|
169 |
< |
// A simple recursive action for testing |
169 |
> |
/** A simple recursive action for testing. */ |
170 |
|
final class FibAction extends CheckedRecursiveAction { |
171 |
|
final int number; |
172 |
|
int result; |
184 |
|
} |
185 |
|
} |
186 |
|
|
187 |
< |
// A recursive action failing in base case |
187 |
> |
/** A recursive action failing in base case. */ |
188 |
|
static final class FailingFibAction extends RecursiveAction { |
189 |
|
final int number; |
190 |
|
int result; |
440 |
|
protected void realCompute() throws Exception { |
441 |
|
FibAction f = new FibAction(8); |
442 |
|
assertSame(f, f.fork()); |
443 |
< |
assertNull(f.get(5L, SECONDS)); |
443 |
> |
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
444 |
|
assertEquals(21, f.result); |
445 |
|
checkCompletedNormally(f); |
446 |
|
}}; |
456 |
|
FibAction f = new FibAction(8); |
457 |
|
assertSame(f, f.fork()); |
458 |
|
try { |
459 |
< |
f.get(5L, null); |
459 |
> |
f.get(randomTimeout(), null); |
460 |
|
shouldThrow(); |
461 |
|
} catch (NullPointerException success) {} |
462 |
|
}}; |
575 |
|
FailingFibAction f = new FailingFibAction(8); |
576 |
|
assertSame(f, f.fork()); |
577 |
|
try { |
578 |
< |
f.get(5L, SECONDS); |
578 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
579 |
|
shouldThrow(); |
580 |
|
} catch (ExecutionException success) { |
581 |
|
Throwable cause = success.getCause(); |
667 |
|
assertTrue(f.cancel(true)); |
668 |
|
assertSame(f, f.fork()); |
669 |
|
try { |
670 |
< |
f.get(5L, SECONDS); |
670 |
> |
f.get(LONG_DELAY_MS, MILLISECONDS); |
671 |
|
shouldThrow(); |
672 |
|
} catch (CancellationException success) { |
673 |
|
checkCancelled(f); |