3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
< |
import java.util.concurrent.ExecutionException; |
6 |
> |
|
7 |
> |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
8 |
> |
import static java.util.concurrent.TimeUnit.SECONDS; |
9 |
> |
|
10 |
> |
import java.util.HashSet; |
11 |
|
import java.util.concurrent.CancellationException; |
12 |
+ |
import java.util.concurrent.CountedCompleter; |
13 |
+ |
import java.util.concurrent.ExecutionException; |
14 |
|
import java.util.concurrent.ForkJoinPool; |
15 |
|
import java.util.concurrent.ForkJoinTask; |
10 |
– |
import java.util.concurrent.CountedCompleter; |
11 |
– |
import java.util.concurrent.ForkJoinWorkerThread; |
12 |
– |
import java.util.concurrent.RecursiveAction; |
13 |
– |
import java.util.concurrent.TimeUnit; |
16 |
|
import java.util.concurrent.TimeoutException; |
17 |
< |
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
18 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
19 |
< |
import static java.util.concurrent.TimeUnit.SECONDS; |
20 |
< |
import java.util.HashSet; |
21 |
< |
import junit.framework.*; |
17 |
> |
import java.util.concurrent.atomic.AtomicInteger; |
18 |
> |
import java.util.concurrent.atomic.AtomicReference; |
19 |
> |
|
20 |
> |
import junit.framework.Test; |
21 |
> |
import junit.framework.TestSuite; |
22 |
|
|
23 |
|
public class CountedCompleterTest extends JSR166TestCase { |
24 |
|
|
85 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
86 |
|
} |
87 |
|
|
88 |
< |
<T> void checkCompletedNormally(CountedCompleter<T> a) { |
87 |
< |
checkCompletedNormally(a, null); |
88 |
< |
} |
89 |
< |
|
90 |
< |
<T> void checkCompletedNormally(CountedCompleter<T> a, T expected) { |
88 |
> |
void checkCompletedNormally(CountedCompleter<?> a) { |
89 |
|
assertTrue(a.isDone()); |
90 |
|
assertFalse(a.isCancelled()); |
91 |
|
assertTrue(a.isCompletedNormally()); |
92 |
|
assertFalse(a.isCompletedAbnormally()); |
93 |
|
assertNull(a.getException()); |
94 |
< |
assertSame(expected, a.getRawResult()); |
94 |
> |
assertNull(a.getRawResult()); |
95 |
|
|
96 |
|
{ |
97 |
|
Thread.currentThread().interrupt(); |
98 |
|
long t0 = System.nanoTime(); |
99 |
< |
assertSame(expected, a.join()); |
99 |
> |
assertNull(a.join()); |
100 |
|
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
101 |
|
Thread.interrupted(); |
102 |
|
} |
112 |
|
assertFalse(a.cancel(false)); |
113 |
|
assertFalse(a.cancel(true)); |
114 |
|
try { |
115 |
< |
assertSame(expected, a.get()); |
115 |
> |
assertNull(a.get()); |
116 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
117 |
|
try { |
118 |
< |
assertSame(expected, a.get(5L, SECONDS)); |
118 |
> |
assertNull(a.get(5L, SECONDS)); |
119 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
120 |
|
} |
121 |
|
|
194 |
|
} catch (ExecutionException success) { |
195 |
|
assertSame(t.getClass(), success.getCause().getClass()); |
196 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
197 |
+ |
|
198 |
+ |
try { |
199 |
+ |
a.invoke(); |
200 |
+ |
shouldThrow(); |
201 |
+ |
} catch (Throwable ex) { |
202 |
+ |
assertSame(t, ex); |
203 |
+ |
} |
204 |
|
} |
205 |
|
|
206 |
|
public static final class FJException extends RuntimeException { |
207 |
|
FJException() { super(); } |
208 |
|
} |
209 |
|
|
210 |
< |
static final class NoopCountedCompleter extends CountedCompleter { |
211 |
< |
boolean post; // set true if onCompletion called |
212 |
< |
NoopCountedCompleter() { super(); } |
213 |
< |
NoopCountedCompleter(CountedCompleter p) { super(p); } |
214 |
< |
public void compute() {} |
215 |
< |
public final void onCompletion(CountedCompleter caller) { |
216 |
< |
post = true; |
210 |
> |
abstract class CheckedCC extends CountedCompleter<Object> { |
211 |
> |
final AtomicInteger computeN = new AtomicInteger(0); |
212 |
> |
final AtomicInteger onCompletionN = new AtomicInteger(0); |
213 |
> |
final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0); |
214 |
> |
final AtomicInteger setRawResultN = new AtomicInteger(0); |
215 |
> |
final AtomicReference<Object> rawResult = new AtomicReference<Object>(null); |
216 |
> |
int computeN() { return computeN.get(); } |
217 |
> |
int onCompletionN() { return onCompletionN.get(); } |
218 |
> |
int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); } |
219 |
> |
int setRawResultN() { return setRawResultN.get(); } |
220 |
> |
|
221 |
> |
CheckedCC() { super(); } |
222 |
> |
CheckedCC(CountedCompleter p) { super(p); } |
223 |
> |
CheckedCC(CountedCompleter p, int n) { super(p, n); } |
224 |
> |
abstract void realCompute(); |
225 |
> |
public final void compute() { |
226 |
> |
computeN.incrementAndGet(); |
227 |
> |
realCompute(); |
228 |
> |
} |
229 |
> |
public void onCompletion(CountedCompleter caller) { |
230 |
> |
onCompletionN.incrementAndGet(); |
231 |
> |
super.onCompletion(caller); |
232 |
> |
} |
233 |
> |
public boolean onExceptionalCompletion(Throwable ex, |
234 |
> |
CountedCompleter caller) { |
235 |
> |
onExceptionalCompletionN.incrementAndGet(); |
236 |
> |
assertNotNull(ex); |
237 |
> |
assertTrue(isCompletedAbnormally()); |
238 |
> |
assertTrue(super.onExceptionalCompletion(ex, caller)); |
239 |
> |
return true; |
240 |
> |
} |
241 |
> |
protected void setRawResult(Object t) { |
242 |
> |
setRawResultN.incrementAndGet(); |
243 |
> |
rawResult.set(t); |
244 |
> |
super.setRawResult(t); |
245 |
> |
} |
246 |
> |
void checkIncomplete() { |
247 |
> |
assertEquals(0, computeN()); |
248 |
> |
assertEquals(0, onCompletionN()); |
249 |
> |
assertEquals(0, onExceptionalCompletionN()); |
250 |
> |
assertEquals(0, setRawResultN()); |
251 |
> |
checkNotDone(this); |
252 |
> |
} |
253 |
> |
void checkCompletes(Object rawResult) { |
254 |
> |
checkIncomplete(); |
255 |
> |
int pendingCount = getPendingCount(); |
256 |
> |
complete(rawResult); |
257 |
> |
assertEquals(pendingCount, getPendingCount()); |
258 |
> |
assertEquals(0, computeN()); |
259 |
> |
assertEquals(1, onCompletionN()); |
260 |
> |
assertEquals(0, onExceptionalCompletionN()); |
261 |
> |
assertEquals(1, setRawResultN()); |
262 |
> |
assertSame(rawResult, this.rawResult.get()); |
263 |
> |
checkCompletedNormally(this); |
264 |
> |
} |
265 |
> |
void checkCompletesExceptionally(Throwable ex) { |
266 |
> |
checkIncomplete(); |
267 |
> |
completeExceptionally(ex); |
268 |
> |
checkCompletedExceptionally(ex); |
269 |
> |
} |
270 |
> |
void checkCompletedExceptionally(Throwable ex) { |
271 |
> |
assertEquals(0, computeN()); |
272 |
> |
assertEquals(0, onCompletionN()); |
273 |
> |
assertEquals(1, onExceptionalCompletionN()); |
274 |
> |
assertEquals(0, setRawResultN()); |
275 |
> |
assertNull(this.rawResult.get()); |
276 |
> |
checkCompletedAbnormally(this, ex); |
277 |
|
} |
278 |
|
} |
279 |
|
|
280 |
+ |
final class NoopCC extends CheckedCC { |
281 |
+ |
NoopCC() { super(); } |
282 |
+ |
NoopCC(CountedCompleter p) { super(p); } |
283 |
+ |
protected void realCompute() {} |
284 |
+ |
} |
285 |
+ |
|
286 |
|
/** |
287 |
|
* A newly constructed CountedCompleter is not completed; |
288 |
< |
* complete() causes completion. |
288 |
> |
* complete() causes completion. pendingCount is ignored. |
289 |
|
*/ |
290 |
|
public void testComplete() { |
291 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
292 |
< |
assertFalse(a.isDone()); |
293 |
< |
assertFalse(a.isCompletedNormally()); |
294 |
< |
assertFalse(a.isCompletedAbnormally()); |
295 |
< |
assertFalse(a.isCancelled()); |
296 |
< |
assertNull(a.getException()); |
297 |
< |
assertNull(a.getRawResult()); |
298 |
< |
assertFalse(a.post); |
299 |
< |
a.complete(null); |
300 |
< |
assertTrue(a.post); |
230 |
< |
assertTrue(a.isDone()); |
231 |
< |
assertTrue(a.isCompletedNormally()); |
232 |
< |
assertFalse(a.isCompletedAbnormally()); |
233 |
< |
assertFalse(a.isCancelled()); |
234 |
< |
assertNull(a.getException()); |
235 |
< |
assertNull(a.getRawResult()); |
291 |
> |
for (Object x : new Object[] { Boolean.TRUE, null }) { |
292 |
> |
for (int pendingCount : new int[] { 0, 42 }) { |
293 |
> |
testComplete(new NoopCC(), x, pendingCount); |
294 |
> |
testComplete(new NoopCC(new NoopCC()), x, pendingCount); |
295 |
> |
} |
296 |
> |
} |
297 |
> |
} |
298 |
> |
void testComplete(NoopCC cc, Object x, int pendingCount) { |
299 |
> |
cc.setPendingCount(pendingCount); |
300 |
> |
cc.checkCompletes(x); |
301 |
|
} |
302 |
|
|
303 |
|
/** |
304 |
|
* completeExceptionally completes exceptionally |
305 |
|
*/ |
306 |
|
public void testCompleteExceptionally() { |
307 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
308 |
< |
assertFalse(a.isDone()); |
309 |
< |
assertFalse(a.isCompletedNormally()); |
310 |
< |
assertFalse(a.isCompletedAbnormally()); |
311 |
< |
assertFalse(a.isCancelled()); |
312 |
< |
assertNull(a.getException()); |
313 |
< |
assertNull(a.getRawResult()); |
314 |
< |
assertFalse(a.post); |
315 |
< |
a.completeExceptionally(new FJException()); |
316 |
< |
assertFalse(a.post); |
317 |
< |
assertTrue(a.isDone()); |
318 |
< |
assertFalse(a.isCompletedNormally()); |
319 |
< |
assertTrue(a.isCompletedAbnormally()); |
320 |
< |
assertFalse(a.isCancelled()); |
321 |
< |
assertTrue(a.getException() instanceof FJException); |
257 |
< |
assertNull(a.getRawResult()); |
307 |
> |
new NoopCC() |
308 |
> |
.checkCompletesExceptionally(new FJException()); |
309 |
> |
new NoopCC(new NoopCC()) |
310 |
> |
.checkCompletesExceptionally(new FJException()); |
311 |
> |
} |
312 |
> |
|
313 |
> |
/** |
314 |
> |
* completeExceptionally(null) throws NullPointerException |
315 |
> |
*/ |
316 |
> |
public void testCompleteExceptionally_null() { |
317 |
> |
try { |
318 |
> |
new NoopCC() |
319 |
> |
.checkCompletesExceptionally(null); |
320 |
> |
shouldThrow(); |
321 |
> |
} catch (NullPointerException success) {} |
322 |
|
} |
323 |
|
|
324 |
|
/** |
325 |
|
* setPendingCount sets the reported pending count |
326 |
|
*/ |
327 |
|
public void testSetPendingCount() { |
328 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
328 |
> |
NoopCC a = new NoopCC(); |
329 |
|
assertEquals(0, a.getPendingCount()); |
330 |
|
a.setPendingCount(1); |
331 |
|
assertEquals(1, a.getPendingCount()); |
337 |
|
* addToPendingCount adds to the reported pending count |
338 |
|
*/ |
339 |
|
public void testAddToPendingCount() { |
340 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
340 |
> |
NoopCC a = new NoopCC(); |
341 |
|
assertEquals(0, a.getPendingCount()); |
342 |
|
a.addToPendingCount(1); |
343 |
|
assertEquals(1, a.getPendingCount()); |
350 |
|
* count unless zero |
351 |
|
*/ |
352 |
|
public void testDecrementPendingCount() { |
353 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
353 |
> |
NoopCC a = new NoopCC(); |
354 |
|
assertEquals(0, a.getPendingCount()); |
355 |
|
a.addToPendingCount(1); |
356 |
|
assertEquals(1, a.getPendingCount()); |
361 |
|
} |
362 |
|
|
363 |
|
/** |
364 |
+ |
* compareAndSetPendingCount compares and sets the reported |
365 |
+ |
* pending count |
366 |
+ |
*/ |
367 |
+ |
public void testCompareAndSetPendingCount() { |
368 |
+ |
NoopCC a = new NoopCC(); |
369 |
+ |
assertEquals(0, a.getPendingCount()); |
370 |
+ |
assertTrue(a.compareAndSetPendingCount(0, 1)); |
371 |
+ |
assertEquals(1, a.getPendingCount()); |
372 |
+ |
assertTrue(a.compareAndSetPendingCount(1, 2)); |
373 |
+ |
assertEquals(2, a.getPendingCount()); |
374 |
+ |
assertFalse(a.compareAndSetPendingCount(1, 3)); |
375 |
+ |
assertEquals(2, a.getPendingCount()); |
376 |
+ |
} |
377 |
+ |
|
378 |
+ |
/** |
379 |
|
* getCompleter returns parent or null if at root |
380 |
|
*/ |
381 |
|
public void testGetCompleter() { |
382 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
382 |
> |
NoopCC a = new NoopCC(); |
383 |
|
assertNull(a.getCompleter()); |
384 |
< |
CountedCompleter b = new NoopCountedCompleter(a); |
385 |
< |
assertEquals(a, b.getCompleter()); |
384 |
> |
CountedCompleter b = new NoopCC(a); |
385 |
> |
assertSame(a, b.getCompleter()); |
386 |
> |
CountedCompleter c = new NoopCC(b); |
387 |
> |
assertSame(b, c.getCompleter()); |
388 |
|
} |
389 |
|
|
390 |
|
/** |
391 |
|
* getRoot returns self if no parent, else parent's root |
392 |
|
*/ |
393 |
|
public void testGetRoot() { |
394 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
395 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
396 |
< |
assertEquals(a, a.getRoot()); |
397 |
< |
assertEquals(a, b.getRoot()); |
394 |
> |
NoopCC a = new NoopCC(); |
395 |
> |
NoopCC b = new NoopCC(a); |
396 |
> |
NoopCC c = new NoopCC(b); |
397 |
> |
assertSame(a, a.getRoot()); |
398 |
> |
assertSame(a, b.getRoot()); |
399 |
> |
assertSame(a, c.getRoot()); |
400 |
|
} |
401 |
|
|
402 |
|
/** |
403 |
< |
* tryComplete causes completion if pending count is zero |
403 |
> |
* tryComplete decrements pending count unless zero, in which case |
404 |
> |
* causes completion |
405 |
|
*/ |
406 |
< |
public void testTryComplete1() { |
407 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
406 |
> |
public void testTryComplete() { |
407 |
> |
NoopCC a = new NoopCC(); |
408 |
|
assertEquals(0, a.getPendingCount()); |
409 |
+ |
int n = 3; |
410 |
+ |
a.setPendingCount(n); |
411 |
+ |
for (; n > 0; n--) { |
412 |
+ |
assertEquals(n, a.getPendingCount()); |
413 |
+ |
a.tryComplete(); |
414 |
+ |
a.checkIncomplete(); |
415 |
+ |
assertEquals(n - 1, a.getPendingCount()); |
416 |
+ |
} |
417 |
|
a.tryComplete(); |
418 |
< |
assertTrue(a.post); |
419 |
< |
assertTrue(a.isDone()); |
418 |
> |
assertEquals(0, a.computeN()); |
419 |
> |
assertEquals(1, a.onCompletionN()); |
420 |
> |
assertEquals(0, a.onExceptionalCompletionN()); |
421 |
> |
assertEquals(0, a.setRawResultN()); |
422 |
> |
checkCompletedNormally(a); |
423 |
|
} |
424 |
|
|
425 |
|
/** |
426 |
< |
* propagateCompletion causes completion without invoking |
427 |
< |
* onCompletion if pending count is zero |
426 |
> |
* propagateCompletion decrements pending count unless zero, in |
427 |
> |
* which case causes completion, without invoking onCompletion |
428 |
|
*/ |
429 |
|
public void testPropagateCompletion() { |
430 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
430 |
> |
NoopCC a = new NoopCC(); |
431 |
|
assertEquals(0, a.getPendingCount()); |
432 |
+ |
int n = 3; |
433 |
+ |
a.setPendingCount(n); |
434 |
+ |
for (; n > 0; n--) { |
435 |
+ |
assertEquals(n, a.getPendingCount()); |
436 |
+ |
a.propagateCompletion(); |
437 |
+ |
a.checkIncomplete(); |
438 |
+ |
assertEquals(n - 1, a.getPendingCount()); |
439 |
+ |
} |
440 |
|
a.propagateCompletion(); |
441 |
< |
assertFalse(a.post); |
442 |
< |
assertTrue(a.isDone()); |
443 |
< |
} |
444 |
< |
|
445 |
< |
/** |
343 |
< |
* tryComplete decrements pending count unless zero |
344 |
< |
*/ |
345 |
< |
public void testTryComplete2() { |
346 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
347 |
< |
assertEquals(0, a.getPendingCount()); |
348 |
< |
a.setPendingCount(1); |
349 |
< |
a.tryComplete(); |
350 |
< |
assertFalse(a.post); |
351 |
< |
assertFalse(a.isDone()); |
352 |
< |
assertEquals(0, a.getPendingCount()); |
353 |
< |
a.tryComplete(); |
354 |
< |
assertTrue(a.post); |
355 |
< |
assertTrue(a.isDone()); |
441 |
> |
assertEquals(0, a.computeN()); |
442 |
> |
assertEquals(0, a.onCompletionN()); |
443 |
> |
assertEquals(0, a.onExceptionalCompletionN()); |
444 |
> |
assertEquals(0, a.setRawResultN()); |
445 |
> |
checkCompletedNormally(a); |
446 |
|
} |
447 |
|
|
448 |
|
/** |
449 |
|
* firstComplete returns this if pending count is zero else null |
450 |
|
*/ |
451 |
|
public void testFirstComplete() { |
452 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
452 |
> |
NoopCC a = new NoopCC(); |
453 |
|
a.setPendingCount(1); |
454 |
|
assertNull(a.firstComplete()); |
455 |
< |
assertEquals(a, a.firstComplete()); |
455 |
> |
a.checkIncomplete(); |
456 |
> |
assertSame(a, a.firstComplete()); |
457 |
> |
a.checkIncomplete(); |
458 |
|
} |
459 |
|
|
460 |
|
/** |
462 |
|
* zero else null |
463 |
|
*/ |
464 |
|
public void testNextComplete() { |
465 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
466 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
465 |
> |
NoopCC a = new NoopCC(); |
466 |
> |
NoopCC b = new NoopCC(a); |
467 |
|
a.setPendingCount(1); |
468 |
|
b.setPendingCount(1); |
469 |
|
assertNull(b.firstComplete()); |
470 |
< |
CountedCompleter c = b.firstComplete(); |
471 |
< |
assertEquals(b, c); |
472 |
< |
CountedCompleter d = c.nextComplete(); |
473 |
< |
assertNull(d); |
474 |
< |
CountedCompleter e = c.nextComplete(); |
475 |
< |
assertEquals(a, e); |
470 |
> |
assertSame(b, b.firstComplete()); |
471 |
> |
assertNull(b.nextComplete()); |
472 |
> |
a.checkIncomplete(); |
473 |
> |
b.checkIncomplete(); |
474 |
> |
assertSame(a, b.nextComplete()); |
475 |
> |
assertSame(a, b.nextComplete()); |
476 |
> |
a.checkIncomplete(); |
477 |
> |
b.checkIncomplete(); |
478 |
> |
assertNull(a.nextComplete()); |
479 |
> |
b.checkIncomplete(); |
480 |
> |
checkCompletedNormally(a); |
481 |
|
} |
482 |
|
|
483 |
|
/** |
484 |
|
* quietlyCompleteRoot completes root task |
485 |
|
*/ |
486 |
|
public void testQuietlyCompleteRoot() { |
487 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
488 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
487 |
> |
NoopCC a = new NoopCC(); |
488 |
> |
NoopCC b = new NoopCC(a); |
489 |
> |
NoopCC c = new NoopCC(b); |
490 |
|
a.setPendingCount(1); |
491 |
|
b.setPendingCount(1); |
492 |
< |
b.quietlyCompleteRoot(); |
492 |
> |
c.setPendingCount(1); |
493 |
> |
c.quietlyCompleteRoot(); |
494 |
|
assertTrue(a.isDone()); |
495 |
|
assertFalse(b.isDone()); |
496 |
+ |
assertFalse(c.isDone()); |
497 |
|
} |
498 |
|
|
499 |
|
// Invocation tests use some interdependent task classes |
500 |
|
// to better test propagation etc |
501 |
|
|
502 |
< |
|
503 |
< |
// Version of Fibonacci with different classes for left vs right forks |
504 |
< |
abstract static class CCF extends CountedCompleter { |
502 |
> |
/** |
503 |
> |
* Version of Fibonacci with different classes for left vs right forks |
504 |
> |
*/ |
505 |
> |
abstract class CCF extends CheckedCC { |
506 |
|
int number; |
507 |
|
int rnumber; |
508 |
|
|
511 |
|
this.number = n; |
512 |
|
} |
513 |
|
|
514 |
< |
public final void compute() { |
414 |
< |
CountedCompleter p; |
514 |
> |
protected final void realCompute() { |
515 |
|
CCF f = this; |
516 |
|
int n = number; |
517 |
|
while (n >= 2) { |
518 |
|
new RCCF(f, n - 2).fork(); |
519 |
|
f = new LCCF(f, --n); |
520 |
|
} |
521 |
< |
f.number = n; |
422 |
< |
f.onCompletion(f); |
423 |
< |
if ((p = f.getCompleter()) != null) |
424 |
< |
p.tryComplete(); |
425 |
< |
else |
426 |
< |
f.quietlyComplete(); |
521 |
> |
f.complete(null); |
522 |
|
} |
523 |
|
} |
524 |
|
|
525 |
< |
static final class LCCF extends CCF { |
525 |
> |
final class LCCF extends CCF { |
526 |
> |
public LCCF(int n) { this(null, n); } |
527 |
|
public LCCF(CountedCompleter parent, int n) { |
528 |
|
super(parent, n); |
529 |
|
} |
530 |
|
public final void onCompletion(CountedCompleter caller) { |
531 |
+ |
super.onCompletion(caller); |
532 |
|
CCF p = (CCF)getCompleter(); |
533 |
|
int n = number + rnumber; |
534 |
|
if (p != null) |
537 |
|
number = n; |
538 |
|
} |
539 |
|
} |
540 |
< |
static final class RCCF extends CCF { |
540 |
> |
final class RCCF extends CCF { |
541 |
|
public RCCF(CountedCompleter parent, int n) { |
542 |
|
super(parent, n); |
543 |
|
} |
544 |
|
public final void onCompletion(CountedCompleter caller) { |
545 |
+ |
super.onCompletion(caller); |
546 |
|
CCF p = (CCF)getCompleter(); |
547 |
|
int n = number + rnumber; |
548 |
|
if (p != null) |
553 |
|
} |
554 |
|
|
555 |
|
// Version of CCF with forced failure in left completions |
556 |
< |
abstract static class FailingCCF extends CountedCompleter { |
556 |
> |
abstract class FailingCCF extends CheckedCC { |
557 |
|
int number; |
558 |
|
int rnumber; |
559 |
|
|
562 |
|
this.number = n; |
563 |
|
} |
564 |
|
|
565 |
< |
public final void compute() { |
468 |
< |
CountedCompleter p; |
565 |
> |
protected final void realCompute() { |
566 |
|
FailingCCF f = this; |
567 |
|
int n = number; |
568 |
|
while (n >= 2) { |
569 |
|
new RFCCF(f, n - 2).fork(); |
570 |
|
f = new LFCCF(f, --n); |
571 |
|
} |
572 |
< |
f.number = n; |
476 |
< |
f.onCompletion(f); |
477 |
< |
if ((p = f.getCompleter()) != null) |
478 |
< |
p.tryComplete(); |
479 |
< |
else |
480 |
< |
f.quietlyComplete(); |
572 |
> |
f.complete(null); |
573 |
|
} |
574 |
|
} |
575 |
|
|
576 |
< |
static final class LFCCF extends FailingCCF { |
576 |
> |
final class LFCCF extends FailingCCF { |
577 |
> |
public LFCCF(int n) { this(null, n); } |
578 |
|
public LFCCF(CountedCompleter parent, int n) { |
579 |
|
super(parent, n); |
580 |
|
} |
581 |
|
public final void onCompletion(CountedCompleter caller) { |
582 |
+ |
super.onCompletion(caller); |
583 |
|
FailingCCF p = (FailingCCF)getCompleter(); |
584 |
|
int n = number + rnumber; |
585 |
|
if (p != null) |
588 |
|
number = n; |
589 |
|
} |
590 |
|
} |
591 |
< |
static final class RFCCF extends FailingCCF { |
591 |
> |
final class RFCCF extends FailingCCF { |
592 |
|
public RFCCF(CountedCompleter parent, int n) { |
593 |
|
super(parent, n); |
594 |
|
} |
595 |
|
public final void onCompletion(CountedCompleter caller) { |
596 |
+ |
super.onCompletion(caller); |
597 |
|
completeExceptionally(new FJException()); |
598 |
|
} |
599 |
|
} |
606 |
|
public void testInvoke() { |
607 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
608 |
|
protected void realCompute() { |
609 |
< |
CCF f = new LCCF(null, 8); |
609 |
> |
CCF f = new LCCF(8); |
610 |
|
assertNull(f.invoke()); |
611 |
|
assertEquals(21, f.number); |
612 |
|
checkCompletedNormally(f); |
622 |
|
public void testQuietlyInvoke() { |
623 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
624 |
|
protected void realCompute() { |
625 |
< |
CCF f = new LCCF(null, 8); |
625 |
> |
CCF f = new LCCF(8); |
626 |
|
f.quietlyInvoke(); |
627 |
|
assertEquals(21, f.number); |
628 |
|
checkCompletedNormally(f); |
636 |
|
public void testForkJoin() { |
637 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
638 |
|
protected void realCompute() { |
639 |
< |
CCF f = new LCCF(null, 8); |
639 |
> |
CCF f = new LCCF(8); |
640 |
|
assertSame(f, f.fork()); |
641 |
|
assertNull(f.join()); |
642 |
|
assertEquals(21, f.number); |
651 |
|
public void testForkGet() { |
652 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
653 |
|
protected void realCompute() throws Exception { |
654 |
< |
CCF f = new LCCF(null, 8); |
654 |
> |
CCF f = new LCCF(8); |
655 |
|
assertSame(f, f.fork()); |
656 |
|
assertNull(f.get()); |
657 |
|
assertEquals(21, f.number); |
666 |
|
public void testForkTimedGet() { |
667 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
668 |
|
protected void realCompute() throws Exception { |
669 |
< |
CCF f = new LCCF(null, 8); |
669 |
> |
CCF f = new LCCF(8); |
670 |
|
assertSame(f, f.fork()); |
671 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
672 |
|
assertEquals(21, f.number); |
681 |
|
public void testForkTimedGetNPE() { |
682 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
683 |
|
protected void realCompute() throws Exception { |
684 |
< |
CCF f = new LCCF(null, 8); |
684 |
> |
CCF f = new LCCF(8); |
685 |
|
assertSame(f, f.fork()); |
686 |
|
try { |
687 |
|
f.get(5L, null); |
697 |
|
public void testForkQuietlyJoin() { |
698 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
699 |
|
protected void realCompute() { |
700 |
< |
CCF f = new LCCF(null, 8); |
700 |
> |
CCF f = new LCCF(8); |
701 |
|
assertSame(f, f.fork()); |
702 |
|
f.quietlyJoin(); |
703 |
|
assertEquals(21, f.number); |
713 |
|
public void testForkHelpQuiesce() { |
714 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
715 |
|
protected void realCompute() { |
716 |
< |
CCF f = new LCCF(null, 8); |
716 |
> |
CCF f = new LCCF(8); |
717 |
|
assertSame(f, f.fork()); |
718 |
|
helpQuiesce(); |
719 |
|
assertEquals(21, f.number); |
729 |
|
public void testAbnormalInvoke() { |
730 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
731 |
|
protected void realCompute() { |
732 |
< |
FailingCCF f = new LFCCF(null, 8); |
732 |
> |
FailingCCF f = new LFCCF(8); |
733 |
|
try { |
734 |
|
f.invoke(); |
735 |
|
shouldThrow(); |
746 |
|
public void testAbnormalQuietlyInvoke() { |
747 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
748 |
|
protected void realCompute() { |
749 |
< |
FailingCCF f = new LFCCF(null, 8); |
749 |
> |
FailingCCF f = new LFCCF(8); |
750 |
|
f.quietlyInvoke(); |
751 |
|
assertTrue(f.getException() instanceof FJException); |
752 |
|
checkCompletedAbnormally(f, f.getException()); |
760 |
|
public void testAbnormalForkJoin() { |
761 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
762 |
|
protected void realCompute() { |
763 |
< |
FailingCCF f = new LFCCF(null, 8); |
763 |
> |
FailingCCF f = new LFCCF(8); |
764 |
|
assertSame(f, f.fork()); |
765 |
|
try { |
766 |
|
f.join(); |
778 |
|
public void testAbnormalForkGet() { |
779 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
780 |
|
protected void realCompute() throws Exception { |
781 |
< |
FailingCCF f = new LFCCF(null, 8); |
781 |
> |
FailingCCF f = new LFCCF(8); |
782 |
|
assertSame(f, f.fork()); |
783 |
|
try { |
784 |
|
f.get(); |
798 |
|
public void testAbnormalForkTimedGet() { |
799 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
800 |
|
protected void realCompute() throws Exception { |
801 |
< |
FailingCCF f = new LFCCF(null, 8); |
801 |
> |
FailingCCF f = new LFCCF(8); |
802 |
|
assertSame(f, f.fork()); |
803 |
|
try { |
804 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
818 |
|
public void testAbnormalForkQuietlyJoin() { |
819 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
820 |
|
protected void realCompute() { |
821 |
< |
FailingCCF f = new LFCCF(null, 8); |
821 |
> |
FailingCCF f = new LFCCF(8); |
822 |
|
assertSame(f, f.fork()); |
823 |
|
f.quietlyJoin(); |
824 |
|
assertTrue(f.getException() instanceof FJException); |
833 |
|
public void testCancelledInvoke() { |
834 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
835 |
|
protected void realCompute() { |
836 |
< |
CCF f = new LCCF(null, 8); |
836 |
> |
CCF f = new LCCF(8); |
837 |
|
assertTrue(f.cancel(true)); |
838 |
|
try { |
839 |
|
f.invoke(); |
851 |
|
public void testCancelledForkJoin() { |
852 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
853 |
|
protected void realCompute() { |
854 |
< |
CCF f = new LCCF(null, 8); |
854 |
> |
CCF f = new LCCF(8); |
855 |
|
assertTrue(f.cancel(true)); |
856 |
|
assertSame(f, f.fork()); |
857 |
|
try { |
870 |
|
public void testCancelledForkGet() { |
871 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
872 |
|
protected void realCompute() throws Exception { |
873 |
< |
CCF f = new LCCF(null, 8); |
873 |
> |
CCF f = new LCCF(8); |
874 |
|
assertTrue(f.cancel(true)); |
875 |
|
assertSame(f, f.fork()); |
876 |
|
try { |
889 |
|
public void testCancelledForkTimedGet() throws Exception { |
890 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
891 |
|
protected void realCompute() throws Exception { |
892 |
< |
CCF f = new LCCF(null, 8); |
892 |
> |
CCF f = new LCCF(8); |
893 |
|
assertTrue(f.cancel(true)); |
894 |
|
assertSame(f, f.fork()); |
895 |
|
try { |
908 |
|
public void testCancelledForkQuietlyJoin() { |
909 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
910 |
|
protected void realCompute() { |
911 |
< |
CCF f = new LCCF(null, 8); |
911 |
> |
CCF f = new LCCF(8); |
912 |
|
assertTrue(f.cancel(true)); |
913 |
|
assertSame(f, f.fork()); |
914 |
|
f.quietlyJoin(); |
980 |
|
public void testCompleteExceptionally2() { |
981 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
982 |
|
protected void realCompute() { |
983 |
< |
CCF f = new LCCF(null, 8); |
984 |
< |
f.completeExceptionally(new FJException()); |
985 |
< |
try { |
986 |
< |
f.invoke(); |
987 |
< |
shouldThrow(); |
988 |
< |
} catch (FJException success) { |
894 |
< |
checkCompletedAbnormally(f, success); |
895 |
< |
} |
983 |
> |
CCF n = new LCCF(8); |
984 |
> |
CCF f = new LCCF(n, 8); |
985 |
> |
FJException ex = new FJException(); |
986 |
> |
f.completeExceptionally(ex); |
987 |
> |
f.checkCompletedExceptionally(ex); |
988 |
> |
n.checkCompletedExceptionally(ex); |
989 |
|
}}; |
990 |
|
testInvokeOnPool(mainPool(), a); |
991 |
|
} |
996 |
|
public void testInvokeAll2() { |
997 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
998 |
|
protected void realCompute() { |
999 |
< |
CCF f = new LCCF(null, 8); |
1000 |
< |
CCF g = new LCCF(null, 9); |
999 |
> |
CCF f = new LCCF(8); |
1000 |
> |
CCF g = new LCCF(9); |
1001 |
|
invokeAll(f, g); |
1002 |
|
assertEquals(21, f.number); |
1003 |
|
assertEquals(34, g.number); |
1013 |
|
public void testInvokeAll1() { |
1014 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1015 |
|
protected void realCompute() { |
1016 |
< |
CCF f = new LCCF(null, 8); |
1016 |
> |
CCF f = new LCCF(8); |
1017 |
|
invokeAll(f); |
1018 |
|
checkCompletedNormally(f); |
1019 |
|
assertEquals(21, f.number); |
1027 |
|
public void testInvokeAll3() { |
1028 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1029 |
|
protected void realCompute() { |
1030 |
< |
CCF f = new LCCF(null, 8); |
1031 |
< |
CCF g = new LCCF(null, 9); |
1032 |
< |
CCF h = new LCCF(null, 7); |
1030 |
> |
CCF f = new LCCF(8); |
1031 |
> |
CCF g = new LCCF(9); |
1032 |
> |
CCF h = new LCCF(7); |
1033 |
|
invokeAll(f, g, h); |
1034 |
|
assertEquals(21, f.number); |
1035 |
|
assertEquals(34, g.number); |
1047 |
|
public void testInvokeAllCollection() { |
1048 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1049 |
|
protected void realCompute() { |
1050 |
< |
CCF f = new LCCF(null, 8); |
1051 |
< |
CCF g = new LCCF(null, 9); |
1052 |
< |
CCF h = new LCCF(null, 7); |
1050 |
> |
CCF f = new LCCF(8); |
1051 |
> |
CCF g = new LCCF(9); |
1052 |
> |
CCF h = new LCCF(7); |
1053 |
|
HashSet set = new HashSet(); |
1054 |
|
set.add(f); |
1055 |
|
set.add(g); |
1071 |
|
public void testInvokeAllNPE() { |
1072 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1073 |
|
protected void realCompute() { |
1074 |
< |
CCF f = new LCCF(null, 8); |
1075 |
< |
CCF g = new LCCF(null, 9); |
1074 |
> |
CCF f = new LCCF(8); |
1075 |
> |
CCF g = new LCCF(9); |
1076 |
|
CCF h = null; |
1077 |
|
try { |
1078 |
|
invokeAll(f, g, h); |
1088 |
|
public void testAbnormalInvokeAll2() { |
1089 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1090 |
|
protected void realCompute() { |
1091 |
< |
CCF f = new LCCF(null, 8); |
1092 |
< |
FailingCCF g = new LFCCF(null, 9); |
1091 |
> |
CCF f = new LCCF(8); |
1092 |
> |
FailingCCF g = new LFCCF(9); |
1093 |
|
try { |
1094 |
|
invokeAll(f, g); |
1095 |
|
shouldThrow(); |
1106 |
|
public void testAbnormalInvokeAll1() { |
1107 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1108 |
|
protected void realCompute() { |
1109 |
< |
FailingCCF g = new LFCCF(null, 9); |
1109 |
> |
FailingCCF g = new LFCCF(9); |
1110 |
|
try { |
1111 |
|
invokeAll(g); |
1112 |
|
shouldThrow(); |
1123 |
|
public void testAbnormalInvokeAll3() { |
1124 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1125 |
|
protected void realCompute() { |
1126 |
< |
CCF f = new LCCF(null, 8); |
1127 |
< |
FailingCCF g = new LFCCF(null, 9); |
1128 |
< |
CCF h = new LCCF(null, 7); |
1126 |
> |
CCF f = new LCCF(8); |
1127 |
> |
FailingCCF g = new LFCCF(9); |
1128 |
> |
CCF h = new LCCF(7); |
1129 |
|
try { |
1130 |
|
invokeAll(f, g, h); |
1131 |
|
shouldThrow(); |
1137 |
|
} |
1138 |
|
|
1139 |
|
/** |
1140 |
< |
* invokeAll(collection) throws exception if any task does |
1140 |
> |
* invokeAll(collection) throws exception if any task does |
1141 |
|
*/ |
1142 |
|
public void testAbnormalInvokeAllCollection() { |
1143 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1144 |
|
protected void realCompute() { |
1145 |
< |
FailingCCF f = new LFCCF(null, 8); |
1146 |
< |
CCF g = new LCCF(null, 9); |
1147 |
< |
CCF h = new LCCF(null, 7); |
1145 |
> |
FailingCCF f = new LFCCF(8); |
1146 |
> |
CCF g = new LCCF(9); |
1147 |
> |
CCF h = new LCCF(7); |
1148 |
|
HashSet set = new HashSet(); |
1149 |
|
set.add(f); |
1150 |
|
set.add(g); |
1166 |
|
public void testTryUnfork() { |
1167 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1168 |
|
protected void realCompute() { |
1169 |
< |
CCF g = new LCCF(null, 9); |
1169 |
> |
CCF g = new LCCF(9); |
1170 |
|
assertSame(g, g.fork()); |
1171 |
< |
CCF f = new LCCF(null, 8); |
1171 |
> |
CCF f = new LCCF(8); |
1172 |
|
assertSame(f, f.fork()); |
1173 |
|
assertTrue(f.tryUnfork()); |
1174 |
|
helpQuiesce(); |
1185 |
|
public void testGetSurplusQueuedTaskCount() { |
1186 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1187 |
|
protected void realCompute() { |
1188 |
< |
CCF h = new LCCF(null, 7); |
1188 |
> |
CCF h = new LCCF(7); |
1189 |
|
assertSame(h, h.fork()); |
1190 |
< |
CCF g = new LCCF(null, 9); |
1190 |
> |
CCF g = new LCCF(9); |
1191 |
|
assertSame(g, g.fork()); |
1192 |
< |
CCF f = new LCCF(null, 8); |
1192 |
> |
CCF f = new LCCF(8); |
1193 |
|
assertSame(f, f.fork()); |
1194 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
1195 |
|
helpQuiesce(); |
1207 |
|
public void testPeekNextLocalTask() { |
1208 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1209 |
|
protected void realCompute() { |
1210 |
< |
CCF g = new LCCF(null, 9); |
1210 |
> |
CCF g = new LCCF(9); |
1211 |
|
assertSame(g, g.fork()); |
1212 |
< |
CCF f = new LCCF(null, 8); |
1212 |
> |
CCF f = new LCCF(8); |
1213 |
|
assertSame(f, f.fork()); |
1214 |
|
assertSame(f, peekNextLocalTask()); |
1215 |
|
assertNull(f.join()); |
1227 |
|
public void testPollNextLocalTask() { |
1228 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1229 |
|
protected void realCompute() { |
1230 |
< |
CCF g = new LCCF(null, 9); |
1230 |
> |
CCF g = new LCCF(9); |
1231 |
|
assertSame(g, g.fork()); |
1232 |
< |
CCF f = new LCCF(null, 8); |
1232 |
> |
CCF f = new LCCF(8); |
1233 |
|
assertSame(f, f.fork()); |
1234 |
|
assertSame(f, pollNextLocalTask()); |
1235 |
|
helpQuiesce(); |
1246 |
|
public void testPollTask() { |
1247 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1248 |
|
protected void realCompute() { |
1249 |
< |
CCF g = new LCCF(null, 9); |
1249 |
> |
CCF g = new LCCF(9); |
1250 |
|
assertSame(g, g.fork()); |
1251 |
< |
CCF f = new LCCF(null, 8); |
1251 |
> |
CCF f = new LCCF(8); |
1252 |
|
assertSame(f, f.fork()); |
1253 |
|
assertSame(f, pollTask()); |
1254 |
|
helpQuiesce(); |
1264 |
|
public void testPeekNextLocalTaskAsync() { |
1265 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1266 |
|
protected void realCompute() { |
1267 |
< |
CCF g = new LCCF(null, 9); |
1267 |
> |
CCF g = new LCCF(9); |
1268 |
|
assertSame(g, g.fork()); |
1269 |
< |
CCF f = new LCCF(null, 8); |
1269 |
> |
CCF f = new LCCF(8); |
1270 |
|
assertSame(f, f.fork()); |
1271 |
|
assertSame(g, peekNextLocalTask()); |
1272 |
|
assertNull(f.join()); |
1285 |
|
public void testPollNextLocalTaskAsync() { |
1286 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1287 |
|
protected void realCompute() { |
1288 |
< |
CCF g = new LCCF(null, 9); |
1288 |
> |
CCF g = new LCCF(9); |
1289 |
|
assertSame(g, g.fork()); |
1290 |
< |
CCF f = new LCCF(null, 8); |
1290 |
> |
CCF f = new LCCF(8); |
1291 |
|
assertSame(f, f.fork()); |
1292 |
|
assertSame(g, pollNextLocalTask()); |
1293 |
|
helpQuiesce(); |
1305 |
|
public void testPollTaskAsync() { |
1306 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1307 |
|
protected void realCompute() { |
1308 |
< |
CCF g = new LCCF(null, 9); |
1308 |
> |
CCF g = new LCCF(9); |
1309 |
|
assertSame(g, g.fork()); |
1310 |
< |
CCF f = new LCCF(null, 8); |
1310 |
> |
CCF f = new LCCF(8); |
1311 |
|
assertSame(f, f.fork()); |
1312 |
|
assertSame(g, pollTask()); |
1313 |
|
helpQuiesce(); |
1328 |
|
public void testInvokeSingleton() { |
1329 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1330 |
|
protected void realCompute() { |
1331 |
< |
CCF f = new LCCF(null, 8); |
1331 |
> |
CCF f = new LCCF(8); |
1332 |
|
assertNull(f.invoke()); |
1333 |
|
assertEquals(21, f.number); |
1334 |
|
checkCompletedNormally(f); |
1344 |
|
public void testQuietlyInvokeSingleton() { |
1345 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1346 |
|
protected void realCompute() { |
1347 |
< |
CCF f = new LCCF(null, 8); |
1347 |
> |
CCF f = new LCCF(8); |
1348 |
|
f.quietlyInvoke(); |
1349 |
|
assertEquals(21, f.number); |
1350 |
|
checkCompletedNormally(f); |
1358 |
|
public void testForkJoinSingleton() { |
1359 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1360 |
|
protected void realCompute() { |
1361 |
< |
CCF f = new LCCF(null, 8); |
1361 |
> |
CCF f = new LCCF(8); |
1362 |
|
assertSame(f, f.fork()); |
1363 |
|
assertNull(f.join()); |
1364 |
|
assertEquals(21, f.number); |
1373 |
|
public void testForkGetSingleton() { |
1374 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1375 |
|
protected void realCompute() throws Exception { |
1376 |
< |
CCF f = new LCCF(null, 8); |
1376 |
> |
CCF f = new LCCF(8); |
1377 |
|
assertSame(f, f.fork()); |
1378 |
|
assertNull(f.get()); |
1379 |
|
assertEquals(21, f.number); |
1388 |
|
public void testForkTimedGetSingleton() { |
1389 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1390 |
|
protected void realCompute() throws Exception { |
1391 |
< |
CCF f = new LCCF(null, 8); |
1391 |
> |
CCF f = new LCCF(8); |
1392 |
|
assertSame(f, f.fork()); |
1393 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1394 |
|
assertEquals(21, f.number); |
1403 |
|
public void testForkTimedGetNPESingleton() { |
1404 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1405 |
|
protected void realCompute() throws Exception { |
1406 |
< |
CCF f = new LCCF(null, 8); |
1406 |
> |
CCF f = new LCCF(8); |
1407 |
|
assertSame(f, f.fork()); |
1408 |
|
try { |
1409 |
|
f.get(5L, null); |
1419 |
|
public void testForkQuietlyJoinSingleton() { |
1420 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1421 |
|
protected void realCompute() { |
1422 |
< |
CCF f = new LCCF(null, 8); |
1422 |
> |
CCF f = new LCCF(8); |
1423 |
|
assertSame(f, f.fork()); |
1424 |
|
f.quietlyJoin(); |
1425 |
|
assertEquals(21, f.number); |
1435 |
|
public void testForkHelpQuiesceSingleton() { |
1436 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1437 |
|
protected void realCompute() { |
1438 |
< |
CCF f = new LCCF(null, 8); |
1438 |
> |
CCF f = new LCCF(8); |
1439 |
|
assertSame(f, f.fork()); |
1440 |
|
helpQuiesce(); |
1441 |
|
assertEquals(0, getQueuedTaskCount()); |
1451 |
|
public void testAbnormalInvokeSingleton() { |
1452 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1453 |
|
protected void realCompute() { |
1454 |
< |
FailingCCF f = new LFCCF(null, 8); |
1454 |
> |
FailingCCF f = new LFCCF(8); |
1455 |
|
try { |
1456 |
|
f.invoke(); |
1457 |
|
shouldThrow(); |
1468 |
|
public void testAbnormalQuietlyInvokeSingleton() { |
1469 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1470 |
|
protected void realCompute() { |
1471 |
< |
FailingCCF f = new LFCCF(null, 8); |
1471 |
> |
FailingCCF f = new LFCCF(8); |
1472 |
|
f.quietlyInvoke(); |
1473 |
|
assertTrue(f.getException() instanceof FJException); |
1474 |
|
checkCompletedAbnormally(f, f.getException()); |
1482 |
|
public void testAbnormalForkJoinSingleton() { |
1483 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1484 |
|
protected void realCompute() { |
1485 |
< |
FailingCCF f = new LFCCF(null, 8); |
1485 |
> |
FailingCCF f = new LFCCF(8); |
1486 |
|
assertSame(f, f.fork()); |
1487 |
|
try { |
1488 |
|
f.join(); |
1500 |
|
public void testAbnormalForkGetSingleton() { |
1501 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1502 |
|
protected void realCompute() throws Exception { |
1503 |
< |
FailingCCF f = new LFCCF(null, 8); |
1503 |
> |
FailingCCF f = new LFCCF(8); |
1504 |
|
assertSame(f, f.fork()); |
1505 |
|
try { |
1506 |
|
f.get(); |
1520 |
|
public void testAbnormalForkTimedGetSingleton() { |
1521 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1522 |
|
protected void realCompute() throws Exception { |
1523 |
< |
FailingCCF f = new LFCCF(null, 8); |
1523 |
> |
FailingCCF f = new LFCCF(8); |
1524 |
|
assertSame(f, f.fork()); |
1525 |
|
try { |
1526 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
1540 |
|
public void testAbnormalForkQuietlyJoinSingleton() { |
1541 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1542 |
|
protected void realCompute() { |
1543 |
< |
FailingCCF f = new LFCCF(null, 8); |
1543 |
> |
FailingCCF f = new LFCCF(8); |
1544 |
|
assertSame(f, f.fork()); |
1545 |
|
f.quietlyJoin(); |
1546 |
|
assertTrue(f.getException() instanceof FJException); |
1555 |
|
public void testCancelledInvokeSingleton() { |
1556 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1557 |
|
protected void realCompute() { |
1558 |
< |
CCF f = new LCCF(null, 8); |
1558 |
> |
CCF f = new LCCF(8); |
1559 |
|
assertTrue(f.cancel(true)); |
1560 |
|
try { |
1561 |
|
f.invoke(); |
1573 |
|
public void testCancelledForkJoinSingleton() { |
1574 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1575 |
|
protected void realCompute() { |
1576 |
< |
CCF f = new LCCF(null, 8); |
1576 |
> |
CCF f = new LCCF(8); |
1577 |
|
assertTrue(f.cancel(true)); |
1578 |
|
assertSame(f, f.fork()); |
1579 |
|
try { |
1592 |
|
public void testCancelledForkGetSingleton() { |
1593 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1594 |
|
protected void realCompute() throws Exception { |
1595 |
< |
CCF f = new LCCF(null, 8); |
1595 |
> |
CCF f = new LCCF(8); |
1596 |
|
assertTrue(f.cancel(true)); |
1597 |
|
assertSame(f, f.fork()); |
1598 |
|
try { |
1611 |
|
public void testCancelledForkTimedGetSingleton() throws Exception { |
1612 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1613 |
|
protected void realCompute() throws Exception { |
1614 |
< |
CCF f = new LCCF(null, 8); |
1614 |
> |
CCF f = new LCCF(8); |
1615 |
|
assertTrue(f.cancel(true)); |
1616 |
|
assertSame(f, f.fork()); |
1617 |
|
try { |
1630 |
|
public void testCancelledForkQuietlyJoinSingleton() { |
1631 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1632 |
|
protected void realCompute() { |
1633 |
< |
CCF f = new LCCF(null, 8); |
1633 |
> |
CCF f = new LCCF(8); |
1634 |
|
assertTrue(f.cancel(true)); |
1635 |
|
assertSame(f, f.fork()); |
1636 |
|
f.quietlyJoin(); |
1645 |
|
public void testCompleteExceptionallySingleton() { |
1646 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1647 |
|
protected void realCompute() { |
1648 |
< |
CCF f = new LCCF(null, 8); |
1649 |
< |
f.completeExceptionally(new FJException()); |
1650 |
< |
try { |
1651 |
< |
f.invoke(); |
1652 |
< |
shouldThrow(); |
1653 |
< |
} catch (FJException success) { |
1561 |
< |
checkCompletedAbnormally(f, success); |
1562 |
< |
} |
1648 |
> |
CCF n = new LCCF(8); |
1649 |
> |
CCF f = new LCCF(n, 8); |
1650 |
> |
FJException ex = new FJException(); |
1651 |
> |
f.completeExceptionally(ex); |
1652 |
> |
f.checkCompletedExceptionally(ex); |
1653 |
> |
n.checkCompletedExceptionally(ex); |
1654 |
|
}}; |
1655 |
|
testInvokeOnPool(singletonPool(), a); |
1656 |
|
} |
1661 |
|
public void testInvokeAll2Singleton() { |
1662 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1663 |
|
protected void realCompute() { |
1664 |
< |
CCF f = new LCCF(null, 8); |
1665 |
< |
CCF g = new LCCF(null, 9); |
1664 |
> |
CCF f = new LCCF(8); |
1665 |
> |
CCF g = new LCCF(9); |
1666 |
|
invokeAll(f, g); |
1667 |
|
assertEquals(21, f.number); |
1668 |
|
assertEquals(34, g.number); |
1678 |
|
public void testInvokeAll1Singleton() { |
1679 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1680 |
|
protected void realCompute() { |
1681 |
< |
CCF f = new LCCF(null, 8); |
1681 |
> |
CCF f = new LCCF(8); |
1682 |
|
invokeAll(f); |
1683 |
|
checkCompletedNormally(f); |
1684 |
|
assertEquals(21, f.number); |
1692 |
|
public void testInvokeAll3Singleton() { |
1693 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1694 |
|
protected void realCompute() { |
1695 |
< |
CCF f = new LCCF(null, 8); |
1696 |
< |
CCF g = new LCCF(null, 9); |
1697 |
< |
CCF h = new LCCF(null, 7); |
1695 |
> |
CCF f = new LCCF(8); |
1696 |
> |
CCF g = new LCCF(9); |
1697 |
> |
CCF h = new LCCF(7); |
1698 |
|
invokeAll(f, g, h); |
1699 |
|
assertEquals(21, f.number); |
1700 |
|
assertEquals(34, g.number); |
1712 |
|
public void testInvokeAllCollectionSingleton() { |
1713 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1714 |
|
protected void realCompute() { |
1715 |
< |
CCF f = new LCCF(null, 8); |
1716 |
< |
CCF g = new LCCF(null, 9); |
1717 |
< |
CCF h = new LCCF(null, 7); |
1715 |
> |
CCF f = new LCCF(8); |
1716 |
> |
CCF g = new LCCF(9); |
1717 |
> |
CCF h = new LCCF(7); |
1718 |
|
HashSet set = new HashSet(); |
1719 |
|
set.add(f); |
1720 |
|
set.add(g); |
1736 |
|
public void testInvokeAllNPESingleton() { |
1737 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1738 |
|
protected void realCompute() { |
1739 |
< |
CCF f = new LCCF(null, 8); |
1740 |
< |
CCF g = new LCCF(null, 9); |
1739 |
> |
CCF f = new LCCF(8); |
1740 |
> |
CCF g = new LCCF(9); |
1741 |
|
CCF h = null; |
1742 |
|
try { |
1743 |
|
invokeAll(f, g, h); |
1753 |
|
public void testAbnormalInvokeAll2Singleton() { |
1754 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1755 |
|
protected void realCompute() { |
1756 |
< |
CCF f = new LCCF(null, 8); |
1757 |
< |
FailingCCF g = new LFCCF(null, 9); |
1756 |
> |
CCF f = new LCCF(8); |
1757 |
> |
FailingCCF g = new LFCCF(9); |
1758 |
|
try { |
1759 |
|
invokeAll(f, g); |
1760 |
|
shouldThrow(); |
1771 |
|
public void testAbnormalInvokeAll1Singleton() { |
1772 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1773 |
|
protected void realCompute() { |
1774 |
< |
FailingCCF g = new LFCCF(null, 9); |
1774 |
> |
FailingCCF g = new LFCCF(9); |
1775 |
|
try { |
1776 |
|
invokeAll(g); |
1777 |
|
shouldThrow(); |
1788 |
|
public void testAbnormalInvokeAll3Singleton() { |
1789 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1790 |
|
protected void realCompute() { |
1791 |
< |
CCF f = new LCCF(null, 8); |
1792 |
< |
FailingCCF g = new LFCCF(null, 9); |
1793 |
< |
CCF h = new LCCF(null, 7); |
1791 |
> |
CCF f = new LCCF(8); |
1792 |
> |
FailingCCF g = new LFCCF(9); |
1793 |
> |
CCF h = new LCCF(7); |
1794 |
|
try { |
1795 |
|
invokeAll(f, g, h); |
1796 |
|
shouldThrow(); |
1802 |
|
} |
1803 |
|
|
1804 |
|
/** |
1805 |
< |
* invokeAll(collection) throws exception if any task does |
1805 |
> |
* invokeAll(collection) throws exception if any task does |
1806 |
|
*/ |
1807 |
|
public void testAbnormalInvokeAllCollectionSingleton() { |
1808 |
|
ForkJoinTask a = new CheckedRecursiveAction() { |
1809 |
|
protected void realCompute() { |
1810 |
< |
FailingCCF f = new LFCCF(null, 8); |
1811 |
< |
CCF g = new LCCF(null, 9); |
1812 |
< |
CCF h = new LCCF(null, 7); |
1810 |
> |
FailingCCF f = new LFCCF(8); |
1811 |
> |
CCF g = new LCCF(9); |
1812 |
> |
CCF h = new LCCF(7); |
1813 |
|
HashSet set = new HashSet(); |
1814 |
|
set.add(f); |
1815 |
|
set.add(g); |