3 |
|
* Expert Group and released to the public domain, as explained at |
4 |
|
* http://creativecommons.org/licenses/publicdomain |
5 |
|
*/ |
6 |
– |
import junit.framework.*; |
7 |
– |
import java.util.concurrent.*; |
8 |
– |
import java.util.*; |
6 |
|
|
7 |
+ |
import junit.framework.*; |
8 |
+ |
import java.util.concurrent.CancellationException; |
9 |
+ |
import java.util.concurrent.ExecutionException; |
10 |
+ |
import java.util.concurrent.ForkJoinPool; |
11 |
+ |
import java.util.concurrent.RecursiveTask; |
12 |
+ |
import java.util.concurrent.TimeUnit; |
13 |
+ |
import java.util.HashSet; |
14 |
|
|
15 |
|
public class RecursiveTaskTest extends JSR166TestCase { |
16 |
|
|
17 |
|
public static void main(String[] args) { |
18 |
< |
junit.textui.TestRunner.run (suite()); |
18 |
> |
junit.textui.TestRunner.run(suite()); |
19 |
|
} |
20 |
|
public static Test suite() { |
21 |
< |
return new TestSuite(RecursiveTaskTest.class); |
21 |
> |
return new TestSuite(RecursiveTaskTest.class); |
22 |
> |
} |
23 |
> |
|
24 |
> |
private static ForkJoinPool mainPool() { |
25 |
> |
return new ForkJoinPool(); |
26 |
|
} |
27 |
|
|
28 |
< |
static final ForkJoinPool mainPool = new ForkJoinPool(); |
29 |
< |
static final ForkJoinPool singletonPool = new ForkJoinPool(1); |
30 |
< |
static final ForkJoinPool asyncSingletonPool = new ForkJoinPool(1); |
31 |
< |
static { |
32 |
< |
asyncSingletonPool.setAsyncMode(true); |
28 |
> |
private static ForkJoinPool singletonPool() { |
29 |
> |
return new ForkJoinPool(1); |
30 |
> |
} |
31 |
> |
|
32 |
> |
private static ForkJoinPool asyncSingletonPool() { |
33 |
> |
return new ForkJoinPool(1, |
34 |
> |
ForkJoinPool.defaultForkJoinWorkerThreadFactory, |
35 |
> |
null, true); |
36 |
> |
} |
37 |
> |
|
38 |
> |
private <T> T testInvokeOnPool(ForkJoinPool pool, RecursiveTask<T> a) { |
39 |
> |
try { |
40 |
> |
return pool.invoke(a); |
41 |
> |
} finally { |
42 |
> |
joinPool(pool); |
43 |
> |
} |
44 |
|
} |
45 |
|
|
46 |
|
static final class FJException extends RuntimeException { |
84 |
|
* isCompletedAbnormally and isCancelled return false for normally |
85 |
|
* completed tasks. getRawResult of a completed non-null task |
86 |
|
* returns value; |
68 |
– |
* |
87 |
|
*/ |
88 |
|
public void testInvoke() { |
89 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
98 |
|
return r; |
99 |
|
} |
100 |
|
}; |
101 |
< |
assertTrue(mainPool.invoke(a) == 21); |
101 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
102 |
|
} |
103 |
|
|
104 |
|
/** |
119 |
|
return r; |
120 |
|
} |
121 |
|
}; |
122 |
< |
assertTrue(mainPool.invoke(a) == 21); |
122 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
123 |
|
} |
124 |
|
|
125 |
|
/** |
129 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
130 |
|
public Integer compute() { |
131 |
|
FibTask f = new FibTask(8); |
132 |
< |
f.fork(); |
132 |
> |
threadAssertSame(f, f.fork()); |
133 |
|
Integer r = f.join(); |
134 |
|
threadAssertTrue(r == 21); |
135 |
|
threadAssertTrue(f.isDone()); |
136 |
|
return r; |
137 |
|
} |
138 |
|
}; |
139 |
< |
assertTrue(mainPool.invoke(a) == 21); |
139 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
140 |
|
} |
141 |
|
|
142 |
|
/** |
147 |
|
public Integer compute() { |
148 |
|
try { |
149 |
|
FibTask f = new FibTask(8); |
150 |
< |
f.fork(); |
150 |
> |
threadAssertSame(f, f.fork()); |
151 |
|
Integer r = f.get(); |
152 |
|
threadAssertTrue(r == 21); |
153 |
|
threadAssertTrue(f.isDone()); |
158 |
|
return NoResult; |
159 |
|
} |
160 |
|
}; |
161 |
< |
assertTrue(mainPool.invoke(a) == 21); |
161 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
162 |
|
} |
163 |
|
|
164 |
|
/** |
169 |
|
public Integer compute() { |
170 |
|
try { |
171 |
|
FibTask f = new FibTask(8); |
172 |
< |
f.fork(); |
172 |
> |
threadAssertSame(f, f.fork()); |
173 |
|
Integer r = f.get(5L, TimeUnit.SECONDS); |
174 |
|
threadAssertTrue(r == 21); |
175 |
|
threadAssertTrue(f.isDone()); |
180 |
|
return NoResult; |
181 |
|
} |
182 |
|
}; |
183 |
< |
assertTrue(mainPool.invoke(a) == 21); |
166 |
< |
} |
167 |
< |
|
168 |
< |
/** |
169 |
< |
* helpJoin of a forked task returns when task completes |
170 |
< |
*/ |
171 |
< |
public void testForkHelpJoin() { |
172 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
173 |
< |
public Integer compute() { |
174 |
< |
FibTask f = new FibTask(8); |
175 |
< |
f.fork(); |
176 |
< |
Integer r = f.helpJoin(); |
177 |
< |
threadAssertTrue(r == 21); |
178 |
< |
threadAssertTrue(f.isDone()); |
179 |
< |
return r; |
180 |
< |
} |
181 |
< |
}; |
182 |
< |
assertTrue(mainPool.invoke(a) == 21); |
183 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
184 |
|
} |
185 |
|
|
186 |
|
/** |
190 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
191 |
|
public Integer compute() { |
192 |
|
FibTask f = new FibTask(8); |
193 |
< |
f.fork(); |
193 |
> |
threadAssertSame(f, f.fork()); |
194 |
|
f.quietlyJoin(); |
195 |
|
Integer r = f.getRawResult(); |
196 |
|
threadAssertTrue(r == 21); |
198 |
|
return r; |
199 |
|
} |
200 |
|
}; |
201 |
< |
assertTrue(mainPool.invoke(a) == 21); |
201 |
< |
} |
202 |
< |
|
203 |
< |
|
204 |
< |
/** |
205 |
< |
* quietlyHelpJoin of a forked task returns when task completes |
206 |
< |
*/ |
207 |
< |
public void testForkQuietlyHelpJoin() { |
208 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
209 |
< |
public Integer compute() { |
210 |
< |
FibTask f = new FibTask(8); |
211 |
< |
f.fork(); |
212 |
< |
f.quietlyHelpJoin(); |
213 |
< |
Integer r = f.getRawResult(); |
214 |
< |
threadAssertTrue(r == 21); |
215 |
< |
threadAssertTrue(f.isDone()); |
216 |
< |
return r; |
217 |
< |
} |
218 |
< |
}; |
219 |
< |
assertTrue(mainPool.invoke(a) == 21); |
201 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
202 |
|
} |
203 |
|
|
204 |
|
|
210 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
211 |
|
public Integer compute() { |
212 |
|
FibTask f = new FibTask(8); |
213 |
< |
f.fork(); |
213 |
> |
threadAssertSame(f, f.fork()); |
214 |
|
f.helpQuiesce(); |
215 |
|
Integer r = f.getRawResult(); |
216 |
|
threadAssertTrue(r == 21); |
219 |
|
return r; |
220 |
|
} |
221 |
|
}; |
222 |
< |
assertTrue(mainPool.invoke(a) == 21); |
222 |
> |
assertEquals(21, (int) testInvokeOnPool(mainPool(), a)); |
223 |
|
} |
224 |
|
|
225 |
|
|
239 |
|
return NoResult; |
240 |
|
} |
241 |
|
}; |
242 |
< |
mainPool.invoke(a); |
242 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
243 |
|
} |
244 |
|
|
245 |
|
/** |
254 |
|
return NoResult; |
255 |
|
} |
256 |
|
}; |
257 |
< |
mainPool.invoke(a); |
257 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
258 |
|
} |
259 |
|
|
260 |
|
/** |
265 |
|
public Integer compute() { |
266 |
|
try { |
267 |
|
FailingFibTask f = new FailingFibTask(8); |
268 |
< |
f.fork(); |
268 |
> |
threadAssertSame(f, f.fork()); |
269 |
|
Integer r = f.join(); |
270 |
|
shouldThrow(); |
271 |
|
return r; |
274 |
|
return NoResult; |
275 |
|
} |
276 |
|
}; |
277 |
< |
mainPool.invoke(a); |
277 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
278 |
|
} |
279 |
|
|
280 |
|
/** |
285 |
|
public Integer compute() { |
286 |
|
try { |
287 |
|
FailingFibTask f = new FailingFibTask(8); |
288 |
< |
f.fork(); |
288 |
> |
threadAssertSame(f, f.fork()); |
289 |
|
Integer r = f.get(); |
290 |
|
shouldThrow(); |
291 |
|
return r; |
296 |
|
return NoResult; |
297 |
|
} |
298 |
|
}; |
299 |
< |
mainPool.invoke(a); |
299 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
300 |
|
} |
301 |
|
|
302 |
|
/** |
307 |
|
public Integer compute() { |
308 |
|
try { |
309 |
|
FailingFibTask f = new FailingFibTask(8); |
310 |
< |
f.fork(); |
310 |
> |
threadAssertSame(f, f.fork()); |
311 |
|
Integer r = f.get(5L, TimeUnit.SECONDS); |
312 |
|
shouldThrow(); |
313 |
|
return r; |
318 |
|
return NoResult; |
319 |
|
} |
320 |
|
}; |
321 |
< |
mainPool.invoke(a); |
340 |
< |
} |
341 |
< |
|
342 |
< |
/** |
343 |
< |
* join of a forked task throws exception when task completes abnormally |
344 |
< |
*/ |
345 |
< |
public void testAbnormalForkHelpJoin() { |
346 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
347 |
< |
public Integer compute() { |
348 |
< |
try { |
349 |
< |
FailingFibTask f = new FailingFibTask(8); |
350 |
< |
f.fork(); |
351 |
< |
Integer r = f.helpJoin(); |
352 |
< |
shouldThrow(); |
353 |
< |
return r; |
354 |
< |
} catch (FJException success) { |
355 |
< |
} |
356 |
< |
return NoResult; |
357 |
< |
} |
358 |
< |
}; |
359 |
< |
mainPool.invoke(a); |
360 |
< |
} |
361 |
< |
|
362 |
< |
/** |
363 |
< |
* quietlyHelpJoin of a forked task returns when task completes abnormally. |
364 |
< |
* getException of failed task returns its exception. |
365 |
< |
* isCompletedAbnormally of a failed task returns true. |
366 |
< |
* isCancelled of a failed uncancelled task returns false |
367 |
< |
*/ |
368 |
< |
public void testAbnormalForkQuietlyHelpJoin() { |
369 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
370 |
< |
public Integer compute() { |
371 |
< |
FailingFibTask f = new FailingFibTask(8); |
372 |
< |
f.fork(); |
373 |
< |
f.quietlyHelpJoin(); |
374 |
< |
threadAssertTrue(f.isDone()); |
375 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
376 |
< |
threadAssertFalse(f.isCancelled()); |
377 |
< |
threadAssertTrue(f.getException() instanceof FJException); |
378 |
< |
return NoResult; |
379 |
< |
} |
380 |
< |
}; |
381 |
< |
mainPool.invoke(a); |
321 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
322 |
|
} |
323 |
|
|
324 |
|
/** |
328 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
329 |
|
public Integer compute() { |
330 |
|
FailingFibTask f = new FailingFibTask(8); |
331 |
< |
f.fork(); |
331 |
> |
threadAssertSame(f, f.fork()); |
332 |
|
f.quietlyJoin(); |
333 |
|
threadAssertTrue(f.isDone()); |
334 |
|
threadAssertTrue(f.isCompletedAbnormally()); |
336 |
|
return NoResult; |
337 |
|
} |
338 |
|
}; |
339 |
< |
mainPool.invoke(a); |
339 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
340 |
|
} |
341 |
|
|
342 |
|
/** |
347 |
|
public Integer compute() { |
348 |
|
try { |
349 |
|
FibTask f = new FibTask(8); |
350 |
< |
f.cancel(true); |
350 |
> |
threadAssertTrue(f.cancel(true)); |
351 |
|
Integer r = f.invoke(); |
352 |
|
shouldThrow(); |
353 |
|
return r; |
356 |
|
return NoResult; |
357 |
|
} |
358 |
|
}; |
359 |
< |
mainPool.invoke(a); |
359 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
360 |
|
} |
361 |
|
|
362 |
|
/** |
367 |
|
public Integer compute() { |
368 |
|
try { |
369 |
|
FibTask f = new FibTask(8); |
370 |
< |
f.cancel(true); |
371 |
< |
f.fork(); |
370 |
> |
threadAssertTrue(f.cancel(true)); |
371 |
> |
threadAssertSame(f, f.fork()); |
372 |
|
Integer r = f.join(); |
373 |
|
shouldThrow(); |
374 |
|
return r; |
377 |
|
return NoResult; |
378 |
|
} |
379 |
|
}; |
380 |
< |
mainPool.invoke(a); |
380 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
381 |
|
} |
382 |
|
|
383 |
|
/** |
388 |
|
public Integer compute() { |
389 |
|
try { |
390 |
|
FibTask f = new FibTask(8); |
391 |
< |
f.cancel(true); |
392 |
< |
f.fork(); |
391 |
> |
threadAssertTrue(f.cancel(true)); |
392 |
> |
threadAssertSame(f, f.fork()); |
393 |
|
Integer r = f.get(); |
394 |
|
shouldThrow(); |
395 |
|
return r; |
400 |
|
return NoResult; |
401 |
|
} |
402 |
|
}; |
403 |
< |
mainPool.invoke(a); |
403 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
404 |
|
} |
405 |
|
|
406 |
|
/** |
411 |
|
public Integer compute() { |
412 |
|
try { |
413 |
|
FibTask f = new FibTask(8); |
414 |
< |
f.cancel(true); |
415 |
< |
f.fork(); |
414 |
> |
threadAssertTrue(f.cancel(true)); |
415 |
> |
threadAssertSame(f, f.fork()); |
416 |
|
Integer r = f.get(5L, TimeUnit.SECONDS); |
417 |
|
shouldThrow(); |
418 |
|
return r; |
423 |
|
return NoResult; |
424 |
|
} |
425 |
|
}; |
426 |
< |
mainPool.invoke(a); |
487 |
< |
} |
488 |
< |
|
489 |
< |
/** |
490 |
< |
* join of a forked task throws exception when task cancelled |
491 |
< |
*/ |
492 |
< |
public void testCancelledForkHelpJoin() { |
493 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
494 |
< |
public Integer compute() { |
495 |
< |
try { |
496 |
< |
FibTask f = new FibTask(8); |
497 |
< |
f.cancel(true); |
498 |
< |
f.fork(); |
499 |
< |
Integer r = f.helpJoin(); |
500 |
< |
shouldThrow(); |
501 |
< |
return r; |
502 |
< |
} catch (CancellationException success) { |
503 |
< |
} |
504 |
< |
return NoResult; |
505 |
< |
} |
506 |
< |
}; |
507 |
< |
mainPool.invoke(a); |
508 |
< |
} |
509 |
< |
|
510 |
< |
/** |
511 |
< |
* quietlyHelpJoin of a forked task returns when task cancelled. |
512 |
< |
* getException of cancelled task returns its exception |
513 |
< |
* isCompletedAbnormally of a cancelled task returns true. |
514 |
< |
* isCancelled of a cancelled task returns true |
515 |
< |
*/ |
516 |
< |
public void testCancelledForkQuietlyHelpJoin() { |
517 |
< |
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
518 |
< |
public Integer compute() { |
519 |
< |
FibTask f = new FibTask(8); |
520 |
< |
f.cancel(true); |
521 |
< |
f.fork(); |
522 |
< |
f.quietlyHelpJoin(); |
523 |
< |
threadAssertTrue(f.isDone()); |
524 |
< |
threadAssertTrue(f.isCompletedAbnormally()); |
525 |
< |
threadAssertTrue(f.isCancelled()); |
526 |
< |
threadAssertTrue(f.getException() instanceof CancellationException); |
527 |
< |
return NoResult; |
528 |
< |
} |
529 |
< |
}; |
530 |
< |
mainPool.invoke(a); |
426 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
427 |
|
} |
428 |
|
|
429 |
|
/** |
433 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
434 |
|
public Integer compute() { |
435 |
|
FibTask f = new FibTask(8); |
436 |
< |
f.cancel(true); |
437 |
< |
f.fork(); |
436 |
> |
threadAssertTrue(f.cancel(true)); |
437 |
> |
threadAssertSame(f, f.fork()); |
438 |
|
f.quietlyJoin(); |
439 |
|
threadAssertTrue(f.isDone()); |
440 |
|
threadAssertTrue(f.isCompletedAbnormally()); |
442 |
|
return NoResult; |
443 |
|
} |
444 |
|
}; |
445 |
< |
mainPool.invoke(a); |
445 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
446 |
|
} |
447 |
|
|
448 |
|
/** |
449 |
|
* getPool of executing task returns its pool |
450 |
|
*/ |
451 |
|
public void testGetPool() { |
452 |
+ |
final ForkJoinPool mainPool = mainPool(); |
453 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
454 |
|
public Integer compute() { |
455 |
|
threadAssertTrue(getPool() == mainPool); |
456 |
|
return NoResult; |
457 |
|
} |
458 |
|
}; |
459 |
< |
mainPool.invoke(a); |
459 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool, a)); |
460 |
|
} |
461 |
|
|
462 |
|
/** |
469 |
|
return NoResult; |
470 |
|
} |
471 |
|
}; |
472 |
< |
a.invoke(); |
472 |
> |
assertSame(NoResult, a.invoke()); |
473 |
|
} |
474 |
|
|
475 |
|
/** |
482 |
|
return NoResult; |
483 |
|
} |
484 |
|
}; |
485 |
< |
mainPool.invoke(a); |
485 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
486 |
|
} |
487 |
|
|
488 |
|
/** |
495 |
|
return NoResult; |
496 |
|
} |
497 |
|
}; |
498 |
< |
a.invoke(); |
498 |
> |
assertSame(NoResult, a.invoke()); |
499 |
|
} |
500 |
|
|
501 |
|
/** |
502 |
< |
* setRawResult(null) succeeds |
502 |
> |
* The value set by setRawResult is returned by getRawResult |
503 |
|
*/ |
504 |
|
public void testSetRawResult() { |
505 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
506 |
|
public Integer compute() { |
507 |
|
setRawResult(NoResult); |
508 |
+ |
threadAssertSame(getRawResult(), NoResult); |
509 |
|
return NoResult; |
510 |
|
} |
511 |
|
}; |
512 |
< |
assertEquals(a.invoke(), NoResult); |
512 |
> |
a.invoke(); |
513 |
|
} |
514 |
|
|
515 |
|
/** |
530 |
|
return NoResult; |
531 |
|
} |
532 |
|
}; |
533 |
< |
mainPool.invoke(a); |
533 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
534 |
|
} |
535 |
|
|
536 |
|
/** |
550 |
|
return NoResult; |
551 |
|
} |
552 |
|
}; |
553 |
< |
mainPool.invoke(a); |
553 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
554 |
|
} |
555 |
|
|
556 |
|
/** |
567 |
|
return r; |
568 |
|
} |
569 |
|
}; |
570 |
< |
mainPool.invoke(a); |
570 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
571 |
|
} |
572 |
|
|
573 |
|
/** |
586 |
|
return NoResult; |
587 |
|
} |
588 |
|
}; |
589 |
< |
mainPool.invoke(a); |
589 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
590 |
|
} |
591 |
|
|
592 |
|
/** |
602 |
|
return NoResult; |
603 |
|
} |
604 |
|
}; |
605 |
< |
mainPool.invoke(a); |
605 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
606 |
|
} |
607 |
|
|
608 |
|
/** |
624 |
|
return NoResult; |
625 |
|
} |
626 |
|
}; |
627 |
< |
mainPool.invoke(a); |
627 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
628 |
|
} |
629 |
|
|
630 |
|
/** |
650 |
|
return NoResult; |
651 |
|
} |
652 |
|
}; |
653 |
< |
mainPool.invoke(a); |
653 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
654 |
|
} |
655 |
|
|
656 |
|
|
671 |
|
return NoResult; |
672 |
|
} |
673 |
|
}; |
674 |
< |
mainPool.invoke(a); |
674 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
675 |
|
} |
676 |
|
|
677 |
|
/** |
690 |
|
return NoResult; |
691 |
|
} |
692 |
|
}; |
693 |
< |
mainPool.invoke(a); |
693 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
694 |
|
} |
695 |
|
|
696 |
|
/** |
711 |
|
return NoResult; |
712 |
|
} |
713 |
|
}; |
714 |
< |
mainPool.invoke(a); |
714 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
715 |
|
} |
716 |
|
|
717 |
|
/** |
736 |
|
return NoResult; |
737 |
|
} |
738 |
|
}; |
739 |
< |
mainPool.invoke(a); |
739 |
> |
assertSame(NoResult, testInvokeOnPool(mainPool(), a)); |
740 |
|
} |
741 |
|
|
742 |
|
/** |
747 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
748 |
|
public Integer compute() { |
749 |
|
FibTask g = new FibTask(9); |
750 |
< |
g.fork(); |
750 |
> |
threadAssertSame(g, g.fork()); |
751 |
|
FibTask f = new FibTask(8); |
752 |
< |
f.fork(); |
752 |
> |
threadAssertSame(f, f.fork()); |
753 |
|
threadAssertTrue(f.tryUnfork()); |
754 |
|
helpQuiesce(); |
755 |
|
threadAssertFalse(f.isDone()); |
757 |
|
return NoResult; |
758 |
|
} |
759 |
|
}; |
760 |
< |
singletonPool.invoke(a); |
760 |
> |
assertSame(NoResult, testInvokeOnPool(singletonPool(), a)); |
761 |
|
} |
762 |
|
|
763 |
|
/** |
768 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
769 |
|
public Integer compute() { |
770 |
|
FibTask h = new FibTask(7); |
771 |
< |
h.fork(); |
771 |
> |
threadAssertSame(h, h.fork()); |
772 |
|
FibTask g = new FibTask(9); |
773 |
< |
g.fork(); |
773 |
> |
threadAssertSame(g, g.fork()); |
774 |
|
FibTask f = new FibTask(8); |
775 |
< |
f.fork(); |
775 |
> |
threadAssertSame(f, f.fork()); |
776 |
|
threadAssertTrue(getSurplusQueuedTaskCount() > 0); |
777 |
|
helpQuiesce(); |
778 |
|
return NoResult; |
779 |
|
} |
780 |
|
}; |
781 |
< |
singletonPool.invoke(a); |
781 |
> |
assertSame(NoResult, testInvokeOnPool(singletonPool(), a)); |
782 |
|
} |
783 |
|
|
784 |
|
/** |
788 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
789 |
|
public Integer compute() { |
790 |
|
FibTask g = new FibTask(9); |
791 |
< |
g.fork(); |
791 |
> |
threadAssertSame(g, g.fork()); |
792 |
|
FibTask f = new FibTask(8); |
793 |
< |
f.fork(); |
793 |
> |
threadAssertSame(f, f.fork()); |
794 |
|
threadAssertTrue(peekNextLocalTask() == f); |
795 |
< |
f.join(); |
795 |
> |
threadAssertTrue(f.join() == 21); |
796 |
|
threadAssertTrue(f.isDone()); |
797 |
|
helpQuiesce(); |
798 |
|
return NoResult; |
799 |
|
} |
800 |
|
}; |
801 |
< |
singletonPool.invoke(a); |
801 |
> |
assertSame(NoResult, testInvokeOnPool(singletonPool(), a)); |
802 |
|
} |
803 |
|
|
804 |
|
/** |
809 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
810 |
|
public Integer compute() { |
811 |
|
FibTask g = new FibTask(9); |
812 |
< |
g.fork(); |
812 |
> |
threadAssertSame(g, g.fork()); |
813 |
|
FibTask f = new FibTask(8); |
814 |
< |
f.fork(); |
814 |
> |
threadAssertSame(f, f.fork()); |
815 |
|
threadAssertTrue(pollNextLocalTask() == f); |
816 |
|
helpQuiesce(); |
817 |
|
threadAssertFalse(f.isDone()); |
818 |
|
return NoResult; |
819 |
|
} |
820 |
|
}; |
821 |
< |
singletonPool.invoke(a); |
821 |
> |
assertSame(NoResult, testInvokeOnPool(singletonPool(), a)); |
822 |
|
} |
823 |
|
|
824 |
|
/** |
825 |
< |
* pollTask returns an unexecuted task |
928 |
< |
* without executing it |
825 |
> |
* pollTask returns an unexecuted task without executing it |
826 |
|
*/ |
827 |
|
public void testPollTask() { |
828 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
829 |
|
public Integer compute() { |
830 |
|
FibTask g = new FibTask(9); |
831 |
< |
g.fork(); |
831 |
> |
threadAssertSame(g, g.fork()); |
832 |
|
FibTask f = new FibTask(8); |
833 |
< |
f.fork(); |
833 |
> |
threadAssertSame(f, f.fork()); |
834 |
|
threadAssertTrue(pollTask() == f); |
835 |
|
helpQuiesce(); |
836 |
|
threadAssertFalse(f.isDone()); |
838 |
|
return NoResult; |
839 |
|
} |
840 |
|
}; |
841 |
< |
singletonPool.invoke(a); |
841 |
> |
assertSame(NoResult, testInvokeOnPool(singletonPool(), a)); |
842 |
|
} |
843 |
|
|
844 |
|
/** |
848 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
849 |
|
public Integer compute() { |
850 |
|
FibTask g = new FibTask(9); |
851 |
< |
g.fork(); |
851 |
> |
threadAssertSame(g, g.fork()); |
852 |
|
FibTask f = new FibTask(8); |
853 |
< |
f.fork(); |
853 |
> |
threadAssertSame(f, f.fork()); |
854 |
|
threadAssertTrue(peekNextLocalTask() == g); |
855 |
< |
f.join(); |
855 |
> |
threadAssertEquals(21, (int) f.join()); |
856 |
|
helpQuiesce(); |
857 |
|
threadAssertTrue(f.isDone()); |
858 |
|
return NoResult; |
859 |
|
} |
860 |
|
}; |
861 |
< |
asyncSingletonPool.invoke(a); |
861 |
> |
assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a)); |
862 |
|
} |
863 |
|
|
864 |
|
/** |
869 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
870 |
|
public Integer compute() { |
871 |
|
FibTask g = new FibTask(9); |
872 |
< |
g.fork(); |
872 |
> |
threadAssertSame(g, g.fork()); |
873 |
|
FibTask f = new FibTask(8); |
874 |
< |
f.fork(); |
874 |
> |
threadAssertSame(f, f.fork()); |
875 |
|
threadAssertTrue(pollNextLocalTask() == g); |
876 |
|
helpQuiesce(); |
877 |
|
threadAssertTrue(f.isDone()); |
879 |
|
return NoResult; |
880 |
|
} |
881 |
|
}; |
882 |
< |
asyncSingletonPool.invoke(a); |
882 |
> |
assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a)); |
883 |
|
} |
884 |
|
|
885 |
|
/** |
890 |
|
RecursiveTask<Integer> a = new RecursiveTask<Integer>() { |
891 |
|
public Integer compute() { |
892 |
|
FibTask g = new FibTask(9); |
893 |
< |
g.fork(); |
893 |
> |
threadAssertSame(g, g.fork()); |
894 |
|
FibTask f = new FibTask(8); |
895 |
< |
f.fork(); |
895 |
> |
threadAssertSame(f, f.fork()); |
896 |
|
threadAssertTrue(pollTask() == g); |
897 |
|
helpQuiesce(); |
898 |
|
threadAssertTrue(f.isDone()); |
900 |
|
return NoResult; |
901 |
|
} |
902 |
|
}; |
903 |
< |
asyncSingletonPool.invoke(a); |
903 |
> |
assertSame(NoResult, testInvokeOnPool(asyncSingletonPool(), a)); |
904 |
|
} |
905 |
|
|
906 |
|
} |