5 |
|
*/ |
6 |
|
|
7 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
– |
import static java.util.concurrent.TimeUnit.SECONDS; |
8 |
|
|
9 |
|
import java.util.HashSet; |
10 |
|
import java.util.concurrent.CancellationException; |
12 |
|
import java.util.concurrent.ExecutionException; |
13 |
|
import java.util.concurrent.ForkJoinPool; |
14 |
|
import java.util.concurrent.ForkJoinTask; |
16 |
– |
import java.util.concurrent.ThreadLocalRandom; |
15 |
|
import java.util.concurrent.TimeoutException; |
16 |
|
import java.util.concurrent.atomic.AtomicInteger; |
17 |
|
import java.util.concurrent.atomic.AtomicReference; |
76 |
|
assertNull(a.getRawResult()); |
77 |
|
|
78 |
|
try { |
79 |
< |
a.get(0L, SECONDS); |
79 |
> |
a.get(randomExpiredTimeout(), randomTimeUnit()); |
80 |
|
shouldThrow(); |
81 |
|
} catch (TimeoutException success) { |
82 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
94 |
|
Thread.currentThread().interrupt(); |
95 |
|
long startTime = System.nanoTime(); |
96 |
|
assertNull(a.join()); |
97 |
< |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
97 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
98 |
|
Thread.interrupted(); |
99 |
|
} |
100 |
|
|
102 |
|
Thread.currentThread().interrupt(); |
103 |
|
long startTime = System.nanoTime(); |
104 |
|
a.quietlyJoin(); // should be no-op |
105 |
< |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
105 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
106 |
|
Thread.interrupted(); |
107 |
|
} |
108 |
|
|
109 |
|
assertFalse(a.cancel(false)); |
110 |
|
assertFalse(a.cancel(true)); |
111 |
+ |
|
112 |
+ |
Object v1 = null, v2 = null; |
113 |
|
try { |
114 |
< |
assertNull(a.get()); |
115 |
< |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
116 |
< |
try { |
117 |
< |
assertNull(a.get(5L, SECONDS)); |
114 |
> |
v1 = a.get(); |
115 |
> |
v2 = a.get(randomTimeout(), randomTimeUnit()); |
116 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
117 |
+ |
assertNull(v1); |
118 |
+ |
assertNull(v2); |
119 |
|
} |
120 |
|
|
121 |
|
void checkCancelled(CountedCompleter a) { |
139 |
|
{ |
140 |
|
long startTime = System.nanoTime(); |
141 |
|
a.quietlyJoin(); // should be no-op |
142 |
< |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
142 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
143 |
|
} |
144 |
|
|
145 |
|
try { |
149 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
150 |
|
|
151 |
|
try { |
152 |
< |
a.get(5L, SECONDS); |
152 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
153 |
|
shouldThrow(); |
154 |
|
} catch (CancellationException success) { |
155 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
177 |
|
{ |
178 |
|
long startTime = System.nanoTime(); |
179 |
|
a.quietlyJoin(); // should be no-op |
180 |
< |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
180 |
> |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
181 |
|
} |
182 |
|
|
183 |
|
try { |
188 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
189 |
|
|
190 |
|
try { |
191 |
< |
a.get(5L, SECONDS); |
191 |
> |
a.get(randomTimeout(), randomTimeUnit()); |
192 |
|
shouldThrow(); |
193 |
|
} catch (ExecutionException success) { |
194 |
|
assertSame(t.getClass(), success.getCause().getClass()); |
211 |
|
final AtomicInteger onCompletionN = new AtomicInteger(0); |
212 |
|
final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0); |
213 |
|
final AtomicInteger setRawResultN = new AtomicInteger(0); |
214 |
< |
final AtomicReference<Object> rawResult = new AtomicReference<Object>(null); |
214 |
> |
final AtomicReference<Object> rawResult = new AtomicReference<>(null); |
215 |
|
int computeN() { return computeN.get(); } |
216 |
|
int onCompletionN() { return onCompletionN.get(); } |
217 |
|
int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); } |
703 |
|
CCF f = new LCCF(8); |
704 |
|
assertSame(f, f.fork()); |
705 |
|
try { |
706 |
< |
f.get(5L, null); |
706 |
> |
f.get(randomTimeout(), null); |
707 |
|
shouldThrow(); |
708 |
|
} catch (NullPointerException success) {} |
709 |
|
}}; |
735 |
|
CCF f = new LCCF(8); |
736 |
|
assertSame(f, f.fork()); |
737 |
|
helpQuiesce(); |
738 |
+ |
while (!f.isDone()) // wait out race |
739 |
+ |
; |
740 |
|
assertEquals(21, f.number); |
741 |
|
assertEquals(0, getQueuedTaskCount()); |
742 |
|
checkCompletedNormally(f); |
1427 |
|
CCF f = new LCCF(8); |
1428 |
|
assertSame(f, f.fork()); |
1429 |
|
try { |
1430 |
< |
f.get(5L, null); |
1430 |
> |
f.get(randomTimeout(), null); |
1431 |
|
shouldThrow(); |
1432 |
|
} catch (NullPointerException success) {} |
1433 |
|
}}; |