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 |
|
|
25 |
|
public static void main(String[] args) { |
26 |
< |
junit.textui.TestRunner.run(suite()); |
26 |
> |
main(suite(), args); |
27 |
|
} |
28 |
|
|
29 |
|
public static Test suite() { |
34 |
|
static final int mainPoolSize = |
35 |
|
Math.max(2, Runtime.getRuntime().availableProcessors()); |
36 |
|
|
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 |
– |
|
37 |
|
private static ForkJoinPool mainPool() { |
38 |
|
return new ForkJoinPool(mainPoolSize); |
39 |
|
} |
49 |
|
} |
50 |
|
|
51 |
|
private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) { |
52 |
< |
try { |
52 |
> |
try (PoolCleaner cleaner = cleaner(pool)) { |
53 |
|
assertFalse(a.isDone()); |
54 |
|
assertFalse(a.isCompletedNormally()); |
55 |
|
assertFalse(a.isCompletedAbnormally()); |
65 |
|
assertFalse(a.isCancelled()); |
66 |
|
assertNull(a.getException()); |
67 |
|
assertNull(a.getRawResult()); |
81 |
– |
} finally { |
82 |
– |
joinPool(pool); |
68 |
|
} |
69 |
|
} |
70 |
|
|
83 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
84 |
|
} |
85 |
|
|
86 |
< |
<T> void checkCompletedNormally(CountedCompleter<T> a) { |
102 |
< |
checkCompletedNormally(a, null); |
103 |
< |
} |
104 |
< |
|
105 |
< |
<T> void checkCompletedNormally(CountedCompleter<T> a, T expected) { |
86 |
> |
void checkCompletedNormally(CountedCompleter<?> a) { |
87 |
|
assertTrue(a.isDone()); |
88 |
|
assertFalse(a.isCancelled()); |
89 |
|
assertTrue(a.isCompletedNormally()); |
90 |
|
assertFalse(a.isCompletedAbnormally()); |
91 |
|
assertNull(a.getException()); |
92 |
< |
assertSame(expected, a.getRawResult()); |
92 |
> |
assertNull(a.getRawResult()); |
93 |
|
|
94 |
|
{ |
95 |
|
Thread.currentThread().interrupt(); |
96 |
< |
long t0 = System.nanoTime(); |
97 |
< |
assertSame(expected, a.join()); |
98 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
96 |
> |
long startTime = System.nanoTime(); |
97 |
> |
assertNull(a.join()); |
98 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
99 |
|
Thread.interrupted(); |
100 |
|
} |
101 |
|
|
102 |
|
{ |
103 |
|
Thread.currentThread().interrupt(); |
104 |
< |
long t0 = System.nanoTime(); |
104 |
> |
long startTime = System.nanoTime(); |
105 |
|
a.quietlyJoin(); // should be no-op |
106 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
106 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
107 |
|
Thread.interrupted(); |
108 |
|
} |
109 |
|
|
110 |
|
assertFalse(a.cancel(false)); |
111 |
|
assertFalse(a.cancel(true)); |
112 |
|
try { |
113 |
< |
assertSame(expected, a.get()); |
113 |
> |
assertNull(a.get()); |
114 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
115 |
|
try { |
116 |
< |
assertSame(expected, a.get(5L, SECONDS)); |
116 |
> |
assertNull(a.get(5L, SECONDS)); |
117 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
118 |
|
} |
119 |
|
|
136 |
|
Thread.interrupted(); |
137 |
|
|
138 |
|
{ |
139 |
< |
long t0 = System.nanoTime(); |
139 |
> |
long startTime = System.nanoTime(); |
140 |
|
a.quietlyJoin(); // should be no-op |
141 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
141 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
142 |
|
} |
143 |
|
|
144 |
|
try { |
174 |
|
Thread.interrupted(); |
175 |
|
|
176 |
|
{ |
177 |
< |
long t0 = System.nanoTime(); |
177 |
> |
long startTime = System.nanoTime(); |
178 |
|
a.quietlyJoin(); // should be no-op |
179 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
179 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
180 |
|
} |
181 |
|
|
182 |
|
try { |
192 |
|
} catch (ExecutionException success) { |
193 |
|
assertSame(t.getClass(), success.getCause().getClass()); |
194 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
195 |
+ |
|
196 |
+ |
try { |
197 |
+ |
a.invoke(); |
198 |
+ |
shouldThrow(); |
199 |
+ |
} catch (Throwable success) { |
200 |
+ |
assertSame(t, success); |
201 |
+ |
} |
202 |
|
} |
203 |
|
|
204 |
|
public static final class FJException extends RuntimeException { |
205 |
|
FJException() { super(); } |
206 |
|
} |
207 |
|
|
208 |
< |
static final class NoopCountedCompleter extends CountedCompleter { |
209 |
< |
boolean post; // set true if onCompletion called |
210 |
< |
NoopCountedCompleter() { super(); } |
211 |
< |
NoopCountedCompleter(CountedCompleter p) { super(p); } |
212 |
< |
public void compute() {} |
213 |
< |
public final void onCompletion(CountedCompleter caller) { |
214 |
< |
post = true; |
208 |
> |
abstract class CheckedCC extends CountedCompleter<Object> { |
209 |
> |
final AtomicInteger computeN = new AtomicInteger(0); |
210 |
> |
final AtomicInteger onCompletionN = new AtomicInteger(0); |
211 |
> |
final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0); |
212 |
> |
final AtomicInteger setRawResultN = new AtomicInteger(0); |
213 |
> |
final AtomicReference<Object> rawResult = new AtomicReference<Object>(null); |
214 |
> |
int computeN() { return computeN.get(); } |
215 |
> |
int onCompletionN() { return onCompletionN.get(); } |
216 |
> |
int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); } |
217 |
> |
int setRawResultN() { return setRawResultN.get(); } |
218 |
> |
|
219 |
> |
CheckedCC() { super(); } |
220 |
> |
CheckedCC(CountedCompleter p) { super(p); } |
221 |
> |
CheckedCC(CountedCompleter p, int n) { super(p, n); } |
222 |
> |
abstract void realCompute(); |
223 |
> |
public final void compute() { |
224 |
> |
computeN.incrementAndGet(); |
225 |
> |
realCompute(); |
226 |
> |
} |
227 |
> |
public void onCompletion(CountedCompleter caller) { |
228 |
> |
onCompletionN.incrementAndGet(); |
229 |
> |
super.onCompletion(caller); |
230 |
> |
} |
231 |
> |
public boolean onExceptionalCompletion(Throwable ex, |
232 |
> |
CountedCompleter caller) { |
233 |
> |
onExceptionalCompletionN.incrementAndGet(); |
234 |
> |
assertNotNull(ex); |
235 |
> |
assertTrue(isCompletedAbnormally()); |
236 |
> |
assertTrue(super.onExceptionalCompletion(ex, caller)); |
237 |
> |
return true; |
238 |
> |
} |
239 |
> |
protected void setRawResult(Object t) { |
240 |
> |
setRawResultN.incrementAndGet(); |
241 |
> |
rawResult.set(t); |
242 |
> |
super.setRawResult(t); |
243 |
> |
} |
244 |
> |
void checkIncomplete() { |
245 |
> |
assertEquals(0, computeN()); |
246 |
> |
assertEquals(0, onCompletionN()); |
247 |
> |
assertEquals(0, onExceptionalCompletionN()); |
248 |
> |
assertEquals(0, setRawResultN()); |
249 |
> |
checkNotDone(this); |
250 |
> |
} |
251 |
> |
void checkCompletes(Object rawResult) { |
252 |
> |
checkIncomplete(); |
253 |
> |
int pendingCount = getPendingCount(); |
254 |
> |
complete(rawResult); |
255 |
> |
assertEquals(pendingCount, getPendingCount()); |
256 |
> |
assertEquals(0, computeN()); |
257 |
> |
assertEquals(1, onCompletionN()); |
258 |
> |
assertEquals(0, onExceptionalCompletionN()); |
259 |
> |
assertEquals(1, setRawResultN()); |
260 |
> |
assertSame(rawResult, this.rawResult.get()); |
261 |
> |
checkCompletedNormally(this); |
262 |
> |
} |
263 |
> |
void checkCompletesExceptionally(Throwable ex) { |
264 |
> |
checkIncomplete(); |
265 |
> |
completeExceptionally(ex); |
266 |
> |
checkCompletedExceptionally(ex); |
267 |
> |
} |
268 |
> |
void checkCompletedExceptionally(Throwable ex) { |
269 |
> |
assertEquals(0, computeN()); |
270 |
> |
assertEquals(0, onCompletionN()); |
271 |
> |
assertEquals(1, onExceptionalCompletionN()); |
272 |
> |
assertEquals(0, setRawResultN()); |
273 |
> |
assertNull(this.rawResult.get()); |
274 |
> |
checkCompletedAbnormally(this, ex); |
275 |
|
} |
276 |
|
} |
277 |
|
|
278 |
+ |
final class NoopCC extends CheckedCC { |
279 |
+ |
NoopCC() { super(); } |
280 |
+ |
NoopCC(CountedCompleter p) { super(p); } |
281 |
+ |
protected void realCompute() {} |
282 |
+ |
} |
283 |
+ |
|
284 |
|
/** |
285 |
|
* A newly constructed CountedCompleter is not completed; |
286 |
< |
* complete() causes completion. |
286 |
> |
* complete() causes completion. pendingCount is ignored. |
287 |
|
*/ |
288 |
|
public void testComplete() { |
289 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
290 |
< |
assertFalse(a.isDone()); |
291 |
< |
assertFalse(a.isCompletedNormally()); |
292 |
< |
assertFalse(a.isCompletedAbnormally()); |
293 |
< |
assertFalse(a.isCancelled()); |
294 |
< |
assertNull(a.getException()); |
295 |
< |
assertNull(a.getRawResult()); |
296 |
< |
assertFalse(a.post); |
297 |
< |
a.complete(null); |
298 |
< |
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()); |
289 |
> |
for (Object x : new Object[] { Boolean.TRUE, null }) { |
290 |
> |
for (int pendingCount : new int[] { 0, 42 }) { |
291 |
> |
testComplete(new NoopCC(), x, pendingCount); |
292 |
> |
testComplete(new NoopCC(new NoopCC()), x, pendingCount); |
293 |
> |
} |
294 |
> |
} |
295 |
> |
} |
296 |
> |
void testComplete(NoopCC cc, Object x, int pendingCount) { |
297 |
> |
cc.setPendingCount(pendingCount); |
298 |
> |
cc.checkCompletes(x); |
299 |
|
} |
300 |
|
|
301 |
|
/** |
302 |
|
* completeExceptionally completes exceptionally |
303 |
|
*/ |
304 |
|
public void testCompleteExceptionally() { |
305 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
306 |
< |
assertFalse(a.isDone()); |
307 |
< |
assertFalse(a.isCompletedNormally()); |
308 |
< |
assertFalse(a.isCompletedAbnormally()); |
309 |
< |
assertFalse(a.isCancelled()); |
310 |
< |
assertNull(a.getException()); |
311 |
< |
assertNull(a.getRawResult()); |
312 |
< |
assertFalse(a.post); |
313 |
< |
a.completeExceptionally(new FJException()); |
314 |
< |
assertFalse(a.post); |
315 |
< |
assertTrue(a.isDone()); |
316 |
< |
assertFalse(a.isCompletedNormally()); |
317 |
< |
assertTrue(a.isCompletedAbnormally()); |
318 |
< |
assertFalse(a.isCancelled()); |
319 |
< |
assertTrue(a.getException() instanceof FJException); |
272 |
< |
assertNull(a.getRawResult()); |
305 |
> |
new NoopCC() |
306 |
> |
.checkCompletesExceptionally(new FJException()); |
307 |
> |
new NoopCC(new NoopCC()) |
308 |
> |
.checkCompletesExceptionally(new FJException()); |
309 |
> |
} |
310 |
> |
|
311 |
> |
/** |
312 |
> |
* completeExceptionally(null) throws NullPointerException |
313 |
> |
*/ |
314 |
> |
public void testCompleteExceptionally_null() { |
315 |
> |
try { |
316 |
> |
new NoopCC() |
317 |
> |
.checkCompletesExceptionally(null); |
318 |
> |
shouldThrow(); |
319 |
> |
} catch (NullPointerException success) {} |
320 |
|
} |
321 |
|
|
322 |
|
/** |
323 |
|
* setPendingCount sets the reported pending count |
324 |
|
*/ |
325 |
|
public void testSetPendingCount() { |
326 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
326 |
> |
NoopCC a = new NoopCC(); |
327 |
|
assertEquals(0, a.getPendingCount()); |
328 |
|
a.setPendingCount(1); |
329 |
|
assertEquals(1, a.getPendingCount()); |
335 |
|
* addToPendingCount adds to the reported pending count |
336 |
|
*/ |
337 |
|
public void testAddToPendingCount() { |
338 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
338 |
> |
NoopCC a = new NoopCC(); |
339 |
|
assertEquals(0, a.getPendingCount()); |
340 |
|
a.addToPendingCount(1); |
341 |
|
assertEquals(1, a.getPendingCount()); |
348 |
|
* count unless zero |
349 |
|
*/ |
350 |
|
public void testDecrementPendingCount() { |
351 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
351 |
> |
NoopCC a = new NoopCC(); |
352 |
|
assertEquals(0, a.getPendingCount()); |
353 |
|
a.addToPendingCount(1); |
354 |
|
assertEquals(1, a.getPendingCount()); |
359 |
|
} |
360 |
|
|
361 |
|
/** |
362 |
+ |
* compareAndSetPendingCount compares and sets the reported |
363 |
+ |
* pending count |
364 |
+ |
*/ |
365 |
+ |
public void testCompareAndSetPendingCount() { |
366 |
+ |
NoopCC a = new NoopCC(); |
367 |
+ |
assertEquals(0, a.getPendingCount()); |
368 |
+ |
assertTrue(a.compareAndSetPendingCount(0, 1)); |
369 |
+ |
assertEquals(1, a.getPendingCount()); |
370 |
+ |
assertTrue(a.compareAndSetPendingCount(1, 2)); |
371 |
+ |
assertEquals(2, a.getPendingCount()); |
372 |
+ |
assertFalse(a.compareAndSetPendingCount(1, 3)); |
373 |
+ |
assertEquals(2, a.getPendingCount()); |
374 |
+ |
} |
375 |
+ |
|
376 |
+ |
/** |
377 |
|
* getCompleter returns parent or null if at root |
378 |
|
*/ |
379 |
|
public void testGetCompleter() { |
380 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
380 |
> |
NoopCC a = new NoopCC(); |
381 |
|
assertNull(a.getCompleter()); |
382 |
< |
CountedCompleter b = new NoopCountedCompleter(a); |
383 |
< |
assertEquals(a, b.getCompleter()); |
382 |
> |
CountedCompleter b = new NoopCC(a); |
383 |
> |
assertSame(a, b.getCompleter()); |
384 |
> |
CountedCompleter c = new NoopCC(b); |
385 |
> |
assertSame(b, c.getCompleter()); |
386 |
|
} |
387 |
|
|
388 |
|
/** |
389 |
|
* getRoot returns self if no parent, else parent's root |
390 |
|
*/ |
391 |
|
public void testGetRoot() { |
392 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
393 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
394 |
< |
assertEquals(a, a.getRoot()); |
395 |
< |
assertEquals(a, b.getRoot()); |
392 |
> |
NoopCC a = new NoopCC(); |
393 |
> |
NoopCC b = new NoopCC(a); |
394 |
> |
NoopCC c = new NoopCC(b); |
395 |
> |
assertSame(a, a.getRoot()); |
396 |
> |
assertSame(a, b.getRoot()); |
397 |
> |
assertSame(a, c.getRoot()); |
398 |
|
} |
399 |
|
|
400 |
|
/** |
401 |
< |
* tryComplete causes completion if pending count is zero |
401 |
> |
* tryComplete decrements pending count unless zero, in which case |
402 |
> |
* causes completion |
403 |
|
*/ |
404 |
< |
public void testTryComplete1() { |
405 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
404 |
> |
public void testTryComplete() { |
405 |
> |
NoopCC a = new NoopCC(); |
406 |
|
assertEquals(0, a.getPendingCount()); |
407 |
+ |
int n = 3; |
408 |
+ |
a.setPendingCount(n); |
409 |
+ |
for (; n > 0; n--) { |
410 |
+ |
assertEquals(n, a.getPendingCount()); |
411 |
+ |
a.tryComplete(); |
412 |
+ |
a.checkIncomplete(); |
413 |
+ |
assertEquals(n - 1, a.getPendingCount()); |
414 |
+ |
} |
415 |
|
a.tryComplete(); |
416 |
< |
assertTrue(a.post); |
417 |
< |
assertTrue(a.isDone()); |
416 |
> |
assertEquals(0, a.computeN()); |
417 |
> |
assertEquals(1, a.onCompletionN()); |
418 |
> |
assertEquals(0, a.onExceptionalCompletionN()); |
419 |
> |
assertEquals(0, a.setRawResultN()); |
420 |
> |
checkCompletedNormally(a); |
421 |
|
} |
422 |
|
|
423 |
|
/** |
424 |
< |
* propagateCompletion causes completion without invoking |
425 |
< |
* onCompletion if pending count is zero |
424 |
> |
* propagateCompletion decrements pending count unless zero, in |
425 |
> |
* which case causes completion, without invoking onCompletion |
426 |
|
*/ |
427 |
|
public void testPropagateCompletion() { |
428 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
428 |
> |
NoopCC a = new NoopCC(); |
429 |
|
assertEquals(0, a.getPendingCount()); |
430 |
+ |
int n = 3; |
431 |
+ |
a.setPendingCount(n); |
432 |
+ |
for (; n > 0; n--) { |
433 |
+ |
assertEquals(n, a.getPendingCount()); |
434 |
+ |
a.propagateCompletion(); |
435 |
+ |
a.checkIncomplete(); |
436 |
+ |
assertEquals(n - 1, a.getPendingCount()); |
437 |
+ |
} |
438 |
|
a.propagateCompletion(); |
439 |
< |
assertFalse(a.post); |
440 |
< |
assertTrue(a.isDone()); |
441 |
< |
} |
442 |
< |
|
443 |
< |
/** |
358 |
< |
* tryComplete decrements 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()); |
439 |
> |
assertEquals(0, a.computeN()); |
440 |
> |
assertEquals(0, a.onCompletionN()); |
441 |
> |
assertEquals(0, a.onExceptionalCompletionN()); |
442 |
> |
assertEquals(0, a.setRawResultN()); |
443 |
> |
checkCompletedNormally(a); |
444 |
|
} |
445 |
|
|
446 |
|
/** |
447 |
|
* firstComplete returns this if pending count is zero else null |
448 |
|
*/ |
449 |
|
public void testFirstComplete() { |
450 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
450 |
> |
NoopCC a = new NoopCC(); |
451 |
|
a.setPendingCount(1); |
452 |
|
assertNull(a.firstComplete()); |
453 |
< |
assertEquals(a, a.firstComplete()); |
453 |
> |
a.checkIncomplete(); |
454 |
> |
assertSame(a, a.firstComplete()); |
455 |
> |
a.checkIncomplete(); |
456 |
|
} |
457 |
|
|
458 |
|
/** |
460 |
|
* zero else null |
461 |
|
*/ |
462 |
|
public void testNextComplete() { |
463 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
464 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
463 |
> |
NoopCC a = new NoopCC(); |
464 |
> |
NoopCC b = new NoopCC(a); |
465 |
|
a.setPendingCount(1); |
466 |
|
b.setPendingCount(1); |
467 |
|
assertNull(b.firstComplete()); |
468 |
< |
CountedCompleter c = b.firstComplete(); |
469 |
< |
assertEquals(b, c); |
470 |
< |
CountedCompleter d = c.nextComplete(); |
471 |
< |
assertNull(d); |
472 |
< |
CountedCompleter e = c.nextComplete(); |
473 |
< |
assertEquals(a, e); |
468 |
> |
assertSame(b, b.firstComplete()); |
469 |
> |
assertNull(b.nextComplete()); |
470 |
> |
a.checkIncomplete(); |
471 |
> |
b.checkIncomplete(); |
472 |
> |
assertSame(a, b.nextComplete()); |
473 |
> |
assertSame(a, b.nextComplete()); |
474 |
> |
a.checkIncomplete(); |
475 |
> |
b.checkIncomplete(); |
476 |
> |
assertNull(a.nextComplete()); |
477 |
> |
b.checkIncomplete(); |
478 |
> |
checkCompletedNormally(a); |
479 |
|
} |
480 |
|
|
481 |
|
/** |
482 |
|
* quietlyCompleteRoot completes root task |
483 |
|
*/ |
484 |
|
public void testQuietlyCompleteRoot() { |
485 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
486 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
485 |
> |
NoopCC a = new NoopCC(); |
486 |
> |
NoopCC b = new NoopCC(a); |
487 |
> |
NoopCC c = new NoopCC(b); |
488 |
|
a.setPendingCount(1); |
489 |
|
b.setPendingCount(1); |
490 |
< |
b.quietlyCompleteRoot(); |
490 |
> |
c.setPendingCount(1); |
491 |
> |
c.quietlyCompleteRoot(); |
492 |
|
assertTrue(a.isDone()); |
493 |
|
assertFalse(b.isDone()); |
494 |
+ |
assertFalse(c.isDone()); |
495 |
|
} |
496 |
|
|
497 |
|
// Invocation tests use some interdependent task classes |
498 |
|
// to better test propagation etc |
499 |
|
|
500 |
< |
|
501 |
< |
// Version of Fibonacci with different classes for left vs right forks |
502 |
< |
abstract static class CCF extends CountedCompleter { |
500 |
> |
/** |
501 |
> |
* Version of Fibonacci with different classes for left vs right forks |
502 |
> |
*/ |
503 |
> |
abstract class CCF extends CheckedCC { |
504 |
|
int number; |
505 |
|
int rnumber; |
506 |
|
|
509 |
|
this.number = n; |
510 |
|
} |
511 |
|
|
512 |
< |
public final void compute() { |
429 |
< |
CountedCompleter p; |
512 |
> |
protected final void realCompute() { |
513 |
|
CCF f = this; |
514 |
|
int n = number; |
515 |
|
while (n >= 2) { |
516 |
|
new RCCF(f, n - 2).fork(); |
517 |
|
f = new LCCF(f, --n); |
518 |
|
} |
519 |
< |
f.number = n; |
437 |
< |
f.onCompletion(f); |
438 |
< |
if ((p = f.getCompleter()) != null) |
439 |
< |
p.tryComplete(); |
440 |
< |
else |
441 |
< |
f.quietlyComplete(); |
519 |
> |
f.complete(null); |
520 |
|
} |
521 |
|
} |
522 |
|
|
523 |
< |
static final class LCCF extends CCF { |
523 |
> |
final class LCCF extends CCF { |
524 |
> |
public LCCF(int n) { this(null, n); } |
525 |
|
public LCCF(CountedCompleter parent, int n) { |
526 |
|
super(parent, n); |
527 |
|
} |
528 |
|
public final void onCompletion(CountedCompleter caller) { |
529 |
+ |
super.onCompletion(caller); |
530 |
|
CCF p = (CCF)getCompleter(); |
531 |
|
int n = number + rnumber; |
532 |
|
if (p != null) |
535 |
|
number = n; |
536 |
|
} |
537 |
|
} |
538 |
< |
static final class RCCF extends CCF { |
538 |
> |
final class RCCF extends CCF { |
539 |
|
public RCCF(CountedCompleter parent, int n) { |
540 |
|
super(parent, n); |
541 |
|
} |
542 |
|
public final void onCompletion(CountedCompleter caller) { |
543 |
+ |
super.onCompletion(caller); |
544 |
|
CCF p = (CCF)getCompleter(); |
545 |
|
int n = number + rnumber; |
546 |
|
if (p != null) |
551 |
|
} |
552 |
|
|
553 |
|
// Version of CCF with forced failure in left completions |
554 |
< |
abstract static class FailingCCF extends CountedCompleter { |
554 |
> |
abstract class FailingCCF extends CheckedCC { |
555 |
|
int number; |
556 |
|
int rnumber; |
557 |
|
|
560 |
|
this.number = n; |
561 |
|
} |
562 |
|
|
563 |
< |
public final void compute() { |
483 |
< |
CountedCompleter p; |
563 |
> |
protected final void realCompute() { |
564 |
|
FailingCCF f = this; |
565 |
|
int n = number; |
566 |
|
while (n >= 2) { |
567 |
|
new RFCCF(f, n - 2).fork(); |
568 |
|
f = new LFCCF(f, --n); |
569 |
|
} |
570 |
< |
f.number = n; |
491 |
< |
f.onCompletion(f); |
492 |
< |
if ((p = f.getCompleter()) != null) |
493 |
< |
p.tryComplete(); |
494 |
< |
else |
495 |
< |
f.quietlyComplete(); |
570 |
> |
f.complete(null); |
571 |
|
} |
572 |
|
} |
573 |
|
|
574 |
< |
static final class LFCCF extends FailingCCF { |
574 |
> |
final class LFCCF extends FailingCCF { |
575 |
> |
public LFCCF(int n) { this(null, n); } |
576 |
|
public LFCCF(CountedCompleter parent, int n) { |
577 |
|
super(parent, n); |
578 |
|
} |
579 |
|
public final void onCompletion(CountedCompleter caller) { |
580 |
+ |
super.onCompletion(caller); |
581 |
|
FailingCCF p = (FailingCCF)getCompleter(); |
582 |
|
int n = number + rnumber; |
583 |
|
if (p != null) |
586 |
|
number = n; |
587 |
|
} |
588 |
|
} |
589 |
< |
static final class RFCCF extends FailingCCF { |
589 |
> |
final class RFCCF extends FailingCCF { |
590 |
|
public RFCCF(CountedCompleter parent, int n) { |
591 |
|
super(parent, n); |
592 |
|
} |
593 |
|
public final void onCompletion(CountedCompleter caller) { |
594 |
+ |
super.onCompletion(caller); |
595 |
|
completeExceptionally(new FJException()); |
596 |
|
} |
597 |
|
} |
602 |
|
* completed tasks; getRawResult returns null. |
603 |
|
*/ |
604 |
|
public void testInvoke() { |
605 |
< |
ForkJoinTask a = new CheckedFJTask() { |
606 |
< |
public void realCompute() { |
607 |
< |
CCF f = new LCCF(null, 8); |
605 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
606 |
> |
protected void realCompute() { |
607 |
> |
CCF f = new LCCF(8); |
608 |
|
assertNull(f.invoke()); |
609 |
|
assertEquals(21, f.number); |
610 |
|
checkCompletedNormally(f); |
618 |
|
* completed tasks |
619 |
|
*/ |
620 |
|
public void testQuietlyInvoke() { |
621 |
< |
ForkJoinTask a = new CheckedFJTask() { |
622 |
< |
public void realCompute() { |
623 |
< |
CCF f = new LCCF(null, 8); |
621 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
622 |
> |
protected void realCompute() { |
623 |
> |
CCF f = new LCCF(8); |
624 |
|
f.quietlyInvoke(); |
625 |
|
assertEquals(21, f.number); |
626 |
|
checkCompletedNormally(f); |
632 |
|
* join of a forked task returns when task completes |
633 |
|
*/ |
634 |
|
public void testForkJoin() { |
635 |
< |
ForkJoinTask a = new CheckedFJTask() { |
636 |
< |
public void realCompute() { |
637 |
< |
CCF f = new LCCF(null, 8); |
635 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
636 |
> |
protected void realCompute() { |
637 |
> |
CCF f = new LCCF(8); |
638 |
|
assertSame(f, f.fork()); |
639 |
|
assertNull(f.join()); |
640 |
|
assertEquals(21, f.number); |
647 |
|
* get of a forked task returns when task completes |
648 |
|
*/ |
649 |
|
public void testForkGet() { |
650 |
< |
ForkJoinTask a = new CheckedFJTask() { |
651 |
< |
public void realCompute() throws Exception { |
652 |
< |
CCF f = new LCCF(null, 8); |
650 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
651 |
> |
protected void realCompute() throws Exception { |
652 |
> |
CCF f = new LCCF(8); |
653 |
|
assertSame(f, f.fork()); |
654 |
|
assertNull(f.get()); |
655 |
|
assertEquals(21, f.number); |
662 |
|
* timed get of a forked task returns when task completes |
663 |
|
*/ |
664 |
|
public void testForkTimedGet() { |
665 |
< |
ForkJoinTask a = new CheckedFJTask() { |
666 |
< |
public void realCompute() throws Exception { |
667 |
< |
CCF f = new LCCF(null, 8); |
665 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
666 |
> |
protected void realCompute() throws Exception { |
667 |
> |
CCF f = new LCCF(8); |
668 |
|
assertSame(f, f.fork()); |
669 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
670 |
|
assertEquals(21, f.number); |
677 |
|
* timed get with null time unit throws NPE |
678 |
|
*/ |
679 |
|
public void testForkTimedGetNPE() { |
680 |
< |
ForkJoinTask a = new CheckedFJTask() { |
681 |
< |
public void realCompute() throws Exception { |
682 |
< |
CCF f = new LCCF(null, 8); |
680 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
681 |
> |
protected void realCompute() throws Exception { |
682 |
> |
CCF f = new LCCF(8); |
683 |
|
assertSame(f, f.fork()); |
684 |
|
try { |
685 |
|
f.get(5L, null); |
693 |
|
* quietlyJoin of a forked task returns when task completes |
694 |
|
*/ |
695 |
|
public void testForkQuietlyJoin() { |
696 |
< |
ForkJoinTask a = new CheckedFJTask() { |
697 |
< |
public void realCompute() { |
698 |
< |
CCF f = new LCCF(null, 8); |
696 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
697 |
> |
protected void realCompute() { |
698 |
> |
CCF f = new LCCF(8); |
699 |
|
assertSame(f, f.fork()); |
700 |
|
f.quietlyJoin(); |
701 |
|
assertEquals(21, f.number); |
709 |
|
* getQueuedTaskCount returns 0 when quiescent |
710 |
|
*/ |
711 |
|
public void testForkHelpQuiesce() { |
712 |
< |
ForkJoinTask a = new CheckedFJTask() { |
713 |
< |
public void realCompute() { |
714 |
< |
CCF f = new LCCF(null, 8); |
712 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
713 |
> |
protected void realCompute() { |
714 |
> |
CCF f = new LCCF(8); |
715 |
|
assertSame(f, f.fork()); |
716 |
|
helpQuiesce(); |
717 |
|
assertEquals(21, f.number); |
725 |
|
* invoke task throws exception when task completes abnormally |
726 |
|
*/ |
727 |
|
public void testAbnormalInvoke() { |
728 |
< |
ForkJoinTask a = new CheckedFJTask() { |
729 |
< |
public void realCompute() { |
730 |
< |
FailingCCF f = new LFCCF(null, 8); |
728 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
729 |
> |
protected void realCompute() { |
730 |
> |
FailingCCF f = new LFCCF(8); |
731 |
|
try { |
732 |
|
f.invoke(); |
733 |
|
shouldThrow(); |
742 |
|
* quietlyInvoke task returns when task completes abnormally |
743 |
|
*/ |
744 |
|
public void testAbnormalQuietlyInvoke() { |
745 |
< |
ForkJoinTask a = new CheckedFJTask() { |
746 |
< |
public void realCompute() { |
747 |
< |
FailingCCF f = new LFCCF(null, 8); |
745 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
746 |
> |
protected void realCompute() { |
747 |
> |
FailingCCF f = new LFCCF(8); |
748 |
|
f.quietlyInvoke(); |
749 |
|
assertTrue(f.getException() instanceof FJException); |
750 |
|
checkCompletedAbnormally(f, f.getException()); |
756 |
|
* join of a forked task throws exception when task completes abnormally |
757 |
|
*/ |
758 |
|
public void testAbnormalForkJoin() { |
759 |
< |
ForkJoinTask a = new CheckedFJTask() { |
760 |
< |
public void realCompute() { |
761 |
< |
FailingCCF f = new LFCCF(null, 8); |
759 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
760 |
> |
protected void realCompute() { |
761 |
> |
FailingCCF f = new LFCCF(8); |
762 |
|
assertSame(f, f.fork()); |
763 |
|
try { |
764 |
|
f.join(); |
774 |
|
* get of a forked task throws exception when task completes abnormally |
775 |
|
*/ |
776 |
|
public void testAbnormalForkGet() { |
777 |
< |
ForkJoinTask a = new CheckedFJTask() { |
778 |
< |
public void realCompute() throws Exception { |
779 |
< |
FailingCCF f = new LFCCF(null, 8); |
777 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
778 |
> |
protected void realCompute() throws Exception { |
779 |
> |
FailingCCF f = new LFCCF(8); |
780 |
|
assertSame(f, f.fork()); |
781 |
|
try { |
782 |
|
f.get(); |
794 |
|
* timed get of a forked task throws exception when task completes abnormally |
795 |
|
*/ |
796 |
|
public void testAbnormalForkTimedGet() { |
797 |
< |
ForkJoinTask a = new CheckedFJTask() { |
798 |
< |
public void realCompute() throws Exception { |
799 |
< |
FailingCCF f = new LFCCF(null, 8); |
797 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
798 |
> |
protected void realCompute() throws Exception { |
799 |
> |
FailingCCF f = new LFCCF(8); |
800 |
|
assertSame(f, f.fork()); |
801 |
|
try { |
802 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
814 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
815 |
|
*/ |
816 |
|
public void testAbnormalForkQuietlyJoin() { |
817 |
< |
ForkJoinTask a = new CheckedFJTask() { |
818 |
< |
public void realCompute() { |
819 |
< |
FailingCCF f = new LFCCF(null, 8); |
817 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
818 |
> |
protected void realCompute() { |
819 |
> |
FailingCCF f = new LFCCF(8); |
820 |
|
assertSame(f, f.fork()); |
821 |
|
f.quietlyJoin(); |
822 |
|
assertTrue(f.getException() instanceof FJException); |
829 |
|
* invoke task throws exception when task cancelled |
830 |
|
*/ |
831 |
|
public void testCancelledInvoke() { |
832 |
< |
ForkJoinTask a = new CheckedFJTask() { |
833 |
< |
public void realCompute() { |
834 |
< |
CCF f = new LCCF(null, 8); |
832 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
833 |
> |
protected void realCompute() { |
834 |
> |
CCF f = new LCCF(8); |
835 |
|
assertTrue(f.cancel(true)); |
836 |
|
try { |
837 |
|
f.invoke(); |
847 |
|
* join of a forked task throws exception when task cancelled |
848 |
|
*/ |
849 |
|
public void testCancelledForkJoin() { |
850 |
< |
ForkJoinTask a = new CheckedFJTask() { |
851 |
< |
public void realCompute() { |
852 |
< |
CCF f = new LCCF(null, 8); |
850 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
851 |
> |
protected void realCompute() { |
852 |
> |
CCF f = new LCCF(8); |
853 |
|
assertTrue(f.cancel(true)); |
854 |
|
assertSame(f, f.fork()); |
855 |
|
try { |
866 |
|
* get of a forked task throws exception when task cancelled |
867 |
|
*/ |
868 |
|
public void testCancelledForkGet() { |
869 |
< |
ForkJoinTask a = new CheckedFJTask() { |
870 |
< |
public void realCompute() throws Exception { |
871 |
< |
CCF f = new LCCF(null, 8); |
869 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
870 |
> |
protected void realCompute() throws Exception { |
871 |
> |
CCF f = new LCCF(8); |
872 |
|
assertTrue(f.cancel(true)); |
873 |
|
assertSame(f, f.fork()); |
874 |
|
try { |
885 |
|
* timed get of a forked task throws exception when task cancelled |
886 |
|
*/ |
887 |
|
public void testCancelledForkTimedGet() throws Exception { |
888 |
< |
ForkJoinTask a = new CheckedFJTask() { |
889 |
< |
public void realCompute() throws Exception { |
890 |
< |
CCF f = new LCCF(null, 8); |
888 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
889 |
> |
protected void realCompute() throws Exception { |
890 |
> |
CCF f = new LCCF(8); |
891 |
|
assertTrue(f.cancel(true)); |
892 |
|
assertSame(f, f.fork()); |
893 |
|
try { |
904 |
|
* quietlyJoin of a forked task returns when task cancelled |
905 |
|
*/ |
906 |
|
public void testCancelledForkQuietlyJoin() { |
907 |
< |
ForkJoinTask a = new CheckedFJTask() { |
908 |
< |
public void realCompute() { |
909 |
< |
CCF f = new LCCF(null, 8); |
907 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
908 |
> |
protected void realCompute() { |
909 |
> |
CCF f = new LCCF(8); |
910 |
|
assertTrue(f.cancel(true)); |
911 |
|
assertSame(f, f.fork()); |
912 |
|
f.quietlyJoin(); |
920 |
|
*/ |
921 |
|
public void testGetPool() { |
922 |
|
final ForkJoinPool mainPool = mainPool(); |
923 |
< |
ForkJoinTask a = new CheckedFJTask() { |
924 |
< |
public void realCompute() { |
923 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
924 |
> |
protected void realCompute() { |
925 |
|
assertSame(mainPool, getPool()); |
926 |
|
}}; |
927 |
|
testInvokeOnPool(mainPool, a); |
931 |
|
* getPool of non-FJ task returns null |
932 |
|
*/ |
933 |
|
public void testGetPool2() { |
934 |
< |
ForkJoinTask a = new CheckedFJTask() { |
935 |
< |
public void realCompute() { |
934 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
935 |
> |
protected void realCompute() { |
936 |
|
assertNull(getPool()); |
937 |
|
}}; |
938 |
|
assertNull(a.invoke()); |
942 |
|
* inForkJoinPool of executing task returns true |
943 |
|
*/ |
944 |
|
public void testInForkJoinPool() { |
945 |
< |
ForkJoinTask a = new CheckedFJTask() { |
946 |
< |
public void realCompute() { |
945 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
946 |
> |
protected void realCompute() { |
947 |
|
assertTrue(inForkJoinPool()); |
948 |
|
}}; |
949 |
|
testInvokeOnPool(mainPool(), a); |
953 |
|
* inForkJoinPool of non-FJ task returns false |
954 |
|
*/ |
955 |
|
public void testInForkJoinPool2() { |
956 |
< |
ForkJoinTask a = new CheckedFJTask() { |
957 |
< |
public void realCompute() { |
956 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
957 |
> |
protected void realCompute() { |
958 |
|
assertFalse(inForkJoinPool()); |
959 |
|
}}; |
960 |
|
assertNull(a.invoke()); |
964 |
|
* setRawResult(null) succeeds |
965 |
|
*/ |
966 |
|
public void testSetRawResult() { |
967 |
< |
ForkJoinTask a = new CheckedFJTask() { |
968 |
< |
public void realCompute() { |
967 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
968 |
> |
protected void realCompute() { |
969 |
|
setRawResult(null); |
970 |
|
assertNull(getRawResult()); |
971 |
|
}}; |
976 |
|
* invoke task throws exception after invoking completeExceptionally |
977 |
|
*/ |
978 |
|
public void testCompleteExceptionally2() { |
979 |
< |
ForkJoinTask a = new CheckedFJTask() { |
980 |
< |
public void realCompute() { |
981 |
< |
CCF f = new LCCF(null, 8); |
982 |
< |
f.completeExceptionally(new FJException()); |
983 |
< |
try { |
984 |
< |
f.invoke(); |
985 |
< |
shouldThrow(); |
986 |
< |
} catch (FJException success) { |
909 |
< |
checkCompletedAbnormally(f, success); |
910 |
< |
} |
979 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
980 |
> |
protected void realCompute() { |
981 |
> |
CCF n = new LCCF(8); |
982 |
> |
CCF f = new LCCF(n, 8); |
983 |
> |
FJException ex = new FJException(); |
984 |
> |
f.completeExceptionally(ex); |
985 |
> |
f.checkCompletedExceptionally(ex); |
986 |
> |
n.checkCompletedExceptionally(ex); |
987 |
|
}}; |
988 |
|
testInvokeOnPool(mainPool(), a); |
989 |
|
} |
992 |
|
* invokeAll(t1, t2) invokes all task arguments |
993 |
|
*/ |
994 |
|
public void testInvokeAll2() { |
995 |
< |
ForkJoinTask a = new CheckedFJTask() { |
996 |
< |
public void realCompute() { |
997 |
< |
CCF f = new LCCF(null, 8); |
998 |
< |
CCF g = new LCCF(null, 9); |
995 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
996 |
> |
protected void realCompute() { |
997 |
> |
CCF f = new LCCF(8); |
998 |
> |
CCF g = new LCCF(9); |
999 |
|
invokeAll(f, g); |
1000 |
|
assertEquals(21, f.number); |
1001 |
|
assertEquals(34, g.number); |
1009 |
|
* invokeAll(tasks) with 1 argument invokes task |
1010 |
|
*/ |
1011 |
|
public void testInvokeAll1() { |
1012 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1013 |
< |
public void realCompute() { |
1014 |
< |
CCF f = new LCCF(null, 8); |
1012 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1013 |
> |
protected void realCompute() { |
1014 |
> |
CCF f = new LCCF(8); |
1015 |
|
invokeAll(f); |
1016 |
|
checkCompletedNormally(f); |
1017 |
|
assertEquals(21, f.number); |
1023 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
1024 |
|
*/ |
1025 |
|
public void testInvokeAll3() { |
1026 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1027 |
< |
public void realCompute() { |
1028 |
< |
CCF f = new LCCF(null, 8); |
1029 |
< |
CCF g = new LCCF(null, 9); |
1030 |
< |
CCF h = new LCCF(null, 7); |
1026 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1027 |
> |
protected void realCompute() { |
1028 |
> |
CCF f = new LCCF(8); |
1029 |
> |
CCF g = new LCCF(9); |
1030 |
> |
CCF h = new LCCF(7); |
1031 |
|
invokeAll(f, g, h); |
1032 |
|
assertEquals(21, f.number); |
1033 |
|
assertEquals(34, g.number); |
1043 |
|
* invokeAll(collection) invokes all tasks in the collection |
1044 |
|
*/ |
1045 |
|
public void testInvokeAllCollection() { |
1046 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1047 |
< |
public void realCompute() { |
1048 |
< |
CCF f = new LCCF(null, 8); |
1049 |
< |
CCF g = new LCCF(null, 9); |
1050 |
< |
CCF h = new LCCF(null, 7); |
1046 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1047 |
> |
protected void realCompute() { |
1048 |
> |
CCF f = new LCCF(8); |
1049 |
> |
CCF g = new LCCF(9); |
1050 |
> |
CCF h = new LCCF(7); |
1051 |
|
HashSet set = new HashSet(); |
1052 |
|
set.add(f); |
1053 |
|
set.add(g); |
1067 |
|
* invokeAll(tasks) with any null task throws NPE |
1068 |
|
*/ |
1069 |
|
public void testInvokeAllNPE() { |
1070 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1071 |
< |
public void realCompute() { |
1072 |
< |
CCF f = new LCCF(null, 8); |
1073 |
< |
CCF g = new LCCF(null, 9); |
1070 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1071 |
> |
protected void realCompute() { |
1072 |
> |
CCF f = new LCCF(8); |
1073 |
> |
CCF g = new LCCF(9); |
1074 |
|
CCF h = null; |
1075 |
|
try { |
1076 |
|
invokeAll(f, g, h); |
1084 |
|
* invokeAll(t1, t2) throw exception if any task does |
1085 |
|
*/ |
1086 |
|
public void testAbnormalInvokeAll2() { |
1087 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1088 |
< |
public void realCompute() { |
1089 |
< |
CCF f = new LCCF(null, 8); |
1090 |
< |
FailingCCF g = new LFCCF(null, 9); |
1087 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1088 |
> |
protected void realCompute() { |
1089 |
> |
CCF f = new LCCF(8); |
1090 |
> |
FailingCCF g = new LFCCF(9); |
1091 |
|
try { |
1092 |
|
invokeAll(f, g); |
1093 |
|
shouldThrow(); |
1102 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
1103 |
|
*/ |
1104 |
|
public void testAbnormalInvokeAll1() { |
1105 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1106 |
< |
public void realCompute() { |
1107 |
< |
FailingCCF g = new LFCCF(null, 9); |
1105 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1106 |
> |
protected void realCompute() { |
1107 |
> |
FailingCCF g = new LFCCF(9); |
1108 |
|
try { |
1109 |
|
invokeAll(g); |
1110 |
|
shouldThrow(); |
1119 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1120 |
|
*/ |
1121 |
|
public void testAbnormalInvokeAll3() { |
1122 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1123 |
< |
public void realCompute() { |
1124 |
< |
CCF f = new LCCF(null, 8); |
1125 |
< |
FailingCCF g = new LFCCF(null, 9); |
1126 |
< |
CCF h = new LCCF(null, 7); |
1122 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1123 |
> |
protected void realCompute() { |
1124 |
> |
CCF f = new LCCF(8); |
1125 |
> |
FailingCCF g = new LFCCF(9); |
1126 |
> |
CCF h = new LCCF(7); |
1127 |
|
try { |
1128 |
|
invokeAll(f, g, h); |
1129 |
|
shouldThrow(); |
1135 |
|
} |
1136 |
|
|
1137 |
|
/** |
1138 |
< |
* invokeAll(collection) throws exception if any task does |
1138 |
> |
* invokeAll(collection) throws exception if any task does |
1139 |
|
*/ |
1140 |
|
public void testAbnormalInvokeAllCollection() { |
1141 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1142 |
< |
public void realCompute() { |
1143 |
< |
FailingCCF f = new LFCCF(null, 8); |
1144 |
< |
CCF g = new LCCF(null, 9); |
1145 |
< |
CCF h = new LCCF(null, 7); |
1141 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1142 |
> |
protected void realCompute() { |
1143 |
> |
FailingCCF f = new LFCCF(8); |
1144 |
> |
CCF g = new LCCF(9); |
1145 |
> |
CCF h = new LCCF(7); |
1146 |
|
HashSet set = new HashSet(); |
1147 |
|
set.add(f); |
1148 |
|
set.add(g); |
1162 |
|
* and suppresses execution |
1163 |
|
*/ |
1164 |
|
public void testTryUnfork() { |
1165 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1166 |
< |
public void realCompute() { |
1167 |
< |
CCF g = new LCCF(null, 9); |
1165 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1166 |
> |
protected void realCompute() { |
1167 |
> |
CCF g = new LCCF(9); |
1168 |
|
assertSame(g, g.fork()); |
1169 |
< |
CCF f = new LCCF(null, 8); |
1169 |
> |
CCF f = new LCCF(8); |
1170 |
|
assertSame(f, f.fork()); |
1171 |
|
assertTrue(f.tryUnfork()); |
1172 |
|
helpQuiesce(); |
1181 |
|
* there are more tasks than threads |
1182 |
|
*/ |
1183 |
|
public void testGetSurplusQueuedTaskCount() { |
1184 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1185 |
< |
public void realCompute() { |
1186 |
< |
CCF h = new LCCF(null, 7); |
1184 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1185 |
> |
protected void realCompute() { |
1186 |
> |
CCF h = new LCCF(7); |
1187 |
|
assertSame(h, h.fork()); |
1188 |
< |
CCF g = new LCCF(null, 9); |
1188 |
> |
CCF g = new LCCF(9); |
1189 |
|
assertSame(g, g.fork()); |
1190 |
< |
CCF f = new LCCF(null, 8); |
1190 |
> |
CCF f = new LCCF(8); |
1191 |
|
assertSame(f, f.fork()); |
1192 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
1193 |
|
helpQuiesce(); |
1203 |
|
* peekNextLocalTask returns most recent unexecuted task. |
1204 |
|
*/ |
1205 |
|
public void testPeekNextLocalTask() { |
1206 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1207 |
< |
public void realCompute() { |
1208 |
< |
CCF g = new LCCF(null, 9); |
1206 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1207 |
> |
protected void realCompute() { |
1208 |
> |
CCF g = new LCCF(9); |
1209 |
|
assertSame(g, g.fork()); |
1210 |
< |
CCF f = new LCCF(null, 8); |
1210 |
> |
CCF f = new LCCF(8); |
1211 |
|
assertSame(f, f.fork()); |
1212 |
|
assertSame(f, peekNextLocalTask()); |
1213 |
|
assertNull(f.join()); |
1223 |
|
* executing it |
1224 |
|
*/ |
1225 |
|
public void testPollNextLocalTask() { |
1226 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1227 |
< |
public void realCompute() { |
1228 |
< |
CCF g = new LCCF(null, 9); |
1226 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1227 |
> |
protected void realCompute() { |
1228 |
> |
CCF g = new LCCF(9); |
1229 |
|
assertSame(g, g.fork()); |
1230 |
< |
CCF f = new LCCF(null, 8); |
1230 |
> |
CCF f = new LCCF(8); |
1231 |
|
assertSame(f, f.fork()); |
1232 |
|
assertSame(f, pollNextLocalTask()); |
1233 |
|
helpQuiesce(); |
1242 |
|
* pollTask returns an unexecuted task without executing it |
1243 |
|
*/ |
1244 |
|
public void testPollTask() { |
1245 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1246 |
< |
public void realCompute() { |
1247 |
< |
CCF g = new LCCF(null, 9); |
1245 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1246 |
> |
protected void realCompute() { |
1247 |
> |
CCF g = new LCCF(9); |
1248 |
|
assertSame(g, g.fork()); |
1249 |
< |
CCF f = new LCCF(null, 8); |
1249 |
> |
CCF f = new LCCF(8); |
1250 |
|
assertSame(f, f.fork()); |
1251 |
|
assertSame(f, pollTask()); |
1252 |
|
helpQuiesce(); |
1260 |
|
* peekNextLocalTask returns least recent unexecuted task in async mode |
1261 |
|
*/ |
1262 |
|
public void testPeekNextLocalTaskAsync() { |
1263 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1264 |
< |
public void realCompute() { |
1265 |
< |
CCF g = new LCCF(null, 9); |
1263 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1264 |
> |
protected void realCompute() { |
1265 |
> |
CCF g = new LCCF(9); |
1266 |
|
assertSame(g, g.fork()); |
1267 |
< |
CCF f = new LCCF(null, 8); |
1267 |
> |
CCF f = new LCCF(8); |
1268 |
|
assertSame(f, f.fork()); |
1269 |
|
assertSame(g, peekNextLocalTask()); |
1270 |
|
assertNull(f.join()); |
1281 |
|
* executing it, in async mode |
1282 |
|
*/ |
1283 |
|
public void testPollNextLocalTaskAsync() { |
1284 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1285 |
< |
public void realCompute() { |
1286 |
< |
CCF g = new LCCF(null, 9); |
1284 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1285 |
> |
protected void realCompute() { |
1286 |
> |
CCF g = new LCCF(9); |
1287 |
|
assertSame(g, g.fork()); |
1288 |
< |
CCF f = new LCCF(null, 8); |
1288 |
> |
CCF f = new LCCF(8); |
1289 |
|
assertSame(f, f.fork()); |
1290 |
|
assertSame(g, pollNextLocalTask()); |
1291 |
|
helpQuiesce(); |
1301 |
|
* async mode |
1302 |
|
*/ |
1303 |
|
public void testPollTaskAsync() { |
1304 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1305 |
< |
public void realCompute() { |
1306 |
< |
CCF g = new LCCF(null, 9); |
1304 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1305 |
> |
protected void realCompute() { |
1306 |
> |
CCF g = new LCCF(9); |
1307 |
|
assertSame(g, g.fork()); |
1308 |
< |
CCF f = new LCCF(null, 8); |
1308 |
> |
CCF f = new LCCF(8); |
1309 |
|
assertSame(f, f.fork()); |
1310 |
|
assertSame(g, pollTask()); |
1311 |
|
helpQuiesce(); |
1324 |
|
* completed tasks; getRawResult returns null. |
1325 |
|
*/ |
1326 |
|
public void testInvokeSingleton() { |
1327 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1328 |
< |
public void realCompute() { |
1329 |
< |
CCF f = new LCCF(null, 8); |
1327 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1328 |
> |
protected void realCompute() { |
1329 |
> |
CCF f = new LCCF(8); |
1330 |
|
assertNull(f.invoke()); |
1331 |
|
assertEquals(21, f.number); |
1332 |
|
checkCompletedNormally(f); |
1340 |
|
* completed tasks |
1341 |
|
*/ |
1342 |
|
public void testQuietlyInvokeSingleton() { |
1343 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1344 |
< |
public void realCompute() { |
1345 |
< |
CCF f = new LCCF(null, 8); |
1343 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1344 |
> |
protected void realCompute() { |
1345 |
> |
CCF f = new LCCF(8); |
1346 |
|
f.quietlyInvoke(); |
1347 |
|
assertEquals(21, f.number); |
1348 |
|
checkCompletedNormally(f); |
1354 |
|
* join of a forked task returns when task completes |
1355 |
|
*/ |
1356 |
|
public void testForkJoinSingleton() { |
1357 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1358 |
< |
public void realCompute() { |
1359 |
< |
CCF f = new LCCF(null, 8); |
1357 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1358 |
> |
protected void realCompute() { |
1359 |
> |
CCF f = new LCCF(8); |
1360 |
|
assertSame(f, f.fork()); |
1361 |
|
assertNull(f.join()); |
1362 |
|
assertEquals(21, f.number); |
1369 |
|
* get of a forked task returns when task completes |
1370 |
|
*/ |
1371 |
|
public void testForkGetSingleton() { |
1372 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1373 |
< |
public void realCompute() throws Exception { |
1374 |
< |
CCF f = new LCCF(null, 8); |
1372 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1373 |
> |
protected void realCompute() throws Exception { |
1374 |
> |
CCF f = new LCCF(8); |
1375 |
|
assertSame(f, f.fork()); |
1376 |
|
assertNull(f.get()); |
1377 |
|
assertEquals(21, f.number); |
1384 |
|
* timed get of a forked task returns when task completes |
1385 |
|
*/ |
1386 |
|
public void testForkTimedGetSingleton() { |
1387 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1388 |
< |
public void realCompute() throws Exception { |
1389 |
< |
CCF f = new LCCF(null, 8); |
1387 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1388 |
> |
protected void realCompute() throws Exception { |
1389 |
> |
CCF f = new LCCF(8); |
1390 |
|
assertSame(f, f.fork()); |
1391 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1392 |
|
assertEquals(21, f.number); |
1399 |
|
* timed get with null time unit throws NPE |
1400 |
|
*/ |
1401 |
|
public void testForkTimedGetNPESingleton() { |
1402 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1403 |
< |
public void realCompute() throws Exception { |
1404 |
< |
CCF f = new LCCF(null, 8); |
1402 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1403 |
> |
protected void realCompute() throws Exception { |
1404 |
> |
CCF f = new LCCF(8); |
1405 |
|
assertSame(f, f.fork()); |
1406 |
|
try { |
1407 |
|
f.get(5L, null); |
1415 |
|
* quietlyJoin of a forked task returns when task completes |
1416 |
|
*/ |
1417 |
|
public void testForkQuietlyJoinSingleton() { |
1418 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1419 |
< |
public void realCompute() { |
1420 |
< |
CCF f = new LCCF(null, 8); |
1418 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1419 |
> |
protected void realCompute() { |
1420 |
> |
CCF f = new LCCF(8); |
1421 |
|
assertSame(f, f.fork()); |
1422 |
|
f.quietlyJoin(); |
1423 |
|
assertEquals(21, f.number); |
1431 |
|
* getQueuedTaskCount returns 0 when quiescent |
1432 |
|
*/ |
1433 |
|
public void testForkHelpQuiesceSingleton() { |
1434 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1435 |
< |
public void realCompute() { |
1436 |
< |
CCF f = new LCCF(null, 8); |
1434 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1435 |
> |
protected void realCompute() { |
1436 |
> |
CCF f = new LCCF(8); |
1437 |
|
assertSame(f, f.fork()); |
1438 |
|
helpQuiesce(); |
1439 |
|
assertEquals(0, getQueuedTaskCount()); |
1447 |
|
* invoke task throws exception when task completes abnormally |
1448 |
|
*/ |
1449 |
|
public void testAbnormalInvokeSingleton() { |
1450 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1451 |
< |
public void realCompute() { |
1452 |
< |
FailingCCF f = new LFCCF(null, 8); |
1450 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1451 |
> |
protected void realCompute() { |
1452 |
> |
FailingCCF f = new LFCCF(8); |
1453 |
|
try { |
1454 |
|
f.invoke(); |
1455 |
|
shouldThrow(); |
1464 |
|
* quietlyInvoke task returns when task completes abnormally |
1465 |
|
*/ |
1466 |
|
public void testAbnormalQuietlyInvokeSingleton() { |
1467 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1468 |
< |
public void realCompute() { |
1469 |
< |
FailingCCF f = new LFCCF(null, 8); |
1467 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1468 |
> |
protected void realCompute() { |
1469 |
> |
FailingCCF f = new LFCCF(8); |
1470 |
|
f.quietlyInvoke(); |
1471 |
|
assertTrue(f.getException() instanceof FJException); |
1472 |
|
checkCompletedAbnormally(f, f.getException()); |
1478 |
|
* join of a forked task throws exception when task completes abnormally |
1479 |
|
*/ |
1480 |
|
public void testAbnormalForkJoinSingleton() { |
1481 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1482 |
< |
public void realCompute() { |
1483 |
< |
FailingCCF f = new LFCCF(null, 8); |
1481 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1482 |
> |
protected void realCompute() { |
1483 |
> |
FailingCCF f = new LFCCF(8); |
1484 |
|
assertSame(f, f.fork()); |
1485 |
|
try { |
1486 |
|
f.join(); |
1496 |
|
* get of a forked task throws exception when task completes abnormally |
1497 |
|
*/ |
1498 |
|
public void testAbnormalForkGetSingleton() { |
1499 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1500 |
< |
public void realCompute() throws Exception { |
1501 |
< |
FailingCCF f = new LFCCF(null, 8); |
1499 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1500 |
> |
protected void realCompute() throws Exception { |
1501 |
> |
FailingCCF f = new LFCCF(8); |
1502 |
|
assertSame(f, f.fork()); |
1503 |
|
try { |
1504 |
|
f.get(); |
1516 |
|
* timed get of a forked task throws exception when task completes abnormally |
1517 |
|
*/ |
1518 |
|
public void testAbnormalForkTimedGetSingleton() { |
1519 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1520 |
< |
public void realCompute() throws Exception { |
1521 |
< |
FailingCCF f = new LFCCF(null, 8); |
1519 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1520 |
> |
protected void realCompute() throws Exception { |
1521 |
> |
FailingCCF f = new LFCCF(8); |
1522 |
|
assertSame(f, f.fork()); |
1523 |
|
try { |
1524 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
1536 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
1537 |
|
*/ |
1538 |
|
public void testAbnormalForkQuietlyJoinSingleton() { |
1539 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1540 |
< |
public void realCompute() { |
1541 |
< |
FailingCCF f = new LFCCF(null, 8); |
1539 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1540 |
> |
protected void realCompute() { |
1541 |
> |
FailingCCF f = new LFCCF(8); |
1542 |
|
assertSame(f, f.fork()); |
1543 |
|
f.quietlyJoin(); |
1544 |
|
assertTrue(f.getException() instanceof FJException); |
1551 |
|
* invoke task throws exception when task cancelled |
1552 |
|
*/ |
1553 |
|
public void testCancelledInvokeSingleton() { |
1554 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1555 |
< |
public void realCompute() { |
1556 |
< |
CCF f = new LCCF(null, 8); |
1554 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1555 |
> |
protected void realCompute() { |
1556 |
> |
CCF f = new LCCF(8); |
1557 |
|
assertTrue(f.cancel(true)); |
1558 |
|
try { |
1559 |
|
f.invoke(); |
1569 |
|
* join of a forked task throws exception when task cancelled |
1570 |
|
*/ |
1571 |
|
public void testCancelledForkJoinSingleton() { |
1572 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1573 |
< |
public void realCompute() { |
1574 |
< |
CCF f = new LCCF(null, 8); |
1572 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1573 |
> |
protected void realCompute() { |
1574 |
> |
CCF f = new LCCF(8); |
1575 |
|
assertTrue(f.cancel(true)); |
1576 |
|
assertSame(f, f.fork()); |
1577 |
|
try { |
1588 |
|
* get of a forked task throws exception when task cancelled |
1589 |
|
*/ |
1590 |
|
public void testCancelledForkGetSingleton() { |
1591 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1592 |
< |
public void realCompute() throws Exception { |
1593 |
< |
CCF f = new LCCF(null, 8); |
1591 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1592 |
> |
protected void realCompute() throws Exception { |
1593 |
> |
CCF f = new LCCF(8); |
1594 |
|
assertTrue(f.cancel(true)); |
1595 |
|
assertSame(f, f.fork()); |
1596 |
|
try { |
1607 |
|
* timed get of a forked task throws exception when task cancelled |
1608 |
|
*/ |
1609 |
|
public void testCancelledForkTimedGetSingleton() throws Exception { |
1610 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1611 |
< |
public void realCompute() throws Exception { |
1612 |
< |
CCF f = new LCCF(null, 8); |
1610 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1611 |
> |
protected void realCompute() throws Exception { |
1612 |
> |
CCF f = new LCCF(8); |
1613 |
|
assertTrue(f.cancel(true)); |
1614 |
|
assertSame(f, f.fork()); |
1615 |
|
try { |
1626 |
|
* quietlyJoin of a forked task returns when task cancelled |
1627 |
|
*/ |
1628 |
|
public void testCancelledForkQuietlyJoinSingleton() { |
1629 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1630 |
< |
public void realCompute() { |
1631 |
< |
CCF f = new LCCF(null, 8); |
1629 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1630 |
> |
protected void realCompute() { |
1631 |
> |
CCF f = new LCCF(8); |
1632 |
|
assertTrue(f.cancel(true)); |
1633 |
|
assertSame(f, f.fork()); |
1634 |
|
f.quietlyJoin(); |
1641 |
|
* invoke task throws exception after invoking completeExceptionally |
1642 |
|
*/ |
1643 |
|
public void testCompleteExceptionallySingleton() { |
1644 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1645 |
< |
public void realCompute() { |
1646 |
< |
CCF f = new LCCF(null, 8); |
1647 |
< |
f.completeExceptionally(new FJException()); |
1648 |
< |
try { |
1649 |
< |
f.invoke(); |
1650 |
< |
shouldThrow(); |
1651 |
< |
} catch (FJException success) { |
1576 |
< |
checkCompletedAbnormally(f, success); |
1577 |
< |
} |
1644 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1645 |
> |
protected void realCompute() { |
1646 |
> |
CCF n = new LCCF(8); |
1647 |
> |
CCF f = new LCCF(n, 8); |
1648 |
> |
FJException ex = new FJException(); |
1649 |
> |
f.completeExceptionally(ex); |
1650 |
> |
f.checkCompletedExceptionally(ex); |
1651 |
> |
n.checkCompletedExceptionally(ex); |
1652 |
|
}}; |
1653 |
|
testInvokeOnPool(singletonPool(), a); |
1654 |
|
} |
1657 |
|
* invokeAll(t1, t2) invokes all task arguments |
1658 |
|
*/ |
1659 |
|
public void testInvokeAll2Singleton() { |
1660 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1661 |
< |
public void realCompute() { |
1662 |
< |
CCF f = new LCCF(null, 8); |
1663 |
< |
CCF g = new LCCF(null, 9); |
1660 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1661 |
> |
protected void realCompute() { |
1662 |
> |
CCF f = new LCCF(8); |
1663 |
> |
CCF g = new LCCF(9); |
1664 |
|
invokeAll(f, g); |
1665 |
|
assertEquals(21, f.number); |
1666 |
|
assertEquals(34, g.number); |
1674 |
|
* invokeAll(tasks) with 1 argument invokes task |
1675 |
|
*/ |
1676 |
|
public void testInvokeAll1Singleton() { |
1677 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1678 |
< |
public void realCompute() { |
1679 |
< |
CCF f = new LCCF(null, 8); |
1677 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1678 |
> |
protected void realCompute() { |
1679 |
> |
CCF f = new LCCF(8); |
1680 |
|
invokeAll(f); |
1681 |
|
checkCompletedNormally(f); |
1682 |
|
assertEquals(21, f.number); |
1688 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
1689 |
|
*/ |
1690 |
|
public void testInvokeAll3Singleton() { |
1691 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1692 |
< |
public void realCompute() { |
1693 |
< |
CCF f = new LCCF(null, 8); |
1694 |
< |
CCF g = new LCCF(null, 9); |
1695 |
< |
CCF h = new LCCF(null, 7); |
1691 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1692 |
> |
protected void realCompute() { |
1693 |
> |
CCF f = new LCCF(8); |
1694 |
> |
CCF g = new LCCF(9); |
1695 |
> |
CCF h = new LCCF(7); |
1696 |
|
invokeAll(f, g, h); |
1697 |
|
assertEquals(21, f.number); |
1698 |
|
assertEquals(34, g.number); |
1708 |
|
* invokeAll(collection) invokes all tasks in the collection |
1709 |
|
*/ |
1710 |
|
public void testInvokeAllCollectionSingleton() { |
1711 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1712 |
< |
public void realCompute() { |
1713 |
< |
CCF f = new LCCF(null, 8); |
1714 |
< |
CCF g = new LCCF(null, 9); |
1715 |
< |
CCF h = new LCCF(null, 7); |
1711 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1712 |
> |
protected void realCompute() { |
1713 |
> |
CCF f = new LCCF(8); |
1714 |
> |
CCF g = new LCCF(9); |
1715 |
> |
CCF h = new LCCF(7); |
1716 |
|
HashSet set = new HashSet(); |
1717 |
|
set.add(f); |
1718 |
|
set.add(g); |
1732 |
|
* invokeAll(tasks) with any null task throws NPE |
1733 |
|
*/ |
1734 |
|
public void testInvokeAllNPESingleton() { |
1735 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1736 |
< |
public void realCompute() { |
1737 |
< |
CCF f = new LCCF(null, 8); |
1738 |
< |
CCF g = new LCCF(null, 9); |
1735 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1736 |
> |
protected void realCompute() { |
1737 |
> |
CCF f = new LCCF(8); |
1738 |
> |
CCF g = new LCCF(9); |
1739 |
|
CCF h = null; |
1740 |
|
try { |
1741 |
|
invokeAll(f, g, h); |
1749 |
|
* invokeAll(t1, t2) throw exception if any task does |
1750 |
|
*/ |
1751 |
|
public void testAbnormalInvokeAll2Singleton() { |
1752 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1753 |
< |
public void realCompute() { |
1754 |
< |
CCF f = new LCCF(null, 8); |
1755 |
< |
FailingCCF g = new LFCCF(null, 9); |
1752 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1753 |
> |
protected void realCompute() { |
1754 |
> |
CCF f = new LCCF(8); |
1755 |
> |
FailingCCF g = new LFCCF(9); |
1756 |
|
try { |
1757 |
|
invokeAll(f, g); |
1758 |
|
shouldThrow(); |
1767 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
1768 |
|
*/ |
1769 |
|
public void testAbnormalInvokeAll1Singleton() { |
1770 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1771 |
< |
public void realCompute() { |
1772 |
< |
FailingCCF g = new LFCCF(null, 9); |
1770 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1771 |
> |
protected void realCompute() { |
1772 |
> |
FailingCCF g = new LFCCF(9); |
1773 |
|
try { |
1774 |
|
invokeAll(g); |
1775 |
|
shouldThrow(); |
1784 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1785 |
|
*/ |
1786 |
|
public void testAbnormalInvokeAll3Singleton() { |
1787 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1788 |
< |
public void realCompute() { |
1789 |
< |
CCF f = new LCCF(null, 8); |
1790 |
< |
FailingCCF g = new LFCCF(null, 9); |
1791 |
< |
CCF h = new LCCF(null, 7); |
1787 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1788 |
> |
protected void realCompute() { |
1789 |
> |
CCF f = new LCCF(8); |
1790 |
> |
FailingCCF g = new LFCCF(9); |
1791 |
> |
CCF h = new LCCF(7); |
1792 |
|
try { |
1793 |
|
invokeAll(f, g, h); |
1794 |
|
shouldThrow(); |
1800 |
|
} |
1801 |
|
|
1802 |
|
/** |
1803 |
< |
* invokeAll(collection) throws exception if any task does |
1803 |
> |
* invokeAll(collection) throws exception if any task does |
1804 |
|
*/ |
1805 |
|
public void testAbnormalInvokeAllCollectionSingleton() { |
1806 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1807 |
< |
public void realCompute() { |
1808 |
< |
FailingCCF f = new LFCCF(null, 8); |
1809 |
< |
CCF g = new LCCF(null, 9); |
1810 |
< |
CCF h = new LCCF(null, 7); |
1806 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1807 |
> |
protected void realCompute() { |
1808 |
> |
FailingCCF f = new LFCCF(8); |
1809 |
> |
CCF g = new LCCF(9); |
1810 |
> |
CCF h = new LCCF(7); |
1811 |
|
HashSet set = new HashSet(); |
1812 |
|
set.add(f); |
1813 |
|
set.add(g); |