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; |
16 |
< |
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.ThreadLocalRandom; |
17 |
|
import java.util.concurrent.TimeoutException; |
18 |
< |
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; |
19 |
< |
import static java.util.concurrent.TimeUnit.MILLISECONDS; |
20 |
< |
import static java.util.concurrent.TimeUnit.SECONDS; |
21 |
< |
import java.util.HashSet; |
22 |
< |
import junit.framework.*; |
18 |
> |
import java.util.concurrent.atomic.AtomicInteger; |
19 |
> |
import java.util.concurrent.atomic.AtomicReference; |
20 |
> |
|
21 |
> |
import junit.framework.Test; |
22 |
> |
import junit.framework.TestSuite; |
23 |
|
|
24 |
|
public class CountedCompleterTest extends JSR166TestCase { |
25 |
|
|
26 |
|
public static void main(String[] args) { |
27 |
< |
junit.textui.TestRunner.run(suite()); |
27 |
> |
main(suite(), args); |
28 |
|
} |
29 |
|
|
30 |
|
public static Test suite() { |
35 |
|
static final int mainPoolSize = |
36 |
|
Math.max(2, Runtime.getRuntime().availableProcessors()); |
37 |
|
|
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 |
– |
|
38 |
|
private static ForkJoinPool mainPool() { |
39 |
|
return new ForkJoinPool(mainPoolSize); |
40 |
|
} |
50 |
|
} |
51 |
|
|
52 |
|
private void testInvokeOnPool(ForkJoinPool pool, ForkJoinTask a) { |
53 |
< |
try { |
53 |
> |
try (PoolCleaner cleaner = cleaner(pool)) { |
54 |
|
assertFalse(a.isDone()); |
55 |
|
assertFalse(a.isCompletedNormally()); |
56 |
|
assertFalse(a.isCompletedAbnormally()); |
66 |
|
assertFalse(a.isCancelled()); |
67 |
|
assertNull(a.getException()); |
68 |
|
assertNull(a.getRawResult()); |
81 |
– |
} finally { |
82 |
– |
joinPool(pool); |
69 |
|
} |
70 |
|
} |
71 |
|
|
84 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
85 |
|
} |
86 |
|
|
87 |
< |
<T> void checkCompletedNormally(CountedCompleter<T> a) { |
102 |
< |
checkCompletedNormally(a, null); |
103 |
< |
} |
104 |
< |
|
105 |
< |
<T> void checkCompletedNormally(CountedCompleter<T> a, T expected) { |
87 |
> |
void checkCompletedNormally(CountedCompleter<?> a) { |
88 |
|
assertTrue(a.isDone()); |
89 |
|
assertFalse(a.isCancelled()); |
90 |
|
assertTrue(a.isCompletedNormally()); |
91 |
|
assertFalse(a.isCompletedAbnormally()); |
92 |
|
assertNull(a.getException()); |
93 |
< |
assertSame(expected, a.getRawResult()); |
93 |
> |
assertNull(a.getRawResult()); |
94 |
|
|
95 |
|
{ |
96 |
|
Thread.currentThread().interrupt(); |
97 |
< |
long t0 = System.nanoTime(); |
98 |
< |
assertSame(expected, a.join()); |
99 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
97 |
> |
long startTime = System.nanoTime(); |
98 |
> |
assertNull(a.join()); |
99 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
100 |
|
Thread.interrupted(); |
101 |
|
} |
102 |
|
|
103 |
|
{ |
104 |
|
Thread.currentThread().interrupt(); |
105 |
< |
long t0 = System.nanoTime(); |
105 |
> |
long startTime = System.nanoTime(); |
106 |
|
a.quietlyJoin(); // should be no-op |
107 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
107 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
108 |
|
Thread.interrupted(); |
109 |
|
} |
110 |
|
|
111 |
|
assertFalse(a.cancel(false)); |
112 |
|
assertFalse(a.cancel(true)); |
113 |
|
try { |
114 |
< |
assertSame(expected, a.get()); |
114 |
> |
assertNull(a.get()); |
115 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
116 |
|
try { |
117 |
< |
assertSame(expected, a.get(5L, SECONDS)); |
117 |
> |
assertNull(a.get(5L, SECONDS)); |
118 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
119 |
|
} |
120 |
|
|
137 |
|
Thread.interrupted(); |
138 |
|
|
139 |
|
{ |
140 |
< |
long t0 = System.nanoTime(); |
140 |
> |
long startTime = System.nanoTime(); |
141 |
|
a.quietlyJoin(); // should be no-op |
142 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
142 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
143 |
|
} |
144 |
|
|
145 |
|
try { |
175 |
|
Thread.interrupted(); |
176 |
|
|
177 |
|
{ |
178 |
< |
long t0 = System.nanoTime(); |
178 |
> |
long startTime = System.nanoTime(); |
179 |
|
a.quietlyJoin(); // should be no-op |
180 |
< |
assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS); |
180 |
> |
assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS); |
181 |
|
} |
182 |
|
|
183 |
|
try { |
193 |
|
} catch (ExecutionException success) { |
194 |
|
assertSame(t.getClass(), success.getCause().getClass()); |
195 |
|
} catch (Throwable fail) { threadUnexpectedException(fail); } |
196 |
+ |
|
197 |
+ |
try { |
198 |
+ |
a.invoke(); |
199 |
+ |
shouldThrow(); |
200 |
+ |
} catch (Throwable success) { |
201 |
+ |
assertSame(t, success); |
202 |
+ |
} |
203 |
|
} |
204 |
|
|
205 |
|
public static final class FJException extends RuntimeException { |
206 |
|
FJException() { super(); } |
207 |
|
} |
208 |
|
|
209 |
< |
static final class NoopCountedCompleter extends CountedCompleter { |
210 |
< |
boolean post; // set true if onCompletion called |
211 |
< |
NoopCountedCompleter() { super(); } |
212 |
< |
NoopCountedCompleter(CountedCompleter p) { super(p); } |
213 |
< |
public void compute() {} |
214 |
< |
public final void onCompletion(CountedCompleter caller) { |
215 |
< |
post = true; |
209 |
> |
abstract class CheckedCC extends CountedCompleter<Object> { |
210 |
> |
final AtomicInteger computeN = new AtomicInteger(0); |
211 |
> |
final AtomicInteger onCompletionN = new AtomicInteger(0); |
212 |
> |
final AtomicInteger onExceptionalCompletionN = new AtomicInteger(0); |
213 |
> |
final AtomicInteger setRawResultN = new AtomicInteger(0); |
214 |
> |
final AtomicReference<Object> rawResult = new AtomicReference<>(null); |
215 |
> |
int computeN() { return computeN.get(); } |
216 |
> |
int onCompletionN() { return onCompletionN.get(); } |
217 |
> |
int onExceptionalCompletionN() { return onExceptionalCompletionN.get(); } |
218 |
> |
int setRawResultN() { return setRawResultN.get(); } |
219 |
> |
|
220 |
> |
CheckedCC() { super(); } |
221 |
> |
CheckedCC(CountedCompleter p) { super(p); } |
222 |
> |
CheckedCC(CountedCompleter p, int n) { super(p, n); } |
223 |
> |
abstract void realCompute(); |
224 |
> |
public final void compute() { |
225 |
> |
computeN.incrementAndGet(); |
226 |
> |
realCompute(); |
227 |
> |
} |
228 |
> |
public void onCompletion(CountedCompleter caller) { |
229 |
> |
onCompletionN.incrementAndGet(); |
230 |
> |
super.onCompletion(caller); |
231 |
> |
} |
232 |
> |
public boolean onExceptionalCompletion(Throwable ex, |
233 |
> |
CountedCompleter caller) { |
234 |
> |
onExceptionalCompletionN.incrementAndGet(); |
235 |
> |
assertNotNull(ex); |
236 |
> |
assertTrue(isCompletedAbnormally()); |
237 |
> |
assertTrue(super.onExceptionalCompletion(ex, caller)); |
238 |
> |
return true; |
239 |
> |
} |
240 |
> |
protected void setRawResult(Object t) { |
241 |
> |
setRawResultN.incrementAndGet(); |
242 |
> |
rawResult.set(t); |
243 |
> |
super.setRawResult(t); |
244 |
> |
} |
245 |
> |
void checkIncomplete() { |
246 |
> |
assertEquals(0, computeN()); |
247 |
> |
assertEquals(0, onCompletionN()); |
248 |
> |
assertEquals(0, onExceptionalCompletionN()); |
249 |
> |
assertEquals(0, setRawResultN()); |
250 |
> |
checkNotDone(this); |
251 |
> |
} |
252 |
> |
void checkCompletes(Object rawResult) { |
253 |
> |
checkIncomplete(); |
254 |
> |
int pendingCount = getPendingCount(); |
255 |
> |
complete(rawResult); |
256 |
> |
assertEquals(pendingCount, getPendingCount()); |
257 |
> |
assertEquals(0, computeN()); |
258 |
> |
assertEquals(1, onCompletionN()); |
259 |
> |
assertEquals(0, onExceptionalCompletionN()); |
260 |
> |
assertEquals(1, setRawResultN()); |
261 |
> |
assertSame(rawResult, this.rawResult.get()); |
262 |
> |
checkCompletedNormally(this); |
263 |
> |
} |
264 |
> |
void checkCompletesExceptionally(Throwable ex) { |
265 |
> |
checkIncomplete(); |
266 |
> |
completeExceptionally(ex); |
267 |
> |
checkCompletedExceptionally(ex); |
268 |
> |
} |
269 |
> |
void checkCompletedExceptionally(Throwable ex) { |
270 |
> |
assertEquals(0, computeN()); |
271 |
> |
assertEquals(0, onCompletionN()); |
272 |
> |
assertEquals(1, onExceptionalCompletionN()); |
273 |
> |
assertEquals(0, setRawResultN()); |
274 |
> |
assertNull(this.rawResult.get()); |
275 |
> |
checkCompletedAbnormally(this, ex); |
276 |
|
} |
277 |
|
} |
278 |
|
|
279 |
+ |
final class NoopCC extends CheckedCC { |
280 |
+ |
NoopCC() { super(); } |
281 |
+ |
NoopCC(CountedCompleter p) { super(p); } |
282 |
+ |
NoopCC(CountedCompleter p, int initialPendingCount) { |
283 |
+ |
super(p, initialPendingCount); |
284 |
+ |
} |
285 |
+ |
protected void realCompute() {} |
286 |
+ |
} |
287 |
+ |
|
288 |
|
/** |
289 |
< |
* A newly constructed CountedCompleter is not completed; |
290 |
< |
* complete() causes completion. |
289 |
> |
* A newly constructed CountedCompleter is not completed; |
290 |
> |
* complete() causes completion. pendingCount is ignored. |
291 |
|
*/ |
292 |
|
public void testComplete() { |
293 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
294 |
< |
assertFalse(a.isDone()); |
295 |
< |
assertFalse(a.isCompletedNormally()); |
296 |
< |
assertFalse(a.isCompletedAbnormally()); |
297 |
< |
assertFalse(a.isCancelled()); |
298 |
< |
assertNull(a.getException()); |
299 |
< |
assertNull(a.getRawResult()); |
300 |
< |
assertFalse(a.post); |
301 |
< |
a.complete(null); |
302 |
< |
assertTrue(a.post); |
303 |
< |
assertTrue(a.isDone()); |
246 |
< |
assertTrue(a.isCompletedNormally()); |
247 |
< |
assertFalse(a.isCompletedAbnormally()); |
248 |
< |
assertFalse(a.isCancelled()); |
249 |
< |
assertNull(a.getException()); |
250 |
< |
assertNull(a.getRawResult()); |
293 |
> |
for (Object x : new Object[] { Boolean.TRUE, null }) { |
294 |
> |
for (int pendingCount : new int[] { 0, 42 }) { |
295 |
> |
testComplete(new NoopCC(), x, pendingCount); |
296 |
> |
testComplete(new NoopCC(new NoopCC()), x, pendingCount); |
297 |
> |
} |
298 |
> |
} |
299 |
> |
} |
300 |
> |
void testComplete(NoopCC cc, Object x, int pendingCount) { |
301 |
> |
cc.setPendingCount(pendingCount); |
302 |
> |
cc.checkCompletes(x); |
303 |
> |
assertEquals(pendingCount, cc.getPendingCount()); |
304 |
|
} |
305 |
|
|
306 |
|
/** |
307 |
|
* completeExceptionally completes exceptionally |
308 |
|
*/ |
309 |
|
public void testCompleteExceptionally() { |
310 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
311 |
< |
assertFalse(a.isDone()); |
312 |
< |
assertFalse(a.isCompletedNormally()); |
313 |
< |
assertFalse(a.isCompletedAbnormally()); |
314 |
< |
assertFalse(a.isCancelled()); |
315 |
< |
assertNull(a.getException()); |
316 |
< |
assertNull(a.getRawResult()); |
317 |
< |
assertFalse(a.post); |
318 |
< |
a.completeExceptionally(new FJException()); |
319 |
< |
assertFalse(a.post); |
320 |
< |
assertTrue(a.isDone()); |
321 |
< |
assertFalse(a.isCompletedNormally()); |
322 |
< |
assertTrue(a.isCompletedAbnormally()); |
323 |
< |
assertFalse(a.isCancelled()); |
324 |
< |
assertTrue(a.getException() instanceof FJException); |
325 |
< |
assertNull(a.getRawResult()); |
310 |
> |
new NoopCC() |
311 |
> |
.checkCompletesExceptionally(new FJException()); |
312 |
> |
new NoopCC(new NoopCC()) |
313 |
> |
.checkCompletesExceptionally(new FJException()); |
314 |
> |
} |
315 |
> |
|
316 |
> |
/** |
317 |
> |
* completeExceptionally(null) surprisingly has the same effect as |
318 |
> |
* completeExceptionally(new RuntimeException()) |
319 |
> |
*/ |
320 |
> |
public void testCompleteExceptionally_null() { |
321 |
> |
NoopCC a = new NoopCC(); |
322 |
> |
a.completeExceptionally(null); |
323 |
> |
try { |
324 |
> |
a.invoke(); |
325 |
> |
shouldThrow(); |
326 |
> |
} catch (RuntimeException success) { |
327 |
> |
assertSame(success.getClass(), RuntimeException.class); |
328 |
> |
assertNull(success.getCause()); |
329 |
> |
a.checkCompletedExceptionally(success); |
330 |
> |
} |
331 |
|
} |
332 |
|
|
333 |
|
/** |
334 |
|
* setPendingCount sets the reported pending count |
335 |
|
*/ |
336 |
|
public void testSetPendingCount() { |
337 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
337 |
> |
NoopCC a = new NoopCC(); |
338 |
|
assertEquals(0, a.getPendingCount()); |
339 |
< |
a.setPendingCount(1); |
340 |
< |
assertEquals(1, a.getPendingCount()); |
341 |
< |
a.setPendingCount(27); |
342 |
< |
assertEquals(27, a.getPendingCount()); |
339 |
> |
int[] vals = { |
340 |
> |
-1, 0, 1, |
341 |
> |
Integer.MIN_VALUE, |
342 |
> |
Integer.MAX_VALUE, |
343 |
> |
}; |
344 |
> |
for (int val : vals) { |
345 |
> |
a.setPendingCount(val); |
346 |
> |
assertEquals(val, a.getPendingCount()); |
347 |
> |
} |
348 |
|
} |
349 |
|
|
350 |
|
/** |
351 |
|
* addToPendingCount adds to the reported pending count |
352 |
|
*/ |
353 |
|
public void testAddToPendingCount() { |
354 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
354 |
> |
NoopCC a = new NoopCC(); |
355 |
|
assertEquals(0, a.getPendingCount()); |
356 |
|
a.addToPendingCount(1); |
357 |
|
assertEquals(1, a.getPendingCount()); |
358 |
|
a.addToPendingCount(27); |
359 |
|
assertEquals(28, a.getPendingCount()); |
360 |
+ |
a.addToPendingCount(-28); |
361 |
+ |
assertEquals(0, a.getPendingCount()); |
362 |
|
} |
363 |
|
|
364 |
|
/** |
365 |
|
* decrementPendingCountUnlessZero decrements reported pending |
366 |
|
* count unless zero |
367 |
|
*/ |
368 |
< |
public void testDecrementPendingCount() { |
369 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
370 |
< |
assertEquals(0, a.getPendingCount()); |
371 |
< |
a.addToPendingCount(1); |
368 |
> |
public void testDecrementPendingCountUnlessZero() { |
369 |
> |
NoopCC a = new NoopCC(null, 2); |
370 |
> |
assertEquals(2, a.getPendingCount()); |
371 |
> |
assertEquals(2, a.decrementPendingCountUnlessZero()); |
372 |
|
assertEquals(1, a.getPendingCount()); |
373 |
< |
a.decrementPendingCountUnlessZero(); |
373 |
> |
assertEquals(1, a.decrementPendingCountUnlessZero()); |
374 |
|
assertEquals(0, a.getPendingCount()); |
375 |
< |
a.decrementPendingCountUnlessZero(); |
375 |
> |
assertEquals(0, a.decrementPendingCountUnlessZero()); |
376 |
|
assertEquals(0, a.getPendingCount()); |
377 |
+ |
a.setPendingCount(-1); |
378 |
+ |
assertEquals(-1, a.decrementPendingCountUnlessZero()); |
379 |
+ |
assertEquals(-2, a.getPendingCount()); |
380 |
+ |
} |
381 |
+ |
|
382 |
+ |
/** |
383 |
+ |
* compareAndSetPendingCount compares and sets the reported |
384 |
+ |
* pending count |
385 |
+ |
*/ |
386 |
+ |
public void testCompareAndSetPendingCount() { |
387 |
+ |
NoopCC a = new NoopCC(); |
388 |
+ |
assertEquals(0, a.getPendingCount()); |
389 |
+ |
assertTrue(a.compareAndSetPendingCount(0, 1)); |
390 |
+ |
assertEquals(1, a.getPendingCount()); |
391 |
+ |
assertTrue(a.compareAndSetPendingCount(1, 2)); |
392 |
+ |
assertEquals(2, a.getPendingCount()); |
393 |
+ |
assertFalse(a.compareAndSetPendingCount(1, 3)); |
394 |
+ |
assertEquals(2, a.getPendingCount()); |
395 |
|
} |
396 |
|
|
397 |
|
/** |
398 |
|
* getCompleter returns parent or null if at root |
399 |
|
*/ |
400 |
|
public void testGetCompleter() { |
401 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
401 |
> |
NoopCC a = new NoopCC(); |
402 |
|
assertNull(a.getCompleter()); |
403 |
< |
CountedCompleter b = new NoopCountedCompleter(a); |
404 |
< |
assertEquals(a, b.getCompleter()); |
403 |
> |
CountedCompleter b = new NoopCC(a); |
404 |
> |
assertSame(a, b.getCompleter()); |
405 |
> |
CountedCompleter c = new NoopCC(b); |
406 |
> |
assertSame(b, c.getCompleter()); |
407 |
|
} |
408 |
< |
|
408 |
> |
|
409 |
|
/** |
410 |
|
* getRoot returns self if no parent, else parent's root |
411 |
|
*/ |
412 |
|
public void testGetRoot() { |
413 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
414 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
415 |
< |
assertEquals(a, a.getRoot()); |
416 |
< |
assertEquals(a, b.getRoot()); |
413 |
> |
NoopCC a = new NoopCC(); |
414 |
> |
NoopCC b = new NoopCC(a); |
415 |
> |
NoopCC c = new NoopCC(b); |
416 |
> |
assertSame(a, a.getRoot()); |
417 |
> |
assertSame(a, b.getRoot()); |
418 |
> |
assertSame(a, c.getRoot()); |
419 |
|
} |
420 |
< |
|
420 |
> |
|
421 |
|
/** |
422 |
< |
* tryComplete causes completion if pending count is zero |
422 |
> |
* tryComplete decrements pending count unless zero, in which case |
423 |
> |
* causes completion |
424 |
|
*/ |
425 |
< |
public void testTryComplete1() { |
426 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
425 |
> |
public void testTryComplete() { |
426 |
> |
NoopCC a = new NoopCC(); |
427 |
|
assertEquals(0, a.getPendingCount()); |
428 |
+ |
int n = 3; |
429 |
+ |
a.setPendingCount(n); |
430 |
+ |
for (; n > 0; n--) { |
431 |
+ |
assertEquals(n, a.getPendingCount()); |
432 |
+ |
a.tryComplete(); |
433 |
+ |
a.checkIncomplete(); |
434 |
+ |
assertEquals(n - 1, a.getPendingCount()); |
435 |
+ |
} |
436 |
|
a.tryComplete(); |
437 |
< |
assertTrue(a.post); |
438 |
< |
assertTrue(a.isDone()); |
437 |
> |
assertEquals(0, a.computeN()); |
438 |
> |
assertEquals(1, a.onCompletionN()); |
439 |
> |
assertEquals(0, a.onExceptionalCompletionN()); |
440 |
> |
assertEquals(0, a.setRawResultN()); |
441 |
> |
checkCompletedNormally(a); |
442 |
|
} |
443 |
|
|
444 |
|
/** |
445 |
< |
* propagateCompletion causes completion without invokein |
446 |
< |
* onCompletion if pending count is zero |
445 |
> |
* propagateCompletion decrements pending count unless zero, in |
446 |
> |
* which case causes completion, without invoking onCompletion |
447 |
|
*/ |
448 |
|
public void testPropagateCompletion() { |
449 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
449 |
> |
NoopCC a = new NoopCC(); |
450 |
|
assertEquals(0, a.getPendingCount()); |
451 |
+ |
int n = 3; |
452 |
+ |
a.setPendingCount(n); |
453 |
+ |
for (; n > 0; n--) { |
454 |
+ |
assertEquals(n, a.getPendingCount()); |
455 |
+ |
a.propagateCompletion(); |
456 |
+ |
a.checkIncomplete(); |
457 |
+ |
assertEquals(n - 1, a.getPendingCount()); |
458 |
+ |
} |
459 |
|
a.propagateCompletion(); |
460 |
< |
assertFalse(a.post); |
461 |
< |
assertTrue(a.isDone()); |
462 |
< |
} |
463 |
< |
|
464 |
< |
/** |
358 |
< |
* tryComplete decrments pending count unless zero |
359 |
< |
*/ |
360 |
< |
public void testTryComplete2() { |
361 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
362 |
< |
assertEquals(0, a.getPendingCount()); |
363 |
< |
a.setPendingCount(1); |
364 |
< |
a.tryComplete(); |
365 |
< |
assertFalse(a.post); |
366 |
< |
assertFalse(a.isDone()); |
367 |
< |
assertEquals(0, a.getPendingCount()); |
368 |
< |
a.tryComplete(); |
369 |
< |
assertTrue(a.post); |
370 |
< |
assertTrue(a.isDone()); |
460 |
> |
assertEquals(0, a.computeN()); |
461 |
> |
assertEquals(0, a.onCompletionN()); |
462 |
> |
assertEquals(0, a.onExceptionalCompletionN()); |
463 |
> |
assertEquals(0, a.setRawResultN()); |
464 |
> |
checkCompletedNormally(a); |
465 |
|
} |
466 |
|
|
467 |
|
/** |
468 |
|
* firstComplete returns this if pending count is zero else null |
469 |
|
*/ |
470 |
|
public void testFirstComplete() { |
471 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
471 |
> |
NoopCC a = new NoopCC(); |
472 |
|
a.setPendingCount(1); |
473 |
|
assertNull(a.firstComplete()); |
474 |
< |
assertEquals(a, a.firstComplete()); |
474 |
> |
a.checkIncomplete(); |
475 |
> |
assertSame(a, a.firstComplete()); |
476 |
> |
a.checkIncomplete(); |
477 |
|
} |
478 |
|
|
479 |
|
/** |
481 |
|
* zero else null |
482 |
|
*/ |
483 |
|
public void testNextComplete() { |
484 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
485 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
484 |
> |
NoopCC a = new NoopCC(); |
485 |
> |
NoopCC b = new NoopCC(a); |
486 |
|
a.setPendingCount(1); |
487 |
|
b.setPendingCount(1); |
488 |
|
assertNull(b.firstComplete()); |
489 |
< |
CountedCompleter c = b.firstComplete(); |
490 |
< |
assertEquals(b, c); |
491 |
< |
CountedCompleter d = c.nextComplete(); |
492 |
< |
assertNull(d); |
493 |
< |
CountedCompleter e = c.nextComplete(); |
494 |
< |
assertEquals(a, e); |
489 |
> |
assertSame(b, b.firstComplete()); |
490 |
> |
assertNull(b.nextComplete()); |
491 |
> |
a.checkIncomplete(); |
492 |
> |
b.checkIncomplete(); |
493 |
> |
assertSame(a, b.nextComplete()); |
494 |
> |
assertSame(a, b.nextComplete()); |
495 |
> |
a.checkIncomplete(); |
496 |
> |
b.checkIncomplete(); |
497 |
> |
assertNull(a.nextComplete()); |
498 |
> |
b.checkIncomplete(); |
499 |
> |
checkCompletedNormally(a); |
500 |
|
} |
501 |
|
|
502 |
|
/** |
503 |
< |
* quietlyCompleteRoot completes root task |
503 |
> |
* quietlyCompleteRoot completes root task and only root task |
504 |
|
*/ |
505 |
|
public void testQuietlyCompleteRoot() { |
506 |
< |
NoopCountedCompleter a = new NoopCountedCompleter(); |
507 |
< |
NoopCountedCompleter b = new NoopCountedCompleter(a); |
506 |
> |
NoopCC a = new NoopCC(); |
507 |
> |
NoopCC b = new NoopCC(a); |
508 |
> |
NoopCC c = new NoopCC(b); |
509 |
|
a.setPendingCount(1); |
510 |
|
b.setPendingCount(1); |
511 |
< |
b.quietlyCompleteRoot(); |
511 |
> |
c.setPendingCount(1); |
512 |
> |
c.quietlyCompleteRoot(); |
513 |
|
assertTrue(a.isDone()); |
514 |
|
assertFalse(b.isDone()); |
515 |
+ |
assertFalse(c.isDone()); |
516 |
|
} |
517 |
|
|
518 |
|
// Invocation tests use some interdependent task classes |
519 |
|
// to better test propagation etc |
520 |
|
|
521 |
< |
|
522 |
< |
// Version of Fibonacci with different classes for left vs right forks |
523 |
< |
static abstract class CCF extends CountedCompleter { |
521 |
> |
/** |
522 |
> |
* Version of Fibonacci with different classes for left vs right forks |
523 |
> |
*/ |
524 |
> |
abstract class CCF extends CheckedCC { |
525 |
|
int number; |
526 |
|
int rnumber; |
527 |
|
|
530 |
|
this.number = n; |
531 |
|
} |
532 |
|
|
533 |
< |
public final void compute() { |
429 |
< |
CountedCompleter p; |
533 |
> |
protected final void realCompute() { |
534 |
|
CCF f = this; |
535 |
|
int n = number; |
536 |
|
while (n >= 2) { |
537 |
|
new RCCF(f, n - 2).fork(); |
538 |
|
f = new LCCF(f, --n); |
539 |
|
} |
540 |
< |
f.number = n; |
437 |
< |
f.onCompletion(f); |
438 |
< |
if ((p = f.getCompleter()) != null) |
439 |
< |
p.tryComplete(); |
440 |
< |
else |
441 |
< |
f.quietlyComplete(); |
540 |
> |
f.complete(null); |
541 |
|
} |
542 |
|
} |
543 |
|
|
544 |
< |
static final class LCCF extends CCF { |
544 |
> |
final class LCCF extends CCF { |
545 |
> |
public LCCF(int n) { this(null, n); } |
546 |
|
public LCCF(CountedCompleter parent, int n) { |
547 |
|
super(parent, n); |
548 |
|
} |
549 |
|
public final void onCompletion(CountedCompleter caller) { |
550 |
+ |
super.onCompletion(caller); |
551 |
|
CCF p = (CCF)getCompleter(); |
552 |
|
int n = number + rnumber; |
553 |
|
if (p != null) |
556 |
|
number = n; |
557 |
|
} |
558 |
|
} |
559 |
< |
static final class RCCF extends CCF { |
559 |
> |
final class RCCF extends CCF { |
560 |
|
public RCCF(CountedCompleter parent, int n) { |
561 |
|
super(parent, n); |
562 |
|
} |
563 |
|
public final void onCompletion(CountedCompleter caller) { |
564 |
+ |
super.onCompletion(caller); |
565 |
|
CCF p = (CCF)getCompleter(); |
566 |
|
int n = number + rnumber; |
567 |
|
if (p != null) |
572 |
|
} |
573 |
|
|
574 |
|
// Version of CCF with forced failure in left completions |
575 |
< |
static abstract class FailingCCF extends CountedCompleter { |
575 |
> |
abstract class FailingCCF extends CheckedCC { |
576 |
|
int number; |
577 |
|
int rnumber; |
578 |
|
|
581 |
|
this.number = n; |
582 |
|
} |
583 |
|
|
584 |
< |
public final void compute() { |
483 |
< |
CountedCompleter p; |
584 |
> |
protected final void realCompute() { |
585 |
|
FailingCCF f = this; |
586 |
|
int n = number; |
587 |
|
while (n >= 2) { |
588 |
|
new RFCCF(f, n - 2).fork(); |
589 |
|
f = new LFCCF(f, --n); |
590 |
|
} |
591 |
< |
f.number = n; |
491 |
< |
f.onCompletion(f); |
492 |
< |
if ((p = f.getCompleter()) != null) |
493 |
< |
p.tryComplete(); |
494 |
< |
else |
495 |
< |
f.quietlyComplete(); |
591 |
> |
f.complete(null); |
592 |
|
} |
593 |
|
} |
594 |
|
|
595 |
< |
static final class LFCCF extends FailingCCF { |
595 |
> |
final class LFCCF extends FailingCCF { |
596 |
> |
public LFCCF(int n) { this(null, n); } |
597 |
|
public LFCCF(CountedCompleter parent, int n) { |
598 |
|
super(parent, n); |
599 |
|
} |
600 |
|
public final void onCompletion(CountedCompleter caller) { |
601 |
+ |
super.onCompletion(caller); |
602 |
|
FailingCCF p = (FailingCCF)getCompleter(); |
603 |
|
int n = number + rnumber; |
604 |
|
if (p != null) |
607 |
|
number = n; |
608 |
|
} |
609 |
|
} |
610 |
< |
static final class RFCCF extends FailingCCF { |
610 |
> |
final class RFCCF extends FailingCCF { |
611 |
|
public RFCCF(CountedCompleter parent, int n) { |
612 |
|
super(parent, n); |
613 |
|
} |
614 |
|
public final void onCompletion(CountedCompleter caller) { |
615 |
+ |
super.onCompletion(caller); |
616 |
|
completeExceptionally(new FJException()); |
617 |
|
} |
618 |
|
} |
619 |
< |
|
619 |
> |
|
620 |
|
/** |
621 |
|
* invoke returns when task completes normally. |
622 |
|
* isCompletedAbnormally and isCancelled return false for normally |
623 |
|
* completed tasks; getRawResult returns null. |
624 |
|
*/ |
625 |
|
public void testInvoke() { |
626 |
< |
ForkJoinTask a = new CheckedFJTask() { |
627 |
< |
public void realCompute() { |
628 |
< |
CCF f = new LCCF(null, 8); |
626 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
627 |
> |
protected void realCompute() { |
628 |
> |
CCF f = new LCCF(8); |
629 |
|
assertNull(f.invoke()); |
630 |
|
assertEquals(21, f.number); |
631 |
|
checkCompletedNormally(f); |
639 |
|
* completed tasks |
640 |
|
*/ |
641 |
|
public void testQuietlyInvoke() { |
642 |
< |
ForkJoinTask a = new CheckedFJTask() { |
643 |
< |
public void realCompute() { |
644 |
< |
CCF f = new LCCF(null, 8); |
642 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
643 |
> |
protected void realCompute() { |
644 |
> |
CCF f = new LCCF(8); |
645 |
|
f.quietlyInvoke(); |
646 |
|
assertEquals(21, f.number); |
647 |
|
checkCompletedNormally(f); |
653 |
|
* join of a forked task returns when task completes |
654 |
|
*/ |
655 |
|
public void testForkJoin() { |
656 |
< |
ForkJoinTask a = new CheckedFJTask() { |
657 |
< |
public void realCompute() { |
658 |
< |
CCF f = new LCCF(null, 8); |
656 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
657 |
> |
protected void realCompute() { |
658 |
> |
CCF f = new LCCF(8); |
659 |
|
assertSame(f, f.fork()); |
660 |
|
assertNull(f.join()); |
661 |
|
assertEquals(21, f.number); |
668 |
|
* get of a forked task returns when task completes |
669 |
|
*/ |
670 |
|
public void testForkGet() { |
671 |
< |
ForkJoinTask a = new CheckedFJTask() { |
672 |
< |
public void realCompute() throws Exception { |
673 |
< |
CCF f = new LCCF(null, 8); |
671 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
672 |
> |
protected void realCompute() throws Exception { |
673 |
> |
CCF f = new LCCF(8); |
674 |
|
assertSame(f, f.fork()); |
675 |
|
assertNull(f.get()); |
676 |
|
assertEquals(21, f.number); |
683 |
|
* timed get of a forked task returns when task completes |
684 |
|
*/ |
685 |
|
public void testForkTimedGet() { |
686 |
< |
ForkJoinTask a = new CheckedFJTask() { |
687 |
< |
public void realCompute() throws Exception { |
688 |
< |
CCF f = new LCCF(null, 8); |
686 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
687 |
> |
protected void realCompute() throws Exception { |
688 |
> |
CCF f = new LCCF(8); |
689 |
|
assertSame(f, f.fork()); |
690 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
691 |
|
assertEquals(21, f.number); |
698 |
|
* timed get with null time unit throws NPE |
699 |
|
*/ |
700 |
|
public void testForkTimedGetNPE() { |
701 |
< |
ForkJoinTask a = new CheckedFJTask() { |
702 |
< |
public void realCompute() throws Exception { |
703 |
< |
CCF f = new LCCF(null, 8); |
701 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
702 |
> |
protected void realCompute() throws Exception { |
703 |
> |
CCF f = new LCCF(8); |
704 |
|
assertSame(f, f.fork()); |
705 |
|
try { |
706 |
|
f.get(5L, null); |
714 |
|
* quietlyJoin of a forked task returns when task completes |
715 |
|
*/ |
716 |
|
public void testForkQuietlyJoin() { |
717 |
< |
ForkJoinTask a = new CheckedFJTask() { |
718 |
< |
public void realCompute() { |
719 |
< |
CCF f = new LCCF(null, 8); |
717 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
718 |
> |
protected void realCompute() { |
719 |
> |
CCF f = new LCCF(8); |
720 |
|
assertSame(f, f.fork()); |
721 |
|
f.quietlyJoin(); |
722 |
|
assertEquals(21, f.number); |
730 |
|
* getQueuedTaskCount returns 0 when quiescent |
731 |
|
*/ |
732 |
|
public void testForkHelpQuiesce() { |
733 |
< |
ForkJoinTask a = new CheckedFJTask() { |
734 |
< |
public void realCompute() { |
735 |
< |
CCF f = new LCCF(null, 8); |
733 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
734 |
> |
protected void realCompute() { |
735 |
> |
CCF f = new LCCF(8); |
736 |
|
assertSame(f, f.fork()); |
737 |
|
helpQuiesce(); |
738 |
|
assertEquals(21, f.number); |
746 |
|
* invoke task throws exception when task completes abnormally |
747 |
|
*/ |
748 |
|
public void testAbnormalInvoke() { |
749 |
< |
ForkJoinTask a = new CheckedFJTask() { |
750 |
< |
public void realCompute() { |
751 |
< |
FailingCCF f = new LFCCF(null, 8); |
749 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
750 |
> |
protected void realCompute() { |
751 |
> |
FailingCCF f = new LFCCF(8); |
752 |
|
try { |
753 |
|
f.invoke(); |
754 |
|
shouldThrow(); |
763 |
|
* quietlyInvoke task returns when task completes abnormally |
764 |
|
*/ |
765 |
|
public void testAbnormalQuietlyInvoke() { |
766 |
< |
ForkJoinTask a = new CheckedFJTask() { |
767 |
< |
public void realCompute() { |
768 |
< |
FailingCCF f = new LFCCF(null, 8); |
766 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
767 |
> |
protected void realCompute() { |
768 |
> |
FailingCCF f = new LFCCF(8); |
769 |
|
f.quietlyInvoke(); |
770 |
|
assertTrue(f.getException() instanceof FJException); |
771 |
|
checkCompletedAbnormally(f, f.getException()); |
777 |
|
* join of a forked task throws exception when task completes abnormally |
778 |
|
*/ |
779 |
|
public void testAbnormalForkJoin() { |
780 |
< |
ForkJoinTask a = new CheckedFJTask() { |
781 |
< |
public void realCompute() { |
782 |
< |
FailingCCF f = new LFCCF(null, 8); |
780 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
781 |
> |
protected void realCompute() { |
782 |
> |
FailingCCF f = new LFCCF(8); |
783 |
|
assertSame(f, f.fork()); |
784 |
|
try { |
785 |
|
f.join(); |
795 |
|
* get of a forked task throws exception when task completes abnormally |
796 |
|
*/ |
797 |
|
public void testAbnormalForkGet() { |
798 |
< |
ForkJoinTask a = new CheckedFJTask() { |
799 |
< |
public void realCompute() throws Exception { |
800 |
< |
FailingCCF f = new LFCCF(null, 8); |
798 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
799 |
> |
protected void realCompute() throws Exception { |
800 |
> |
FailingCCF f = new LFCCF(8); |
801 |
|
assertSame(f, f.fork()); |
802 |
|
try { |
803 |
|
f.get(); |
815 |
|
* timed get of a forked task throws exception when task completes abnormally |
816 |
|
*/ |
817 |
|
public void testAbnormalForkTimedGet() { |
818 |
< |
ForkJoinTask a = new CheckedFJTask() { |
819 |
< |
public void realCompute() throws Exception { |
820 |
< |
FailingCCF f = new LFCCF(null, 8); |
818 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
819 |
> |
protected void realCompute() throws Exception { |
820 |
> |
FailingCCF f = new LFCCF(8); |
821 |
|
assertSame(f, f.fork()); |
822 |
|
try { |
823 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
835 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
836 |
|
*/ |
837 |
|
public void testAbnormalForkQuietlyJoin() { |
838 |
< |
ForkJoinTask a = new CheckedFJTask() { |
839 |
< |
public void realCompute() { |
840 |
< |
FailingCCF f = new LFCCF(null, 8); |
838 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
839 |
> |
protected void realCompute() { |
840 |
> |
FailingCCF f = new LFCCF(8); |
841 |
|
assertSame(f, f.fork()); |
842 |
|
f.quietlyJoin(); |
843 |
|
assertTrue(f.getException() instanceof FJException); |
850 |
|
* invoke task throws exception when task cancelled |
851 |
|
*/ |
852 |
|
public void testCancelledInvoke() { |
853 |
< |
ForkJoinTask a = new CheckedFJTask() { |
854 |
< |
public void realCompute() { |
855 |
< |
CCF f = new LCCF(null, 8); |
853 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
854 |
> |
protected void realCompute() { |
855 |
> |
CCF f = new LCCF(8); |
856 |
|
assertTrue(f.cancel(true)); |
857 |
|
try { |
858 |
|
f.invoke(); |
868 |
|
* join of a forked task throws exception when task cancelled |
869 |
|
*/ |
870 |
|
public void testCancelledForkJoin() { |
871 |
< |
ForkJoinTask a = new CheckedFJTask() { |
872 |
< |
public void realCompute() { |
873 |
< |
CCF f = new LCCF(null, 8); |
871 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
872 |
> |
protected void realCompute() { |
873 |
> |
CCF f = new LCCF(8); |
874 |
|
assertTrue(f.cancel(true)); |
875 |
|
assertSame(f, f.fork()); |
876 |
|
try { |
887 |
|
* get of a forked task throws exception when task cancelled |
888 |
|
*/ |
889 |
|
public void testCancelledForkGet() { |
890 |
< |
ForkJoinTask a = new CheckedFJTask() { |
891 |
< |
public void realCompute() throws Exception { |
892 |
< |
CCF f = new LCCF(null, 8); |
890 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
891 |
> |
protected void realCompute() throws Exception { |
892 |
> |
CCF f = new LCCF(8); |
893 |
|
assertTrue(f.cancel(true)); |
894 |
|
assertSame(f, f.fork()); |
895 |
|
try { |
906 |
|
* timed get of a forked task throws exception when task cancelled |
907 |
|
*/ |
908 |
|
public void testCancelledForkTimedGet() throws Exception { |
909 |
< |
ForkJoinTask a = new CheckedFJTask() { |
910 |
< |
public void realCompute() throws Exception { |
911 |
< |
CCF f = new LCCF(null, 8); |
909 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
910 |
> |
protected void realCompute() throws Exception { |
911 |
> |
CCF f = new LCCF(8); |
912 |
|
assertTrue(f.cancel(true)); |
913 |
|
assertSame(f, f.fork()); |
914 |
|
try { |
925 |
|
* quietlyJoin of a forked task returns when task cancelled |
926 |
|
*/ |
927 |
|
public void testCancelledForkQuietlyJoin() { |
928 |
< |
ForkJoinTask a = new CheckedFJTask() { |
929 |
< |
public void realCompute() { |
930 |
< |
CCF f = new LCCF(null, 8); |
928 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
929 |
> |
protected void realCompute() { |
930 |
> |
CCF f = new LCCF(8); |
931 |
|
assertTrue(f.cancel(true)); |
932 |
|
assertSame(f, f.fork()); |
933 |
|
f.quietlyJoin(); |
941 |
|
*/ |
942 |
|
public void testGetPool() { |
943 |
|
final ForkJoinPool mainPool = mainPool(); |
944 |
< |
ForkJoinTask a = new CheckedFJTask() { |
945 |
< |
public void realCompute() { |
944 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
945 |
> |
protected void realCompute() { |
946 |
|
assertSame(mainPool, getPool()); |
947 |
|
}}; |
948 |
|
testInvokeOnPool(mainPool, a); |
952 |
|
* getPool of non-FJ task returns null |
953 |
|
*/ |
954 |
|
public void testGetPool2() { |
955 |
< |
ForkJoinTask a = new CheckedFJTask() { |
956 |
< |
public void realCompute() { |
955 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
956 |
> |
protected void realCompute() { |
957 |
|
assertNull(getPool()); |
958 |
|
}}; |
959 |
|
assertNull(a.invoke()); |
963 |
|
* inForkJoinPool of executing task returns true |
964 |
|
*/ |
965 |
|
public void testInForkJoinPool() { |
966 |
< |
ForkJoinTask a = new CheckedFJTask() { |
967 |
< |
public void realCompute() { |
966 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
967 |
> |
protected void realCompute() { |
968 |
|
assertTrue(inForkJoinPool()); |
969 |
|
}}; |
970 |
|
testInvokeOnPool(mainPool(), a); |
974 |
|
* inForkJoinPool of non-FJ task returns false |
975 |
|
*/ |
976 |
|
public void testInForkJoinPool2() { |
977 |
< |
ForkJoinTask a = new CheckedFJTask() { |
978 |
< |
public void realCompute() { |
977 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
978 |
> |
protected void realCompute() { |
979 |
|
assertFalse(inForkJoinPool()); |
980 |
|
}}; |
981 |
|
assertNull(a.invoke()); |
985 |
|
* setRawResult(null) succeeds |
986 |
|
*/ |
987 |
|
public void testSetRawResult() { |
988 |
< |
ForkJoinTask a = new CheckedFJTask() { |
989 |
< |
public void realCompute() { |
988 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
989 |
> |
protected void realCompute() { |
990 |
|
setRawResult(null); |
991 |
|
assertNull(getRawResult()); |
992 |
|
}}; |
997 |
|
* invoke task throws exception after invoking completeExceptionally |
998 |
|
*/ |
999 |
|
public void testCompleteExceptionally2() { |
1000 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1001 |
< |
public void realCompute() { |
1002 |
< |
CCF f = new LCCF(null, 8); |
1003 |
< |
f.completeExceptionally(new FJException()); |
1004 |
< |
try { |
1005 |
< |
f.invoke(); |
1006 |
< |
shouldThrow(); |
1007 |
< |
} catch (FJException success) { |
909 |
< |
checkCompletedAbnormally(f, success); |
910 |
< |
} |
1000 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1001 |
> |
protected void realCompute() { |
1002 |
> |
CCF n = new LCCF(8); |
1003 |
> |
CCF f = new LCCF(n, 8); |
1004 |
> |
FJException ex = new FJException(); |
1005 |
> |
f.completeExceptionally(ex); |
1006 |
> |
f.checkCompletedExceptionally(ex); |
1007 |
> |
n.checkCompletedExceptionally(ex); |
1008 |
|
}}; |
1009 |
|
testInvokeOnPool(mainPool(), a); |
1010 |
|
} |
1013 |
|
* invokeAll(t1, t2) invokes all task arguments |
1014 |
|
*/ |
1015 |
|
public void testInvokeAll2() { |
1016 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1017 |
< |
public void realCompute() { |
1018 |
< |
CCF f = new LCCF(null, 8); |
1019 |
< |
CCF g = new LCCF(null, 9); |
1016 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1017 |
> |
protected void realCompute() { |
1018 |
> |
CCF f = new LCCF(8); |
1019 |
> |
CCF g = new LCCF(9); |
1020 |
|
invokeAll(f, g); |
1021 |
|
assertEquals(21, f.number); |
1022 |
|
assertEquals(34, g.number); |
1030 |
|
* invokeAll(tasks) with 1 argument invokes task |
1031 |
|
*/ |
1032 |
|
public void testInvokeAll1() { |
1033 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1034 |
< |
public void realCompute() { |
1035 |
< |
CCF f = new LCCF(null, 8); |
1033 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1034 |
> |
protected void realCompute() { |
1035 |
> |
CCF f = new LCCF(8); |
1036 |
|
invokeAll(f); |
1037 |
|
checkCompletedNormally(f); |
1038 |
|
assertEquals(21, f.number); |
1044 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
1045 |
|
*/ |
1046 |
|
public void testInvokeAll3() { |
1047 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1048 |
< |
public void realCompute() { |
1049 |
< |
CCF f = new LCCF(null, 8); |
1050 |
< |
CCF g = new LCCF(null, 9); |
1051 |
< |
CCF h = new LCCF(null, 7); |
1047 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1048 |
> |
protected void realCompute() { |
1049 |
> |
CCF f = new LCCF(8); |
1050 |
> |
CCF g = new LCCF(9); |
1051 |
> |
CCF h = new LCCF(7); |
1052 |
|
invokeAll(f, g, h); |
1053 |
|
assertEquals(21, f.number); |
1054 |
|
assertEquals(34, g.number); |
1064 |
|
* invokeAll(collection) invokes all tasks in the collection |
1065 |
|
*/ |
1066 |
|
public void testInvokeAllCollection() { |
1067 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1068 |
< |
public void realCompute() { |
1069 |
< |
CCF f = new LCCF(null, 8); |
1070 |
< |
CCF g = new LCCF(null, 9); |
1071 |
< |
CCF h = new LCCF(null, 7); |
1067 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1068 |
> |
protected void realCompute() { |
1069 |
> |
CCF f = new LCCF(8); |
1070 |
> |
CCF g = new LCCF(9); |
1071 |
> |
CCF h = new LCCF(7); |
1072 |
|
HashSet set = new HashSet(); |
1073 |
|
set.add(f); |
1074 |
|
set.add(g); |
1088 |
|
* invokeAll(tasks) with any null task throws NPE |
1089 |
|
*/ |
1090 |
|
public void testInvokeAllNPE() { |
1091 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1092 |
< |
public void realCompute() { |
1093 |
< |
CCF f = new LCCF(null, 8); |
1094 |
< |
CCF g = new LCCF(null, 9); |
1091 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1092 |
> |
protected void realCompute() { |
1093 |
> |
CCF f = new LCCF(8); |
1094 |
> |
CCF g = new LCCF(9); |
1095 |
|
CCF h = null; |
1096 |
|
try { |
1097 |
|
invokeAll(f, g, h); |
1105 |
|
* invokeAll(t1, t2) throw exception if any task does |
1106 |
|
*/ |
1107 |
|
public void testAbnormalInvokeAll2() { |
1108 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1109 |
< |
public void realCompute() { |
1110 |
< |
CCF f = new LCCF(null, 8); |
1111 |
< |
FailingCCF g = new LFCCF(null, 9); |
1108 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1109 |
> |
protected void realCompute() { |
1110 |
> |
CCF f = new LCCF(8); |
1111 |
> |
FailingCCF g = new LFCCF(9); |
1112 |
|
try { |
1113 |
|
invokeAll(f, g); |
1114 |
|
shouldThrow(); |
1123 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
1124 |
|
*/ |
1125 |
|
public void testAbnormalInvokeAll1() { |
1126 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1127 |
< |
public void realCompute() { |
1128 |
< |
FailingCCF g = new LFCCF(null, 9); |
1126 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1127 |
> |
protected void realCompute() { |
1128 |
> |
FailingCCF g = new LFCCF(9); |
1129 |
|
try { |
1130 |
|
invokeAll(g); |
1131 |
|
shouldThrow(); |
1140 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1141 |
|
*/ |
1142 |
|
public void testAbnormalInvokeAll3() { |
1143 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1144 |
< |
public void realCompute() { |
1145 |
< |
CCF f = new LCCF(null, 8); |
1146 |
< |
FailingCCF g = new LFCCF(null, 9); |
1147 |
< |
CCF h = new LCCF(null, 7); |
1143 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1144 |
> |
protected void realCompute() { |
1145 |
> |
CCF f = new LCCF(8); |
1146 |
> |
FailingCCF g = new LFCCF(9); |
1147 |
> |
CCF h = new LCCF(7); |
1148 |
|
try { |
1149 |
|
invokeAll(f, g, h); |
1150 |
|
shouldThrow(); |
1156 |
|
} |
1157 |
|
|
1158 |
|
/** |
1159 |
< |
* invokeAll(collection) throws exception if any task does |
1159 |
> |
* invokeAll(collection) throws exception if any task does |
1160 |
|
*/ |
1161 |
|
public void testAbnormalInvokeAllCollection() { |
1162 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1163 |
< |
public void realCompute() { |
1164 |
< |
FailingCCF f = new LFCCF(null, 8); |
1165 |
< |
CCF g = new LCCF(null, 9); |
1166 |
< |
CCF h = new LCCF(null, 7); |
1162 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1163 |
> |
protected void realCompute() { |
1164 |
> |
FailingCCF f = new LFCCF(8); |
1165 |
> |
CCF g = new LCCF(9); |
1166 |
> |
CCF h = new LCCF(7); |
1167 |
|
HashSet set = new HashSet(); |
1168 |
|
set.add(f); |
1169 |
|
set.add(g); |
1183 |
|
* and suppresses execution |
1184 |
|
*/ |
1185 |
|
public void testTryUnfork() { |
1186 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1187 |
< |
public void realCompute() { |
1188 |
< |
CCF g = new LCCF(null, 9); |
1186 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1187 |
> |
protected void realCompute() { |
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(f.tryUnfork()); |
1193 |
|
helpQuiesce(); |
1202 |
|
* there are more tasks than threads |
1203 |
|
*/ |
1204 |
|
public void testGetSurplusQueuedTaskCount() { |
1205 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1206 |
< |
public void realCompute() { |
1207 |
< |
CCF h = new LCCF(null, 7); |
1205 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1206 |
> |
protected void realCompute() { |
1207 |
> |
CCF h = new LCCF(7); |
1208 |
|
assertSame(h, h.fork()); |
1209 |
< |
CCF g = new LCCF(null, 9); |
1209 |
> |
CCF g = new LCCF(9); |
1210 |
|
assertSame(g, g.fork()); |
1211 |
< |
CCF f = new LCCF(null, 8); |
1211 |
> |
CCF f = new LCCF(8); |
1212 |
|
assertSame(f, f.fork()); |
1213 |
|
assertTrue(getSurplusQueuedTaskCount() > 0); |
1214 |
|
helpQuiesce(); |
1224 |
|
* peekNextLocalTask returns most recent unexecuted task. |
1225 |
|
*/ |
1226 |
|
public void testPeekNextLocalTask() { |
1227 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1228 |
< |
public void realCompute() { |
1229 |
< |
CCF g = new LCCF(null, 9); |
1227 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1228 |
> |
protected void realCompute() { |
1229 |
> |
CCF g = new LCCF(9); |
1230 |
|
assertSame(g, g.fork()); |
1231 |
< |
CCF f = new LCCF(null, 8); |
1231 |
> |
CCF f = new LCCF(8); |
1232 |
|
assertSame(f, f.fork()); |
1233 |
|
assertSame(f, peekNextLocalTask()); |
1234 |
|
assertNull(f.join()); |
1244 |
|
* executing it |
1245 |
|
*/ |
1246 |
|
public void testPollNextLocalTask() { |
1247 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1248 |
< |
public void realCompute() { |
1249 |
< |
CCF g = new LCCF(null, 9); |
1247 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1248 |
> |
protected void realCompute() { |
1249 |
> |
CCF g = new LCCF(9); |
1250 |
|
assertSame(g, g.fork()); |
1251 |
< |
CCF f = new LCCF(null, 8); |
1251 |
> |
CCF f = new LCCF(8); |
1252 |
|
assertSame(f, f.fork()); |
1253 |
|
assertSame(f, pollNextLocalTask()); |
1254 |
|
helpQuiesce(); |
1263 |
|
* pollTask returns an unexecuted task without executing it |
1264 |
|
*/ |
1265 |
|
public void testPollTask() { |
1266 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1267 |
< |
public void realCompute() { |
1268 |
< |
CCF g = new LCCF(null, 9); |
1266 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1267 |
> |
protected void realCompute() { |
1268 |
> |
CCF g = new LCCF(9); |
1269 |
|
assertSame(g, g.fork()); |
1270 |
< |
CCF f = new LCCF(null, 8); |
1270 |
> |
CCF f = new LCCF(8); |
1271 |
|
assertSame(f, f.fork()); |
1272 |
|
assertSame(f, pollTask()); |
1273 |
|
helpQuiesce(); |
1281 |
|
* peekNextLocalTask returns least recent unexecuted task in async mode |
1282 |
|
*/ |
1283 |
|
public void testPeekNextLocalTaskAsync() { |
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, peekNextLocalTask()); |
1291 |
|
assertNull(f.join()); |
1302 |
|
* executing it, in async mode |
1303 |
|
*/ |
1304 |
|
public void testPollNextLocalTaskAsync() { |
1305 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1306 |
< |
public void realCompute() { |
1307 |
< |
CCF g = new LCCF(null, 9); |
1305 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1306 |
> |
protected void realCompute() { |
1307 |
> |
CCF g = new LCCF(9); |
1308 |
|
assertSame(g, g.fork()); |
1309 |
< |
CCF f = new LCCF(null, 8); |
1309 |
> |
CCF f = new LCCF(8); |
1310 |
|
assertSame(f, f.fork()); |
1311 |
|
assertSame(g, pollNextLocalTask()); |
1312 |
|
helpQuiesce(); |
1322 |
|
* async mode |
1323 |
|
*/ |
1324 |
|
public void testPollTaskAsync() { |
1325 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1326 |
< |
public void realCompute() { |
1327 |
< |
CCF g = new LCCF(null, 9); |
1325 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1326 |
> |
protected void realCompute() { |
1327 |
> |
CCF g = new LCCF(9); |
1328 |
|
assertSame(g, g.fork()); |
1329 |
< |
CCF f = new LCCF(null, 8); |
1329 |
> |
CCF f = new LCCF(8); |
1330 |
|
assertSame(f, f.fork()); |
1331 |
|
assertSame(g, pollTask()); |
1332 |
|
helpQuiesce(); |
1345 |
|
* completed tasks; getRawResult returns null. |
1346 |
|
*/ |
1347 |
|
public void testInvokeSingleton() { |
1348 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1349 |
< |
public void realCompute() { |
1350 |
< |
CCF f = new LCCF(null, 8); |
1348 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1349 |
> |
protected void realCompute() { |
1350 |
> |
CCF f = new LCCF(8); |
1351 |
|
assertNull(f.invoke()); |
1352 |
|
assertEquals(21, f.number); |
1353 |
|
checkCompletedNormally(f); |
1361 |
|
* completed tasks |
1362 |
|
*/ |
1363 |
|
public void testQuietlyInvokeSingleton() { |
1364 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1365 |
< |
public void realCompute() { |
1366 |
< |
CCF f = new LCCF(null, 8); |
1364 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1365 |
> |
protected void realCompute() { |
1366 |
> |
CCF f = new LCCF(8); |
1367 |
|
f.quietlyInvoke(); |
1368 |
|
assertEquals(21, f.number); |
1369 |
|
checkCompletedNormally(f); |
1375 |
|
* join of a forked task returns when task completes |
1376 |
|
*/ |
1377 |
|
public void testForkJoinSingleton() { |
1378 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1379 |
< |
public void realCompute() { |
1380 |
< |
CCF f = new LCCF(null, 8); |
1378 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1379 |
> |
protected void realCompute() { |
1380 |
> |
CCF f = new LCCF(8); |
1381 |
|
assertSame(f, f.fork()); |
1382 |
|
assertNull(f.join()); |
1383 |
|
assertEquals(21, f.number); |
1390 |
|
* get of a forked task returns when task completes |
1391 |
|
*/ |
1392 |
|
public void testForkGetSingleton() { |
1393 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1394 |
< |
public void realCompute() throws Exception { |
1395 |
< |
CCF f = new LCCF(null, 8); |
1393 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1394 |
> |
protected void realCompute() throws Exception { |
1395 |
> |
CCF f = new LCCF(8); |
1396 |
|
assertSame(f, f.fork()); |
1397 |
|
assertNull(f.get()); |
1398 |
|
assertEquals(21, f.number); |
1405 |
|
* timed get of a forked task returns when task completes |
1406 |
|
*/ |
1407 |
|
public void testForkTimedGetSingleton() { |
1408 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1409 |
< |
public void realCompute() throws Exception { |
1410 |
< |
CCF f = new LCCF(null, 8); |
1408 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1409 |
> |
protected void realCompute() throws Exception { |
1410 |
> |
CCF f = new LCCF(8); |
1411 |
|
assertSame(f, f.fork()); |
1412 |
|
assertNull(f.get(LONG_DELAY_MS, MILLISECONDS)); |
1413 |
|
assertEquals(21, f.number); |
1420 |
|
* timed get with null time unit throws NPE |
1421 |
|
*/ |
1422 |
|
public void testForkTimedGetNPESingleton() { |
1423 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1424 |
< |
public void realCompute() throws Exception { |
1425 |
< |
CCF f = new LCCF(null, 8); |
1423 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1424 |
> |
protected void realCompute() throws Exception { |
1425 |
> |
CCF f = new LCCF(8); |
1426 |
|
assertSame(f, f.fork()); |
1427 |
|
try { |
1428 |
|
f.get(5L, null); |
1436 |
|
* quietlyJoin of a forked task returns when task completes |
1437 |
|
*/ |
1438 |
|
public void testForkQuietlyJoinSingleton() { |
1439 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1440 |
< |
public void realCompute() { |
1441 |
< |
CCF f = new LCCF(null, 8); |
1439 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1440 |
> |
protected void realCompute() { |
1441 |
> |
CCF f = new LCCF(8); |
1442 |
|
assertSame(f, f.fork()); |
1443 |
|
f.quietlyJoin(); |
1444 |
|
assertEquals(21, f.number); |
1452 |
|
* getQueuedTaskCount returns 0 when quiescent |
1453 |
|
*/ |
1454 |
|
public void testForkHelpQuiesceSingleton() { |
1455 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1456 |
< |
public void realCompute() { |
1457 |
< |
CCF f = new LCCF(null, 8); |
1455 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1456 |
> |
protected void realCompute() { |
1457 |
> |
CCF f = new LCCF(8); |
1458 |
|
assertSame(f, f.fork()); |
1459 |
|
helpQuiesce(); |
1460 |
|
assertEquals(0, getQueuedTaskCount()); |
1468 |
|
* invoke task throws exception when task completes abnormally |
1469 |
|
*/ |
1470 |
|
public void testAbnormalInvokeSingleton() { |
1471 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1472 |
< |
public void realCompute() { |
1473 |
< |
FailingCCF f = new LFCCF(null, 8); |
1471 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1472 |
> |
protected void realCompute() { |
1473 |
> |
FailingCCF f = new LFCCF(8); |
1474 |
|
try { |
1475 |
|
f.invoke(); |
1476 |
|
shouldThrow(); |
1485 |
|
* quietlyInvoke task returns when task completes abnormally |
1486 |
|
*/ |
1487 |
|
public void testAbnormalQuietlyInvokeSingleton() { |
1488 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1489 |
< |
public void realCompute() { |
1490 |
< |
FailingCCF f = new LFCCF(null, 8); |
1488 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1489 |
> |
protected void realCompute() { |
1490 |
> |
FailingCCF f = new LFCCF(8); |
1491 |
|
f.quietlyInvoke(); |
1492 |
|
assertTrue(f.getException() instanceof FJException); |
1493 |
|
checkCompletedAbnormally(f, f.getException()); |
1499 |
|
* join of a forked task throws exception when task completes abnormally |
1500 |
|
*/ |
1501 |
|
public void testAbnormalForkJoinSingleton() { |
1502 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1503 |
< |
public void realCompute() { |
1504 |
< |
FailingCCF f = new LFCCF(null, 8); |
1502 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1503 |
> |
protected void realCompute() { |
1504 |
> |
FailingCCF f = new LFCCF(8); |
1505 |
|
assertSame(f, f.fork()); |
1506 |
|
try { |
1507 |
|
f.join(); |
1517 |
|
* get of a forked task throws exception when task completes abnormally |
1518 |
|
*/ |
1519 |
|
public void testAbnormalForkGetSingleton() { |
1520 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1521 |
< |
public void realCompute() throws Exception { |
1522 |
< |
FailingCCF f = new LFCCF(null, 8); |
1520 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1521 |
> |
protected void realCompute() throws Exception { |
1522 |
> |
FailingCCF f = new LFCCF(8); |
1523 |
|
assertSame(f, f.fork()); |
1524 |
|
try { |
1525 |
|
f.get(); |
1537 |
|
* timed get of a forked task throws exception when task completes abnormally |
1538 |
|
*/ |
1539 |
|
public void testAbnormalForkTimedGetSingleton() { |
1540 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1541 |
< |
public void realCompute() throws Exception { |
1542 |
< |
FailingCCF f = new LFCCF(null, 8); |
1540 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1541 |
> |
protected void realCompute() throws Exception { |
1542 |
> |
FailingCCF f = new LFCCF(8); |
1543 |
|
assertSame(f, f.fork()); |
1544 |
|
try { |
1545 |
|
f.get(LONG_DELAY_MS, MILLISECONDS); |
1557 |
|
* quietlyJoin of a forked task returns when task completes abnormally |
1558 |
|
*/ |
1559 |
|
public void testAbnormalForkQuietlyJoinSingleton() { |
1560 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1561 |
< |
public void realCompute() { |
1562 |
< |
FailingCCF f = new LFCCF(null, 8); |
1560 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1561 |
> |
protected void realCompute() { |
1562 |
> |
FailingCCF f = new LFCCF(8); |
1563 |
|
assertSame(f, f.fork()); |
1564 |
|
f.quietlyJoin(); |
1565 |
|
assertTrue(f.getException() instanceof FJException); |
1572 |
|
* invoke task throws exception when task cancelled |
1573 |
|
*/ |
1574 |
|
public void testCancelledInvokeSingleton() { |
1575 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1576 |
< |
public void realCompute() { |
1577 |
< |
CCF f = new LCCF(null, 8); |
1575 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1576 |
> |
protected void realCompute() { |
1577 |
> |
CCF f = new LCCF(8); |
1578 |
|
assertTrue(f.cancel(true)); |
1579 |
|
try { |
1580 |
|
f.invoke(); |
1590 |
|
* join of a forked task throws exception when task cancelled |
1591 |
|
*/ |
1592 |
|
public void testCancelledForkJoinSingleton() { |
1593 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1594 |
< |
public void realCompute() { |
1595 |
< |
CCF f = new LCCF(null, 8); |
1593 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1594 |
> |
protected void realCompute() { |
1595 |
> |
CCF f = new LCCF(8); |
1596 |
|
assertTrue(f.cancel(true)); |
1597 |
|
assertSame(f, f.fork()); |
1598 |
|
try { |
1609 |
|
* get of a forked task throws exception when task cancelled |
1610 |
|
*/ |
1611 |
|
public void testCancelledForkGetSingleton() { |
1612 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1613 |
< |
public void realCompute() throws Exception { |
1614 |
< |
CCF f = new LCCF(null, 8); |
1612 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1613 |
> |
protected void realCompute() throws Exception { |
1614 |
> |
CCF f = new LCCF(8); |
1615 |
|
assertTrue(f.cancel(true)); |
1616 |
|
assertSame(f, f.fork()); |
1617 |
|
try { |
1628 |
|
* timed get of a forked task throws exception when task cancelled |
1629 |
|
*/ |
1630 |
|
public void testCancelledForkTimedGetSingleton() throws Exception { |
1631 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1632 |
< |
public void realCompute() throws Exception { |
1633 |
< |
CCF f = new LCCF(null, 8); |
1631 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1632 |
> |
protected void realCompute() throws Exception { |
1633 |
> |
CCF f = new LCCF(8); |
1634 |
|
assertTrue(f.cancel(true)); |
1635 |
|
assertSame(f, f.fork()); |
1636 |
|
try { |
1647 |
|
* quietlyJoin of a forked task returns when task cancelled |
1648 |
|
*/ |
1649 |
|
public void testCancelledForkQuietlyJoinSingleton() { |
1650 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1651 |
< |
public void realCompute() { |
1652 |
< |
CCF f = new LCCF(null, 8); |
1650 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1651 |
> |
protected void realCompute() { |
1652 |
> |
CCF f = new LCCF(8); |
1653 |
|
assertTrue(f.cancel(true)); |
1654 |
|
assertSame(f, f.fork()); |
1655 |
|
f.quietlyJoin(); |
1662 |
|
* invoke task throws exception after invoking completeExceptionally |
1663 |
|
*/ |
1664 |
|
public void testCompleteExceptionallySingleton() { |
1665 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1666 |
< |
public void realCompute() { |
1667 |
< |
CCF f = new LCCF(null, 8); |
1668 |
< |
f.completeExceptionally(new FJException()); |
1669 |
< |
try { |
1670 |
< |
f.invoke(); |
1671 |
< |
shouldThrow(); |
1672 |
< |
} catch (FJException success) { |
1576 |
< |
checkCompletedAbnormally(f, success); |
1577 |
< |
} |
1665 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1666 |
> |
protected void realCompute() { |
1667 |
> |
CCF n = new LCCF(8); |
1668 |
> |
CCF f = new LCCF(n, 8); |
1669 |
> |
FJException ex = new FJException(); |
1670 |
> |
f.completeExceptionally(ex); |
1671 |
> |
f.checkCompletedExceptionally(ex); |
1672 |
> |
n.checkCompletedExceptionally(ex); |
1673 |
|
}}; |
1674 |
|
testInvokeOnPool(singletonPool(), a); |
1675 |
|
} |
1678 |
|
* invokeAll(t1, t2) invokes all task arguments |
1679 |
|
*/ |
1680 |
|
public void testInvokeAll2Singleton() { |
1681 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1682 |
< |
public void realCompute() { |
1683 |
< |
CCF f = new LCCF(null, 8); |
1684 |
< |
CCF g = new LCCF(null, 9); |
1681 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1682 |
> |
protected void realCompute() { |
1683 |
> |
CCF f = new LCCF(8); |
1684 |
> |
CCF g = new LCCF(9); |
1685 |
|
invokeAll(f, g); |
1686 |
|
assertEquals(21, f.number); |
1687 |
|
assertEquals(34, g.number); |
1695 |
|
* invokeAll(tasks) with 1 argument invokes task |
1696 |
|
*/ |
1697 |
|
public void testInvokeAll1Singleton() { |
1698 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1699 |
< |
public void realCompute() { |
1700 |
< |
CCF f = new LCCF(null, 8); |
1698 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1699 |
> |
protected void realCompute() { |
1700 |
> |
CCF f = new LCCF(8); |
1701 |
|
invokeAll(f); |
1702 |
|
checkCompletedNormally(f); |
1703 |
|
assertEquals(21, f.number); |
1709 |
|
* invokeAll(tasks) with > 2 argument invokes tasks |
1710 |
|
*/ |
1711 |
|
public void testInvokeAll3Singleton() { |
1712 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1713 |
< |
public void realCompute() { |
1714 |
< |
CCF f = new LCCF(null, 8); |
1715 |
< |
CCF g = new LCCF(null, 9); |
1716 |
< |
CCF h = new LCCF(null, 7); |
1712 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1713 |
> |
protected void realCompute() { |
1714 |
> |
CCF f = new LCCF(8); |
1715 |
> |
CCF g = new LCCF(9); |
1716 |
> |
CCF h = new LCCF(7); |
1717 |
|
invokeAll(f, g, h); |
1718 |
|
assertEquals(21, f.number); |
1719 |
|
assertEquals(34, g.number); |
1729 |
|
* invokeAll(collection) invokes all tasks in the collection |
1730 |
|
*/ |
1731 |
|
public void testInvokeAllCollectionSingleton() { |
1732 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1733 |
< |
public void realCompute() { |
1734 |
< |
CCF f = new LCCF(null, 8); |
1735 |
< |
CCF g = new LCCF(null, 9); |
1736 |
< |
CCF h = new LCCF(null, 7); |
1732 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1733 |
> |
protected void realCompute() { |
1734 |
> |
CCF f = new LCCF(8); |
1735 |
> |
CCF g = new LCCF(9); |
1736 |
> |
CCF h = new LCCF(7); |
1737 |
|
HashSet set = new HashSet(); |
1738 |
|
set.add(f); |
1739 |
|
set.add(g); |
1753 |
|
* invokeAll(tasks) with any null task throws NPE |
1754 |
|
*/ |
1755 |
|
public void testInvokeAllNPESingleton() { |
1756 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1757 |
< |
public void realCompute() { |
1758 |
< |
CCF f = new LCCF(null, 8); |
1759 |
< |
CCF g = new LCCF(null, 9); |
1756 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1757 |
> |
protected void realCompute() { |
1758 |
> |
CCF f = new LCCF(8); |
1759 |
> |
CCF g = new LCCF(9); |
1760 |
|
CCF h = null; |
1761 |
|
try { |
1762 |
|
invokeAll(f, g, h); |
1770 |
|
* invokeAll(t1, t2) throw exception if any task does |
1771 |
|
*/ |
1772 |
|
public void testAbnormalInvokeAll2Singleton() { |
1773 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1774 |
< |
public void realCompute() { |
1775 |
< |
CCF f = new LCCF(null, 8); |
1776 |
< |
FailingCCF g = new LFCCF(null, 9); |
1773 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1774 |
> |
protected void realCompute() { |
1775 |
> |
CCF f = new LCCF(8); |
1776 |
> |
FailingCCF g = new LFCCF(9); |
1777 |
|
try { |
1778 |
|
invokeAll(f, g); |
1779 |
|
shouldThrow(); |
1788 |
|
* invokeAll(tasks) with 1 argument throws exception if task does |
1789 |
|
*/ |
1790 |
|
public void testAbnormalInvokeAll1Singleton() { |
1791 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1792 |
< |
public void realCompute() { |
1793 |
< |
FailingCCF g = new LFCCF(null, 9); |
1791 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1792 |
> |
protected void realCompute() { |
1793 |
> |
FailingCCF g = new LFCCF(9); |
1794 |
|
try { |
1795 |
|
invokeAll(g); |
1796 |
|
shouldThrow(); |
1805 |
|
* invokeAll(tasks) with > 2 argument throws exception if any task does |
1806 |
|
*/ |
1807 |
|
public void testAbnormalInvokeAll3Singleton() { |
1808 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1809 |
< |
public void realCompute() { |
1810 |
< |
CCF f = new LCCF(null, 8); |
1811 |
< |
FailingCCF g = new LFCCF(null, 9); |
1812 |
< |
CCF h = new LCCF(null, 7); |
1808 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1809 |
> |
protected void realCompute() { |
1810 |
> |
CCF f = new LCCF(8); |
1811 |
> |
FailingCCF g = new LFCCF(9); |
1812 |
> |
CCF h = new LCCF(7); |
1813 |
|
try { |
1814 |
|
invokeAll(f, g, h); |
1815 |
|
shouldThrow(); |
1821 |
|
} |
1822 |
|
|
1823 |
|
/** |
1824 |
< |
* invokeAll(collection) throws exception if any task does |
1824 |
> |
* invokeAll(collection) throws exception if any task does |
1825 |
|
*/ |
1826 |
|
public void testAbnormalInvokeAllCollectionSingleton() { |
1827 |
< |
ForkJoinTask a = new CheckedFJTask() { |
1828 |
< |
public void realCompute() { |
1829 |
< |
FailingCCF f = new LFCCF(null, 8); |
1830 |
< |
CCF g = new LCCF(null, 9); |
1831 |
< |
CCF h = new LCCF(null, 7); |
1827 |
> |
ForkJoinTask a = new CheckedRecursiveAction() { |
1828 |
> |
protected void realCompute() { |
1829 |
> |
FailingCCF f = new LFCCF(8); |
1830 |
> |
CCF g = new LCCF(9); |
1831 |
> |
CCF h = new LCCF(7); |
1832 |
|
HashSet set = new HashSet(); |
1833 |
|
set.add(f); |
1834 |
|
set.add(g); |