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<>(null); |
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(); } |
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()); |
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 |
|
for (Object x : new Object[] { Boolean.TRUE, null }) { |
292 |
< |
new NoopCC() |
293 |
< |
.checkCompletes(x); |
294 |
< |
new NoopCC(new NoopCC()) |
295 |
< |
.checkCompletes(x); |
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 |
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 |
|
/** |
467 |
|
a.setPendingCount(1); |
468 |
|
b.setPendingCount(1); |
469 |
|
assertNull(b.firstComplete()); |
470 |
< |
CountedCompleter c = b.firstComplete(); |
471 |
< |
assertSame(b, c); |
472 |
< |
CountedCompleter d = c.nextComplete(); |
473 |
< |
assertNull(d); |
474 |
< |
CountedCompleter e = c.nextComplete(); |
475 |
< |
assertSame(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 |
|
/** |
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 |
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; |
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() { |
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() { |