author | dl |
Sat, 22 Jul 2017 09:18:50 -0700 | |
changeset 45937 | 646816090183 |
parent 44589 | 64d9270bd24c |
permissions | -rw-r--r-- |
35394 | 1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
3 |
* |
|
4 |
* This code is free software; you can redistribute it and/or modify it |
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
|
6 |
* published by the Free Software Foundation. |
|
7 |
* |
|
8 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
9 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
10 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
11 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
12 |
* accompanied this code). |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License version |
|
15 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
16 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17 |
* |
|
18 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
19 |
* or visit www.oracle.com if you need additional information or have any |
|
20 |
* questions. |
|
21 |
*/ |
|
22 |
||
23 |
/* |
|
24 |
* This file is available under and governed by the GNU General Public |
|
25 |
* License version 2 only, as published by the Free Software Foundation. |
|
26 |
* However, the following notice accompanied the original version of this |
|
27 |
* file: |
|
28 |
* |
|
29 |
* Written by Doug Lea with assistance from members of JCP JSR-166 |
|
30 |
* Expert Group and released to the public domain, as explained at |
|
31 |
* http://creativecommons.org/publicdomain/zero/1.0/ |
|
32 |
*/ |
|
33 |
||
34 |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
|
35 |
||
36 |
import java.util.HashSet; |
|
37 |
import java.util.concurrent.CancellationException; |
|
38 |
import java.util.concurrent.CountedCompleter; |
|
39 |
import java.util.concurrent.ExecutionException; |
|
40 |
import java.util.concurrent.ForkJoinPool; |
|
41 |
import java.util.concurrent.ForkJoinTask; |
|
42 |
import java.util.concurrent.RecursiveAction; |
|
43 |
import java.util.concurrent.TimeoutException; |
|
44 |
||
45 |
import junit.framework.Test; |
|
46 |
import junit.framework.TestSuite; |
|
47 |
||
48 |
public class ForkJoinPool8Test extends JSR166TestCase { |
|
49 |
public static void main(String[] args) { |
|
50 |
main(suite(), args); |
|
51 |
} |
|
52 |
||
53 |
public static Test suite() { |
|
54 |
return new TestSuite(ForkJoinPool8Test.class); |
|
55 |
} |
|
56 |
||
57 |
/** |
|
58 |
* Common pool exists and has expected parallelism. |
|
59 |
*/ |
|
60 |
public void testCommonPoolParallelism() { |
|
61 |
assertEquals(ForkJoinPool.getCommonPoolParallelism(), |
|
62 |
ForkJoinPool.commonPool().getParallelism()); |
|
63 |
} |
|
64 |
||
65 |
/** |
|
66 |
* Common pool cannot be shut down |
|
67 |
*/ |
|
68 |
public void testCommonPoolShutDown() { |
|
69 |
assertFalse(ForkJoinPool.commonPool().isShutdown()); |
|
70 |
assertFalse(ForkJoinPool.commonPool().isTerminating()); |
|
71 |
assertFalse(ForkJoinPool.commonPool().isTerminated()); |
|
72 |
ForkJoinPool.commonPool().shutdown(); |
|
73 |
assertFalse(ForkJoinPool.commonPool().isShutdown()); |
|
74 |
assertFalse(ForkJoinPool.commonPool().isTerminating()); |
|
75 |
assertFalse(ForkJoinPool.commonPool().isTerminated()); |
|
76 |
ForkJoinPool.commonPool().shutdownNow(); |
|
77 |
assertFalse(ForkJoinPool.commonPool().isShutdown()); |
|
78 |
assertFalse(ForkJoinPool.commonPool().isTerminating()); |
|
79 |
assertFalse(ForkJoinPool.commonPool().isTerminated()); |
|
80 |
} |
|
81 |
||
82 |
/* |
|
83 |
* All of the following test methods are adaptations of those for |
|
84 |
* RecursiveAction and CountedCompleter, but with all actions |
|
85 |
* executed in the common pool, generally implicitly via |
|
86 |
* checkInvoke. |
|
87 |
*/ |
|
88 |
||
89 |
private void checkInvoke(ForkJoinTask a) { |
|
90 |
checkNotDone(a); |
|
91 |
assertNull(a.invoke()); |
|
92 |
checkCompletedNormally(a); |
|
93 |
} |
|
94 |
||
95 |
void checkNotDone(ForkJoinTask a) { |
|
96 |
assertFalse(a.isDone()); |
|
97 |
assertFalse(a.isCompletedNormally()); |
|
98 |
assertFalse(a.isCompletedAbnormally()); |
|
99 |
assertFalse(a.isCancelled()); |
|
100 |
assertNull(a.getException()); |
|
101 |
assertNull(a.getRawResult()); |
|
102 |
||
103 |
if (! ForkJoinTask.inForkJoinPool()) { |
|
104 |
Thread.currentThread().interrupt(); |
|
105 |
try { |
|
106 |
a.get(); |
|
107 |
shouldThrow(); |
|
108 |
} catch (InterruptedException success) { |
|
109 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
|
110 |
||
111 |
Thread.currentThread().interrupt(); |
|
112 |
try { |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
113 |
a.get(randomTimeout(), randomTimeUnit()); |
35394 | 114 |
shouldThrow(); |
115 |
} catch (InterruptedException success) { |
|
116 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
|
117 |
} |
|
118 |
||
119 |
try { |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
120 |
a.get(randomExpiredTimeout(), randomTimeUnit()); |
35394 | 121 |
shouldThrow(); |
122 |
} catch (TimeoutException success) { |
|
123 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
|
124 |
} |
|
125 |
||
126 |
void checkCompletedNormally(ForkJoinTask a) { |
|
127 |
assertTrue(a.isDone()); |
|
128 |
assertFalse(a.isCancelled()); |
|
129 |
assertTrue(a.isCompletedNormally()); |
|
130 |
assertFalse(a.isCompletedAbnormally()); |
|
131 |
assertNull(a.getException()); |
|
132 |
assertNull(a.getRawResult()); |
|
133 |
assertNull(a.join()); |
|
134 |
assertFalse(a.cancel(false)); |
|
135 |
assertFalse(a.cancel(true)); |
|
136 |
try { |
|
137 |
assertNull(a.get()); |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
138 |
assertNull(a.get(randomTimeout(), randomTimeUnit())); |
35394 | 139 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
140 |
} |
|
141 |
||
142 |
void checkCancelled(ForkJoinTask a) { |
|
143 |
assertTrue(a.isDone()); |
|
144 |
assertTrue(a.isCancelled()); |
|
145 |
assertFalse(a.isCompletedNormally()); |
|
146 |
assertTrue(a.isCompletedAbnormally()); |
|
147 |
assertTrue(a.getException() instanceof CancellationException); |
|
148 |
assertNull(a.getRawResult()); |
|
149 |
||
150 |
try { |
|
151 |
a.join(); |
|
152 |
shouldThrow(); |
|
153 |
} catch (CancellationException success) { |
|
154 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
|
155 |
||
156 |
try { |
|
157 |
a.get(); |
|
158 |
shouldThrow(); |
|
159 |
} catch (CancellationException success) { |
|
160 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
|
161 |
||
162 |
try { |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
163 |
a.get(randomTimeout(), randomTimeUnit()); |
35394 | 164 |
shouldThrow(); |
165 |
} catch (CancellationException success) { |
|
166 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
|
167 |
} |
|
168 |
||
169 |
void checkCompletedAbnormally(ForkJoinTask a, Throwable t) { |
|
170 |
assertTrue(a.isDone()); |
|
171 |
assertFalse(a.isCancelled()); |
|
172 |
assertFalse(a.isCompletedNormally()); |
|
173 |
assertTrue(a.isCompletedAbnormally()); |
|
174 |
assertSame(t.getClass(), a.getException().getClass()); |
|
175 |
assertNull(a.getRawResult()); |
|
176 |
assertFalse(a.cancel(false)); |
|
177 |
assertFalse(a.cancel(true)); |
|
178 |
||
179 |
try { |
|
180 |
a.join(); |
|
181 |
shouldThrow(); |
|
182 |
} catch (Throwable expected) { |
|
183 |
assertSame(expected.getClass(), t.getClass()); |
|
184 |
} |
|
185 |
||
186 |
try { |
|
187 |
a.get(); |
|
188 |
shouldThrow(); |
|
189 |
} catch (ExecutionException success) { |
|
190 |
assertSame(t.getClass(), success.getCause().getClass()); |
|
191 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
|
192 |
||
193 |
try { |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
194 |
a.get(randomTimeout(), randomTimeUnit()); |
35394 | 195 |
shouldThrow(); |
196 |
} catch (ExecutionException success) { |
|
197 |
assertSame(t.getClass(), success.getCause().getClass()); |
|
198 |
} catch (Throwable fail) { threadUnexpectedException(fail); } |
|
199 |
} |
|
200 |
||
201 |
public static final class FJException extends RuntimeException { |
|
202 |
public FJException() { super(); } |
|
203 |
public FJException(Throwable cause) { super(cause); } |
|
204 |
} |
|
205 |
||
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
40817
diff
changeset
|
206 |
/** A simple recursive action for testing. */ |
35394 | 207 |
final class FibAction extends CheckedRecursiveAction { |
208 |
final int number; |
|
209 |
int result; |
|
210 |
FibAction(int n) { number = n; } |
|
211 |
protected void realCompute() { |
|
212 |
int n = number; |
|
213 |
if (n <= 1) |
|
214 |
result = n; |
|
215 |
else { |
|
216 |
FibAction f1 = new FibAction(n - 1); |
|
217 |
FibAction f2 = new FibAction(n - 2); |
|
218 |
invokeAll(f1, f2); |
|
219 |
result = f1.result + f2.result; |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
||
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
40817
diff
changeset
|
224 |
/** A recursive action failing in base case. */ |
35394 | 225 |
static final class FailingFibAction extends RecursiveAction { |
226 |
final int number; |
|
227 |
int result; |
|
228 |
FailingFibAction(int n) { number = n; } |
|
229 |
public void compute() { |
|
230 |
int n = number; |
|
231 |
if (n <= 1) |
|
232 |
throw new FJException(); |
|
233 |
else { |
|
234 |
FailingFibAction f1 = new FailingFibAction(n - 1); |
|
235 |
FailingFibAction f2 = new FailingFibAction(n - 2); |
|
236 |
invokeAll(f1, f2); |
|
237 |
result = f1.result + f2.result; |
|
238 |
} |
|
239 |
} |
|
240 |
} |
|
241 |
||
242 |
/** |
|
243 |
* invoke returns when task completes normally. |
|
244 |
* isCompletedAbnormally and isCancelled return false for normally |
|
245 |
* completed tasks. getRawResult of a RecursiveAction returns null; |
|
246 |
*/ |
|
247 |
public void testInvoke() { |
|
248 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
249 |
protected void realCompute() { |
|
250 |
FibAction f = new FibAction(8); |
|
251 |
assertNull(f.invoke()); |
|
252 |
assertEquals(21, f.result); |
|
253 |
checkCompletedNormally(f); |
|
254 |
}}; |
|
255 |
checkInvoke(a); |
|
256 |
} |
|
257 |
||
258 |
/** |
|
259 |
* quietlyInvoke task returns when task completes normally. |
|
260 |
* isCompletedAbnormally and isCancelled return false for normally |
|
261 |
* completed tasks |
|
262 |
*/ |
|
263 |
public void testQuietlyInvoke() { |
|
264 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
265 |
protected void realCompute() { |
|
266 |
FibAction f = new FibAction(8); |
|
267 |
f.quietlyInvoke(); |
|
268 |
assertEquals(21, f.result); |
|
269 |
checkCompletedNormally(f); |
|
270 |
}}; |
|
271 |
checkInvoke(a); |
|
272 |
} |
|
273 |
||
274 |
/** |
|
275 |
* join of a forked task returns when task completes |
|
276 |
*/ |
|
277 |
public void testForkJoin() { |
|
278 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
279 |
protected void realCompute() { |
|
280 |
FibAction f = new FibAction(8); |
|
281 |
assertSame(f, f.fork()); |
|
282 |
assertNull(f.join()); |
|
283 |
assertEquals(21, f.result); |
|
284 |
checkCompletedNormally(f); |
|
285 |
}}; |
|
286 |
checkInvoke(a); |
|
287 |
} |
|
288 |
||
289 |
/** |
|
290 |
* join/quietlyJoin of a forked task succeeds in the presence of interrupts |
|
291 |
*/ |
|
292 |
public void testJoinIgnoresInterrupts() { |
|
293 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
294 |
protected void realCompute() { |
|
295 |
FibAction f = new FibAction(8); |
|
40817
4f5fb115676d
8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents:
35394
diff
changeset
|
296 |
final Thread currentThread = Thread.currentThread(); |
35394 | 297 |
|
298 |
// test join() |
|
299 |
assertSame(f, f.fork()); |
|
40817
4f5fb115676d
8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents:
35394
diff
changeset
|
300 |
currentThread.interrupt(); |
35394 | 301 |
assertNull(f.join()); |
302 |
Thread.interrupted(); |
|
303 |
assertEquals(21, f.result); |
|
304 |
checkCompletedNormally(f); |
|
305 |
||
306 |
f = new FibAction(8); |
|
307 |
f.cancel(true); |
|
308 |
assertSame(f, f.fork()); |
|
40817
4f5fb115676d
8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents:
35394
diff
changeset
|
309 |
currentThread.interrupt(); |
35394 | 310 |
try { |
311 |
f.join(); |
|
312 |
shouldThrow(); |
|
313 |
} catch (CancellationException success) { |
|
314 |
Thread.interrupted(); |
|
315 |
checkCancelled(f); |
|
316 |
} |
|
317 |
||
318 |
f = new FibAction(8); |
|
319 |
f.completeExceptionally(new FJException()); |
|
320 |
assertSame(f, f.fork()); |
|
40817
4f5fb115676d
8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents:
35394
diff
changeset
|
321 |
currentThread.interrupt(); |
35394 | 322 |
try { |
323 |
f.join(); |
|
324 |
shouldThrow(); |
|
325 |
} catch (FJException success) { |
|
326 |
Thread.interrupted(); |
|
327 |
checkCompletedAbnormally(f, success); |
|
328 |
} |
|
329 |
||
330 |
// test quietlyJoin() |
|
331 |
f = new FibAction(8); |
|
332 |
assertSame(f, f.fork()); |
|
40817
4f5fb115676d
8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents:
35394
diff
changeset
|
333 |
currentThread.interrupt(); |
35394 | 334 |
f.quietlyJoin(); |
335 |
Thread.interrupted(); |
|
336 |
assertEquals(21, f.result); |
|
337 |
checkCompletedNormally(f); |
|
338 |
||
339 |
f = new FibAction(8); |
|
340 |
f.cancel(true); |
|
341 |
assertSame(f, f.fork()); |
|
40817
4f5fb115676d
8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents:
35394
diff
changeset
|
342 |
currentThread.interrupt(); |
35394 | 343 |
f.quietlyJoin(); |
344 |
Thread.interrupted(); |
|
345 |
checkCancelled(f); |
|
346 |
||
347 |
f = new FibAction(8); |
|
348 |
f.completeExceptionally(new FJException()); |
|
349 |
assertSame(f, f.fork()); |
|
40817
4f5fb115676d
8164169: Miscellaneous changes imported from jsr166 CVS 2016-09
dl
parents:
35394
diff
changeset
|
350 |
currentThread.interrupt(); |
35394 | 351 |
f.quietlyJoin(); |
352 |
Thread.interrupted(); |
|
353 |
checkCompletedAbnormally(f, f.getException()); |
|
354 |
}}; |
|
355 |
checkInvoke(a); |
|
356 |
a.reinitialize(); |
|
357 |
checkInvoke(a); |
|
358 |
} |
|
359 |
||
360 |
/** |
|
361 |
* get of a forked task returns when task completes |
|
362 |
*/ |
|
363 |
public void testForkGet() { |
|
364 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
365 |
protected void realCompute() throws Exception { |
|
366 |
FibAction f = new FibAction(8); |
|
367 |
assertSame(f, f.fork()); |
|
368 |
assertNull(f.get()); |
|
369 |
assertEquals(21, f.result); |
|
370 |
checkCompletedNormally(f); |
|
371 |
}}; |
|
372 |
checkInvoke(a); |
|
373 |
} |
|
374 |
||
375 |
/** |
|
376 |
* timed get of a forked task returns when task completes |
|
377 |
*/ |
|
378 |
public void testForkTimedGet() { |
|
379 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
380 |
protected void realCompute() throws Exception { |
|
381 |
FibAction f = new FibAction(8); |
|
382 |
assertSame(f, f.fork()); |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
383 |
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
35394 | 384 |
assertEquals(21, f.result); |
385 |
checkCompletedNormally(f); |
|
386 |
}}; |
|
387 |
checkInvoke(a); |
|
388 |
} |
|
389 |
||
390 |
/** |
|
391 |
* timed get with null time unit throws NPE |
|
392 |
*/ |
|
393 |
public void testForkTimedGetNPE() { |
|
394 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
395 |
protected void realCompute() throws Exception { |
|
396 |
FibAction f = new FibAction(8); |
|
397 |
assertSame(f, f.fork()); |
|
398 |
try { |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
399 |
f.get(randomTimeout(), null); |
35394 | 400 |
shouldThrow(); |
401 |
} catch (NullPointerException success) {} |
|
402 |
}}; |
|
403 |
checkInvoke(a); |
|
404 |
} |
|
405 |
||
406 |
/** |
|
407 |
* quietlyJoin of a forked task returns when task completes |
|
408 |
*/ |
|
409 |
public void testForkQuietlyJoin() { |
|
410 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
411 |
protected void realCompute() { |
|
412 |
FibAction f = new FibAction(8); |
|
413 |
assertSame(f, f.fork()); |
|
414 |
f.quietlyJoin(); |
|
415 |
assertEquals(21, f.result); |
|
416 |
checkCompletedNormally(f); |
|
417 |
}}; |
|
418 |
checkInvoke(a); |
|
419 |
} |
|
420 |
||
421 |
/** |
|
422 |
* invoke task throws exception when task completes abnormally |
|
423 |
*/ |
|
424 |
public void testAbnormalInvoke() { |
|
425 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
426 |
protected void realCompute() { |
|
427 |
FailingFibAction f = new FailingFibAction(8); |
|
428 |
try { |
|
429 |
f.invoke(); |
|
430 |
shouldThrow(); |
|
431 |
} catch (FJException success) { |
|
432 |
checkCompletedAbnormally(f, success); |
|
433 |
} |
|
434 |
}}; |
|
435 |
checkInvoke(a); |
|
436 |
} |
|
437 |
||
438 |
/** |
|
439 |
* quietlyInvoke task returns when task completes abnormally |
|
440 |
*/ |
|
441 |
public void testAbnormalQuietlyInvoke() { |
|
442 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
443 |
protected void realCompute() { |
|
444 |
FailingFibAction f = new FailingFibAction(8); |
|
445 |
f.quietlyInvoke(); |
|
446 |
assertTrue(f.getException() instanceof FJException); |
|
447 |
checkCompletedAbnormally(f, f.getException()); |
|
448 |
}}; |
|
449 |
checkInvoke(a); |
|
450 |
} |
|
451 |
||
452 |
/** |
|
453 |
* join of a forked task throws exception when task completes abnormally |
|
454 |
*/ |
|
455 |
public void testAbnormalForkJoin() { |
|
456 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
457 |
protected void realCompute() { |
|
458 |
FailingFibAction f = new FailingFibAction(8); |
|
459 |
assertSame(f, f.fork()); |
|
460 |
try { |
|
461 |
f.join(); |
|
462 |
shouldThrow(); |
|
463 |
} catch (FJException success) { |
|
464 |
checkCompletedAbnormally(f, success); |
|
465 |
} |
|
466 |
}}; |
|
467 |
checkInvoke(a); |
|
468 |
} |
|
469 |
||
470 |
/** |
|
471 |
* get of a forked task throws exception when task completes abnormally |
|
472 |
*/ |
|
473 |
public void testAbnormalForkGet() { |
|
474 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
475 |
protected void realCompute() throws Exception { |
|
476 |
FailingFibAction f = new FailingFibAction(8); |
|
477 |
assertSame(f, f.fork()); |
|
478 |
try { |
|
479 |
f.get(); |
|
480 |
shouldThrow(); |
|
481 |
} catch (ExecutionException success) { |
|
482 |
Throwable cause = success.getCause(); |
|
483 |
assertTrue(cause instanceof FJException); |
|
484 |
checkCompletedAbnormally(f, cause); |
|
485 |
} |
|
486 |
}}; |
|
487 |
checkInvoke(a); |
|
488 |
} |
|
489 |
||
490 |
/** |
|
491 |
* timed get of a forked task throws exception when task completes abnormally |
|
492 |
*/ |
|
493 |
public void testAbnormalForkTimedGet() { |
|
494 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
495 |
protected void realCompute() throws Exception { |
|
496 |
FailingFibAction f = new FailingFibAction(8); |
|
497 |
assertSame(f, f.fork()); |
|
498 |
try { |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
499 |
f.get(LONG_DELAY_MS, MILLISECONDS); |
35394 | 500 |
shouldThrow(); |
501 |
} catch (ExecutionException success) { |
|
502 |
Throwable cause = success.getCause(); |
|
503 |
assertTrue(cause instanceof FJException); |
|
504 |
checkCompletedAbnormally(f, cause); |
|
505 |
} |
|
506 |
}}; |
|
507 |
checkInvoke(a); |
|
508 |
} |
|
509 |
||
510 |
/** |
|
511 |
* quietlyJoin of a forked task returns when task completes abnormally |
|
512 |
*/ |
|
513 |
public void testAbnormalForkQuietlyJoin() { |
|
514 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
515 |
protected void realCompute() { |
|
516 |
FailingFibAction f = new FailingFibAction(8); |
|
517 |
assertSame(f, f.fork()); |
|
518 |
f.quietlyJoin(); |
|
519 |
assertTrue(f.getException() instanceof FJException); |
|
520 |
checkCompletedAbnormally(f, f.getException()); |
|
521 |
}}; |
|
522 |
checkInvoke(a); |
|
523 |
} |
|
524 |
||
525 |
/** |
|
526 |
* invoke task throws exception when task cancelled |
|
527 |
*/ |
|
528 |
public void testCancelledInvoke() { |
|
529 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
530 |
protected void realCompute() { |
|
531 |
FibAction f = new FibAction(8); |
|
532 |
assertTrue(f.cancel(true)); |
|
533 |
try { |
|
534 |
f.invoke(); |
|
535 |
shouldThrow(); |
|
536 |
} catch (CancellationException success) { |
|
537 |
checkCancelled(f); |
|
538 |
} |
|
539 |
}}; |
|
540 |
checkInvoke(a); |
|
541 |
} |
|
542 |
||
543 |
/** |
|
544 |
* join of a forked task throws exception when task cancelled |
|
545 |
*/ |
|
546 |
public void testCancelledForkJoin() { |
|
547 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
548 |
protected void realCompute() { |
|
549 |
FibAction f = new FibAction(8); |
|
550 |
assertTrue(f.cancel(true)); |
|
551 |
assertSame(f, f.fork()); |
|
552 |
try { |
|
553 |
f.join(); |
|
554 |
shouldThrow(); |
|
555 |
} catch (CancellationException success) { |
|
556 |
checkCancelled(f); |
|
557 |
} |
|
558 |
}}; |
|
559 |
checkInvoke(a); |
|
560 |
} |
|
561 |
||
562 |
/** |
|
563 |
* get of a forked task throws exception when task cancelled |
|
564 |
*/ |
|
565 |
public void testCancelledForkGet() { |
|
566 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
567 |
protected void realCompute() throws Exception { |
|
568 |
FibAction f = new FibAction(8); |
|
569 |
assertTrue(f.cancel(true)); |
|
570 |
assertSame(f, f.fork()); |
|
571 |
try { |
|
572 |
f.get(); |
|
573 |
shouldThrow(); |
|
574 |
} catch (CancellationException success) { |
|
575 |
checkCancelled(f); |
|
576 |
} |
|
577 |
}}; |
|
578 |
checkInvoke(a); |
|
579 |
} |
|
580 |
||
581 |
/** |
|
582 |
* timed get of a forked task throws exception when task cancelled |
|
583 |
*/ |
|
584 |
public void testCancelledForkTimedGet() { |
|
585 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
586 |
protected void realCompute() throws Exception { |
|
587 |
FibAction f = new FibAction(8); |
|
588 |
assertTrue(f.cancel(true)); |
|
589 |
assertSame(f, f.fork()); |
|
590 |
try { |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
591 |
f.get(LONG_DELAY_MS, MILLISECONDS); |
35394 | 592 |
shouldThrow(); |
593 |
} catch (CancellationException success) { |
|
594 |
checkCancelled(f); |
|
595 |
} |
|
596 |
}}; |
|
597 |
checkInvoke(a); |
|
598 |
} |
|
599 |
||
600 |
/** |
|
601 |
* quietlyJoin of a forked task returns when task cancelled |
|
602 |
*/ |
|
603 |
public void testCancelledForkQuietlyJoin() { |
|
604 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
605 |
protected void realCompute() { |
|
606 |
FibAction f = new FibAction(8); |
|
607 |
assertTrue(f.cancel(true)); |
|
608 |
assertSame(f, f.fork()); |
|
609 |
f.quietlyJoin(); |
|
610 |
checkCancelled(f); |
|
611 |
}}; |
|
612 |
checkInvoke(a); |
|
613 |
} |
|
614 |
||
615 |
/** |
|
616 |
* inForkJoinPool of non-FJ task returns false |
|
617 |
*/ |
|
618 |
public void testInForkJoinPool2() { |
|
619 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
620 |
protected void realCompute() { |
|
621 |
assertFalse(inForkJoinPool()); |
|
622 |
}}; |
|
623 |
assertNull(a.invoke()); |
|
624 |
} |
|
625 |
||
626 |
/** |
|
627 |
* A reinitialized normally completed task may be re-invoked |
|
628 |
*/ |
|
629 |
public void testReinitialize() { |
|
630 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
631 |
protected void realCompute() { |
|
632 |
FibAction f = new FibAction(8); |
|
633 |
checkNotDone(f); |
|
634 |
||
635 |
for (int i = 0; i < 3; i++) { |
|
636 |
assertNull(f.invoke()); |
|
637 |
assertEquals(21, f.result); |
|
638 |
checkCompletedNormally(f); |
|
639 |
f.reinitialize(); |
|
640 |
checkNotDone(f); |
|
641 |
} |
|
642 |
}}; |
|
643 |
checkInvoke(a); |
|
644 |
} |
|
645 |
||
646 |
/** |
|
647 |
* A reinitialized abnormally completed task may be re-invoked |
|
648 |
*/ |
|
649 |
public void testReinitializeAbnormal() { |
|
650 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
651 |
protected void realCompute() { |
|
652 |
FailingFibAction f = new FailingFibAction(8); |
|
653 |
checkNotDone(f); |
|
654 |
||
655 |
for (int i = 0; i < 3; i++) { |
|
656 |
try { |
|
657 |
f.invoke(); |
|
658 |
shouldThrow(); |
|
659 |
} catch (FJException success) { |
|
660 |
checkCompletedAbnormally(f, success); |
|
661 |
} |
|
662 |
f.reinitialize(); |
|
663 |
checkNotDone(f); |
|
664 |
} |
|
665 |
}}; |
|
666 |
checkInvoke(a); |
|
667 |
} |
|
668 |
||
669 |
/** |
|
670 |
* invoke task throws exception after invoking completeExceptionally |
|
671 |
*/ |
|
672 |
public void testCompleteExceptionally() { |
|
673 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
674 |
protected void realCompute() { |
|
675 |
FibAction f = new FibAction(8); |
|
676 |
f.completeExceptionally(new FJException()); |
|
677 |
try { |
|
678 |
f.invoke(); |
|
679 |
shouldThrow(); |
|
680 |
} catch (FJException success) { |
|
681 |
checkCompletedAbnormally(f, success); |
|
682 |
} |
|
683 |
}}; |
|
684 |
checkInvoke(a); |
|
685 |
} |
|
686 |
||
687 |
/** |
|
688 |
* invoke task suppresses execution invoking complete |
|
689 |
*/ |
|
690 |
public void testComplete() { |
|
691 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
692 |
protected void realCompute() { |
|
693 |
FibAction f = new FibAction(8); |
|
694 |
f.complete(null); |
|
695 |
assertNull(f.invoke()); |
|
696 |
assertEquals(0, f.result); |
|
697 |
checkCompletedNormally(f); |
|
698 |
}}; |
|
699 |
checkInvoke(a); |
|
700 |
} |
|
701 |
||
702 |
/** |
|
703 |
* invokeAll(t1, t2) invokes all task arguments |
|
704 |
*/ |
|
705 |
public void testInvokeAll2() { |
|
706 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
707 |
protected void realCompute() { |
|
708 |
FibAction f = new FibAction(8); |
|
709 |
FibAction g = new FibAction(9); |
|
710 |
invokeAll(f, g); |
|
711 |
checkCompletedNormally(f); |
|
712 |
assertEquals(21, f.result); |
|
713 |
checkCompletedNormally(g); |
|
714 |
assertEquals(34, g.result); |
|
715 |
}}; |
|
716 |
checkInvoke(a); |
|
717 |
} |
|
718 |
||
719 |
/** |
|
720 |
* invokeAll(tasks) with 1 argument invokes task |
|
721 |
*/ |
|
722 |
public void testInvokeAll1() { |
|
723 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
724 |
protected void realCompute() { |
|
725 |
FibAction f = new FibAction(8); |
|
726 |
invokeAll(f); |
|
727 |
checkCompletedNormally(f); |
|
728 |
assertEquals(21, f.result); |
|
729 |
}}; |
|
730 |
checkInvoke(a); |
|
731 |
} |
|
732 |
||
733 |
/** |
|
734 |
* invokeAll(tasks) with > 2 argument invokes tasks |
|
735 |
*/ |
|
736 |
public void testInvokeAll3() { |
|
737 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
738 |
protected void realCompute() { |
|
739 |
FibAction f = new FibAction(8); |
|
740 |
FibAction g = new FibAction(9); |
|
741 |
FibAction h = new FibAction(7); |
|
742 |
invokeAll(f, g, h); |
|
743 |
assertTrue(f.isDone()); |
|
744 |
assertTrue(g.isDone()); |
|
745 |
assertTrue(h.isDone()); |
|
746 |
checkCompletedNormally(f); |
|
747 |
assertEquals(21, f.result); |
|
748 |
checkCompletedNormally(g); |
|
749 |
assertEquals(34, g.result); |
|
750 |
checkCompletedNormally(g); |
|
751 |
assertEquals(13, h.result); |
|
752 |
}}; |
|
753 |
checkInvoke(a); |
|
754 |
} |
|
755 |
||
756 |
/** |
|
757 |
* invokeAll(collection) invokes all tasks in the collection |
|
758 |
*/ |
|
759 |
public void testInvokeAllCollection() { |
|
760 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
761 |
protected void realCompute() { |
|
762 |
FibAction f = new FibAction(8); |
|
763 |
FibAction g = new FibAction(9); |
|
764 |
FibAction h = new FibAction(7); |
|
765 |
HashSet set = new HashSet(); |
|
766 |
set.add(f); |
|
767 |
set.add(g); |
|
768 |
set.add(h); |
|
769 |
invokeAll(set); |
|
770 |
assertTrue(f.isDone()); |
|
771 |
assertTrue(g.isDone()); |
|
772 |
assertTrue(h.isDone()); |
|
773 |
checkCompletedNormally(f); |
|
774 |
assertEquals(21, f.result); |
|
775 |
checkCompletedNormally(g); |
|
776 |
assertEquals(34, g.result); |
|
777 |
checkCompletedNormally(g); |
|
778 |
assertEquals(13, h.result); |
|
779 |
}}; |
|
780 |
checkInvoke(a); |
|
781 |
} |
|
782 |
||
783 |
/** |
|
784 |
* invokeAll(tasks) with any null task throws NPE |
|
785 |
*/ |
|
786 |
public void testInvokeAllNPE() { |
|
787 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
788 |
protected void realCompute() { |
|
789 |
FibAction f = new FibAction(8); |
|
790 |
FibAction g = new FibAction(9); |
|
791 |
FibAction h = null; |
|
792 |
try { |
|
793 |
invokeAll(f, g, h); |
|
794 |
shouldThrow(); |
|
795 |
} catch (NullPointerException success) {} |
|
796 |
}}; |
|
797 |
checkInvoke(a); |
|
798 |
} |
|
799 |
||
800 |
/** |
|
801 |
* invokeAll(t1, t2) throw exception if any task does |
|
802 |
*/ |
|
803 |
public void testAbnormalInvokeAll2() { |
|
804 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
805 |
protected void realCompute() { |
|
806 |
FibAction f = new FibAction(8); |
|
807 |
FailingFibAction g = new FailingFibAction(9); |
|
808 |
try { |
|
809 |
invokeAll(f, g); |
|
810 |
shouldThrow(); |
|
811 |
} catch (FJException success) { |
|
812 |
checkCompletedAbnormally(g, success); |
|
813 |
} |
|
814 |
}}; |
|
815 |
checkInvoke(a); |
|
816 |
} |
|
817 |
||
818 |
/** |
|
819 |
* invokeAll(tasks) with 1 argument throws exception if task does |
|
820 |
*/ |
|
821 |
public void testAbnormalInvokeAll1() { |
|
822 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
823 |
protected void realCompute() { |
|
824 |
FailingFibAction g = new FailingFibAction(9); |
|
825 |
try { |
|
826 |
invokeAll(g); |
|
827 |
shouldThrow(); |
|
828 |
} catch (FJException success) { |
|
829 |
checkCompletedAbnormally(g, success); |
|
830 |
} |
|
831 |
}}; |
|
832 |
checkInvoke(a); |
|
833 |
} |
|
834 |
||
835 |
/** |
|
836 |
* invokeAll(tasks) with > 2 argument throws exception if any task does |
|
837 |
*/ |
|
838 |
public void testAbnormalInvokeAll3() { |
|
839 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
840 |
protected void realCompute() { |
|
841 |
FibAction f = new FibAction(8); |
|
842 |
FailingFibAction g = new FailingFibAction(9); |
|
843 |
FibAction h = new FibAction(7); |
|
844 |
try { |
|
845 |
invokeAll(f, g, h); |
|
846 |
shouldThrow(); |
|
847 |
} catch (FJException success) { |
|
848 |
checkCompletedAbnormally(g, success); |
|
849 |
} |
|
850 |
}}; |
|
851 |
checkInvoke(a); |
|
852 |
} |
|
853 |
||
854 |
/** |
|
855 |
* invokeAll(collection) throws exception if any task does |
|
856 |
*/ |
|
857 |
public void testAbnormalInvokeAllCollection() { |
|
858 |
RecursiveAction a = new CheckedRecursiveAction() { |
|
859 |
protected void realCompute() { |
|
860 |
FailingFibAction f = new FailingFibAction(8); |
|
861 |
FibAction g = new FibAction(9); |
|
862 |
FibAction h = new FibAction(7); |
|
863 |
HashSet set = new HashSet(); |
|
864 |
set.add(f); |
|
865 |
set.add(g); |
|
866 |
set.add(h); |
|
867 |
try { |
|
868 |
invokeAll(set); |
|
869 |
shouldThrow(); |
|
870 |
} catch (FJException success) { |
|
871 |
checkCompletedAbnormally(f, success); |
|
872 |
} |
|
873 |
}}; |
|
874 |
checkInvoke(a); |
|
875 |
} |
|
876 |
||
877 |
// CountedCompleter versions |
|
878 |
||
879 |
abstract static class CCF extends CountedCompleter { |
|
880 |
int number; |
|
881 |
int rnumber; |
|
882 |
||
883 |
public CCF(CountedCompleter parent, int n) { |
|
884 |
super(parent, 1); |
|
885 |
this.number = n; |
|
886 |
} |
|
887 |
||
888 |
public final void compute() { |
|
889 |
CountedCompleter p; |
|
890 |
CCF f = this; |
|
891 |
int n = number; |
|
892 |
while (n >= 2) { |
|
893 |
new RCCF(f, n - 2).fork(); |
|
894 |
f = new LCCF(f, --n); |
|
895 |
} |
|
896 |
f.number = n; |
|
897 |
f.onCompletion(f); |
|
898 |
if ((p = f.getCompleter()) != null) |
|
899 |
p.tryComplete(); |
|
900 |
else |
|
901 |
f.quietlyComplete(); |
|
902 |
} |
|
903 |
} |
|
904 |
||
905 |
static final class LCCF extends CCF { |
|
906 |
public LCCF(CountedCompleter parent, int n) { |
|
907 |
super(parent, n); |
|
908 |
} |
|
909 |
public final void onCompletion(CountedCompleter caller) { |
|
910 |
CCF p = (CCF)getCompleter(); |
|
911 |
int n = number + rnumber; |
|
912 |
if (p != null) |
|
913 |
p.number = n; |
|
914 |
else |
|
915 |
number = n; |
|
916 |
} |
|
917 |
} |
|
918 |
static final class RCCF extends CCF { |
|
919 |
public RCCF(CountedCompleter parent, int n) { |
|
920 |
super(parent, n); |
|
921 |
} |
|
922 |
public final void onCompletion(CountedCompleter caller) { |
|
923 |
CCF p = (CCF)getCompleter(); |
|
924 |
int n = number + rnumber; |
|
925 |
if (p != null) |
|
926 |
p.rnumber = n; |
|
927 |
else |
|
928 |
number = n; |
|
929 |
} |
|
930 |
} |
|
931 |
||
44589
64d9270bd24c
8176543: Miscellaneous changes imported from jsr166 CVS 2017-04
dl
parents:
40817
diff
changeset
|
932 |
/** Version of CCF with forced failure in left completions. */ |
35394 | 933 |
abstract static class FailingCCF extends CountedCompleter { |
934 |
int number; |
|
935 |
int rnumber; |
|
936 |
||
937 |
public FailingCCF(CountedCompleter parent, int n) { |
|
938 |
super(parent, 1); |
|
939 |
this.number = n; |
|
940 |
} |
|
941 |
||
942 |
public final void compute() { |
|
943 |
CountedCompleter p; |
|
944 |
FailingCCF f = this; |
|
945 |
int n = number; |
|
946 |
while (n >= 2) { |
|
947 |
new RFCCF(f, n - 2).fork(); |
|
948 |
f = new LFCCF(f, --n); |
|
949 |
} |
|
950 |
f.number = n; |
|
951 |
f.onCompletion(f); |
|
952 |
if ((p = f.getCompleter()) != null) |
|
953 |
p.tryComplete(); |
|
954 |
else |
|
955 |
f.quietlyComplete(); |
|
956 |
} |
|
957 |
} |
|
958 |
||
959 |
static final class LFCCF extends FailingCCF { |
|
960 |
public LFCCF(CountedCompleter parent, int n) { |
|
961 |
super(parent, n); |
|
962 |
} |
|
963 |
public final void onCompletion(CountedCompleter caller) { |
|
964 |
FailingCCF p = (FailingCCF)getCompleter(); |
|
965 |
int n = number + rnumber; |
|
966 |
if (p != null) |
|
967 |
p.number = n; |
|
968 |
else |
|
969 |
number = n; |
|
970 |
} |
|
971 |
} |
|
972 |
static final class RFCCF extends FailingCCF { |
|
973 |
public RFCCF(CountedCompleter parent, int n) { |
|
974 |
super(parent, n); |
|
975 |
} |
|
976 |
public final void onCompletion(CountedCompleter caller) { |
|
977 |
completeExceptionally(new FJException()); |
|
978 |
} |
|
979 |
} |
|
980 |
||
981 |
/** |
|
982 |
* invoke returns when task completes normally. |
|
983 |
* isCompletedAbnormally and isCancelled return false for normally |
|
984 |
* completed tasks; getRawResult returns null. |
|
985 |
*/ |
|
986 |
public void testInvokeCC() { |
|
987 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
988 |
protected void realCompute() { |
|
989 |
CCF f = new LCCF(null, 8); |
|
990 |
assertNull(f.invoke()); |
|
991 |
assertEquals(21, f.number); |
|
992 |
checkCompletedNormally(f); |
|
993 |
}}; |
|
994 |
checkInvoke(a); |
|
995 |
} |
|
996 |
||
997 |
/** |
|
998 |
* quietlyInvoke task returns when task completes normally. |
|
999 |
* isCompletedAbnormally and isCancelled return false for normally |
|
1000 |
* completed tasks |
|
1001 |
*/ |
|
1002 |
public void testQuietlyInvokeCC() { |
|
1003 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1004 |
protected void realCompute() { |
|
1005 |
CCF f = new LCCF(null, 8); |
|
1006 |
f.quietlyInvoke(); |
|
1007 |
assertEquals(21, f.number); |
|
1008 |
checkCompletedNormally(f); |
|
1009 |
}}; |
|
1010 |
checkInvoke(a); |
|
1011 |
} |
|
1012 |
||
1013 |
/** |
|
1014 |
* join of a forked task returns when task completes |
|
1015 |
*/ |
|
1016 |
public void testForkJoinCC() { |
|
1017 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1018 |
protected void realCompute() { |
|
1019 |
CCF f = new LCCF(null, 8); |
|
1020 |
assertSame(f, f.fork()); |
|
1021 |
assertNull(f.join()); |
|
1022 |
assertEquals(21, f.number); |
|
1023 |
checkCompletedNormally(f); |
|
1024 |
}}; |
|
1025 |
checkInvoke(a); |
|
1026 |
} |
|
1027 |
||
1028 |
/** |
|
1029 |
* get of a forked task returns when task completes |
|
1030 |
*/ |
|
1031 |
public void testForkGetCC() { |
|
1032 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1033 |
protected void realCompute() throws Exception { |
|
1034 |
CCF f = new LCCF(null, 8); |
|
1035 |
assertSame(f, f.fork()); |
|
1036 |
assertNull(f.get()); |
|
1037 |
assertEquals(21, f.number); |
|
1038 |
checkCompletedNormally(f); |
|
1039 |
}}; |
|
1040 |
checkInvoke(a); |
|
1041 |
} |
|
1042 |
||
1043 |
/** |
|
1044 |
* timed get of a forked task returns when task completes |
|
1045 |
*/ |
|
1046 |
public void testForkTimedGetCC() { |
|
1047 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1048 |
protected void realCompute() throws Exception { |
|
1049 |
CCF f = new LCCF(null, 8); |
|
1050 |
assertSame(f, f.fork()); |
|
1051 |
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
|
1052 |
assertEquals(21, f.number); |
|
1053 |
checkCompletedNormally(f); |
|
1054 |
}}; |
|
1055 |
checkInvoke(a); |
|
1056 |
} |
|
1057 |
||
1058 |
/** |
|
1059 |
* timed get with null time unit throws NPE |
|
1060 |
*/ |
|
1061 |
public void testForkTimedGetNPECC() { |
|
1062 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1063 |
protected void realCompute() throws Exception { |
|
1064 |
CCF f = new LCCF(null, 8); |
|
1065 |
assertSame(f, f.fork()); |
|
1066 |
try { |
|
45937
646816090183
8178409: Miscellaneous changes imported from jsr166 CVS 2017-07
dl
parents:
44589
diff
changeset
|
1067 |
f.get(randomTimeout(), null); |
35394 | 1068 |
shouldThrow(); |
1069 |
} catch (NullPointerException success) {} |
|
1070 |
}}; |
|
1071 |
checkInvoke(a); |
|
1072 |
} |
|
1073 |
||
1074 |
/** |
|
1075 |
* quietlyJoin of a forked task returns when task completes |
|
1076 |
*/ |
|
1077 |
public void testForkQuietlyJoinCC() { |
|
1078 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1079 |
protected void realCompute() { |
|
1080 |
CCF f = new LCCF(null, 8); |
|
1081 |
assertSame(f, f.fork()); |
|
1082 |
f.quietlyJoin(); |
|
1083 |
assertEquals(21, f.number); |
|
1084 |
checkCompletedNormally(f); |
|
1085 |
}}; |
|
1086 |
checkInvoke(a); |
|
1087 |
} |
|
1088 |
||
1089 |
/** |
|
1090 |
* invoke task throws exception when task completes abnormally |
|
1091 |
*/ |
|
1092 |
public void testAbnormalInvokeCC() { |
|
1093 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1094 |
protected void realCompute() { |
|
1095 |
FailingCCF f = new LFCCF(null, 8); |
|
1096 |
try { |
|
1097 |
f.invoke(); |
|
1098 |
shouldThrow(); |
|
1099 |
} catch (FJException success) { |
|
1100 |
checkCompletedAbnormally(f, success); |
|
1101 |
} |
|
1102 |
}}; |
|
1103 |
checkInvoke(a); |
|
1104 |
} |
|
1105 |
||
1106 |
/** |
|
1107 |
* quietlyInvoke task returns when task completes abnormally |
|
1108 |
*/ |
|
1109 |
public void testAbnormalQuietlyInvokeCC() { |
|
1110 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1111 |
protected void realCompute() { |
|
1112 |
FailingCCF f = new LFCCF(null, 8); |
|
1113 |
f.quietlyInvoke(); |
|
1114 |
assertTrue(f.getException() instanceof FJException); |
|
1115 |
checkCompletedAbnormally(f, f.getException()); |
|
1116 |
}}; |
|
1117 |
checkInvoke(a); |
|
1118 |
} |
|
1119 |
||
1120 |
/** |
|
1121 |
* join of a forked task throws exception when task completes abnormally |
|
1122 |
*/ |
|
1123 |
public void testAbnormalForkJoinCC() { |
|
1124 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1125 |
protected void realCompute() { |
|
1126 |
FailingCCF f = new LFCCF(null, 8); |
|
1127 |
assertSame(f, f.fork()); |
|
1128 |
try { |
|
1129 |
f.join(); |
|
1130 |
shouldThrow(); |
|
1131 |
} catch (FJException success) { |
|
1132 |
checkCompletedAbnormally(f, success); |
|
1133 |
} |
|
1134 |
}}; |
|
1135 |
checkInvoke(a); |
|
1136 |
} |
|
1137 |
||
1138 |
/** |
|
1139 |
* get of a forked task throws exception when task completes abnormally |
|
1140 |
*/ |
|
1141 |
public void testAbnormalForkGetCC() { |
|
1142 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1143 |
protected void realCompute() throws Exception { |
|
1144 |
FailingCCF f = new LFCCF(null, 8); |
|
1145 |
assertSame(f, f.fork()); |
|
1146 |
try { |
|
1147 |
f.get(); |
|
1148 |
shouldThrow(); |
|
1149 |
} catch (ExecutionException success) { |
|
1150 |
Throwable cause = success.getCause(); |
|
1151 |
assertTrue(cause instanceof FJException); |
|
1152 |
checkCompletedAbnormally(f, cause); |
|
1153 |
} |
|
1154 |
}}; |
|
1155 |
checkInvoke(a); |
|
1156 |
} |
|
1157 |
||
1158 |
/** |
|
1159 |
* timed get of a forked task throws exception when task completes abnormally |
|
1160 |
*/ |
|
1161 |
public void testAbnormalForkTimedGetCC() { |
|
1162 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1163 |
protected void realCompute() throws Exception { |
|
1164 |
FailingCCF f = new LFCCF(null, 8); |
|
1165 |
assertSame(f, f.fork()); |
|
1166 |
try { |
|
1167 |
f.get(LONG_DELAY_MS, MILLISECONDS); |
|
1168 |
shouldThrow(); |
|
1169 |
} catch (ExecutionException success) { |
|
1170 |
Throwable cause = success.getCause(); |
|
1171 |
assertTrue(cause instanceof FJException); |
|
1172 |
checkCompletedAbnormally(f, cause); |
|
1173 |
} |
|
1174 |
}}; |
|
1175 |
checkInvoke(a); |
|
1176 |
} |
|
1177 |
||
1178 |
/** |
|
1179 |
* quietlyJoin of a forked task returns when task completes abnormally |
|
1180 |
*/ |
|
1181 |
public void testAbnormalForkQuietlyJoinCC() { |
|
1182 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1183 |
protected void realCompute() { |
|
1184 |
FailingCCF f = new LFCCF(null, 8); |
|
1185 |
assertSame(f, f.fork()); |
|
1186 |
f.quietlyJoin(); |
|
1187 |
assertTrue(f.getException() instanceof FJException); |
|
1188 |
checkCompletedAbnormally(f, f.getException()); |
|
1189 |
}}; |
|
1190 |
checkInvoke(a); |
|
1191 |
} |
|
1192 |
||
1193 |
/** |
|
1194 |
* invoke task throws exception when task cancelled |
|
1195 |
*/ |
|
1196 |
public void testCancelledInvokeCC() { |
|
1197 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1198 |
protected void realCompute() { |
|
1199 |
CCF f = new LCCF(null, 8); |
|
1200 |
assertTrue(f.cancel(true)); |
|
1201 |
try { |
|
1202 |
f.invoke(); |
|
1203 |
shouldThrow(); |
|
1204 |
} catch (CancellationException success) { |
|
1205 |
checkCancelled(f); |
|
1206 |
} |
|
1207 |
}}; |
|
1208 |
checkInvoke(a); |
|
1209 |
} |
|
1210 |
||
1211 |
/** |
|
1212 |
* join of a forked task throws exception when task cancelled |
|
1213 |
*/ |
|
1214 |
public void testCancelledForkJoinCC() { |
|
1215 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1216 |
protected void realCompute() { |
|
1217 |
CCF f = new LCCF(null, 8); |
|
1218 |
assertTrue(f.cancel(true)); |
|
1219 |
assertSame(f, f.fork()); |
|
1220 |
try { |
|
1221 |
f.join(); |
|
1222 |
shouldThrow(); |
|
1223 |
} catch (CancellationException success) { |
|
1224 |
checkCancelled(f); |
|
1225 |
} |
|
1226 |
}}; |
|
1227 |
checkInvoke(a); |
|
1228 |
} |
|
1229 |
||
1230 |
/** |
|
1231 |
* get of a forked task throws exception when task cancelled |
|
1232 |
*/ |
|
1233 |
public void testCancelledForkGetCC() { |
|
1234 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1235 |
protected void realCompute() throws Exception { |
|
1236 |
CCF f = new LCCF(null, 8); |
|
1237 |
assertTrue(f.cancel(true)); |
|
1238 |
assertSame(f, f.fork()); |
|
1239 |
try { |
|
1240 |
f.get(); |
|
1241 |
shouldThrow(); |
|
1242 |
} catch (CancellationException success) { |
|
1243 |
checkCancelled(f); |
|
1244 |
} |
|
1245 |
}}; |
|
1246 |
checkInvoke(a); |
|
1247 |
} |
|
1248 |
||
1249 |
/** |
|
1250 |
* timed get of a forked task throws exception when task cancelled |
|
1251 |
*/ |
|
1252 |
public void testCancelledForkTimedGetCC() throws Exception { |
|
1253 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1254 |
protected void realCompute() throws Exception { |
|
1255 |
CCF f = new LCCF(null, 8); |
|
1256 |
assertTrue(f.cancel(true)); |
|
1257 |
assertSame(f, f.fork()); |
|
1258 |
try { |
|
1259 |
f.get(LONG_DELAY_MS, MILLISECONDS); |
|
1260 |
shouldThrow(); |
|
1261 |
} catch (CancellationException success) { |
|
1262 |
checkCancelled(f); |
|
1263 |
} |
|
1264 |
}}; |
|
1265 |
checkInvoke(a); |
|
1266 |
} |
|
1267 |
||
1268 |
/** |
|
1269 |
* quietlyJoin of a forked task returns when task cancelled |
|
1270 |
*/ |
|
1271 |
public void testCancelledForkQuietlyJoinCC() { |
|
1272 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1273 |
protected void realCompute() { |
|
1274 |
CCF f = new LCCF(null, 8); |
|
1275 |
assertTrue(f.cancel(true)); |
|
1276 |
assertSame(f, f.fork()); |
|
1277 |
f.quietlyJoin(); |
|
1278 |
checkCancelled(f); |
|
1279 |
}}; |
|
1280 |
checkInvoke(a); |
|
1281 |
} |
|
1282 |
||
1283 |
/** |
|
1284 |
* getPool of non-FJ task returns null |
|
1285 |
*/ |
|
1286 |
public void testGetPool2CC() { |
|
1287 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1288 |
protected void realCompute() { |
|
1289 |
assertNull(getPool()); |
|
1290 |
}}; |
|
1291 |
assertNull(a.invoke()); |
|
1292 |
} |
|
1293 |
||
1294 |
/** |
|
1295 |
* inForkJoinPool of non-FJ task returns false |
|
1296 |
*/ |
|
1297 |
public void testInForkJoinPool2CC() { |
|
1298 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1299 |
protected void realCompute() { |
|
1300 |
assertFalse(inForkJoinPool()); |
|
1301 |
}}; |
|
1302 |
assertNull(a.invoke()); |
|
1303 |
} |
|
1304 |
||
1305 |
/** |
|
1306 |
* setRawResult(null) succeeds |
|
1307 |
*/ |
|
1308 |
public void testSetRawResultCC() { |
|
1309 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1310 |
protected void realCompute() { |
|
1311 |
setRawResult(null); |
|
1312 |
assertNull(getRawResult()); |
|
1313 |
}}; |
|
1314 |
assertNull(a.invoke()); |
|
1315 |
} |
|
1316 |
||
1317 |
/** |
|
1318 |
* invoke task throws exception after invoking completeExceptionally |
|
1319 |
*/ |
|
1320 |
public void testCompleteExceptionally2CC() { |
|
1321 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1322 |
protected void realCompute() { |
|
1323 |
CCF f = new LCCF(null, 8); |
|
1324 |
f.completeExceptionally(new FJException()); |
|
1325 |
try { |
|
1326 |
f.invoke(); |
|
1327 |
shouldThrow(); |
|
1328 |
} catch (FJException success) { |
|
1329 |
checkCompletedAbnormally(f, success); |
|
1330 |
} |
|
1331 |
}}; |
|
1332 |
checkInvoke(a); |
|
1333 |
} |
|
1334 |
||
1335 |
/** |
|
1336 |
* invokeAll(t1, t2) invokes all task arguments |
|
1337 |
*/ |
|
1338 |
public void testInvokeAll2CC() { |
|
1339 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1340 |
protected void realCompute() { |
|
1341 |
CCF f = new LCCF(null, 8); |
|
1342 |
CCF g = new LCCF(null, 9); |
|
1343 |
invokeAll(f, g); |
|
1344 |
assertEquals(21, f.number); |
|
1345 |
assertEquals(34, g.number); |
|
1346 |
checkCompletedNormally(f); |
|
1347 |
checkCompletedNormally(g); |
|
1348 |
}}; |
|
1349 |
checkInvoke(a); |
|
1350 |
} |
|
1351 |
||
1352 |
/** |
|
1353 |
* invokeAll(tasks) with 1 argument invokes task |
|
1354 |
*/ |
|
1355 |
public void testInvokeAll1CC() { |
|
1356 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1357 |
protected void realCompute() { |
|
1358 |
CCF f = new LCCF(null, 8); |
|
1359 |
invokeAll(f); |
|
1360 |
checkCompletedNormally(f); |
|
1361 |
assertEquals(21, f.number); |
|
1362 |
}}; |
|
1363 |
checkInvoke(a); |
|
1364 |
} |
|
1365 |
||
1366 |
/** |
|
1367 |
* invokeAll(tasks) with > 2 argument invokes tasks |
|
1368 |
*/ |
|
1369 |
public void testInvokeAll3CC() { |
|
1370 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1371 |
protected void realCompute() { |
|
1372 |
CCF f = new LCCF(null, 8); |
|
1373 |
CCF g = new LCCF(null, 9); |
|
1374 |
CCF h = new LCCF(null, 7); |
|
1375 |
invokeAll(f, g, h); |
|
1376 |
assertEquals(21, f.number); |
|
1377 |
assertEquals(34, g.number); |
|
1378 |
assertEquals(13, h.number); |
|
1379 |
checkCompletedNormally(f); |
|
1380 |
checkCompletedNormally(g); |
|
1381 |
checkCompletedNormally(h); |
|
1382 |
}}; |
|
1383 |
checkInvoke(a); |
|
1384 |
} |
|
1385 |
||
1386 |
/** |
|
1387 |
* invokeAll(collection) invokes all tasks in the collection |
|
1388 |
*/ |
|
1389 |
public void testInvokeAllCollectionCC() { |
|
1390 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1391 |
protected void realCompute() { |
|
1392 |
CCF f = new LCCF(null, 8); |
|
1393 |
CCF g = new LCCF(null, 9); |
|
1394 |
CCF h = new LCCF(null, 7); |
|
1395 |
HashSet set = new HashSet(); |
|
1396 |
set.add(f); |
|
1397 |
set.add(g); |
|
1398 |
set.add(h); |
|
1399 |
invokeAll(set); |
|
1400 |
assertEquals(21, f.number); |
|
1401 |
assertEquals(34, g.number); |
|
1402 |
assertEquals(13, h.number); |
|
1403 |
checkCompletedNormally(f); |
|
1404 |
checkCompletedNormally(g); |
|
1405 |
checkCompletedNormally(h); |
|
1406 |
}}; |
|
1407 |
checkInvoke(a); |
|
1408 |
} |
|
1409 |
||
1410 |
/** |
|
1411 |
* invokeAll(tasks) with any null task throws NPE |
|
1412 |
*/ |
|
1413 |
public void testInvokeAllNPECC() { |
|
1414 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1415 |
protected void realCompute() { |
|
1416 |
CCF f = new LCCF(null, 8); |
|
1417 |
CCF g = new LCCF(null, 9); |
|
1418 |
CCF h = null; |
|
1419 |
try { |
|
1420 |
invokeAll(f, g, h); |
|
1421 |
shouldThrow(); |
|
1422 |
} catch (NullPointerException success) {} |
|
1423 |
}}; |
|
1424 |
checkInvoke(a); |
|
1425 |
} |
|
1426 |
||
1427 |
/** |
|
1428 |
* invokeAll(t1, t2) throw exception if any task does |
|
1429 |
*/ |
|
1430 |
public void testAbnormalInvokeAll2CC() { |
|
1431 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1432 |
protected void realCompute() { |
|
1433 |
CCF f = new LCCF(null, 8); |
|
1434 |
FailingCCF g = new LFCCF(null, 9); |
|
1435 |
try { |
|
1436 |
invokeAll(f, g); |
|
1437 |
shouldThrow(); |
|
1438 |
} catch (FJException success) { |
|
1439 |
checkCompletedAbnormally(g, success); |
|
1440 |
} |
|
1441 |
}}; |
|
1442 |
checkInvoke(a); |
|
1443 |
} |
|
1444 |
||
1445 |
/** |
|
1446 |
* invokeAll(tasks) with 1 argument throws exception if task does |
|
1447 |
*/ |
|
1448 |
public void testAbnormalInvokeAll1CC() { |
|
1449 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1450 |
protected void realCompute() { |
|
1451 |
FailingCCF g = new LFCCF(null, 9); |
|
1452 |
try { |
|
1453 |
invokeAll(g); |
|
1454 |
shouldThrow(); |
|
1455 |
} catch (FJException success) { |
|
1456 |
checkCompletedAbnormally(g, success); |
|
1457 |
} |
|
1458 |
}}; |
|
1459 |
checkInvoke(a); |
|
1460 |
} |
|
1461 |
||
1462 |
/** |
|
1463 |
* invokeAll(tasks) with > 2 argument throws exception if any task does |
|
1464 |
*/ |
|
1465 |
public void testAbnormalInvokeAll3CC() { |
|
1466 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1467 |
protected void realCompute() { |
|
1468 |
CCF f = new LCCF(null, 8); |
|
1469 |
FailingCCF g = new LFCCF(null, 9); |
|
1470 |
CCF h = new LCCF(null, 7); |
|
1471 |
try { |
|
1472 |
invokeAll(f, g, h); |
|
1473 |
shouldThrow(); |
|
1474 |
} catch (FJException success) { |
|
1475 |
checkCompletedAbnormally(g, success); |
|
1476 |
} |
|
1477 |
}}; |
|
1478 |
checkInvoke(a); |
|
1479 |
} |
|
1480 |
||
1481 |
/** |
|
1482 |
* invokeAll(collection) throws exception if any task does |
|
1483 |
*/ |
|
1484 |
public void testAbnormalInvokeAllCollectionCC() { |
|
1485 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1486 |
protected void realCompute() { |
|
1487 |
FailingCCF f = new LFCCF(null, 8); |
|
1488 |
CCF g = new LCCF(null, 9); |
|
1489 |
CCF h = new LCCF(null, 7); |
|
1490 |
HashSet set = new HashSet(); |
|
1491 |
set.add(f); |
|
1492 |
set.add(g); |
|
1493 |
set.add(h); |
|
1494 |
try { |
|
1495 |
invokeAll(set); |
|
1496 |
shouldThrow(); |
|
1497 |
} catch (FJException success) { |
|
1498 |
checkCompletedAbnormally(f, success); |
|
1499 |
} |
|
1500 |
}}; |
|
1501 |
checkInvoke(a); |
|
1502 |
} |
|
1503 |
||
1504 |
/** |
|
1505 |
* awaitQuiescence by a worker is equivalent in effect to |
|
1506 |
* ForkJoinTask.helpQuiesce() |
|
1507 |
*/ |
|
1508 |
public void testAwaitQuiescence1() throws Exception { |
|
1509 |
final ForkJoinPool p = new ForkJoinPool(); |
|
1510 |
try (PoolCleaner cleaner = cleaner(p)) { |
|
1511 |
final long startTime = System.nanoTime(); |
|
1512 |
assertTrue(p.isQuiescent()); |
|
1513 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1514 |
protected void realCompute() { |
|
1515 |
FibAction f = new FibAction(8); |
|
1516 |
assertSame(f, f.fork()); |
|
1517 |
assertSame(p, ForkJoinTask.getPool()); |
|
1518 |
boolean quiescent = p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS); |
|
1519 |
assertTrue(quiescent); |
|
1520 |
assertFalse(p.isQuiescent()); |
|
1521 |
while (!f.isDone()) { |
|
1522 |
assertFalse(p.getAsyncMode()); |
|
1523 |
assertFalse(p.isShutdown()); |
|
1524 |
assertFalse(p.isTerminating()); |
|
1525 |
assertFalse(p.isTerminated()); |
|
1526 |
Thread.yield(); |
|
1527 |
} |
|
1528 |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
|
1529 |
assertFalse(p.isQuiescent()); |
|
1530 |
assertEquals(0, ForkJoinTask.getQueuedTaskCount()); |
|
1531 |
assertEquals(21, f.result); |
|
1532 |
}}; |
|
1533 |
p.execute(a); |
|
1534 |
while (!a.isDone() || !p.isQuiescent()) { |
|
1535 |
assertFalse(p.getAsyncMode()); |
|
1536 |
assertFalse(p.isShutdown()); |
|
1537 |
assertFalse(p.isTerminating()); |
|
1538 |
assertFalse(p.isTerminated()); |
|
1539 |
Thread.yield(); |
|
1540 |
} |
|
1541 |
assertEquals(0, p.getQueuedTaskCount()); |
|
1542 |
assertFalse(p.getAsyncMode()); |
|
1543 |
assertEquals(0, p.getQueuedSubmissionCount()); |
|
1544 |
assertFalse(p.hasQueuedSubmissions()); |
|
1545 |
while (p.getActiveThreadCount() != 0 |
|
1546 |
&& millisElapsedSince(startTime) < LONG_DELAY_MS) |
|
1547 |
Thread.yield(); |
|
1548 |
assertFalse(p.isShutdown()); |
|
1549 |
assertFalse(p.isTerminating()); |
|
1550 |
assertFalse(p.isTerminated()); |
|
1551 |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
|
1552 |
} |
|
1553 |
} |
|
1554 |
||
1555 |
/** |
|
1556 |
* awaitQuiescence returns when pool isQuiescent() or the indicated |
|
1557 |
* timeout elapsed |
|
1558 |
*/ |
|
1559 |
public void testAwaitQuiescence2() throws Exception { |
|
1560 |
/** |
|
1561 |
* """It is possible to disable or limit the use of threads in the |
|
1562 |
* common pool by setting the parallelism property to zero. However |
|
1563 |
* doing so may cause unjoined tasks to never be executed.""" |
|
1564 |
*/ |
|
1565 |
if ("0".equals(System.getProperty( |
|
1566 |
"java.util.concurrent.ForkJoinPool.common.parallelism"))) |
|
1567 |
return; |
|
1568 |
final ForkJoinPool p = new ForkJoinPool(); |
|
1569 |
try (PoolCleaner cleaner = cleaner(p)) { |
|
1570 |
assertTrue(p.isQuiescent()); |
|
1571 |
final long startTime = System.nanoTime(); |
|
1572 |
ForkJoinTask a = new CheckedRecursiveAction() { |
|
1573 |
protected void realCompute() { |
|
1574 |
FibAction f = new FibAction(8); |
|
1575 |
assertSame(f, f.fork()); |
|
1576 |
while (!f.isDone() |
|
1577 |
&& millisElapsedSince(startTime) < LONG_DELAY_MS) { |
|
1578 |
assertFalse(p.getAsyncMode()); |
|
1579 |
assertFalse(p.isShutdown()); |
|
1580 |
assertFalse(p.isTerminating()); |
|
1581 |
assertFalse(p.isTerminated()); |
|
1582 |
Thread.yield(); |
|
1583 |
} |
|
1584 |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
|
1585 |
assertEquals(0, ForkJoinTask.getQueuedTaskCount()); |
|
1586 |
assertEquals(21, f.result); |
|
1587 |
}}; |
|
1588 |
p.execute(a); |
|
1589 |
assertTrue(p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS)); |
|
1590 |
assertTrue(p.isQuiescent()); |
|
1591 |
assertTrue(a.isDone()); |
|
1592 |
assertEquals(0, p.getQueuedTaskCount()); |
|
1593 |
assertFalse(p.getAsyncMode()); |
|
1594 |
assertEquals(0, p.getQueuedSubmissionCount()); |
|
1595 |
assertFalse(p.hasQueuedSubmissions()); |
|
1596 |
while (p.getActiveThreadCount() != 0 |
|
1597 |
&& millisElapsedSince(startTime) < LONG_DELAY_MS) |
|
1598 |
Thread.yield(); |
|
1599 |
assertFalse(p.isShutdown()); |
|
1600 |
assertFalse(p.isTerminating()); |
|
1601 |
assertFalse(p.isTerminated()); |
|
1602 |
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS); |
|
1603 |
} |
|
1604 |
} |
|
1605 |
||
1606 |
} |