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 |
> |
import java.util.HashSet; |
7 |
|
import java.util.concurrent.CancellationException; |
8 |
+ |
import java.util.concurrent.CountedCompleter; |
9 |
+ |
import java.util.concurrent.ExecutionException; |
10 |
|
import java.util.concurrent.ForkJoinPool; |
11 |
|
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; |
12 |
|
import java.util.concurrent.TimeoutException; |
13 |
< |
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
13 |
> |
import java.util.concurrent.atomic.AtomicInteger; |
14 |
> |
import java.util.concurrent.atomic.AtomicReference; |
15 |
|
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
16 |
|
import static java.util.concurrent.TimeUnit.SECONDS; |
18 |
– |
import java.util.HashSet; |
17 |
|
import junit.framework.*; |
18 |
|
|
19 |
|
public class CountedCompleterTest extends JSR166TestCase { |
30 |
|
static final int mainPoolSize = |
31 |
|
Math.max(2, Runtime.getRuntime().availableProcessors()); |
32 |
|
|
35 |
– |
/** |
36 |
– |
* Analog of CheckedRunnable for ForkJoinTasks |
37 |
– |
*/ |
38 |
– |
public abstract class CheckedFJTask extends RecursiveAction { |
39 |
– |
protected abstract void realCompute() throws Throwable; |
40 |
– |
|
41 |
– |
public final void compute() { |
42 |
– |
try { |
43 |
– |
realCompute(); |
44 |
– |
} catch (Throwable t) { |
45 |
– |
threadUnexpectedException(t); |
46 |
– |
} |
47 |
– |
} |
48 |
– |
} |
49 |
– |
|
33 |
|
private static ForkJoinPool mainPool() { |
34 |
|
return new ForkJoinPool(mainPoolSize); |
35 |
|
} |
81 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
82 |
|
} |
83 |
|
|
84 |
< |
<T> void checkCompletedNormally(CountedCompleter<T> a) { |
102 |
< |
checkCompletedNormally(a, null); |
103 |
< |
} |
104 |
< |
|
105 |
< |
<T> void checkCompletedNormally(CountedCompleter<T> a, T expected) { |
84 |
> |
void checkCompletedNormally(CountedCompleter<?> a) { |
85 |
|
assertTrue(a.isDone()); |
86 |
|
assertFalse(a.isCancelled()); |
87 |
|
assertTrue(a.isCompletedNormally()); |
88 |
|
assertFalse(a.isCompletedAbnormally()); |
89 |
|
assertNull(a.getException()); |
90 |
< |
assertSame(expected, a.getRawResult()); |
90 |
> |
assertNull(a.getRawResult()); |
91 |
|
|
92 |
|
{ |
93 |
|
Thread.currentThread().interrupt(); |
94 |
|
long t0 = System.nanoTime(); |
95 |
< |
assertSame(expected, a.join()); |
95 |
> |
assertNull(a.join()); |
96 |
|
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
97 |
|
Thread.interrupted(); |
98 |
|
} |
108 |
|
assertFalse(a.cancel(false)); |
109 |
|
assertFalse(a.cancel(true)); |
110 |
|
try { |
111 |
< |
assertSame(expected, a.get()); |
111 |
> |
assertNull(a.get()); |
112 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
113 |
|
try { |
114 |
< |
assertSame(expected, a.get(5L, SECONDS)); |
114 |
> |
assertNull(a.get(5L, SECONDS)); |
115 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
116 |
|
} |
117 |
|
|
190 |
|
} catch (ExecutionException success) { |
191 |
|
assertSame(t.getClass(), success.getCause().getClass()); |
192 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
193 |
+ |
|
194 |
+ |
try { |
195 |
+ |
a.invoke(); |
196 |
+ |
shouldThrow(); |
197 |
+ |
} catch (Throwable ex) { |
198 |
+ |
assertSame(t, ex); |
199 |
+ |
} |
200 |
|
} |
201 |
|
|
202 |
|
public static final class FJException extends RuntimeException { |
203 |
|
FJException() { super(); } |
204 |
|
} |
205 |
|
|
206 |
< |
static final class NoopCountedCompleter extends CountedCompleter { |
207 |
< |
boolean post; // set true if onCompletion called |
208 |
< |
NoopCountedCompleter() { super(); } |
209 |
< |
NoopCountedCompleter(CountedCompleter p) { super(p); } |
210 |
< |
public void compute() {} |
211 |
< |
public final void onCompletion(CountedCompleter caller) { |
212 |
< |
post = true; |
206 |
> |
abstract class CheckedCC extends CountedCompleter<Object> { |
207 |
> |
final AtomicInteger computeN = new AtomicInteger(0); |
208 |
> |
final AtomicInteger onCompletionN = new AtomicInteger(0); |
209 |
> |
final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0); |
210 |
> |
final AtomicInteger setRawResultN = new AtomicInteger(0); |
211 |
> |
final AtomicReference<Object> rawResult = new AtomicReference<Object>(null); |
212 |
> |
int computeN() { return computeN.get(); } |
213 |
> |
int onCompletionN() { return onCompletionN.get(); } |
214 |
> |
int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); } |
215 |
> |
int setRawResultN() { return setRawResultN.get(); } |
216 |
> |
|
217 |
> |
CheckedCC() { super(); } |
218 |
> |
CheckedCC(CountedCompleter p) { super(p); } |
219 |
> |
CheckedCC(CountedCompleter p, int n) { super(p, n); } |
220 |
> |
abstract void realCompute(); |
221 |
> |
public final void compute() { |
222 |
> |
computeN.incrementAndGet(); |
223 |
> |
realCompute(); |
224 |
> |
} |
225 |
> |
public void onCompletion(CountedCompleter caller) { |
226 |
> |
onCompletionN.incrementAndGet(); |
227 |
> |
super.onCompletion(caller); |
228 |
> |
} |
229 |
> |
public boolean onExceptionalCompletion(Throwable ex, |
230 |
> |
CountedCompleter caller) { |
231 |
> |
onExceptionalCompletionN.incrementAndGet(); |
232 |
> |
assertNotNull(ex); |
233 |
> |
assertTrue(isCompletedAbnormally()); |
234 |
> |
assertTrue(super.onExceptionalCompletion(ex, caller)); |
235 |
> |
return true; |
236 |
> |
} |
237 |
> |
protected void setRawResult(Object t) { |
238 |
> |
setRawResultN.incrementAndGet(); |
239 |
> |
rawResult.set(t); |
240 |
> |
super.setRawResult(t); |
241 |
> |
} |
242 |
> |
void checkIncomplete() { |
243 |
> |
assertEquals(0, computeN()); |
244 |
> |
assertEquals(0, onCompletionN()); |
245 |
> |
assertEquals(0, onExceptionalCompletionN()); |
246 |
> |
assertEquals(0, setRawResultN()); |
247 |
> |
checkNotDone(this); |
248 |
> |
} |
249 |
> |
void checkCompletes(Object rawResult) { |
250 |
> |
checkIncomplete(); |
251 |
> |
int pendingCount = getPendingCount(); |
252 |
> |
complete(rawResult); |
253 |
> |
assertEquals(pendingCount, getPendingCount()); |
254 |
> |
assertEquals(0, computeN()); |
255 |
> |
assertEquals(1, onCompletionN()); |
256 |
> |
assertEquals(0, onExceptionalCompletionN()); |
257 |
> |
assertEquals(1, setRawResultN()); |
258 |
> |
assertSame(rawResult, this.rawResult.get()); |
259 |
> |
checkCompletedNormally(this); |
260 |
> |
} |
261 |
> |
void checkCompletesExceptionally(Throwable ex) { |
262 |
> |
checkIncomplete(); |
263 |
> |
completeExceptionally(ex); |
264 |
> |
checkCompletedExceptionally(ex); |
265 |
> |
} |
266 |
> |
void checkCompletedExceptionally(Throwable ex) { |
267 |
> |
assertEquals(0, computeN()); |
268 |
> |
assertEquals(0, onCompletionN()); |
269 |
> |
assertEquals(1, onExceptionalCompletionN()); |
270 |
> |
assertEquals(0, setRawResultN()); |
271 |
> |
assertNull(this.rawResult.get()); |
272 |
> |
checkCompletedAbnormally(this, ex); |
273 |
|
} |
274 |
|
} |
275 |
|
|
276 |
+ |
final class NoopCC extends CheckedCC { |
277 |
+ |
NoopCC() { super(); } |
278 |
+ |
NoopCC(CountedCompleter p) { super(p); } |
279 |
+ |
protected void realCompute() {} |
280 |
+ |
} |
281 |
+ |
|
282 |
|
/** |
283 |
< |
* A newly constructed CountedCompleter is not completed; |
284 |
< |
* complete() causes completion. |
283 |
> |
* A newly constructed CountedCompleter is not completed; |
284 |
> |
* complete() causes completion. pendingCount is ignored. |
285 |
|
*/ |
286 |
|
public void testComplete() { |
287 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
288 |
< |
assertFalse(a.isDone()); |
289 |
< |
assertFalse(a.isCompletedNormally()); |
290 |
< |
assertFalse(a.isCompletedAbnormally()); |
291 |
< |
assertFalse(a.isCancelled()); |
292 |
< |
assertNull(a.getException()); |
293 |
< |
assertNull(a.getRawResult()); |
294 |
< |
assertFalse(a.post); |
295 |
< |
a.complete(null); |
296 |
< |
assertTrue(a.post); |
245 |
< |
assertTrue(a.isDone()); |
246 |
< |
assertTrue(a.isCompletedNormally()); |
247 |
< |
assertFalse(a.isCompletedAbnormally()); |
248 |
< |
assertFalse(a.isCancelled()); |
249 |
< |
assertNull(a.getException()); |
250 |
< |
assertNull(a.getRawResult()); |
287 |
> |
for (Object x : new Object[] { Boolean.TRUE, null }) { |
288 |
> |
for (int pendingCount : new int[] { 0, 42 }) { |
289 |
> |
testComplete(new NoopCC(), x, pendingCount); |
290 |
> |
testComplete(new NoopCC(new NoopCC()), x, pendingCount); |
291 |
> |
} |
292 |
> |
} |
293 |
> |
} |
294 |
> |
void testComplete(NoopCC cc, Object x, int pendingCount) { |
295 |
> |
cc.setPendingCount(pendingCount); |
296 |
> |
cc.checkCompletes(x); |
297 |
|
} |
298 |
|
|
299 |
|
/** |
300 |
|
* completeExceptionally completes exceptionally |
301 |
|
*/ |
302 |
|
public void testCompleteExceptionally() { |
303 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
304 |
< |
assertFalse(a.isDone()); |
305 |
< |
assertFalse(a.isCompletedNormally()); |
306 |
< |
assertFalse(a.isCompletedAbnormally()); |
307 |
< |
assertFalse(a.isCancelled()); |
308 |
< |
assertNull(a.getException()); |
309 |
< |
assertNull(a.getRawResult()); |
310 |
< |
assertFalse(a.post); |
311 |
< |
a.completeExceptionally(new FJException()); |
312 |
< |
assertFalse(a.post); |
313 |
< |
assertTrue(a.isDone()); |
314 |
< |
assertFalse(a.isCompletedNormally()); |
315 |
< |
assertTrue(a.isCompletedAbnormally()); |
316 |
< |
assertFalse(a.isCancelled()); |
317 |
< |
assertTrue(a.getException() instanceof FJException); |
272 |
< |
assertNull(a.getRawResult()); |
303 |
> |
new NoopCC() |
304 |
> |
.checkCompletesExceptionally(new FJException()); |
305 |
> |
new NoopCC(new NoopCC()) |
306 |
> |
.checkCompletesExceptionally(new FJException()); |
307 |
> |
} |
308 |
> |
|
309 |
> |
/** |
310 |
> |
* completeExceptionally(null) throws NullPointerException |
311 |
> |
*/ |
312 |
> |
public void testCompleteExceptionally_null() { |
313 |
> |
try { |
314 |
> |
new NoopCC() |
315 |
> |
.checkCompletesExceptionally(null); |
316 |
> |
shouldThrow(); |
317 |
> |
} catch (NullPointerException success) {} |
318 |
|
} |
319 |
|
|
320 |
|
/** |
321 |
|
* setPendingCount sets the reported pending count |
322 |
|
*/ |
323 |
|
public void testSetPendingCount() { |
324 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
324 |
> |
NoopCC a = new NoopCC(); |
325 |
|
assertEquals(0, a.getPendingCount()); |
326 |
|
a.setPendingCount(1); |
327 |
|
assertEquals(1, a.getPendingCount()); |
333 |
|
* addToPendingCount adds to the reported pending count |
334 |
|
*/ |
335 |
|
public void testAddToPendingCount() { |
336 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
336 |
> |
NoopCC a = new NoopCC(); |
337 |
|
assertEquals(0, a.getPendingCount()); |
338 |
|
a.addToPendingCount(1); |
339 |
|
assertEquals(1, a.getPendingCount()); |
346 |
|
* count unless zero |
347 |
|
*/ |
348 |
|
public void testDecrementPendingCount() { |
349 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
349 |
> |
NoopCC a = new NoopCC(); |
350 |
|
assertEquals(0, a.getPendingCount()); |
351 |
|
a.addToPendingCount(1); |
352 |
|
assertEquals(1, a.getPendingCount()); |
357 |
|
} |
358 |
|
|
359 |
|
/** |
360 |
+ |
* compareAndSetPendingCount compares and sets the reported |
361 |
+ |
* pending count |
362 |
+ |
*/ |
363 |
+ |
public void testCompareAndSetPendingCount() { |
364 |
+ |
NoopCC a = new NoopCC(); |
365 |
+ |
assertEquals(0, a.getPendingCount()); |
366 |
+ |
assertTrue(a.compareAndSetPendingCount(0, 1)); |
367 |
+ |
assertEquals(1, a.getPendingCount()); |
368 |
+ |
assertTrue(a.compareAndSetPendingCount(1, 2)); |
369 |
+ |
assertEquals(2, a.getPendingCount()); |
370 |
+ |
assertFalse(a.compareAndSetPendingCount(1, 3)); |
371 |
+ |
assertEquals(2, a.getPendingCount()); |
372 |
+ |
} |
373 |
+ |
|
374 |
+ |
/** |
375 |
|
* getCompleter returns parent or null if at root |
376 |
|
*/ |
377 |
|
public void testGetCompleter() { |
378 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
378 |
> |
NoopCC a = new NoopCC(); |
379 |
|
assertNull(a.getCompleter()); |
380 |
< |
CountedCompleter b = new NoopCountedCompleter(a); |
381 |
< |
assertEquals(a, b.getCompleter()); |
380 |
> |
CountedCompleter b = new NoopCC(a); |
381 |
> |
assertSame(a, b.getCompleter()); |
382 |
> |
CountedCompleter c = new NoopCC(b); |
383 |
> |
assertSame(b, c.getCompleter()); |
384 |
|
} |
385 |
< |
|
385 |
> |
|
386 |
|
/** |
387 |
|
* getRoot returns self if no parent, else parent's root |
388 |
|
*/ |
389 |
|
public void testGetRoot() { |
390 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
391 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
392 |
< |
assertEquals(a, a.getRoot()); |
393 |
< |
assertEquals(a, b.getRoot()); |
390 |
> |
NoopCC a = new NoopCC(); |
391 |
> |
NoopCC b = new NoopCC(a); |
392 |
> |
NoopCC c = new NoopCC(b); |
393 |
> |
assertSame(a, a.getRoot()); |
394 |
> |
assertSame(a, b.getRoot()); |
395 |
> |
assertSame(a, c.getRoot()); |
396 |
|
} |
397 |
< |
|
397 |
> |
|
398 |
|
/** |
399 |
< |
* tryComplete causes completion if pending count is zero |
399 |
> |
* tryComplete decrements pending count unless zero, in which case |
400 |
> |
* causes completion |
401 |
|
*/ |
402 |
< |
public void testTryComplete1() { |
403 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
402 |
> |
public void testTryComplete() { |
403 |
> |
NoopCC a = new NoopCC(); |
404 |
|
assertEquals(0, a.getPendingCount()); |
405 |
+ |
int n = 3; |
406 |
+ |
a.setPendingCount(n); |
407 |
+ |
for (; n > 0; n--) { |
408 |
+ |
assertEquals(n, a.getPendingCount()); |
409 |
+ |
a.tryComplete(); |
410 |
+ |
a.checkIncomplete(); |
411 |
+ |
assertEquals(n - 1, a.getPendingCount()); |
412 |
+ |
} |
413 |
|
a.tryComplete(); |
414 |
< |
assertTrue(a.post); |
415 |
< |
assertTrue(a.isDone()); |
414 |
> |
assertEquals(0, a.computeN()); |
415 |
> |
assertEquals(1, a.onCompletionN()); |
416 |
> |
assertEquals(0, a.onExceptionalCompletionN()); |
417 |
> |
assertEquals(0, a.setRawResultN()); |
418 |
> |
checkCompletedNormally(a); |
419 |
|
} |
420 |
|
|
421 |
|
/** |
422 |
< |
* propagateCompletion causes completion without invokein |
423 |
< |
* onCompletion if pending count is zero |
422 |
> |
* propagateCompletion decrements pending count unless zero, in |
423 |
> |
* which case causes completion, without invoking onCompletion |
424 |
|
*/ |
425 |
|
public void testPropagateCompletion() { |
426 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
426 |
> |
NoopCC a = new NoopCC(); |
427 |
|
assertEquals(0, a.getPendingCount()); |
428 |
+ |
int n = 3; |
429 |
+ |
a.setPendingCount(n); |
430 |
+ |
for (; n > 0; n--) { |
431 |
+ |
assertEquals(n, a.getPendingCount()); |
432 |
+ |
a.propagateCompletion(); |
433 |
+ |
a.checkIncomplete(); |
434 |
+ |
assertEquals(n - 1, a.getPendingCount()); |
435 |
+ |
} |
436 |
|
a.propagateCompletion(); |
437 |
< |
assertFalse(a.post); |
438 |
< |
assertTrue(a.isDone()); |
439 |
< |
} |
440 |
< |
|
441 |
< |
/** |
358 |
< |
* tryComplete decrments pending count unless zero |
359 |
< |
*/ |
360 |
< |
public void testTryComplete2() { |
361 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
362 |
< |
assertEquals(0, a.getPendingCount()); |
363 |
< |
a.setPendingCount(1); |
364 |
< |
a.tryComplete(); |
365 |
< |
assertFalse(a.post); |
366 |
< |
assertFalse(a.isDone()); |
367 |
< |
assertEquals(0, a.getPendingCount()); |
368 |
< |
a.tryComplete(); |
369 |
< |
assertTrue(a.post); |
370 |
< |
assertTrue(a.isDone()); |
437 |
> |
assertEquals(0, a.computeN()); |
438 |
> |
assertEquals(0, a.onCompletionN()); |
439 |
> |
assertEquals(0, a.onExceptionalCompletionN()); |
440 |
> |
assertEquals(0, a.setRawResultN()); |
441 |
> |
checkCompletedNormally(a); |
442 |
|
} |
443 |
|
|
444 |
|
/** |
445 |
|
* firstComplete returns this if pending count is zero else null |
446 |
|
*/ |
447 |
|
public void testFirstComplete() { |
448 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
448 |
> |
NoopCC a = new NoopCC(); |
449 |
|
a.setPendingCount(1); |
450 |
|
assertNull(a.firstComplete()); |
451 |
< |
assertEquals(a, a.firstComplete()); |
451 |
> |
a.checkIncomplete(); |
452 |
> |
assertSame(a, a.firstComplete()); |
453 |
> |
a.checkIncomplete(); |
454 |
|
} |
455 |
|
|
456 |
|
/** |
458 |
|
* zero else null |
459 |
|
*/ |
460 |
|
public void testNextComplete() { |
461 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
462 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
461 |
> |
NoopCC a = new NoopCC(); |
462 |
> |
NoopCC b = new NoopCC(a); |
463 |
|
a.setPendingCount(1); |
464 |
|
b.setPendingCount(1); |
465 |
|
assertNull(b.firstComplete()); |
466 |
< |
CountedCompleter c = b.firstComplete(); |
467 |
< |
assertEquals(b, c); |
468 |
< |
CountedCompleter d = c.nextComplete(); |
469 |
< |
assertNull(d); |
470 |
< |
CountedCompleter e = c.nextComplete(); |
471 |
< |
assertEquals(a, e); |
466 |
> |
assertSame(b, b.firstComplete()); |
467 |
> |
assertNull(b.nextComplete()); |
468 |
> |
a.checkIncomplete(); |
469 |
> |
b.checkIncomplete(); |
470 |
> |
assertSame(a, b.nextComplete()); |
471 |
> |
assertSame(a, b.nextComplete()); |
472 |
> |
a.checkIncomplete(); |
473 |
> |
b.checkIncomplete(); |
474 |
> |
assertNull(a.nextComplete()); |
475 |
> |
b.checkIncomplete(); |
476 |
> |
checkCompletedNormally(a); |
477 |
|
} |
478 |
|
|
479 |
|
/** |
480 |
|
* quietlyCompleteRoot completes root task |
481 |
|
*/ |
482 |
|
public void testQuietlyCompleteRoot() { |
483 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
484 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
483 |
> |
NoopCC a = new NoopCC(); |
484 |
> |
NoopCC b = new NoopCC(a); |
485 |
> |
NoopCC c = new NoopCC(b); |
486 |
|
a.setPendingCount(1); |
487 |
|
b.setPendingCount(1); |
488 |
< |
b.quietlyCompleteRoot(); |
488 |
> |
c.setPendingCount(1); |
489 |
> |
c.quietlyCompleteRoot(); |
490 |
|
assertTrue(a.isDone()); |
491 |
|
assertFalse(b.isDone()); |
492 |
+ |
assertFalse(c.isDone()); |
493 |
|
} |
494 |
|
|
495 |
|
// Invocation tests use some interdependent task classes |
496 |
|
// to better test propagation etc |
497 |
|
|
498 |
< |
|
499 |
< |
// Version of Fibonacci with different classes for left vs right forks |
500 |
< |
static abstract class CCF extends CountedCompleter { |
498 |
> |
/** |
499 |
> |
* Version of Fibonacci with different classes for left vs right forks |
500 |
> |
*/ |
501 |
> |
abstract class CCF extends CheckedCC { |
502 |
|
int number; |
503 |
|
int rnumber; |
504 |
|
|
507 |
|
this.number = n; |
508 |
|
} |
509 |
|
|
510 |
< |
public final void compute() { |
429 |
< |
CountedCompleter p; |
510 |
> |
protected final void realCompute() { |
511 |
|
CCF f = this; |
512 |
|
int n = number; |
513 |
|
while (n >= 2) { |
514 |
|
new RCCF(f, n - 2).fork(); |
515 |
|
f = new LCCF(f, --n); |
516 |
|
} |
517 |
< |
f.number = n; |
437 |
< |
f.onCompletion(f); |
438 |
< |
if ((p = f.getCompleter()) != null) |
439 |
< |
p.tryComplete(); |
440 |
< |
else |
441 |
< |
f.quietlyComplete(); |
517 |
> |
f.complete(null); |
518 |
|
} |
519 |
|
} |
520 |
|
|
521 |
< |
static final class LCCF extends CCF { |
521 |
> |
final class LCCF extends CCF { |
522 |
> |
public LCCF(int n) { this(null, n); } |
523 |
|
public LCCF(CountedCompleter parent, int n) { |
524 |
|
super(parent, n); |
525 |
|
} |
526 |
|
public final void onCompletion(CountedCompleter caller) { |
527 |
+ |
super.onCompletion(caller); |
528 |
|
CCF p = (CCF)getCompleter(); |
529 |
|
int n = number + rnumber; |
530 |
|
if (p != null) |
533 |
|
number = n; |
534 |
|
} |
535 |
|
} |
536 |
< |
static final class RCCF extends CCF { |
536 |
> |
final class RCCF extends CCF { |
537 |
|
public RCCF(CountedCompleter parent, int n) { |
538 |
|
super(parent, n); |
539 |
|
} |
540 |
|
public final void onCompletion(CountedCompleter caller) { |
541 |
+ |
super.onCompletion(caller); |
542 |
|
CCF p = (CCF)getCompleter(); |
543 |
|
int n = number + rnumber; |
544 |
|
if (p != null) |
549 |
|
} |
550 |
|
|
551 |
|
// Version of CCF with forced failure in left completions |
552 |
< |
static abstract class FailingCCF extends CountedCompleter { |
552 |
> |
abstract class FailingCCF extends CheckedCC { |
553 |
|
int number; |
554 |
|
int rnumber; |
555 |
|
|
558 |
|
this.number = n; |
559 |
|
} |
560 |
|
|
561 |
< |
public final void compute() { |
483 |
< |
CountedCompleter p; |
561 |
> |
protected final void realCompute() { |
562 |
|
FailingCCF f = this; |
563 |
|
int n = number; |
564 |
|
while (n >= 2) { |
565 |
|
new RFCCF(f, n - 2).fork(); |
566 |
|
f = new LFCCF(f, --n); |
567 |
|
} |
568 |
< |
f.number = n; |
491 |
< |
f.onCompletion(f); |
492 |
< |
if ((p = f.getCompleter()) != null) |
493 |
< |
p.tryComplete(); |
494 |
< |
else |
495 |
< |
f.quietlyComplete(); |
568 |
> |
f.complete(null); |
569 |
|
} |
570 |
|
} |
571 |
|
|
572 |
< |
static final class LFCCF extends FailingCCF { |
572 |
> |
final class LFCCF extends FailingCCF { |
573 |
> |
public LFCCF(int n) { this(null, n); } |
574 |
|
public LFCCF(CountedCompleter parent, int n) { |
575 |
|
super(parent, n); |
576 |
|
} |
577 |
|
public final void onCompletion(CountedCompleter caller) { |
578 |
+ |
super.onCompletion(caller); |
579 |
|
FailingCCF p = (FailingCCF)getCompleter(); |
580 |
|
int n = number + rnumber; |
581 |
|
if (p != null) |
584 |
|
number = n; |
585 |
|
} |
586 |
|
} |
587 |
< |
static final class RFCCF extends FailingCCF { |
587 |
> |
final class RFCCF extends FailingCCF { |
588 |
|
public RFCCF(CountedCompleter parent, int n) { |
589 |
|
super(parent, n); |
590 |
|
} |
591 |
|
public final void onCompletion(CountedCompleter caller) { |
592 |
+ |
super.onCompletion(caller); |
593 |
|
completeExceptionally(new FJException()); |
594 |
|
} |
595 |
|
} |
596 |
< |
|
596 |
> |
|
597 |
|
/** |
598 |
|
* invoke returns when task completes normally. |
599 |
|
* isCompletedAbnormally and isCancelled return false for normally |
600 |
|
* completed tasks; getRawResult returns null. |
601 |
|
*/ |
602 |
|
public void testInvoke() { |
603 |
< |
ForkJoinTask a = new CheckedFJTask() { |
604 |
< |
public void realCompute() { |
605 |
< |
CCF f = new LCCF(null, 8); |
603 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
604 |
> |
protected void realCompute() { |
605 |
> |
CCF f = new LCCF(8); |
606 |
|
assertNull(f.invoke()); |
607 |
|
assertEquals(21, f.number); |
608 |
|
checkCompletedNormally(f); |
616 |
|
* completed tasks |
617 |
|
*/ |
618 |
|
public void testQuietlyInvoke() { |
619 |
< |
ForkJoinTask a = new CheckedFJTask() { |
620 |
< |
public void realCompute() { |
621 |
< |
CCF f = new LCCF(null, 8); |
619 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
620 |
> |
protected void realCompute() { |
621 |
> |
CCF f = new LCCF(8); |
622 |
|
f.quietlyInvoke(); |
623 |
|
assertEquals(21, f.number); |
624 |
|
checkCompletedNormally(f); |
630 |
|
* join of a forked task returns when task completes |
631 |
|
*/ |
632 |
|
public void testForkJoin() { |
633 |
< |
ForkJoinTask a = new CheckedFJTask() { |
634 |
< |
public void realCompute() { |
635 |
< |
CCF f = new LCCF(null, 8); |
633 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
634 |
> |
protected void realCompute() { |
635 |
> |
CCF f = new LCCF(8); |
636 |
|
assertSame(f, f.fork()); |
637 |
|
assertNull(f.join()); |
638 |
|
assertEquals(21, f.number); |
645 |
|
* get of a forked task returns when task completes |
646 |
|
*/ |
647 |
|
public void testForkGet() { |
648 |
< |
ForkJoinTask a = new CheckedFJTask() { |
649 |
< |
public void realCompute() throws Exception { |
650 |
< |
CCF f = new LCCF(null, 8); |
648 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
649 |
> |
protected void realCompute() throws Exception { |
650 |
> |
CCF f = new LCCF(8); |
651 |
|
assertSame(f, f.fork()); |
652 |
|
assertNull(f.get()); |
653 |
|
assertEquals(21, f.number); |
660 |
|
* timed get of a forked task returns when task completes |
661 |
|
*/ |
662 |
|
public void testForkTimedGet() { |
663 |
< |
ForkJoinTask a = new CheckedFJTask() { |
664 |
< |
public void realCompute() throws Exception { |
665 |
< |
CCF f = new LCCF(null, 8); |
663 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
664 |
> |
protected void realCompute() throws Exception { |
665 |
> |
CCF f = new LCCF(8); |
666 |
|
assertSame(f, f.fork()); |
667 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
668 |
|
assertEquals(21, f.number); |
675 |
|
* timed get with null time unit throws NPE |
676 |
|
*/ |
677 |
|
public void testForkTimedGetNPE() { |
678 |
< |
ForkJoinTask a = new CheckedFJTask() { |
679 |
< |
public void realCompute() throws Exception { |
680 |
< |
CCF f = new LCCF(null, 8); |
678 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
679 |
> |
protected void realCompute() throws Exception { |
680 |
> |
CCF f = new LCCF(8); |
681 |
|
assertSame(f, f.fork()); |
682 |
|
try { |
683 |
|
f.get(5L, null); |
691 |
|
* quietlyJoin of a forked task returns when task completes |
692 |
|
*/ |
693 |
|
public void testForkQuietlyJoin() { |
694 |
< |
ForkJoinTask a = new CheckedFJTask() { |
695 |
< |
public void realCompute() { |
696 |
< |
CCF f = new LCCF(null, 8); |
694 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
695 |
> |
protected void realCompute() { |
696 |
> |
CCF f = new LCCF(8); |
697 |
|
assertSame(f, f.fork()); |
698 |
|
f.quietlyJoin(); |
699 |
|
assertEquals(21, f.number); |
707 |
|
* getQueuedTaskCount returns 0 when quiescent |
708 |
|
*/ |
709 |
|
public void testForkHelpQuiesce() { |
710 |
< |
ForkJoinTask a = new CheckedFJTask() { |
711 |
< |
public void realCompute() { |
712 |
< |
CCF f = new LCCF(null, 8); |
710 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
711 |
> |
protected void realCompute() { |
712 |
> |
CCF f = new LCCF(8); |
713 |
|
assertSame(f, f.fork()); |
714 |
|
helpQuiesce(); |
715 |
|
assertEquals(21, f.number); |
723 |
|
* invoke task throws exception when task completes abnormally |
724 |
|
*/ |
725 |
|
public void testAbnormalInvoke() { |
726 |
< |
ForkJoinTask a = new CheckedFJTask() { |
727 |
< |
public void realCompute() { |
728 |
< |
FailingCCF f = new LFCCF(null, 8); |
726 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
727 |
> |
protected void realCompute() { |
728 |
> |
FailingCCF f = new LFCCF(8); |
729 |
|
try { |
730 |
|
f.invoke(); |
731 |
|
shouldThrow(); |
740 |
|
* quietlyInvoke task returns when task completes abnormally |
741 |
|
*/ |
742 |
|
public void testAbnormalQuietlyInvoke() { |
743 |
< |
ForkJoinTask a = new CheckedFJTask() { |
744 |
< |
public void realCompute() { |
745 |
< |
FailingCCF f = new LFCCF(null, 8); |
743 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
744 |
> |
protected void realCompute() { |
745 |
> |
FailingCCF f = new LFCCF(8); |
746 |
|
f.quietlyInvoke(); |
747 |
|
assertTrue(f.getException() instanceof FJException); |
748 |
|
checkCompletedAbnormally(f, f.getException()); |
754 |
|
* join of a forked task throws exception when task completes abnormally |
755 |
|
*/ |
756 |
|
public void testAbnormalForkJoin() { |
757 |
< |
ForkJoinTask a = new CheckedFJTask() { |
758 |
< |
public void realCompute() { |
759 |
< |
FailingCCF f = new LFCCF(null, 8); |
757 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
758 |
> |
protected void realCompute() { |
759 |
> |
FailingCCF f = new LFCCF(8); |
760 |
|
assertSame(f, f.fork()); |
761 |
|
try { |
762 |
|
f.join(); |
772 |
|
* get of a forked task throws exception when task completes abnormally |
773 |
|
*/ |
774 |
|
public void testAbnormalForkGet() { |
775 |
< |
ForkJoinTask a = new CheckedFJTask() { |
776 |
< |
public void realCompute() throws Exception { |
777 |
< |
FailingCCF f = new LFCCF(null, 8); |
775 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
776 |
> |
protected void realCompute() throws Exception { |
777 |
> |
FailingCCF f = new LFCCF(8); |
778 |
|
assertSame(f, f.fork()); |
779 |
|
try { |
780 |
|
f.get(); |
792 |
|
* timed get of a forked task throws exception when task completes abnormally |
793 |
|
*/ |
794 |
|
public void testAbnormalForkTimedGet() { |
795 |
< |
ForkJoinTask a = new CheckedFJTask() { |
796 |
< |
public void realCompute() throws Exception { |
797 |
< |
FailingCCF f = new LFCCF(null, 8); |
795 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
796 |
> |
protected void realCompute() throws Exception { |
797 |
> |
FailingCCF f = new LFCCF(8); |
798 |
|
assertSame(f, f.fork()); |
799 |
|
try { |
800 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
812 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
813 |
|
*/ |
814 |
|
public void testAbnormalForkQuietlyJoin() { |
815 |
< |
ForkJoinTask a = new CheckedFJTask() { |
816 |
< |
public void realCompute() { |
817 |
< |
FailingCCF f = new LFCCF(null, 8); |
815 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
816 |
> |
protected void realCompute() { |
817 |
> |
FailingCCF f = new LFCCF(8); |
818 |
|
assertSame(f, f.fork()); |
819 |
|
f.quietlyJoin(); |
820 |
|
assertTrue(f.getException() instanceof FJException); |
827 |
|
* invoke task throws exception when task cancelled |
828 |
|
*/ |
829 |
|
public void testCancelledInvoke() { |
830 |
< |
ForkJoinTask a = new CheckedFJTask() { |
831 |
< |
public void realCompute() { |
832 |
< |
CCF f = new LCCF(null, 8); |
830 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
831 |
> |
protected void realCompute() { |
832 |
> |
CCF f = new LCCF(8); |
833 |
|
assertTrue(f.cancel(true)); |
834 |
|
try { |
835 |
|
f.invoke(); |
845 |
|
* join of a forked task throws exception when task cancelled |
846 |
|
*/ |
847 |
|
public void testCancelledForkJoin() { |
848 |
< |
ForkJoinTask a = new CheckedFJTask() { |
849 |
< |
public void realCompute() { |
850 |
< |
CCF f = new LCCF(null, 8); |
848 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
849 |
> |
protected void realCompute() { |
850 |
> |
CCF f = new LCCF(8); |
851 |
|
assertTrue(f.cancel(true)); |
852 |
|
assertSame(f, f.fork()); |
853 |
|
try { |
864 |
|
* get of a forked task throws exception when task cancelled |
865 |
|
*/ |
866 |
|
public void testCancelledForkGet() { |
867 |
< |
ForkJoinTask a = new CheckedFJTask() { |
868 |
< |
public void realCompute() throws Exception { |
869 |
< |
CCF f = new LCCF(null, 8); |
867 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
868 |
> |
protected void realCompute() throws Exception { |
869 |
> |
CCF f = new LCCF(8); |
870 |
|
assertTrue(f.cancel(true)); |
871 |
|
assertSame(f, f.fork()); |
872 |
|
try { |
883 |
|
* timed get of a forked task throws exception when task cancelled |
884 |
|
*/ |
885 |
|
public void testCancelledForkTimedGet() throws Exception { |
886 |
< |
ForkJoinTask a = new CheckedFJTask() { |
887 |
< |
public void realCompute() throws Exception { |
888 |
< |
CCF f = new LCCF(null, 8); |
886 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
887 |
> |
protected void realCompute() throws Exception { |
888 |
> |
CCF f = new LCCF(8); |
889 |
|
assertTrue(f.cancel(true)); |
890 |
|
assertSame(f, f.fork()); |
891 |
|
try { |
902 |
|
* quietlyJoin of a forked task returns when task cancelled |
903 |
|
*/ |
904 |
|
public void testCancelledForkQuietlyJoin() { |
905 |
< |
ForkJoinTask a = new CheckedFJTask() { |
906 |
< |
public void realCompute() { |
907 |
< |
CCF f = new LCCF(null, 8); |
905 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
906 |
> |
protected void realCompute() { |
907 |
> |
CCF f = new LCCF(8); |
908 |
|
assertTrue(f.cancel(true)); |
909 |
|
assertSame(f, f.fork()); |
910 |
|
f.quietlyJoin(); |
918 |
|
*/ |
919 |
|
public void testGetPool() { |
920 |
|
final ForkJoinPool mainPool = mainPool(); |
921 |
< |
ForkJoinTask a = new CheckedFJTask() { |
922 |
< |
public void realCompute() { |
921 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
922 |
> |
protected void realCompute() { |
923 |
|
assertSame(mainPool, getPool()); |
924 |
|
}}; |
925 |
|
testInvokeOnPool(mainPool, a); |
929 |
|
* getPool of non-FJ task returns null |
930 |
|
*/ |
931 |
|
public void testGetPool2() { |
932 |
< |
ForkJoinTask a = new CheckedFJTask() { |
933 |
< |
public void realCompute() { |
932 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
933 |
> |
protected void realCompute() { |
934 |
|
assertNull(getPool()); |
935 |
|
}}; |
936 |
|
assertNull(a.invoke()); |
940 |
|
* inForkJoinPool of executing task returns true |
941 |
|
*/ |
942 |
|
public void testInForkJoinPool() { |
943 |
< |
ForkJoinTask a = new CheckedFJTask() { |
944 |
< |
public void realCompute() { |
943 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
944 |
> |
protected void realCompute() { |
945 |
|
assertTrue(inForkJoinPool()); |
946 |
|
}}; |
947 |
|
testInvokeOnPool(mainPool(), a); |
951 |
|
* inForkJoinPool of non-FJ task returns false |
952 |
|
*/ |
953 |
|
public void testInForkJoinPool2() { |
954 |
< |
ForkJoinTask a = new CheckedFJTask() { |
955 |
< |
public void realCompute() { |
954 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
955 |
> |
protected void realCompute() { |
956 |
|
assertFalse(inForkJoinPool()); |
957 |
|
}}; |
958 |
|
assertNull(a.invoke()); |
962 |
|
* setRawResult(null) succeeds |
963 |
|
*/ |
964 |
|
public void testSetRawResult() { |
965 |
< |
ForkJoinTask a = new CheckedFJTask() { |
966 |
< |
public void realCompute() { |
965 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
966 |
> |
protected void realCompute() { |
967 |
|
setRawResult(null); |
968 |
|
assertNull(getRawResult()); |
969 |
|
}}; |
974 |
|
* invoke task throws exception after invoking completeExceptionally |
975 |
|
*/ |
976 |
|
public void testCompleteExceptionally2() { |
977 |
< |
ForkJoinTask a = new CheckedFJTask() { |
978 |
< |
public void realCompute() { |
979 |
< |
CCF f = new LCCF(null, 8); |
980 |
< |
f.completeExceptionally(new FJException()); |
981 |
< |
try { |
982 |
< |
f.invoke(); |
983 |
< |
shouldThrow(); |
984 |
< |
} catch (FJException success) { |
909 |
< |
checkCompletedAbnormally(f, success); |
910 |
< |
} |
977 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
978 |
> |
protected void realCompute() { |
979 |
> |
CCF n = new LCCF(8); |
980 |
> |
CCF f = new LCCF(n, 8); |
981 |
> |
FJException ex = new FJException(); |
982 |
> |
f.completeExceptionally(ex); |
983 |
> |
f.checkCompletedExceptionally(ex); |
984 |
> |
n.checkCompletedExceptionally(ex); |
985 |
|
}}; |
986 |
|
testInvokeOnPool(mainPool(), a); |
987 |
|
} |
990 |
|
* invokeAll(t1, t2) invokes all task arguments |
991 |
|
*/ |
992 |
|
public void testInvokeAll2() { |
993 |
< |
ForkJoinTask a = new CheckedFJTask() { |
994 |
< |
public void realCompute() { |
995 |
< |
CCF f = new LCCF(null, 8); |
996 |
< |
CCF g = new LCCF(null, 9); |
993 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
994 |
> |
protected void realCompute() { |
995 |
> |
CCF f = new LCCF(8); |
996 |
> |
CCF g = new LCCF(9); |
997 |
|
invokeAll(f, g); |
998 |
|
assertEquals(21, f.number); |
999 |
|
assertEquals(34, g.number); |
1007 |
|
* invokeAll(tasks) with 1 argument invokes task |
1008 |
|
*/ |
1009 |
|
public void testInvokeAll1() { |
1010 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1011 |
< |
public void realCompute() { |
1012 |
< |
CCF f = new LCCF(null, 8); |
1010 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1011 |
> |
protected void realCompute() { |
1012 |
> |
CCF f = new LCCF(8); |
1013 |
|
invokeAll(f); |
1014 |
|
checkCompletedNormally(f); |
1015 |
|
assertEquals(21, f.number); |
1021 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
1022 |
|
*/ |
1023 |
|
public void testInvokeAll3() { |
1024 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1025 |
< |
public void realCompute() { |
1026 |
< |
CCF f = new LCCF(null, 8); |
1027 |
< |
CCF g = new LCCF(null, 9); |
1028 |
< |
CCF h = new LCCF(null, 7); |
1024 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1025 |
> |
protected void realCompute() { |
1026 |
> |
CCF f = new LCCF(8); |
1027 |
> |
CCF g = new LCCF(9); |
1028 |
> |
CCF h = new LCCF(7); |
1029 |
|
invokeAll(f, g, h); |
1030 |
|
assertEquals(21, f.number); |
1031 |
|
assertEquals(34, g.number); |
1041 |
|
* invokeAll(collection) invokes all tasks in the collection |
1042 |
|
*/ |
1043 |
|
public void testInvokeAllCollection() { |
1044 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1045 |
< |
public void realCompute() { |
1046 |
< |
CCF f = new LCCF(null, 8); |
1047 |
< |
CCF g = new LCCF(null, 9); |
1048 |
< |
CCF h = new LCCF(null, 7); |
1044 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1045 |
> |
protected void realCompute() { |
1046 |
> |
CCF f = new LCCF(8); |
1047 |
> |
CCF g = new LCCF(9); |
1048 |
> |
CCF h = new LCCF(7); |
1049 |
|
HashSet set = new HashSet(); |
1050 |
|
set.add(f); |
1051 |
|
set.add(g); |
1065 |
|
* invokeAll(tasks) with any null task throws NPE |
1066 |
|
*/ |
1067 |
|
public void testInvokeAllNPE() { |
1068 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1069 |
< |
public void realCompute() { |
1070 |
< |
CCF f = new LCCF(null, 8); |
1071 |
< |
CCF g = new LCCF(null, 9); |
1068 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1069 |
> |
protected void realCompute() { |
1070 |
> |
CCF f = new LCCF(8); |
1071 |
> |
CCF g = new LCCF(9); |
1072 |
|
CCF h = null; |
1073 |
|
try { |
1074 |
|
invokeAll(f, g, h); |
1082 |
|
* invokeAll(t1, t2) throw exception if any task does |
1083 |
|
*/ |
1084 |
|
public void testAbnormalInvokeAll2() { |
1085 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1086 |
< |
public void realCompute() { |
1087 |
< |
CCF f = new LCCF(null, 8); |
1088 |
< |
FailingCCF g = new LFCCF(null, 9); |
1085 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1086 |
> |
protected void realCompute() { |
1087 |
> |
CCF f = new LCCF(8); |
1088 |
> |
FailingCCF g = new LFCCF(9); |
1089 |
|
try { |
1090 |
|
invokeAll(f, g); |
1091 |
|
shouldThrow(); |
1100 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
1101 |
|
*/ |
1102 |
|
public void testAbnormalInvokeAll1() { |
1103 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1104 |
< |
public void realCompute() { |
1105 |
< |
FailingCCF g = new LFCCF(null, 9); |
1103 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1104 |
> |
protected void realCompute() { |
1105 |
> |
FailingCCF g = new LFCCF(9); |
1106 |
|
try { |
1107 |
|
invokeAll(g); |
1108 |
|
shouldThrow(); |
1117 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1118 |
|
*/ |
1119 |
|
public void testAbnormalInvokeAll3() { |
1120 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1121 |
< |
public void realCompute() { |
1122 |
< |
CCF f = new LCCF(null, 8); |
1123 |
< |
FailingCCF g = new LFCCF(null, 9); |
1124 |
< |
CCF h = new LCCF(null, 7); |
1120 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1121 |
> |
protected void realCompute() { |
1122 |
> |
CCF f = new LCCF(8); |
1123 |
> |
FailingCCF g = new LFCCF(9); |
1124 |
> |
CCF h = new LCCF(7); |
1125 |
|
try { |
1126 |
|
invokeAll(f, g, h); |
1127 |
|
shouldThrow(); |
1133 |
|
} |
1134 |
|
|
1135 |
|
/** |
1136 |
< |
* invokeAll(collection) throws exception if any task does |
1136 |
> |
* invokeAll(collection) throws exception if any task does |
1137 |
|
*/ |
1138 |
|
public void testAbnormalInvokeAllCollection() { |
1139 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1140 |
< |
public void realCompute() { |
1141 |
< |
FailingCCF f = new LFCCF(null, 8); |
1142 |
< |
CCF g = new LCCF(null, 9); |
1143 |
< |
CCF h = new LCCF(null, 7); |
1139 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1140 |
> |
protected void realCompute() { |
1141 |
> |
FailingCCF f = new LFCCF(8); |
1142 |
> |
CCF g = new LCCF(9); |
1143 |
> |
CCF h = new LCCF(7); |
1144 |
|
HashSet set = new HashSet(); |
1145 |
|
set.add(f); |
1146 |
|
set.add(g); |
1160 |
|
* and suppresses execution |
1161 |
|
*/ |
1162 |
|
public void testTryUnfork() { |
1163 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1164 |
< |
public void realCompute() { |
1165 |
< |
CCF g = new LCCF(null, 9); |
1163 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1164 |
> |
protected void realCompute() { |
1165 |
> |
CCF g = new LCCF(9); |
1166 |
|
assertSame(g, g.fork()); |
1167 |
< |
CCF f = new LCCF(null, 8); |
1167 |
> |
CCF f = new LCCF(8); |
1168 |
|
assertSame(f, f.fork()); |
1169 |
|
assertTrue(f.tryUnfork()); |
1170 |
|
helpQuiesce(); |
1179 |
|
* there are more tasks than threads |
1180 |
|
*/ |
1181 |
|
public void testGetSurplusQueuedTaskCount() { |
1182 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1183 |
< |
public void realCompute() { |
1184 |
< |
CCF h = new LCCF(null, 7); |
1182 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1183 |
> |
protected void realCompute() { |
1184 |
> |
CCF h = new LCCF(7); |
1185 |
|
assertSame(h, h.fork()); |
1186 |
< |
CCF g = new LCCF(null, 9); |
1186 |
> |
CCF g = new LCCF(9); |
1187 |
|
assertSame(g, g.fork()); |
1188 |
< |
CCF f = new LCCF(null, 8); |
1188 |
> |
CCF f = new LCCF(8); |
1189 |
|
assertSame(f, f.fork()); |
1190 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
1191 |
|
helpQuiesce(); |
1201 |
|
* peekNextLocalTask returns most recent unexecuted task. |
1202 |
|
*/ |
1203 |
|
public void testPeekNextLocalTask() { |
1204 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1205 |
< |
public void realCompute() { |
1206 |
< |
CCF g = new LCCF(null, 9); |
1204 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1205 |
> |
protected void realCompute() { |
1206 |
> |
CCF g = new LCCF(9); |
1207 |
|
assertSame(g, g.fork()); |
1208 |
< |
CCF f = new LCCF(null, 8); |
1208 |
> |
CCF f = new LCCF(8); |
1209 |
|
assertSame(f, f.fork()); |
1210 |
|
assertSame(f, peekNextLocalTask()); |
1211 |
|
assertNull(f.join()); |
1221 |
|
* executing it |
1222 |
|
*/ |
1223 |
|
public void testPollNextLocalTask() { |
1224 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1225 |
< |
public void realCompute() { |
1226 |
< |
CCF g = new LCCF(null, 9); |
1224 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1225 |
> |
protected void realCompute() { |
1226 |
> |
CCF g = new LCCF(9); |
1227 |
|
assertSame(g, g.fork()); |
1228 |
< |
CCF f = new LCCF(null, 8); |
1228 |
> |
CCF f = new LCCF(8); |
1229 |
|
assertSame(f, f.fork()); |
1230 |
|
assertSame(f, pollNextLocalTask()); |
1231 |
|
helpQuiesce(); |
1240 |
|
* pollTask returns an unexecuted task without executing it |
1241 |
|
*/ |
1242 |
|
public void testPollTask() { |
1243 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1244 |
< |
public void realCompute() { |
1245 |
< |
CCF g = new LCCF(null, 9); |
1243 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1244 |
> |
protected void realCompute() { |
1245 |
> |
CCF g = new LCCF(9); |
1246 |
|
assertSame(g, g.fork()); |
1247 |
< |
CCF f = new LCCF(null, 8); |
1247 |
> |
CCF f = new LCCF(8); |
1248 |
|
assertSame(f, f.fork()); |
1249 |
|
assertSame(f, pollTask()); |
1250 |
|
helpQuiesce(); |
1258 |
|
* peekNextLocalTask returns least recent unexecuted task in async mode |
1259 |
|
*/ |
1260 |
|
public void testPeekNextLocalTaskAsync() { |
1261 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1262 |
< |
public void realCompute() { |
1263 |
< |
CCF g = new LCCF(null, 9); |
1261 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1262 |
> |
protected void realCompute() { |
1263 |
> |
CCF g = new LCCF(9); |
1264 |
|
assertSame(g, g.fork()); |
1265 |
< |
CCF f = new LCCF(null, 8); |
1265 |
> |
CCF f = new LCCF(8); |
1266 |
|
assertSame(f, f.fork()); |
1267 |
|
assertSame(g, peekNextLocalTask()); |
1268 |
|
assertNull(f.join()); |
1279 |
|
* executing it, in async mode |
1280 |
|
*/ |
1281 |
|
public void testPollNextLocalTaskAsync() { |
1282 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1283 |
< |
public void realCompute() { |
1284 |
< |
CCF g = new LCCF(null, 9); |
1282 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1283 |
> |
protected void realCompute() { |
1284 |
> |
CCF g = new LCCF(9); |
1285 |
|
assertSame(g, g.fork()); |
1286 |
< |
CCF f = new LCCF(null, 8); |
1286 |
> |
CCF f = new LCCF(8); |
1287 |
|
assertSame(f, f.fork()); |
1288 |
|
assertSame(g, pollNextLocalTask()); |
1289 |
|
helpQuiesce(); |
1299 |
|
* async mode |
1300 |
|
*/ |
1301 |
|
public void testPollTaskAsync() { |
1302 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1303 |
< |
public void realCompute() { |
1304 |
< |
CCF g = new LCCF(null, 9); |
1302 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1303 |
> |
protected void realCompute() { |
1304 |
> |
CCF g = new LCCF(9); |
1305 |
|
assertSame(g, g.fork()); |
1306 |
< |
CCF f = new LCCF(null, 8); |
1306 |
> |
CCF f = new LCCF(8); |
1307 |
|
assertSame(f, f.fork()); |
1308 |
|
assertSame(g, pollTask()); |
1309 |
|
helpQuiesce(); |
1322 |
|
* completed tasks; getRawResult returns null. |
1323 |
|
*/ |
1324 |
|
public void testInvokeSingleton() { |
1325 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1326 |
< |
public void realCompute() { |
1327 |
< |
CCF f = new LCCF(null, 8); |
1325 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1326 |
> |
protected void realCompute() { |
1327 |
> |
CCF f = new LCCF(8); |
1328 |
|
assertNull(f.invoke()); |
1329 |
|
assertEquals(21, f.number); |
1330 |
|
checkCompletedNormally(f); |
1338 |
|
* completed tasks |
1339 |
|
*/ |
1340 |
|
public void testQuietlyInvokeSingleton() { |
1341 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1342 |
< |
public void realCompute() { |
1343 |
< |
CCF f = new LCCF(null, 8); |
1341 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1342 |
> |
protected void realCompute() { |
1343 |
> |
CCF f = new LCCF(8); |
1344 |
|
f.quietlyInvoke(); |
1345 |
|
assertEquals(21, f.number); |
1346 |
|
checkCompletedNormally(f); |
1352 |
|
* join of a forked task returns when task completes |
1353 |
|
*/ |
1354 |
|
public void testForkJoinSingleton() { |
1355 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1356 |
< |
public void realCompute() { |
1357 |
< |
CCF f = new LCCF(null, 8); |
1355 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1356 |
> |
protected void realCompute() { |
1357 |
> |
CCF f = new LCCF(8); |
1358 |
|
assertSame(f, f.fork()); |
1359 |
|
assertNull(f.join()); |
1360 |
|
assertEquals(21, f.number); |
1367 |
|
* get of a forked task returns when task completes |
1368 |
|
*/ |
1369 |
|
public void testForkGetSingleton() { |
1370 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1371 |
< |
public void realCompute() throws Exception { |
1372 |
< |
CCF f = new LCCF(null, 8); |
1370 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1371 |
> |
protected void realCompute() throws Exception { |
1372 |
> |
CCF f = new LCCF(8); |
1373 |
|
assertSame(f, f.fork()); |
1374 |
|
assertNull(f.get()); |
1375 |
|
assertEquals(21, f.number); |
1382 |
|
* timed get of a forked task returns when task completes |
1383 |
|
*/ |
1384 |
|
public void testForkTimedGetSingleton() { |
1385 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1386 |
< |
public void realCompute() throws Exception { |
1387 |
< |
CCF f = new LCCF(null, 8); |
1385 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1386 |
> |
protected void realCompute() throws Exception { |
1387 |
> |
CCF f = new LCCF(8); |
1388 |
|
assertSame(f, f.fork()); |
1389 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1390 |
|
assertEquals(21, f.number); |
1397 |
|
* timed get with null time unit throws NPE |
1398 |
|
*/ |
1399 |
|
public void testForkTimedGetNPESingleton() { |
1400 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1401 |
< |
public void realCompute() throws Exception { |
1402 |
< |
CCF f = new LCCF(null, 8); |
1400 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1401 |
> |
protected void realCompute() throws Exception { |
1402 |
> |
CCF f = new LCCF(8); |
1403 |
|
assertSame(f, f.fork()); |
1404 |
|
try { |
1405 |
|
f.get(5L, null); |
1413 |
|
* quietlyJoin of a forked task returns when task completes |
1414 |
|
*/ |
1415 |
|
public void testForkQuietlyJoinSingleton() { |
1416 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1417 |
< |
public void realCompute() { |
1418 |
< |
CCF f = new LCCF(null, 8); |
1416 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1417 |
> |
protected void realCompute() { |
1418 |
> |
CCF f = new LCCF(8); |
1419 |
|
assertSame(f, f.fork()); |
1420 |
|
f.quietlyJoin(); |
1421 |
|
assertEquals(21, f.number); |
1429 |
|
* getQueuedTaskCount returns 0 when quiescent |
1430 |
|
*/ |
1431 |
|
public void testForkHelpQuiesceSingleton() { |
1432 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1433 |
< |
public void realCompute() { |
1434 |
< |
CCF f = new LCCF(null, 8); |
1432 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1433 |
> |
protected void realCompute() { |
1434 |
> |
CCF f = new LCCF(8); |
1435 |
|
assertSame(f, f.fork()); |
1436 |
|
helpQuiesce(); |
1437 |
|
assertEquals(0, getQueuedTaskCount()); |
1445 |
|
* invoke task throws exception when task completes abnormally |
1446 |
|
*/ |
1447 |
|
public void testAbnormalInvokeSingleton() { |
1448 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1449 |
< |
public void realCompute() { |
1450 |
< |
FailingCCF f = new LFCCF(null, 8); |
1448 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1449 |
> |
protected void realCompute() { |
1450 |
> |
FailingCCF f = new LFCCF(8); |
1451 |
|
try { |
1452 |
|
f.invoke(); |
1453 |
|
shouldThrow(); |
1462 |
|
* quietlyInvoke task returns when task completes abnormally |
1463 |
|
*/ |
1464 |
|
public void testAbnormalQuietlyInvokeSingleton() { |
1465 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1466 |
< |
public void realCompute() { |
1467 |
< |
FailingCCF f = new LFCCF(null, 8); |
1465 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1466 |
> |
protected void realCompute() { |
1467 |
> |
FailingCCF f = new LFCCF(8); |
1468 |
|
f.quietlyInvoke(); |
1469 |
|
assertTrue(f.getException() instanceof FJException); |
1470 |
|
checkCompletedAbnormally(f, f.getException()); |
1476 |
|
* join of a forked task throws exception when task completes abnormally |
1477 |
|
*/ |
1478 |
|
public void testAbnormalForkJoinSingleton() { |
1479 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1480 |
< |
public void realCompute() { |
1481 |
< |
FailingCCF f = new LFCCF(null, 8); |
1479 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1480 |
> |
protected void realCompute() { |
1481 |
> |
FailingCCF f = new LFCCF(8); |
1482 |
|
assertSame(f, f.fork()); |
1483 |
|
try { |
1484 |
|
f.join(); |
1494 |
|
* get of a forked task throws exception when task completes abnormally |
1495 |
|
*/ |
1496 |
|
public void testAbnormalForkGetSingleton() { |
1497 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1498 |
< |
public void realCompute() throws Exception { |
1499 |
< |
FailingCCF f = new LFCCF(null, 8); |
1497 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1498 |
> |
protected void realCompute() throws Exception { |
1499 |
> |
FailingCCF f = new LFCCF(8); |
1500 |
|
assertSame(f, f.fork()); |
1501 |
|
try { |
1502 |
|
f.get(); |
1514 |
|
* timed get of a forked task throws exception when task completes abnormally |
1515 |
|
*/ |
1516 |
|
public void testAbnormalForkTimedGetSingleton() { |
1517 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1518 |
< |
public void realCompute() throws Exception { |
1519 |
< |
FailingCCF f = new LFCCF(null, 8); |
1517 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1518 |
> |
protected void realCompute() throws Exception { |
1519 |
> |
FailingCCF f = new LFCCF(8); |
1520 |
|
assertSame(f, f.fork()); |
1521 |
|
try { |
1522 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
1534 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
1535 |
|
*/ |
1536 |
|
public void testAbnormalForkQuietlyJoinSingleton() { |
1537 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1538 |
< |
public void realCompute() { |
1539 |
< |
FailingCCF f = new LFCCF(null, 8); |
1537 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1538 |
> |
protected void realCompute() { |
1539 |
> |
FailingCCF f = new LFCCF(8); |
1540 |
|
assertSame(f, f.fork()); |
1541 |
|
f.quietlyJoin(); |
1542 |
|
assertTrue(f.getException() instanceof FJException); |
1549 |
|
* invoke task throws exception when task cancelled |
1550 |
|
*/ |
1551 |
|
public void testCancelledInvokeSingleton() { |
1552 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1553 |
< |
public void realCompute() { |
1554 |
< |
CCF f = new LCCF(null, 8); |
1552 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1553 |
> |
protected void realCompute() { |
1554 |
> |
CCF f = new LCCF(8); |
1555 |
|
assertTrue(f.cancel(true)); |
1556 |
|
try { |
1557 |
|
f.invoke(); |
1567 |
|
* join of a forked task throws exception when task cancelled |
1568 |
|
*/ |
1569 |
|
public void testCancelledForkJoinSingleton() { |
1570 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1571 |
< |
public void realCompute() { |
1572 |
< |
CCF f = new LCCF(null, 8); |
1570 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1571 |
> |
protected void realCompute() { |
1572 |
> |
CCF f = new LCCF(8); |
1573 |
|
assertTrue(f.cancel(true)); |
1574 |
|
assertSame(f, f.fork()); |
1575 |
|
try { |
1586 |
|
* get of a forked task throws exception when task cancelled |
1587 |
|
*/ |
1588 |
|
public void testCancelledForkGetSingleton() { |
1589 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1590 |
< |
public void realCompute() throws Exception { |
1591 |
< |
CCF f = new LCCF(null, 8); |
1589 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1590 |
> |
protected void realCompute() throws Exception { |
1591 |
> |
CCF f = new LCCF(8); |
1592 |
|
assertTrue(f.cancel(true)); |
1593 |
|
assertSame(f, f.fork()); |
1594 |
|
try { |
1605 |
|
* timed get of a forked task throws exception when task cancelled |
1606 |
|
*/ |
1607 |
|
public void testCancelledForkTimedGetSingleton() throws Exception { |
1608 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1609 |
< |
public void realCompute() throws Exception { |
1610 |
< |
CCF f = new LCCF(null, 8); |
1608 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1609 |
> |
protected void realCompute() throws Exception { |
1610 |
> |
CCF f = new LCCF(8); |
1611 |
|
assertTrue(f.cancel(true)); |
1612 |
|
assertSame(f, f.fork()); |
1613 |
|
try { |
1624 |
|
* quietlyJoin of a forked task returns when task cancelled |
1625 |
|
*/ |
1626 |
|
public void testCancelledForkQuietlyJoinSingleton() { |
1627 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1628 |
< |
public void realCompute() { |
1629 |
< |
CCF f = new LCCF(null, 8); |
1627 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1628 |
> |
protected void realCompute() { |
1629 |
> |
CCF f = new LCCF(8); |
1630 |
|
assertTrue(f.cancel(true)); |
1631 |
|
assertSame(f, f.fork()); |
1632 |
|
f.quietlyJoin(); |
1639 |
|
* invoke task throws exception after invoking completeExceptionally |
1640 |
|
*/ |
1641 |
|
public void testCompleteExceptionallySingleton() { |
1642 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1643 |
< |
public void realCompute() { |
1644 |
< |
CCF f = new LCCF(null, 8); |
1645 |
< |
f.completeExceptionally(new FJException()); |
1646 |
< |
try { |
1647 |
< |
f.invoke(); |
1648 |
< |
shouldThrow(); |
1649 |
< |
} catch (FJException success) { |
1576 |
< |
checkCompletedAbnormally(f, success); |
1577 |
< |
} |
1642 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1643 |
> |
protected void realCompute() { |
1644 |
> |
CCF n = new LCCF(8); |
1645 |
> |
CCF f = new LCCF(n, 8); |
1646 |
> |
FJException ex = new FJException(); |
1647 |
> |
f.completeExceptionally(ex); |
1648 |
> |
f.checkCompletedExceptionally(ex); |
1649 |
> |
n.checkCompletedExceptionally(ex); |
1650 |
|
}}; |
1651 |
|
testInvokeOnPool(singletonPool(), a); |
1652 |
|
} |
1655 |
|
* invokeAll(t1, t2) invokes all task arguments |
1656 |
|
*/ |
1657 |
|
public void testInvokeAll2Singleton() { |
1658 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1659 |
< |
public void realCompute() { |
1660 |
< |
CCF f = new LCCF(null, 8); |
1661 |
< |
CCF g = new LCCF(null, 9); |
1658 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1659 |
> |
protected void realCompute() { |
1660 |
> |
CCF f = new LCCF(8); |
1661 |
> |
CCF g = new LCCF(9); |
1662 |
|
invokeAll(f, g); |
1663 |
|
assertEquals(21, f.number); |
1664 |
|
assertEquals(34, g.number); |
1672 |
|
* invokeAll(tasks) with 1 argument invokes task |
1673 |
|
*/ |
1674 |
|
public void testInvokeAll1Singleton() { |
1675 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1676 |
< |
public void realCompute() { |
1677 |
< |
CCF f = new LCCF(null, 8); |
1675 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1676 |
> |
protected void realCompute() { |
1677 |
> |
CCF f = new LCCF(8); |
1678 |
|
invokeAll(f); |
1679 |
|
checkCompletedNormally(f); |
1680 |
|
assertEquals(21, f.number); |
1686 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
1687 |
|
*/ |
1688 |
|
public void testInvokeAll3Singleton() { |
1689 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1690 |
< |
public void realCompute() { |
1691 |
< |
CCF f = new LCCF(null, 8); |
1692 |
< |
CCF g = new LCCF(null, 9); |
1693 |
< |
CCF h = new LCCF(null, 7); |
1689 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1690 |
> |
protected void realCompute() { |
1691 |
> |
CCF f = new LCCF(8); |
1692 |
> |
CCF g = new LCCF(9); |
1693 |
> |
CCF h = new LCCF(7); |
1694 |
|
invokeAll(f, g, h); |
1695 |
|
assertEquals(21, f.number); |
1696 |
|
assertEquals(34, g.number); |
1706 |
|
* invokeAll(collection) invokes all tasks in the collection |
1707 |
|
*/ |
1708 |
|
public void testInvokeAllCollectionSingleton() { |
1709 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1710 |
< |
public void realCompute() { |
1711 |
< |
CCF f = new LCCF(null, 8); |
1712 |
< |
CCF g = new LCCF(null, 9); |
1713 |
< |
CCF h = new LCCF(null, 7); |
1709 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1710 |
> |
protected void realCompute() { |
1711 |
> |
CCF f = new LCCF(8); |
1712 |
> |
CCF g = new LCCF(9); |
1713 |
> |
CCF h = new LCCF(7); |
1714 |
|
HashSet set = new HashSet(); |
1715 |
|
set.add(f); |
1716 |
|
set.add(g); |
1730 |
|
* invokeAll(tasks) with any null task throws NPE |
1731 |
|
*/ |
1732 |
|
public void testInvokeAllNPESingleton() { |
1733 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1734 |
< |
public void realCompute() { |
1735 |
< |
CCF f = new LCCF(null, 8); |
1736 |
< |
CCF g = new LCCF(null, 9); |
1733 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1734 |
> |
protected void realCompute() { |
1735 |
> |
CCF f = new LCCF(8); |
1736 |
> |
CCF g = new LCCF(9); |
1737 |
|
CCF h = null; |
1738 |
|
try { |
1739 |
|
invokeAll(f, g, h); |
1747 |
|
* invokeAll(t1, t2) throw exception if any task does |
1748 |
|
*/ |
1749 |
|
public void testAbnormalInvokeAll2Singleton() { |
1750 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1751 |
< |
public void realCompute() { |
1752 |
< |
CCF f = new LCCF(null, 8); |
1753 |
< |
FailingCCF g = new LFCCF(null, 9); |
1750 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1751 |
> |
protected void realCompute() { |
1752 |
> |
CCF f = new LCCF(8); |
1753 |
> |
FailingCCF g = new LFCCF(9); |
1754 |
|
try { |
1755 |
|
invokeAll(f, g); |
1756 |
|
shouldThrow(); |
1765 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
1766 |
|
*/ |
1767 |
|
public void testAbnormalInvokeAll1Singleton() { |
1768 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1769 |
< |
public void realCompute() { |
1770 |
< |
FailingCCF g = new LFCCF(null, 9); |
1768 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1769 |
> |
protected void realCompute() { |
1770 |
> |
FailingCCF g = new LFCCF(9); |
1771 |
|
try { |
1772 |
|
invokeAll(g); |
1773 |
|
shouldThrow(); |
1782 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1783 |
|
*/ |
1784 |
|
public void testAbnormalInvokeAll3Singleton() { |
1785 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1786 |
< |
public void realCompute() { |
1787 |
< |
CCF f = new LCCF(null, 8); |
1788 |
< |
FailingCCF g = new LFCCF(null, 9); |
1789 |
< |
CCF h = new LCCF(null, 7); |
1785 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1786 |
> |
protected void realCompute() { |
1787 |
> |
CCF f = new LCCF(8); |
1788 |
> |
FailingCCF g = new LFCCF(9); |
1789 |
> |
CCF h = new LCCF(7); |
1790 |
|
try { |
1791 |
|
invokeAll(f, g, h); |
1792 |
|
shouldThrow(); |
1798 |
|
} |
1799 |
|
|
1800 |
|
/** |
1801 |
< |
* invokeAll(collection) throws exception if any task does |
1801 |
> |
* invokeAll(collection) throws exception if any task does |
1802 |
|
*/ |
1803 |
|
public void testAbnormalInvokeAllCollectionSingleton() { |
1804 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1805 |
< |
public void realCompute() { |
1806 |
< |
FailingCCF f = new LFCCF(null, 8); |
1807 |
< |
CCF g = new LCCF(null, 9); |
1808 |
< |
CCF h = new LCCF(null, 7); |
1804 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1805 |
> |
protected void realCompute() { |
1806 |
> |
FailingCCF f = new LFCCF(8); |
1807 |
> |
CCF g = new LCCF(9); |
1808 |
> |
CCF h = new LCCF(7); |
1809 |
|
HashSet set = new HashSet(); |
1810 |
|
set.add(f); |
1811 |
|
set.add(g); |