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 |
+ |
NoopCC(CountedCompleter p, int initialPendingCount) { |
282 |
+ |
super(p, initialPendingCount); |
283 |
+ |
} |
284 |
+ |
protected void realCompute() {} |
285 |
|
} |
286 |
|
|
287 |
|
/** |
288 |
|
* A newly constructed CountedCompleter is not completed; |
289 |
< |
* complete() causes completion. |
289 |
> |
* complete() causes completion. pendingCount is ignored. |
290 |
|
*/ |
291 |
|
public void testComplete() { |
292 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
293 |
< |
assertFalse(a.isDone()); |
294 |
< |
assertFalse(a.isCompletedNormally()); |
295 |
< |
assertFalse(a.isCompletedAbnormally()); |
296 |
< |
assertFalse(a.isCancelled()); |
297 |
< |
assertNull(a.getException()); |
298 |
< |
assertNull(a.getRawResult()); |
299 |
< |
assertFalse(a.post); |
300 |
< |
a.complete(null); |
301 |
< |
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()); |
292 |
> |
for (Object x : new Object[] { Boolean.TRUE, null }) { |
293 |
> |
for (int pendingCount : new int[] { 0, 42 }) { |
294 |
> |
testComplete(new NoopCC(), x, pendingCount); |
295 |
> |
testComplete(new NoopCC(new NoopCC()), x, pendingCount); |
296 |
> |
} |
297 |
> |
} |
298 |
> |
} |
299 |
> |
void testComplete(NoopCC cc, Object x, int pendingCount) { |
300 |
> |
cc.setPendingCount(pendingCount); |
301 |
> |
cc.checkCompletes(x); |
302 |
|
} |
303 |
|
|
304 |
|
/** |
305 |
|
* completeExceptionally completes exceptionally |
306 |
|
*/ |
307 |
|
public void testCompleteExceptionally() { |
308 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
309 |
< |
assertFalse(a.isDone()); |
310 |
< |
assertFalse(a.isCompletedNormally()); |
311 |
< |
assertFalse(a.isCompletedAbnormally()); |
312 |
< |
assertFalse(a.isCancelled()); |
313 |
< |
assertNull(a.getException()); |
314 |
< |
assertNull(a.getRawResult()); |
315 |
< |
assertFalse(a.post); |
316 |
< |
a.completeExceptionally(new FJException()); |
317 |
< |
assertFalse(a.post); |
318 |
< |
assertTrue(a.isDone()); |
319 |
< |
assertFalse(a.isCompletedNormally()); |
320 |
< |
assertTrue(a.isCompletedAbnormally()); |
321 |
< |
assertFalse(a.isCancelled()); |
322 |
< |
assertTrue(a.getException() instanceof FJException); |
323 |
< |
assertNull(a.getRawResult()); |
308 |
> |
new NoopCC() |
309 |
> |
.checkCompletesExceptionally(new FJException()); |
310 |
> |
new NoopCC(new NoopCC()) |
311 |
> |
.checkCompletesExceptionally(new FJException()); |
312 |
> |
} |
313 |
> |
|
314 |
> |
/** |
315 |
> |
* completeExceptionally(null) surprisingly has the same effect as |
316 |
> |
* completeExceptionally(new RuntimeException()) |
317 |
> |
*/ |
318 |
> |
public void testCompleteExceptionally_null() { |
319 |
> |
NoopCC a = new NoopCC(); |
320 |
> |
a.completeExceptionally(null); |
321 |
> |
try { |
322 |
> |
a.invoke(); |
323 |
> |
shouldThrow(); |
324 |
> |
} catch (RuntimeException success) { |
325 |
> |
assertSame(success.getClass(), RuntimeException.class); |
326 |
> |
assertNull(success.getCause()); |
327 |
> |
a.checkCompletedExceptionally(success); |
328 |
> |
} |
329 |
|
} |
330 |
|
|
331 |
|
/** |
332 |
|
* setPendingCount sets the reported pending count |
333 |
|
*/ |
334 |
|
public void testSetPendingCount() { |
335 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
335 |
> |
NoopCC a = new NoopCC(); |
336 |
|
assertEquals(0, a.getPendingCount()); |
337 |
|
a.setPendingCount(1); |
338 |
|
assertEquals(1, a.getPendingCount()); |
344 |
|
* addToPendingCount adds to the reported pending count |
345 |
|
*/ |
346 |
|
public void testAddToPendingCount() { |
347 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
347 |
> |
NoopCC a = new NoopCC(); |
348 |
|
assertEquals(0, a.getPendingCount()); |
349 |
|
a.addToPendingCount(1); |
350 |
|
assertEquals(1, a.getPendingCount()); |
356 |
|
* decrementPendingCountUnlessZero decrements reported pending |
357 |
|
* count unless zero |
358 |
|
*/ |
359 |
< |
public void testDecrementPendingCount() { |
360 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
361 |
< |
assertEquals(0, a.getPendingCount()); |
362 |
< |
a.addToPendingCount(1); |
359 |
> |
public void testDecrementPendingCountUnlessZero() { |
360 |
> |
NoopCC a = new NoopCC(null, 2); |
361 |
> |
assertEquals(2, a.getPendingCount()); |
362 |
> |
assertEquals(2, a.decrementPendingCountUnlessZero()); |
363 |
|
assertEquals(1, a.getPendingCount()); |
364 |
< |
a.decrementPendingCountUnlessZero(); |
364 |
> |
assertEquals(1, a.decrementPendingCountUnlessZero()); |
365 |
> |
assertEquals(0, a.getPendingCount()); |
366 |
> |
assertEquals(0, a.decrementPendingCountUnlessZero()); |
367 |
|
assertEquals(0, a.getPendingCount()); |
368 |
< |
a.decrementPendingCountUnlessZero(); |
368 |
> |
} |
369 |
> |
|
370 |
> |
/** |
371 |
> |
* compareAndSetPendingCount compares and sets the reported |
372 |
> |
* pending count |
373 |
> |
*/ |
374 |
> |
public void testCompareAndSetPendingCount() { |
375 |
> |
NoopCC a = new NoopCC(); |
376 |
|
assertEquals(0, a.getPendingCount()); |
377 |
+ |
assertTrue(a.compareAndSetPendingCount(0, 1)); |
378 |
+ |
assertEquals(1, a.getPendingCount()); |
379 |
+ |
assertTrue(a.compareAndSetPendingCount(1, 2)); |
380 |
+ |
assertEquals(2, a.getPendingCount()); |
381 |
+ |
assertFalse(a.compareAndSetPendingCount(1, 3)); |
382 |
+ |
assertEquals(2, a.getPendingCount()); |
383 |
|
} |
384 |
|
|
385 |
|
/** |
386 |
|
* getCompleter returns parent or null if at root |
387 |
|
*/ |
388 |
|
public void testGetCompleter() { |
389 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
389 |
> |
NoopCC a = new NoopCC(); |
390 |
|
assertNull(a.getCompleter()); |
391 |
< |
CountedCompleter b = new NoopCountedCompleter(a); |
392 |
< |
assertEquals(a, b.getCompleter()); |
391 |
> |
CountedCompleter b = new NoopCC(a); |
392 |
> |
assertSame(a, b.getCompleter()); |
393 |
> |
CountedCompleter c = new NoopCC(b); |
394 |
> |
assertSame(b, c.getCompleter()); |
395 |
|
} |
396 |
|
|
397 |
|
/** |
398 |
|
* getRoot returns self if no parent, else parent's root |
399 |
|
*/ |
400 |
|
public void testGetRoot() { |
401 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
402 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
403 |
< |
assertEquals(a, a.getRoot()); |
404 |
< |
assertEquals(a, b.getRoot()); |
401 |
> |
NoopCC a = new NoopCC(); |
402 |
> |
NoopCC b = new NoopCC(a); |
403 |
> |
NoopCC c = new NoopCC(b); |
404 |
> |
assertSame(a, a.getRoot()); |
405 |
> |
assertSame(a, b.getRoot()); |
406 |
> |
assertSame(a, c.getRoot()); |
407 |
|
} |
408 |
|
|
409 |
|
/** |
410 |
< |
* tryComplete causes completion if pending count is zero |
410 |
> |
* tryComplete decrements pending count unless zero, in which case |
411 |
> |
* causes completion |
412 |
|
*/ |
413 |
< |
public void testTryComplete1() { |
414 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
413 |
> |
public void testTryComplete() { |
414 |
> |
NoopCC a = new NoopCC(); |
415 |
|
assertEquals(0, a.getPendingCount()); |
416 |
+ |
int n = 3; |
417 |
+ |
a.setPendingCount(n); |
418 |
+ |
for (; n > 0; n--) { |
419 |
+ |
assertEquals(n, a.getPendingCount()); |
420 |
+ |
a.tryComplete(); |
421 |
+ |
a.checkIncomplete(); |
422 |
+ |
assertEquals(n - 1, a.getPendingCount()); |
423 |
+ |
} |
424 |
|
a.tryComplete(); |
425 |
< |
assertTrue(a.post); |
426 |
< |
assertTrue(a.isDone()); |
425 |
> |
assertEquals(0, a.computeN()); |
426 |
> |
assertEquals(1, a.onCompletionN()); |
427 |
> |
assertEquals(0, a.onExceptionalCompletionN()); |
428 |
> |
assertEquals(0, a.setRawResultN()); |
429 |
> |
checkCompletedNormally(a); |
430 |
|
} |
431 |
|
|
432 |
|
/** |
433 |
< |
* propagateCompletion causes completion without invoking |
434 |
< |
* onCompletion if pending count is zero |
433 |
> |
* propagateCompletion decrements pending count unless zero, in |
434 |
> |
* which case causes completion, without invoking onCompletion |
435 |
|
*/ |
436 |
|
public void testPropagateCompletion() { |
437 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
437 |
> |
NoopCC a = new NoopCC(); |
438 |
|
assertEquals(0, a.getPendingCount()); |
439 |
+ |
int n = 3; |
440 |
+ |
a.setPendingCount(n); |
441 |
+ |
for (; n > 0; n--) { |
442 |
+ |
assertEquals(n, a.getPendingCount()); |
443 |
+ |
a.propagateCompletion(); |
444 |
+ |
a.checkIncomplete(); |
445 |
+ |
assertEquals(n - 1, a.getPendingCount()); |
446 |
+ |
} |
447 |
|
a.propagateCompletion(); |
448 |
< |
assertFalse(a.post); |
449 |
< |
assertTrue(a.isDone()); |
450 |
< |
} |
451 |
< |
|
452 |
< |
/** |
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()); |
448 |
> |
assertEquals(0, a.computeN()); |
449 |
> |
assertEquals(0, a.onCompletionN()); |
450 |
> |
assertEquals(0, a.onExceptionalCompletionN()); |
451 |
> |
assertEquals(0, a.setRawResultN()); |
452 |
> |
checkCompletedNormally(a); |
453 |
|
} |
454 |
|
|
455 |
|
/** |
456 |
|
* firstComplete returns this if pending count is zero else null |
457 |
|
*/ |
458 |
|
public void testFirstComplete() { |
459 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
459 |
> |
NoopCC a = new NoopCC(); |
460 |
|
a.setPendingCount(1); |
461 |
|
assertNull(a.firstComplete()); |
462 |
< |
assertEquals(a, a.firstComplete()); |
462 |
> |
a.checkIncomplete(); |
463 |
> |
assertSame(a, a.firstComplete()); |
464 |
> |
a.checkIncomplete(); |
465 |
|
} |
466 |
|
|
467 |
|
/** |
469 |
|
* zero else null |
470 |
|
*/ |
471 |
|
public void testNextComplete() { |
472 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
473 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
472 |
> |
NoopCC a = new NoopCC(); |
473 |
> |
NoopCC b = new NoopCC(a); |
474 |
|
a.setPendingCount(1); |
475 |
|
b.setPendingCount(1); |
476 |
|
assertNull(b.firstComplete()); |
477 |
< |
CountedCompleter c = b.firstComplete(); |
478 |
< |
assertEquals(b, c); |
479 |
< |
CountedCompleter d = c.nextComplete(); |
480 |
< |
assertNull(d); |
481 |
< |
CountedCompleter e = c.nextComplete(); |
482 |
< |
assertEquals(a, e); |
477 |
> |
assertSame(b, b.firstComplete()); |
478 |
> |
assertNull(b.nextComplete()); |
479 |
> |
a.checkIncomplete(); |
480 |
> |
b.checkIncomplete(); |
481 |
> |
assertSame(a, b.nextComplete()); |
482 |
> |
assertSame(a, b.nextComplete()); |
483 |
> |
a.checkIncomplete(); |
484 |
> |
b.checkIncomplete(); |
485 |
> |
assertNull(a.nextComplete()); |
486 |
> |
b.checkIncomplete(); |
487 |
> |
checkCompletedNormally(a); |
488 |
|
} |
489 |
|
|
490 |
|
/** |
491 |
|
* quietlyCompleteRoot completes root task |
492 |
|
*/ |
493 |
|
public void testQuietlyCompleteRoot() { |
494 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
495 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
494 |
> |
NoopCC a = new NoopCC(); |
495 |
> |
NoopCC b = new NoopCC(a); |
496 |
> |
NoopCC c = new NoopCC(b); |
497 |
|
a.setPendingCount(1); |
498 |
|
b.setPendingCount(1); |
499 |
< |
b.quietlyCompleteRoot(); |
499 |
> |
c.setPendingCount(1); |
500 |
> |
c.quietlyCompleteRoot(); |
501 |
|
assertTrue(a.isDone()); |
502 |
|
assertFalse(b.isDone()); |
503 |
+ |
assertFalse(c.isDone()); |
504 |
|
} |
505 |
|
|
506 |
|
// Invocation tests use some interdependent task classes |
507 |
|
// to better test propagation etc |
508 |
|
|
509 |
< |
|
510 |
< |
// Version of Fibonacci with different classes for left vs right forks |
511 |
< |
abstract static class CCF extends CountedCompleter { |
509 |
> |
/** |
510 |
> |
* Version of Fibonacci with different classes for left vs right forks |
511 |
> |
*/ |
512 |
> |
abstract class CCF extends CheckedCC { |
513 |
|
int number; |
514 |
|
int rnumber; |
515 |
|
|
518 |
|
this.number = n; |
519 |
|
} |
520 |
|
|
521 |
< |
public final void compute() { |
429 |
< |
CountedCompleter p; |
521 |
> |
protected final void realCompute() { |
522 |
|
CCF f = this; |
523 |
|
int n = number; |
524 |
|
while (n >= 2) { |
525 |
|
new RCCF(f, n - 2).fork(); |
526 |
|
f = new LCCF(f, --n); |
527 |
|
} |
528 |
< |
f.number = n; |
437 |
< |
f.onCompletion(f); |
438 |
< |
if ((p = f.getCompleter()) != null) |
439 |
< |
p.tryComplete(); |
440 |
< |
else |
441 |
< |
f.quietlyComplete(); |
528 |
> |
f.complete(null); |
529 |
|
} |
530 |
|
} |
531 |
|
|
532 |
< |
static final class LCCF extends CCF { |
532 |
> |
final class LCCF extends CCF { |
533 |
> |
public LCCF(int n) { this(null, n); } |
534 |
|
public LCCF(CountedCompleter parent, int n) { |
535 |
|
super(parent, n); |
536 |
|
} |
537 |
|
public final void onCompletion(CountedCompleter caller) { |
538 |
+ |
super.onCompletion(caller); |
539 |
|
CCF p = (CCF)getCompleter(); |
540 |
|
int n = number + rnumber; |
541 |
|
if (p != null) |
544 |
|
number = n; |
545 |
|
} |
546 |
|
} |
547 |
< |
static final class RCCF extends CCF { |
547 |
> |
final class RCCF extends CCF { |
548 |
|
public RCCF(CountedCompleter parent, int n) { |
549 |
|
super(parent, n); |
550 |
|
} |
551 |
|
public final void onCompletion(CountedCompleter caller) { |
552 |
+ |
super.onCompletion(caller); |
553 |
|
CCF p = (CCF)getCompleter(); |
554 |
|
int n = number + rnumber; |
555 |
|
if (p != null) |
560 |
|
} |
561 |
|
|
562 |
|
// Version of CCF with forced failure in left completions |
563 |
< |
abstract static class FailingCCF extends CountedCompleter { |
563 |
> |
abstract class FailingCCF extends CheckedCC { |
564 |
|
int number; |
565 |
|
int rnumber; |
566 |
|
|
569 |
|
this.number = n; |
570 |
|
} |
571 |
|
|
572 |
< |
public final void compute() { |
483 |
< |
CountedCompleter p; |
572 |
> |
protected final void realCompute() { |
573 |
|
FailingCCF f = this; |
574 |
|
int n = number; |
575 |
|
while (n >= 2) { |
576 |
|
new RFCCF(f, n - 2).fork(); |
577 |
|
f = new LFCCF(f, --n); |
578 |
|
} |
579 |
< |
f.number = n; |
491 |
< |
f.onCompletion(f); |
492 |
< |
if ((p = f.getCompleter()) != null) |
493 |
< |
p.tryComplete(); |
494 |
< |
else |
495 |
< |
f.quietlyComplete(); |
579 |
> |
f.complete(null); |
580 |
|
} |
581 |
|
} |
582 |
|
|
583 |
< |
static final class LFCCF extends FailingCCF { |
583 |
> |
final class LFCCF extends FailingCCF { |
584 |
> |
public LFCCF(int n) { this(null, n); } |
585 |
|
public LFCCF(CountedCompleter parent, int n) { |
586 |
|
super(parent, n); |
587 |
|
} |
588 |
|
public final void onCompletion(CountedCompleter caller) { |
589 |
+ |
super.onCompletion(caller); |
590 |
|
FailingCCF p = (FailingCCF)getCompleter(); |
591 |
|
int n = number + rnumber; |
592 |
|
if (p != null) |
595 |
|
number = n; |
596 |
|
} |
597 |
|
} |
598 |
< |
static final class RFCCF extends FailingCCF { |
598 |
> |
final class RFCCF extends FailingCCF { |
599 |
|
public RFCCF(CountedCompleter parent, int n) { |
600 |
|
super(parent, n); |
601 |
|
} |
602 |
|
public final void onCompletion(CountedCompleter caller) { |
603 |
+ |
super.onCompletion(caller); |
604 |
|
completeExceptionally(new FJException()); |
605 |
|
} |
606 |
|
} |
611 |
|
* completed tasks; getRawResult returns null. |
612 |
|
*/ |
613 |
|
public void testInvoke() { |
614 |
< |
ForkJoinTask a = new CheckedFJTask() { |
615 |
< |
public void realCompute() { |
616 |
< |
CCF f = new LCCF(null, 8); |
614 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
615 |
> |
protected void realCompute() { |
616 |
> |
CCF f = new LCCF(8); |
617 |
|
assertNull(f.invoke()); |
618 |
|
assertEquals(21, f.number); |
619 |
|
checkCompletedNormally(f); |
627 |
|
* completed tasks |
628 |
|
*/ |
629 |
|
public void testQuietlyInvoke() { |
630 |
< |
ForkJoinTask a = new CheckedFJTask() { |
631 |
< |
public void realCompute() { |
632 |
< |
CCF f = new LCCF(null, 8); |
630 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
631 |
> |
protected void realCompute() { |
632 |
> |
CCF f = new LCCF(8); |
633 |
|
f.quietlyInvoke(); |
634 |
|
assertEquals(21, f.number); |
635 |
|
checkCompletedNormally(f); |
641 |
|
* join of a forked task returns when task completes |
642 |
|
*/ |
643 |
|
public void testForkJoin() { |
644 |
< |
ForkJoinTask a = new CheckedFJTask() { |
645 |
< |
public void realCompute() { |
646 |
< |
CCF f = new LCCF(null, 8); |
644 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
645 |
> |
protected void realCompute() { |
646 |
> |
CCF f = new LCCF(8); |
647 |
|
assertSame(f, f.fork()); |
648 |
|
assertNull(f.join()); |
649 |
|
assertEquals(21, f.number); |
656 |
|
* get of a forked task returns when task completes |
657 |
|
*/ |
658 |
|
public void testForkGet() { |
659 |
< |
ForkJoinTask a = new CheckedFJTask() { |
660 |
< |
public void realCompute() throws Exception { |
661 |
< |
CCF f = new LCCF(null, 8); |
659 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
660 |
> |
protected void realCompute() throws Exception { |
661 |
> |
CCF f = new LCCF(8); |
662 |
|
assertSame(f, f.fork()); |
663 |
|
assertNull(f.get()); |
664 |
|
assertEquals(21, f.number); |
671 |
|
* timed get of a forked task returns when task completes |
672 |
|
*/ |
673 |
|
public void testForkTimedGet() { |
674 |
< |
ForkJoinTask a = new CheckedFJTask() { |
675 |
< |
public void realCompute() throws Exception { |
676 |
< |
CCF f = new LCCF(null, 8); |
674 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
675 |
> |
protected void realCompute() throws Exception { |
676 |
> |
CCF f = new LCCF(8); |
677 |
|
assertSame(f, f.fork()); |
678 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
679 |
|
assertEquals(21, f.number); |
686 |
|
* timed get with null time unit throws NPE |
687 |
|
*/ |
688 |
|
public void testForkTimedGetNPE() { |
689 |
< |
ForkJoinTask a = new CheckedFJTask() { |
690 |
< |
public void realCompute() throws Exception { |
691 |
< |
CCF f = new LCCF(null, 8); |
689 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
690 |
> |
protected void realCompute() throws Exception { |
691 |
> |
CCF f = new LCCF(8); |
692 |
|
assertSame(f, f.fork()); |
693 |
|
try { |
694 |
|
f.get(5L, null); |
702 |
|
* quietlyJoin of a forked task returns when task completes |
703 |
|
*/ |
704 |
|
public void testForkQuietlyJoin() { |
705 |
< |
ForkJoinTask a = new CheckedFJTask() { |
706 |
< |
public void realCompute() { |
707 |
< |
CCF f = new LCCF(null, 8); |
705 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
706 |
> |
protected void realCompute() { |
707 |
> |
CCF f = new LCCF(8); |
708 |
|
assertSame(f, f.fork()); |
709 |
|
f.quietlyJoin(); |
710 |
|
assertEquals(21, f.number); |
718 |
|
* getQueuedTaskCount returns 0 when quiescent |
719 |
|
*/ |
720 |
|
public void testForkHelpQuiesce() { |
721 |
< |
ForkJoinTask a = new CheckedFJTask() { |
722 |
< |
public void realCompute() { |
723 |
< |
CCF f = new LCCF(null, 8); |
721 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
722 |
> |
protected void realCompute() { |
723 |
> |
CCF f = new LCCF(8); |
724 |
|
assertSame(f, f.fork()); |
725 |
|
helpQuiesce(); |
726 |
|
assertEquals(21, f.number); |
734 |
|
* invoke task throws exception when task completes abnormally |
735 |
|
*/ |
736 |
|
public void testAbnormalInvoke() { |
737 |
< |
ForkJoinTask a = new CheckedFJTask() { |
738 |
< |
public void realCompute() { |
739 |
< |
FailingCCF f = new LFCCF(null, 8); |
737 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
738 |
> |
protected void realCompute() { |
739 |
> |
FailingCCF f = new LFCCF(8); |
740 |
|
try { |
741 |
|
f.invoke(); |
742 |
|
shouldThrow(); |
751 |
|
* quietlyInvoke task returns when task completes abnormally |
752 |
|
*/ |
753 |
|
public void testAbnormalQuietlyInvoke() { |
754 |
< |
ForkJoinTask a = new CheckedFJTask() { |
755 |
< |
public void realCompute() { |
756 |
< |
FailingCCF f = new LFCCF(null, 8); |
754 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
755 |
> |
protected void realCompute() { |
756 |
> |
FailingCCF f = new LFCCF(8); |
757 |
|
f.quietlyInvoke(); |
758 |
|
assertTrue(f.getException() instanceof FJException); |
759 |
|
checkCompletedAbnormally(f, f.getException()); |
765 |
|
* join of a forked task throws exception when task completes abnormally |
766 |
|
*/ |
767 |
|
public void testAbnormalForkJoin() { |
768 |
< |
ForkJoinTask a = new CheckedFJTask() { |
769 |
< |
public void realCompute() { |
770 |
< |
FailingCCF f = new LFCCF(null, 8); |
768 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
769 |
> |
protected void realCompute() { |
770 |
> |
FailingCCF f = new LFCCF(8); |
771 |
|
assertSame(f, f.fork()); |
772 |
|
try { |
773 |
|
f.join(); |
783 |
|
* get of a forked task throws exception when task completes abnormally |
784 |
|
*/ |
785 |
|
public void testAbnormalForkGet() { |
786 |
< |
ForkJoinTask a = new CheckedFJTask() { |
787 |
< |
public void realCompute() throws Exception { |
788 |
< |
FailingCCF f = new LFCCF(null, 8); |
786 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
787 |
> |
protected void realCompute() throws Exception { |
788 |
> |
FailingCCF f = new LFCCF(8); |
789 |
|
assertSame(f, f.fork()); |
790 |
|
try { |
791 |
|
f.get(); |
803 |
|
* timed get of a forked task throws exception when task completes abnormally |
804 |
|
*/ |
805 |
|
public void testAbnormalForkTimedGet() { |
806 |
< |
ForkJoinTask a = new CheckedFJTask() { |
807 |
< |
public void realCompute() throws Exception { |
808 |
< |
FailingCCF f = new LFCCF(null, 8); |
806 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
807 |
> |
protected void realCompute() throws Exception { |
808 |
> |
FailingCCF f = new LFCCF(8); |
809 |
|
assertSame(f, f.fork()); |
810 |
|
try { |
811 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
823 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
824 |
|
*/ |
825 |
|
public void testAbnormalForkQuietlyJoin() { |
826 |
< |
ForkJoinTask a = new CheckedFJTask() { |
827 |
< |
public void realCompute() { |
828 |
< |
FailingCCF f = new LFCCF(null, 8); |
826 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
827 |
> |
protected void realCompute() { |
828 |
> |
FailingCCF f = new LFCCF(8); |
829 |
|
assertSame(f, f.fork()); |
830 |
|
f.quietlyJoin(); |
831 |
|
assertTrue(f.getException() instanceof FJException); |
838 |
|
* invoke task throws exception when task cancelled |
839 |
|
*/ |
840 |
|
public void testCancelledInvoke() { |
841 |
< |
ForkJoinTask a = new CheckedFJTask() { |
842 |
< |
public void realCompute() { |
843 |
< |
CCF f = new LCCF(null, 8); |
841 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
842 |
> |
protected void realCompute() { |
843 |
> |
CCF f = new LCCF(8); |
844 |
|
assertTrue(f.cancel(true)); |
845 |
|
try { |
846 |
|
f.invoke(); |
856 |
|
* join of a forked task throws exception when task cancelled |
857 |
|
*/ |
858 |
|
public void testCancelledForkJoin() { |
859 |
< |
ForkJoinTask a = new CheckedFJTask() { |
860 |
< |
public void realCompute() { |
861 |
< |
CCF f = new LCCF(null, 8); |
859 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
860 |
> |
protected void realCompute() { |
861 |
> |
CCF f = new LCCF(8); |
862 |
|
assertTrue(f.cancel(true)); |
863 |
|
assertSame(f, f.fork()); |
864 |
|
try { |
875 |
|
* get of a forked task throws exception when task cancelled |
876 |
|
*/ |
877 |
|
public void testCancelledForkGet() { |
878 |
< |
ForkJoinTask a = new CheckedFJTask() { |
879 |
< |
public void realCompute() throws Exception { |
880 |
< |
CCF f = new LCCF(null, 8); |
878 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
879 |
> |
protected void realCompute() throws Exception { |
880 |
> |
CCF f = new LCCF(8); |
881 |
|
assertTrue(f.cancel(true)); |
882 |
|
assertSame(f, f.fork()); |
883 |
|
try { |
894 |
|
* timed get of a forked task throws exception when task cancelled |
895 |
|
*/ |
896 |
|
public void testCancelledForkTimedGet() throws Exception { |
897 |
< |
ForkJoinTask a = new CheckedFJTask() { |
898 |
< |
public void realCompute() throws Exception { |
899 |
< |
CCF f = new LCCF(null, 8); |
897 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
898 |
> |
protected void realCompute() throws Exception { |
899 |
> |
CCF f = new LCCF(8); |
900 |
|
assertTrue(f.cancel(true)); |
901 |
|
assertSame(f, f.fork()); |
902 |
|
try { |
913 |
|
* quietlyJoin of a forked task returns when task cancelled |
914 |
|
*/ |
915 |
|
public void testCancelledForkQuietlyJoin() { |
916 |
< |
ForkJoinTask a = new CheckedFJTask() { |
917 |
< |
public void realCompute() { |
918 |
< |
CCF f = new LCCF(null, 8); |
916 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
917 |
> |
protected void realCompute() { |
918 |
> |
CCF f = new LCCF(8); |
919 |
|
assertTrue(f.cancel(true)); |
920 |
|
assertSame(f, f.fork()); |
921 |
|
f.quietlyJoin(); |
929 |
|
*/ |
930 |
|
public void testGetPool() { |
931 |
|
final ForkJoinPool mainPool = mainPool(); |
932 |
< |
ForkJoinTask a = new CheckedFJTask() { |
933 |
< |
public void realCompute() { |
932 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
933 |
> |
protected void realCompute() { |
934 |
|
assertSame(mainPool, getPool()); |
935 |
|
}}; |
936 |
|
testInvokeOnPool(mainPool, a); |
940 |
|
* getPool of non-FJ task returns null |
941 |
|
*/ |
942 |
|
public void testGetPool2() { |
943 |
< |
ForkJoinTask a = new CheckedFJTask() { |
944 |
< |
public void realCompute() { |
943 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
944 |
> |
protected void realCompute() { |
945 |
|
assertNull(getPool()); |
946 |
|
}}; |
947 |
|
assertNull(a.invoke()); |
951 |
|
* inForkJoinPool of executing task returns true |
952 |
|
*/ |
953 |
|
public void testInForkJoinPool() { |
954 |
< |
ForkJoinTask a = new CheckedFJTask() { |
955 |
< |
public void realCompute() { |
954 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
955 |
> |
protected void realCompute() { |
956 |
|
assertTrue(inForkJoinPool()); |
957 |
|
}}; |
958 |
|
testInvokeOnPool(mainPool(), a); |
962 |
|
* inForkJoinPool of non-FJ task returns false |
963 |
|
*/ |
964 |
|
public void testInForkJoinPool2() { |
965 |
< |
ForkJoinTask a = new CheckedFJTask() { |
966 |
< |
public void realCompute() { |
965 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
966 |
> |
protected void realCompute() { |
967 |
|
assertFalse(inForkJoinPool()); |
968 |
|
}}; |
969 |
|
assertNull(a.invoke()); |
973 |
|
* setRawResult(null) succeeds |
974 |
|
*/ |
975 |
|
public void testSetRawResult() { |
976 |
< |
ForkJoinTask a = new CheckedFJTask() { |
977 |
< |
public void realCompute() { |
976 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
977 |
> |
protected void realCompute() { |
978 |
|
setRawResult(null); |
979 |
|
assertNull(getRawResult()); |
980 |
|
}}; |
985 |
|
* invoke task throws exception after invoking completeExceptionally |
986 |
|
*/ |
987 |
|
public void testCompleteExceptionally2() { |
988 |
< |
ForkJoinTask a = new CheckedFJTask() { |
989 |
< |
public void realCompute() { |
990 |
< |
CCF f = new LCCF(null, 8); |
991 |
< |
f.completeExceptionally(new FJException()); |
992 |
< |
try { |
993 |
< |
f.invoke(); |
994 |
< |
shouldThrow(); |
995 |
< |
} catch (FJException success) { |
909 |
< |
checkCompletedAbnormally(f, success); |
910 |
< |
} |
988 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
989 |
> |
protected void realCompute() { |
990 |
> |
CCF n = new LCCF(8); |
991 |
> |
CCF f = new LCCF(n, 8); |
992 |
> |
FJException ex = new FJException(); |
993 |
> |
f.completeExceptionally(ex); |
994 |
> |
f.checkCompletedExceptionally(ex); |
995 |
> |
n.checkCompletedExceptionally(ex); |
996 |
|
}}; |
997 |
|
testInvokeOnPool(mainPool(), a); |
998 |
|
} |
1001 |
|
* invokeAll(t1, t2) invokes all task arguments |
1002 |
|
*/ |
1003 |
|
public void testInvokeAll2() { |
1004 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1005 |
< |
public void realCompute() { |
1006 |
< |
CCF f = new LCCF(null, 8); |
1007 |
< |
CCF g = new LCCF(null, 9); |
1004 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1005 |
> |
protected void realCompute() { |
1006 |
> |
CCF f = new LCCF(8); |
1007 |
> |
CCF g = new LCCF(9); |
1008 |
|
invokeAll(f, g); |
1009 |
|
assertEquals(21, f.number); |
1010 |
|
assertEquals(34, g.number); |
1018 |
|
* invokeAll(tasks) with 1 argument invokes task |
1019 |
|
*/ |
1020 |
|
public void testInvokeAll1() { |
1021 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1022 |
< |
public void realCompute() { |
1023 |
< |
CCF f = new LCCF(null, 8); |
1021 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1022 |
> |
protected void realCompute() { |
1023 |
> |
CCF f = new LCCF(8); |
1024 |
|
invokeAll(f); |
1025 |
|
checkCompletedNormally(f); |
1026 |
|
assertEquals(21, f.number); |
1032 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
1033 |
|
*/ |
1034 |
|
public void testInvokeAll3() { |
1035 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1036 |
< |
public void realCompute() { |
1037 |
< |
CCF f = new LCCF(null, 8); |
1038 |
< |
CCF g = new LCCF(null, 9); |
1039 |
< |
CCF h = new LCCF(null, 7); |
1035 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1036 |
> |
protected void realCompute() { |
1037 |
> |
CCF f = new LCCF(8); |
1038 |
> |
CCF g = new LCCF(9); |
1039 |
> |
CCF h = new LCCF(7); |
1040 |
|
invokeAll(f, g, h); |
1041 |
|
assertEquals(21, f.number); |
1042 |
|
assertEquals(34, g.number); |
1052 |
|
* invokeAll(collection) invokes all tasks in the collection |
1053 |
|
*/ |
1054 |
|
public void testInvokeAllCollection() { |
1055 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1056 |
< |
public void realCompute() { |
1057 |
< |
CCF f = new LCCF(null, 8); |
1058 |
< |
CCF g = new LCCF(null, 9); |
1059 |
< |
CCF h = new LCCF(null, 7); |
1055 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1056 |
> |
protected void realCompute() { |
1057 |
> |
CCF f = new LCCF(8); |
1058 |
> |
CCF g = new LCCF(9); |
1059 |
> |
CCF h = new LCCF(7); |
1060 |
|
HashSet set = new HashSet(); |
1061 |
|
set.add(f); |
1062 |
|
set.add(g); |
1076 |
|
* invokeAll(tasks) with any null task throws NPE |
1077 |
|
*/ |
1078 |
|
public void testInvokeAllNPE() { |
1079 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1080 |
< |
public void realCompute() { |
1081 |
< |
CCF f = new LCCF(null, 8); |
1082 |
< |
CCF g = new LCCF(null, 9); |
1079 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1080 |
> |
protected void realCompute() { |
1081 |
> |
CCF f = new LCCF(8); |
1082 |
> |
CCF g = new LCCF(9); |
1083 |
|
CCF h = null; |
1084 |
|
try { |
1085 |
|
invokeAll(f, g, h); |
1093 |
|
* invokeAll(t1, t2) throw exception if any task does |
1094 |
|
*/ |
1095 |
|
public void testAbnormalInvokeAll2() { |
1096 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1097 |
< |
public void realCompute() { |
1098 |
< |
CCF f = new LCCF(null, 8); |
1099 |
< |
FailingCCF g = new LFCCF(null, 9); |
1096 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1097 |
> |
protected void realCompute() { |
1098 |
> |
CCF f = new LCCF(8); |
1099 |
> |
FailingCCF g = new LFCCF(9); |
1100 |
|
try { |
1101 |
|
invokeAll(f, g); |
1102 |
|
shouldThrow(); |
1111 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
1112 |
|
*/ |
1113 |
|
public void testAbnormalInvokeAll1() { |
1114 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1115 |
< |
public void realCompute() { |
1116 |
< |
FailingCCF g = new LFCCF(null, 9); |
1114 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1115 |
> |
protected void realCompute() { |
1116 |
> |
FailingCCF g = new LFCCF(9); |
1117 |
|
try { |
1118 |
|
invokeAll(g); |
1119 |
|
shouldThrow(); |
1128 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1129 |
|
*/ |
1130 |
|
public void testAbnormalInvokeAll3() { |
1131 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1132 |
< |
public void realCompute() { |
1133 |
< |
CCF f = new LCCF(null, 8); |
1134 |
< |
FailingCCF g = new LFCCF(null, 9); |
1135 |
< |
CCF h = new LCCF(null, 7); |
1131 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1132 |
> |
protected void realCompute() { |
1133 |
> |
CCF f = new LCCF(8); |
1134 |
> |
FailingCCF g = new LFCCF(9); |
1135 |
> |
CCF h = new LCCF(7); |
1136 |
|
try { |
1137 |
|
invokeAll(f, g, h); |
1138 |
|
shouldThrow(); |
1144 |
|
} |
1145 |
|
|
1146 |
|
/** |
1147 |
< |
* invokeAll(collection) throws exception if any task does |
1147 |
> |
* invokeAll(collection) throws exception if any task does |
1148 |
|
*/ |
1149 |
|
public void testAbnormalInvokeAllCollection() { |
1150 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1151 |
< |
public void realCompute() { |
1152 |
< |
FailingCCF f = new LFCCF(null, 8); |
1153 |
< |
CCF g = new LCCF(null, 9); |
1154 |
< |
CCF h = new LCCF(null, 7); |
1150 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1151 |
> |
protected void realCompute() { |
1152 |
> |
FailingCCF f = new LFCCF(8); |
1153 |
> |
CCF g = new LCCF(9); |
1154 |
> |
CCF h = new LCCF(7); |
1155 |
|
HashSet set = new HashSet(); |
1156 |
|
set.add(f); |
1157 |
|
set.add(g); |
1171 |
|
* and suppresses execution |
1172 |
|
*/ |
1173 |
|
public void testTryUnfork() { |
1174 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1175 |
< |
public void realCompute() { |
1176 |
< |
CCF g = new LCCF(null, 9); |
1174 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1175 |
> |
protected void realCompute() { |
1176 |
> |
CCF g = new LCCF(9); |
1177 |
|
assertSame(g, g.fork()); |
1178 |
< |
CCF f = new LCCF(null, 8); |
1178 |
> |
CCF f = new LCCF(8); |
1179 |
|
assertSame(f, f.fork()); |
1180 |
|
assertTrue(f.tryUnfork()); |
1181 |
|
helpQuiesce(); |
1190 |
|
* there are more tasks than threads |
1191 |
|
*/ |
1192 |
|
public void testGetSurplusQueuedTaskCount() { |
1193 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1194 |
< |
public void realCompute() { |
1195 |
< |
CCF h = new LCCF(null, 7); |
1193 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1194 |
> |
protected void realCompute() { |
1195 |
> |
CCF h = new LCCF(7); |
1196 |
|
assertSame(h, h.fork()); |
1197 |
< |
CCF g = new LCCF(null, 9); |
1197 |
> |
CCF g = new LCCF(9); |
1198 |
|
assertSame(g, g.fork()); |
1199 |
< |
CCF f = new LCCF(null, 8); |
1199 |
> |
CCF f = new LCCF(8); |
1200 |
|
assertSame(f, f.fork()); |
1201 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
1202 |
|
helpQuiesce(); |
1212 |
|
* peekNextLocalTask returns most recent unexecuted task. |
1213 |
|
*/ |
1214 |
|
public void testPeekNextLocalTask() { |
1215 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1216 |
< |
public void realCompute() { |
1217 |
< |
CCF g = new LCCF(null, 9); |
1215 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1216 |
> |
protected void realCompute() { |
1217 |
> |
CCF g = new LCCF(9); |
1218 |
|
assertSame(g, g.fork()); |
1219 |
< |
CCF f = new LCCF(null, 8); |
1219 |
> |
CCF f = new LCCF(8); |
1220 |
|
assertSame(f, f.fork()); |
1221 |
|
assertSame(f, peekNextLocalTask()); |
1222 |
|
assertNull(f.join()); |
1232 |
|
* executing it |
1233 |
|
*/ |
1234 |
|
public void testPollNextLocalTask() { |
1235 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1236 |
< |
public void realCompute() { |
1237 |
< |
CCF g = new LCCF(null, 9); |
1235 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1236 |
> |
protected void realCompute() { |
1237 |
> |
CCF g = new LCCF(9); |
1238 |
|
assertSame(g, g.fork()); |
1239 |
< |
CCF f = new LCCF(null, 8); |
1239 |
> |
CCF f = new LCCF(8); |
1240 |
|
assertSame(f, f.fork()); |
1241 |
|
assertSame(f, pollNextLocalTask()); |
1242 |
|
helpQuiesce(); |
1251 |
|
* pollTask returns an unexecuted task without executing it |
1252 |
|
*/ |
1253 |
|
public void testPollTask() { |
1254 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1255 |
< |
public void realCompute() { |
1256 |
< |
CCF g = new LCCF(null, 9); |
1254 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1255 |
> |
protected void realCompute() { |
1256 |
> |
CCF g = new LCCF(9); |
1257 |
|
assertSame(g, g.fork()); |
1258 |
< |
CCF f = new LCCF(null, 8); |
1258 |
> |
CCF f = new LCCF(8); |
1259 |
|
assertSame(f, f.fork()); |
1260 |
|
assertSame(f, pollTask()); |
1261 |
|
helpQuiesce(); |
1269 |
|
* peekNextLocalTask returns least recent unexecuted task in async mode |
1270 |
|
*/ |
1271 |
|
public void testPeekNextLocalTaskAsync() { |
1272 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1273 |
< |
public void realCompute() { |
1274 |
< |
CCF g = new LCCF(null, 9); |
1272 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1273 |
> |
protected void realCompute() { |
1274 |
> |
CCF g = new LCCF(9); |
1275 |
|
assertSame(g, g.fork()); |
1276 |
< |
CCF f = new LCCF(null, 8); |
1276 |
> |
CCF f = new LCCF(8); |
1277 |
|
assertSame(f, f.fork()); |
1278 |
|
assertSame(g, peekNextLocalTask()); |
1279 |
|
assertNull(f.join()); |
1290 |
|
* executing it, in async mode |
1291 |
|
*/ |
1292 |
|
public void testPollNextLocalTaskAsync() { |
1293 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1294 |
< |
public void realCompute() { |
1295 |
< |
CCF g = new LCCF(null, 9); |
1293 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1294 |
> |
protected void realCompute() { |
1295 |
> |
CCF g = new LCCF(9); |
1296 |
|
assertSame(g, g.fork()); |
1297 |
< |
CCF f = new LCCF(null, 8); |
1297 |
> |
CCF f = new LCCF(8); |
1298 |
|
assertSame(f, f.fork()); |
1299 |
|
assertSame(g, pollNextLocalTask()); |
1300 |
|
helpQuiesce(); |
1310 |
|
* async mode |
1311 |
|
*/ |
1312 |
|
public void testPollTaskAsync() { |
1313 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1314 |
< |
public void realCompute() { |
1315 |
< |
CCF g = new LCCF(null, 9); |
1313 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1314 |
> |
protected void realCompute() { |
1315 |
> |
CCF g = new LCCF(9); |
1316 |
|
assertSame(g, g.fork()); |
1317 |
< |
CCF f = new LCCF(null, 8); |
1317 |
> |
CCF f = new LCCF(8); |
1318 |
|
assertSame(f, f.fork()); |
1319 |
|
assertSame(g, pollTask()); |
1320 |
|
helpQuiesce(); |
1333 |
|
* completed tasks; getRawResult returns null. |
1334 |
|
*/ |
1335 |
|
public void testInvokeSingleton() { |
1336 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1337 |
< |
public void realCompute() { |
1338 |
< |
CCF f = new LCCF(null, 8); |
1336 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1337 |
> |
protected void realCompute() { |
1338 |
> |
CCF f = new LCCF(8); |
1339 |
|
assertNull(f.invoke()); |
1340 |
|
assertEquals(21, f.number); |
1341 |
|
checkCompletedNormally(f); |
1349 |
|
* completed tasks |
1350 |
|
*/ |
1351 |
|
public void testQuietlyInvokeSingleton() { |
1352 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1353 |
< |
public void realCompute() { |
1354 |
< |
CCF f = new LCCF(null, 8); |
1352 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1353 |
> |
protected void realCompute() { |
1354 |
> |
CCF f = new LCCF(8); |
1355 |
|
f.quietlyInvoke(); |
1356 |
|
assertEquals(21, f.number); |
1357 |
|
checkCompletedNormally(f); |
1363 |
|
* join of a forked task returns when task completes |
1364 |
|
*/ |
1365 |
|
public void testForkJoinSingleton() { |
1366 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1367 |
< |
public void realCompute() { |
1368 |
< |
CCF f = new LCCF(null, 8); |
1366 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1367 |
> |
protected void realCompute() { |
1368 |
> |
CCF f = new LCCF(8); |
1369 |
|
assertSame(f, f.fork()); |
1370 |
|
assertNull(f.join()); |
1371 |
|
assertEquals(21, f.number); |
1378 |
|
* get of a forked task returns when task completes |
1379 |
|
*/ |
1380 |
|
public void testForkGetSingleton() { |
1381 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1382 |
< |
public void realCompute() throws Exception { |
1383 |
< |
CCF f = new LCCF(null, 8); |
1381 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1382 |
> |
protected void realCompute() throws Exception { |
1383 |
> |
CCF f = new LCCF(8); |
1384 |
|
assertSame(f, f.fork()); |
1385 |
|
assertNull(f.get()); |
1386 |
|
assertEquals(21, f.number); |
1393 |
|
* timed get of a forked task returns when task completes |
1394 |
|
*/ |
1395 |
|
public void testForkTimedGetSingleton() { |
1396 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1397 |
< |
public void realCompute() throws Exception { |
1398 |
< |
CCF f = new LCCF(null, 8); |
1396 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1397 |
> |
protected void realCompute() throws Exception { |
1398 |
> |
CCF f = new LCCF(8); |
1399 |
|
assertSame(f, f.fork()); |
1400 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1401 |
|
assertEquals(21, f.number); |
1408 |
|
* timed get with null time unit throws NPE |
1409 |
|
*/ |
1410 |
|
public void testForkTimedGetNPESingleton() { |
1411 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1412 |
< |
public void realCompute() throws Exception { |
1413 |
< |
CCF f = new LCCF(null, 8); |
1411 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1412 |
> |
protected void realCompute() throws Exception { |
1413 |
> |
CCF f = new LCCF(8); |
1414 |
|
assertSame(f, f.fork()); |
1415 |
|
try { |
1416 |
|
f.get(5L, null); |
1424 |
|
* quietlyJoin of a forked task returns when task completes |
1425 |
|
*/ |
1426 |
|
public void testForkQuietlyJoinSingleton() { |
1427 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1428 |
< |
public void realCompute() { |
1429 |
< |
CCF f = new LCCF(null, 8); |
1427 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1428 |
> |
protected void realCompute() { |
1429 |
> |
CCF f = new LCCF(8); |
1430 |
|
assertSame(f, f.fork()); |
1431 |
|
f.quietlyJoin(); |
1432 |
|
assertEquals(21, f.number); |
1440 |
|
* getQueuedTaskCount returns 0 when quiescent |
1441 |
|
*/ |
1442 |
|
public void testForkHelpQuiesceSingleton() { |
1443 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1444 |
< |
public void realCompute() { |
1445 |
< |
CCF f = new LCCF(null, 8); |
1443 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1444 |
> |
protected void realCompute() { |
1445 |
> |
CCF f = new LCCF(8); |
1446 |
|
assertSame(f, f.fork()); |
1447 |
|
helpQuiesce(); |
1448 |
|
assertEquals(0, getQueuedTaskCount()); |
1456 |
|
* invoke task throws exception when task completes abnormally |
1457 |
|
*/ |
1458 |
|
public void testAbnormalInvokeSingleton() { |
1459 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1460 |
< |
public void realCompute() { |
1461 |
< |
FailingCCF f = new LFCCF(null, 8); |
1459 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1460 |
> |
protected void realCompute() { |
1461 |
> |
FailingCCF f = new LFCCF(8); |
1462 |
|
try { |
1463 |
|
f.invoke(); |
1464 |
|
shouldThrow(); |
1473 |
|
* quietlyInvoke task returns when task completes abnormally |
1474 |
|
*/ |
1475 |
|
public void testAbnormalQuietlyInvokeSingleton() { |
1476 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1477 |
< |
public void realCompute() { |
1478 |
< |
FailingCCF f = new LFCCF(null, 8); |
1476 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1477 |
> |
protected void realCompute() { |
1478 |
> |
FailingCCF f = new LFCCF(8); |
1479 |
|
f.quietlyInvoke(); |
1480 |
|
assertTrue(f.getException() instanceof FJException); |
1481 |
|
checkCompletedAbnormally(f, f.getException()); |
1487 |
|
* join of a forked task throws exception when task completes abnormally |
1488 |
|
*/ |
1489 |
|
public void testAbnormalForkJoinSingleton() { |
1490 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1491 |
< |
public void realCompute() { |
1492 |
< |
FailingCCF f = new LFCCF(null, 8); |
1490 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1491 |
> |
protected void realCompute() { |
1492 |
> |
FailingCCF f = new LFCCF(8); |
1493 |
|
assertSame(f, f.fork()); |
1494 |
|
try { |
1495 |
|
f.join(); |
1505 |
|
* get of a forked task throws exception when task completes abnormally |
1506 |
|
*/ |
1507 |
|
public void testAbnormalForkGetSingleton() { |
1508 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1509 |
< |
public void realCompute() throws Exception { |
1510 |
< |
FailingCCF f = new LFCCF(null, 8); |
1508 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1509 |
> |
protected void realCompute() throws Exception { |
1510 |
> |
FailingCCF f = new LFCCF(8); |
1511 |
|
assertSame(f, f.fork()); |
1512 |
|
try { |
1513 |
|
f.get(); |
1525 |
|
* timed get of a forked task throws exception when task completes abnormally |
1526 |
|
*/ |
1527 |
|
public void testAbnormalForkTimedGetSingleton() { |
1528 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1529 |
< |
public void realCompute() throws Exception { |
1530 |
< |
FailingCCF f = new LFCCF(null, 8); |
1528 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1529 |
> |
protected void realCompute() throws Exception { |
1530 |
> |
FailingCCF f = new LFCCF(8); |
1531 |
|
assertSame(f, f.fork()); |
1532 |
|
try { |
1533 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
1545 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
1546 |
|
*/ |
1547 |
|
public void testAbnormalForkQuietlyJoinSingleton() { |
1548 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1549 |
< |
public void realCompute() { |
1550 |
< |
FailingCCF f = new LFCCF(null, 8); |
1548 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1549 |
> |
protected void realCompute() { |
1550 |
> |
FailingCCF f = new LFCCF(8); |
1551 |
|
assertSame(f, f.fork()); |
1552 |
|
f.quietlyJoin(); |
1553 |
|
assertTrue(f.getException() instanceof FJException); |
1560 |
|
* invoke task throws exception when task cancelled |
1561 |
|
*/ |
1562 |
|
public void testCancelledInvokeSingleton() { |
1563 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1564 |
< |
public void realCompute() { |
1565 |
< |
CCF f = new LCCF(null, 8); |
1563 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1564 |
> |
protected void realCompute() { |
1565 |
> |
CCF f = new LCCF(8); |
1566 |
|
assertTrue(f.cancel(true)); |
1567 |
|
try { |
1568 |
|
f.invoke(); |
1578 |
|
* join of a forked task throws exception when task cancelled |
1579 |
|
*/ |
1580 |
|
public void testCancelledForkJoinSingleton() { |
1581 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1582 |
< |
public void realCompute() { |
1583 |
< |
CCF f = new LCCF(null, 8); |
1581 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1582 |
> |
protected void realCompute() { |
1583 |
> |
CCF f = new LCCF(8); |
1584 |
|
assertTrue(f.cancel(true)); |
1585 |
|
assertSame(f, f.fork()); |
1586 |
|
try { |
1597 |
|
* get of a forked task throws exception when task cancelled |
1598 |
|
*/ |
1599 |
|
public void testCancelledForkGetSingleton() { |
1600 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1601 |
< |
public void realCompute() throws Exception { |
1602 |
< |
CCF f = new LCCF(null, 8); |
1600 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1601 |
> |
protected void realCompute() throws Exception { |
1602 |
> |
CCF f = new LCCF(8); |
1603 |
|
assertTrue(f.cancel(true)); |
1604 |
|
assertSame(f, f.fork()); |
1605 |
|
try { |
1616 |
|
* timed get of a forked task throws exception when task cancelled |
1617 |
|
*/ |
1618 |
|
public void testCancelledForkTimedGetSingleton() throws Exception { |
1619 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1620 |
< |
public void realCompute() throws Exception { |
1621 |
< |
CCF f = new LCCF(null, 8); |
1619 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1620 |
> |
protected void realCompute() throws Exception { |
1621 |
> |
CCF f = new LCCF(8); |
1622 |
|
assertTrue(f.cancel(true)); |
1623 |
|
assertSame(f, f.fork()); |
1624 |
|
try { |
1635 |
|
* quietlyJoin of a forked task returns when task cancelled |
1636 |
|
*/ |
1637 |
|
public void testCancelledForkQuietlyJoinSingleton() { |
1638 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1639 |
< |
public void realCompute() { |
1640 |
< |
CCF f = new LCCF(null, 8); |
1638 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1639 |
> |
protected void realCompute() { |
1640 |
> |
CCF f = new LCCF(8); |
1641 |
|
assertTrue(f.cancel(true)); |
1642 |
|
assertSame(f, f.fork()); |
1643 |
|
f.quietlyJoin(); |
1650 |
|
* invoke task throws exception after invoking completeExceptionally |
1651 |
|
*/ |
1652 |
|
public void testCompleteExceptionallySingleton() { |
1653 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1654 |
< |
public void realCompute() { |
1655 |
< |
CCF f = new LCCF(null, 8); |
1656 |
< |
f.completeExceptionally(new FJException()); |
1657 |
< |
try { |
1658 |
< |
f.invoke(); |
1659 |
< |
shouldThrow(); |
1660 |
< |
} catch (FJException success) { |
1576 |
< |
checkCompletedAbnormally(f, success); |
1577 |
< |
} |
1653 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1654 |
> |
protected void realCompute() { |
1655 |
> |
CCF n = new LCCF(8); |
1656 |
> |
CCF f = new LCCF(n, 8); |
1657 |
> |
FJException ex = new FJException(); |
1658 |
> |
f.completeExceptionally(ex); |
1659 |
> |
f.checkCompletedExceptionally(ex); |
1660 |
> |
n.checkCompletedExceptionally(ex); |
1661 |
|
}}; |
1662 |
|
testInvokeOnPool(singletonPool(), a); |
1663 |
|
} |
1666 |
|
* invokeAll(t1, t2) invokes all task arguments |
1667 |
|
*/ |
1668 |
|
public void testInvokeAll2Singleton() { |
1669 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1670 |
< |
public void realCompute() { |
1671 |
< |
CCF f = new LCCF(null, 8); |
1672 |
< |
CCF g = new LCCF(null, 9); |
1669 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1670 |
> |
protected void realCompute() { |
1671 |
> |
CCF f = new LCCF(8); |
1672 |
> |
CCF g = new LCCF(9); |
1673 |
|
invokeAll(f, g); |
1674 |
|
assertEquals(21, f.number); |
1675 |
|
assertEquals(34, g.number); |
1683 |
|
* invokeAll(tasks) with 1 argument invokes task |
1684 |
|
*/ |
1685 |
|
public void testInvokeAll1Singleton() { |
1686 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1687 |
< |
public void realCompute() { |
1688 |
< |
CCF f = new LCCF(null, 8); |
1686 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1687 |
> |
protected void realCompute() { |
1688 |
> |
CCF f = new LCCF(8); |
1689 |
|
invokeAll(f); |
1690 |
|
checkCompletedNormally(f); |
1691 |
|
assertEquals(21, f.number); |
1697 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
1698 |
|
*/ |
1699 |
|
public void testInvokeAll3Singleton() { |
1700 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1701 |
< |
public void realCompute() { |
1702 |
< |
CCF f = new LCCF(null, 8); |
1703 |
< |
CCF g = new LCCF(null, 9); |
1704 |
< |
CCF h = new LCCF(null, 7); |
1700 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1701 |
> |
protected void realCompute() { |
1702 |
> |
CCF f = new LCCF(8); |
1703 |
> |
CCF g = new LCCF(9); |
1704 |
> |
CCF h = new LCCF(7); |
1705 |
|
invokeAll(f, g, h); |
1706 |
|
assertEquals(21, f.number); |
1707 |
|
assertEquals(34, g.number); |
1717 |
|
* invokeAll(collection) invokes all tasks in the collection |
1718 |
|
*/ |
1719 |
|
public void testInvokeAllCollectionSingleton() { |
1720 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1721 |
< |
public void realCompute() { |
1722 |
< |
CCF f = new LCCF(null, 8); |
1723 |
< |
CCF g = new LCCF(null, 9); |
1724 |
< |
CCF h = new LCCF(null, 7); |
1720 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1721 |
> |
protected void realCompute() { |
1722 |
> |
CCF f = new LCCF(8); |
1723 |
> |
CCF g = new LCCF(9); |
1724 |
> |
CCF h = new LCCF(7); |
1725 |
|
HashSet set = new HashSet(); |
1726 |
|
set.add(f); |
1727 |
|
set.add(g); |
1741 |
|
* invokeAll(tasks) with any null task throws NPE |
1742 |
|
*/ |
1743 |
|
public void testInvokeAllNPESingleton() { |
1744 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1745 |
< |
public void realCompute() { |
1746 |
< |
CCF f = new LCCF(null, 8); |
1747 |
< |
CCF g = new LCCF(null, 9); |
1744 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1745 |
> |
protected void realCompute() { |
1746 |
> |
CCF f = new LCCF(8); |
1747 |
> |
CCF g = new LCCF(9); |
1748 |
|
CCF h = null; |
1749 |
|
try { |
1750 |
|
invokeAll(f, g, h); |
1758 |
|
* invokeAll(t1, t2) throw exception if any task does |
1759 |
|
*/ |
1760 |
|
public void testAbnormalInvokeAll2Singleton() { |
1761 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1762 |
< |
public void realCompute() { |
1763 |
< |
CCF f = new LCCF(null, 8); |
1764 |
< |
FailingCCF g = new LFCCF(null, 9); |
1761 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1762 |
> |
protected void realCompute() { |
1763 |
> |
CCF f = new LCCF(8); |
1764 |
> |
FailingCCF g = new LFCCF(9); |
1765 |
|
try { |
1766 |
|
invokeAll(f, g); |
1767 |
|
shouldThrow(); |
1776 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
1777 |
|
*/ |
1778 |
|
public void testAbnormalInvokeAll1Singleton() { |
1779 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1780 |
< |
public void realCompute() { |
1781 |
< |
FailingCCF g = new LFCCF(null, 9); |
1779 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1780 |
> |
protected void realCompute() { |
1781 |
> |
FailingCCF g = new LFCCF(9); |
1782 |
|
try { |
1783 |
|
invokeAll(g); |
1784 |
|
shouldThrow(); |
1793 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1794 |
|
*/ |
1795 |
|
public void testAbnormalInvokeAll3Singleton() { |
1796 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1797 |
< |
public void realCompute() { |
1798 |
< |
CCF f = new LCCF(null, 8); |
1799 |
< |
FailingCCF g = new LFCCF(null, 9); |
1800 |
< |
CCF h = new LCCF(null, 7); |
1796 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1797 |
> |
protected void realCompute() { |
1798 |
> |
CCF f = new LCCF(8); |
1799 |
> |
FailingCCF g = new LFCCF(9); |
1800 |
> |
CCF h = new LCCF(7); |
1801 |
|
try { |
1802 |
|
invokeAll(f, g, h); |
1803 |
|
shouldThrow(); |
1809 |
|
} |
1810 |
|
|
1811 |
|
/** |
1812 |
< |
* invokeAll(collection) throws exception if any task does |
1812 |
> |
* invokeAll(collection) throws exception if any task does |
1813 |
|
*/ |
1814 |
|
public void testAbnormalInvokeAllCollectionSingleton() { |
1815 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1816 |
< |
public void realCompute() { |
1817 |
< |
FailingCCF f = new LFCCF(null, 8); |
1818 |
< |
CCF g = new LCCF(null, 9); |
1819 |
< |
CCF h = new LCCF(null, 7); |
1815 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1816 |
> |
protected void realCompute() { |
1817 |
> |
FailingCCF f = new LFCCF(8); |
1818 |
> |
CCF g = new LCCF(9); |
1819 |
> |
CCF h = new LCCF(7); |
1820 |
|
HashSet set = new HashSet(); |
1821 |
|
set.add(f); |
1822 |
|
set.add(g); |