5 |
|
*/ |
6 |
|
|
7 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
– |
import static java.util.concurrent.TimeUnit.SECONDS; |
8 |
|
|
9 |
|
import java.util.Arrays; |
10 |
|
import java.util.concurrent.CountDownLatch; |
99 |
|
assertNull(a.getException()); |
100 |
|
assertNull(a.getRawResult()); |
101 |
|
if (a instanceof BinaryAsyncAction) |
102 |
< |
assertTrue(((BinaryAsyncAction)a).getForkJoinTaskTag() == INITIAL_STATE); |
102 |
> |
assertEquals(INITIAL_STATE, |
103 |
> |
((BinaryAsyncAction)a).getForkJoinTaskTag()); |
104 |
|
|
105 |
|
try { |
106 |
< |
a.get(0L, SECONDS); |
106 |
> |
a.get(randomExpiredTimeout(), randomTimeUnit()); |
107 |
|
shouldThrow(); |
108 |
|
} catch (TimeoutException success) { |
109 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
113 |
|
checkCompletedNormally(a, null); |
114 |
|
} |
115 |
|
|
116 |
< |
<T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) { |
116 |
> |
<T> void checkCompletedNormally(ForkJoinTask<T> a, T expectedValue) { |
117 |
|
assertTrue(a.isDone()); |
118 |
|
assertFalse(a.isCancelled()); |
119 |
|
assertTrue(a.isCompletedNormally()); |
120 |
|
assertFalse(a.isCompletedAbnormally()); |
121 |
|
assertNull(a.getException()); |
122 |
< |
assertSame(expected, a.getRawResult()); |
122 |
> |
assertSame(expectedValue, a.getRawResult()); |
123 |
|
if (a instanceof BinaryAsyncAction) |
124 |
< |
assertTrue(((BinaryAsyncAction)a).getForkJoinTaskTag() == COMPLETE_STATE); |
124 |
> |
assertEquals(COMPLETE_STATE, |
125 |
> |
((BinaryAsyncAction)a).getForkJoinTaskTag()); |
126 |
|
|
127 |
|
{ |
128 |
|
Thread.currentThread().interrupt(); |
129 |
|
long startTime = System.nanoTime(); |
130 |
< |
assertSame(expected, a.join()); |
131 |
< |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
130 |
> |
assertSame(expectedValue, a.join()); |
131 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
132 |
|
Thread.interrupted(); |
133 |
|
} |
134 |
|
|
136 |
|
Thread.currentThread().interrupt(); |
137 |
|
long startTime = System.nanoTime(); |
138 |
|
a.quietlyJoin(); // should be no-op |
139 |
< |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
139 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
140 |
|
Thread.interrupted(); |
141 |
|
} |
142 |
|
|
143 |
|
assertFalse(a.cancel(false)); |
144 |
|
assertFalse(a.cancel(true)); |
145 |
+ |
|
146 |
+ |
T v1 = null, v2 = null; |
147 |
|
try { |
148 |
< |
assertSame(expected, a.get()); |
149 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
147 |
< |
try { |
148 |
< |
assertSame(expected, a.get(5L, SECONDS)); |
148 |
> |
v1 = a.get(); |
149 |
> |
v2 = a.get(randomTimeout(), randomTimeUnit()); |
150 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
151 |
+ |
assertSame(expectedValue, v1); |
152 |
+ |
assertSame(expectedValue, v2); |
153 |
|
} |
154 |
|
|
155 |
|
void checkCompletedAbnormally(ForkJoinTask a, Throwable t) { |
176 |
|
{ |
177 |
|
long startTime = System.nanoTime(); |
178 |
|
a.quietlyJoin(); // should be no-op |
179 |
< |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
179 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
180 |
|
} |
181 |
|
|
182 |
|
try { |
187 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
188 |
|
|
189 |
|
try { |
190 |
< |
a.get(5L, SECONDS); |
190 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
191 |
|
shouldThrow(); |
192 |
|
} catch (ExecutionException success) { |
193 |
|
assertSame(t.getClass(), success.getCause().getClass()); |
489 |
|
AsyncFib f = new AsyncFib(8); |
490 |
|
assertSame(f, f.fork()); |
491 |
|
try { |
492 |
< |
f.get(5L, null); |
492 |
> |
f.get(randomTimeout(), null); |
493 |
|
shouldThrow(); |
494 |
|
} catch (NullPointerException success) {} |
495 |
|
}}; |