ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/RecursiveTaskTest.java
Revision: 1.11
Committed: Wed Sep 1 06:41:55 2010 UTC (13 years, 8 months ago) by jsr166
Branch: MAIN
Changes since 1.10: +2 -2 lines
Log Message:
trailing whitespace

File Contents

# Content
1 /*
2 * Written by Doug Lea with assistance from members of JCP JSR-166
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.*;
9
10
11 public class RecursiveTaskTest extends JSR166TestCase {
12
13 public static void main(String[] args) {
14 junit.textui.TestRunner.run(suite());
15 }
16 public static Test suite() {
17 return new TestSuite(RecursiveTaskTest.class);
18 }
19
20 static final ForkJoinPool mainPool = new ForkJoinPool();
21 static final ForkJoinPool singletonPool = new ForkJoinPool(1);
22 static final ForkJoinPool asyncSingletonPool =
23 new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory,
24 null, true);
25
26 static final class FJException extends RuntimeException {
27 FJException() { super(); }
28 }
29
30 // An invalid return value for Fib
31 static final Integer NoResult = Integer.valueOf(-17);
32
33 // A simple recursive task for testing
34 static final class FibTask extends RecursiveTask<Integer> {
35 final int number;
36 FibTask(int n) { number = n; }
37 public Integer compute() {
38 int n = number;
39 if (n <= 1)
40 return n;
41 FibTask f1 = new FibTask(n - 1);
42 f1.fork();
43 return (new FibTask(n - 2)).compute() + f1.join();
44 }
45 }
46
47 // A recursive action failing in base case
48 static final class FailingFibTask extends RecursiveTask<Integer> {
49 final int number;
50 int result;
51 FailingFibTask(int n) { number = n; }
52 public Integer compute() {
53 int n = number;
54 if (n <= 1)
55 throw new FJException();
56 FailingFibTask f1 = new FailingFibTask(n - 1);
57 f1.fork();
58 return (new FibTask(n - 2)).compute() + f1.join();
59 }
60 }
61
62 /**
63 * invoke returns value when task completes normally.
64 * isCompletedAbnormally and isCancelled return false for normally
65 * completed tasks. getRawResult of a completed non-null task
66 * returns value;
67 *
68 */
69 public void testInvoke() {
70 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
71 public Integer compute() {
72 FibTask f = new FibTask(8);
73 Integer r = f.invoke();
74 threadAssertTrue(r == 21);
75 threadAssertTrue(f.isDone());
76 threadAssertFalse(f.isCancelled());
77 threadAssertFalse(f.isCompletedAbnormally());
78 threadAssertTrue(f.getRawResult() == 21);
79 return r;
80 }
81 };
82 assertTrue(mainPool.invoke(a) == 21);
83 }
84
85 /**
86 * quietlyInvoke task returns when task completes normally.
87 * isCompletedAbnormally and isCancelled return false for normally
88 * completed tasks
89 */
90 public void testQuietlyInvoke() {
91 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
92 public Integer compute() {
93 FibTask f = new FibTask(8);
94 f.quietlyInvoke();
95 Integer r = f.getRawResult();
96 threadAssertTrue(r == 21);
97 threadAssertTrue(f.isDone());
98 threadAssertFalse(f.isCancelled());
99 threadAssertFalse(f.isCompletedAbnormally());
100 return r;
101 }
102 };
103 assertTrue(mainPool.invoke(a) == 21);
104 }
105
106 /**
107 * join of a forked task returns when task completes
108 */
109 public void testForkJoin() {
110 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
111 public Integer compute() {
112 FibTask f = new FibTask(8);
113 f.fork();
114 Integer r = f.join();
115 threadAssertTrue(r == 21);
116 threadAssertTrue(f.isDone());
117 return r;
118 }
119 };
120 assertTrue(mainPool.invoke(a) == 21);
121 }
122
123 /**
124 * get of a forked task returns when task completes
125 */
126 public void testForkGet() {
127 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
128 public Integer compute() {
129 try {
130 FibTask f = new FibTask(8);
131 f.fork();
132 Integer r = f.get();
133 threadAssertTrue(r == 21);
134 threadAssertTrue(f.isDone());
135 return r;
136 } catch (Exception ex) {
137 unexpectedException(ex);
138 }
139 return NoResult;
140 }
141 };
142 assertTrue(mainPool.invoke(a) == 21);
143 }
144
145 /**
146 * timed get of a forked task returns when task completes
147 */
148 public void testForkTimedGet() {
149 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
150 public Integer compute() {
151 try {
152 FibTask f = new FibTask(8);
153 f.fork();
154 Integer r = f.get(5L, TimeUnit.SECONDS);
155 threadAssertTrue(r == 21);
156 threadAssertTrue(f.isDone());
157 return r;
158 } catch (Exception ex) {
159 unexpectedException(ex);
160 }
161 return NoResult;
162 }
163 };
164 assertTrue(mainPool.invoke(a) == 21);
165 }
166
167 /**
168 * quietlyJoin of a forked task returns when task completes
169 */
170 public void testForkQuietlyJoin() {
171 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
172 public Integer compute() {
173 FibTask f = new FibTask(8);
174 f.fork();
175 f.quietlyJoin();
176 Integer r = f.getRawResult();
177 threadAssertTrue(r == 21);
178 threadAssertTrue(f.isDone());
179 return r;
180 }
181 };
182 assertTrue(mainPool.invoke(a) == 21);
183 }
184
185
186 /**
187 * helpQuiesce returns when tasks are complete.
188 * getQueuedTaskCount returns 0 when quiescent
189 */
190 public void testForkHelpQuiesce() {
191 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
192 public Integer compute() {
193 FibTask f = new FibTask(8);
194 f.fork();
195 f.helpQuiesce();
196 Integer r = f.getRawResult();
197 threadAssertTrue(r == 21);
198 threadAssertTrue(f.isDone());
199 threadAssertTrue(getQueuedTaskCount() == 0);
200 return r;
201 }
202 };
203 assertTrue(mainPool.invoke(a) == 21);
204 }
205
206
207 /**
208 * invoke task throws exception when task completes abnormally
209 */
210 public void testAbnormalInvoke() {
211 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
212 public Integer compute() {
213 try {
214 FailingFibTask f = new FailingFibTask(8);
215 f.invoke();
216 shouldThrow();
217 return NoResult;
218 } catch (FJException success) {
219 }
220 return NoResult;
221 }
222 };
223 mainPool.invoke(a);
224 }
225
226 /**
227 * quietlyInvoke task returns when task completes abnormally
228 */
229 public void testAbnormalQuietlyInvoke() {
230 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
231 public Integer compute() {
232 FailingFibTask f = new FailingFibTask(8);
233 f.quietlyInvoke();
234 threadAssertTrue(f.isDone());
235 return NoResult;
236 }
237 };
238 mainPool.invoke(a);
239 }
240
241 /**
242 * join of a forked task throws exception when task completes abnormally
243 */
244 public void testAbnormalForkJoin() {
245 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
246 public Integer compute() {
247 try {
248 FailingFibTask f = new FailingFibTask(8);
249 f.fork();
250 Integer r = f.join();
251 shouldThrow();
252 return r;
253 } catch (FJException success) {
254 }
255 return NoResult;
256 }
257 };
258 mainPool.invoke(a);
259 }
260
261 /**
262 * get of a forked task throws exception when task completes abnormally
263 */
264 public void testAbnormalForkGet() {
265 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
266 public Integer compute() {
267 try {
268 FailingFibTask f = new FailingFibTask(8);
269 f.fork();
270 Integer r = f.get();
271 shouldThrow();
272 return r;
273 } catch (ExecutionException success) {
274 } catch (Exception ex) {
275 unexpectedException(ex);
276 }
277 return NoResult;
278 }
279 };
280 mainPool.invoke(a);
281 }
282
283 /**
284 * timed get of a forked task throws exception when task completes abnormally
285 */
286 public void testAbnormalForkTimedGet() {
287 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
288 public Integer compute() {
289 try {
290 FailingFibTask f = new FailingFibTask(8);
291 f.fork();
292 Integer r = f.get(5L, TimeUnit.SECONDS);
293 shouldThrow();
294 return r;
295 } catch (ExecutionException success) {
296 } catch (Exception ex) {
297 unexpectedException(ex);
298 }
299 return NoResult;
300 }
301 };
302 mainPool.invoke(a);
303 }
304
305 /**
306 * quietlyJoin of a forked task returns when task completes abnormally
307 */
308 public void testAbnormalForkQuietlyJoin() {
309 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
310 public Integer compute() {
311 FailingFibTask f = new FailingFibTask(8);
312 f.fork();
313 f.quietlyJoin();
314 threadAssertTrue(f.isDone());
315 threadAssertTrue(f.isCompletedAbnormally());
316 threadAssertTrue(f.getException() instanceof FJException);
317 return NoResult;
318 }
319 };
320 mainPool.invoke(a);
321 }
322
323 /**
324 * invoke task throws exception when task cancelled
325 */
326 public void testCancelledInvoke() {
327 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
328 public Integer compute() {
329 try {
330 FibTask f = new FibTask(8);
331 f.cancel(true);
332 Integer r = f.invoke();
333 shouldThrow();
334 return r;
335 } catch (CancellationException success) {
336 }
337 return NoResult;
338 }
339 };
340 mainPool.invoke(a);
341 }
342
343 /**
344 * join of a forked task throws exception when task cancelled
345 */
346 public void testCancelledForkJoin() {
347 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
348 public Integer compute() {
349 try {
350 FibTask f = new FibTask(8);
351 f.cancel(true);
352 f.fork();
353 Integer r = f.join();
354 shouldThrow();
355 return r;
356 } catch (CancellationException success) {
357 }
358 return NoResult;
359 }
360 };
361 mainPool.invoke(a);
362 }
363
364 /**
365 * get of a forked task throws exception when task cancelled
366 */
367 public void testCancelledForkGet() {
368 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
369 public Integer compute() {
370 try {
371 FibTask f = new FibTask(8);
372 f.cancel(true);
373 f.fork();
374 Integer r = f.get();
375 shouldThrow();
376 return r;
377 } catch (CancellationException success) {
378 } catch (Exception ex) {
379 unexpectedException(ex);
380 }
381 return NoResult;
382 }
383 };
384 mainPool.invoke(a);
385 }
386
387 /**
388 * timed get of a forked task throws exception when task cancelled
389 */
390 public void testCancelledForkTimedGet() {
391 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
392 public Integer compute() {
393 try {
394 FibTask f = new FibTask(8);
395 f.cancel(true);
396 f.fork();
397 Integer r = f.get(5L, TimeUnit.SECONDS);
398 shouldThrow();
399 return r;
400 } catch (CancellationException success) {
401 } catch (Exception ex) {
402 unexpectedException(ex);
403 }
404 return NoResult;
405 }
406 };
407 mainPool.invoke(a);
408 }
409
410 /**
411 * quietlyJoin of a forked task returns when task cancelled
412 */
413 public void testCancelledForkQuietlyJoin() {
414 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
415 public Integer compute() {
416 FibTask f = new FibTask(8);
417 f.cancel(true);
418 f.fork();
419 f.quietlyJoin();
420 threadAssertTrue(f.isDone());
421 threadAssertTrue(f.isCompletedAbnormally());
422 threadAssertTrue(f.getException() instanceof CancellationException);
423 return NoResult;
424 }
425 };
426 mainPool.invoke(a);
427 }
428
429 /**
430 * getPool of executing task returns its pool
431 */
432 public void testGetPool() {
433 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
434 public Integer compute() {
435 threadAssertTrue(getPool() == mainPool);
436 return NoResult;
437 }
438 };
439 mainPool.invoke(a);
440 }
441
442 /**
443 * getPool of non-FJ task returns null
444 */
445 public void testGetPool2() {
446 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
447 public Integer compute() {
448 threadAssertTrue(getPool() == null);
449 return NoResult;
450 }
451 };
452 a.invoke();
453 }
454
455 /**
456 * inForkJoinPool of executing task returns true
457 */
458 public void testInForkJoinPool() {
459 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
460 public Integer compute() {
461 threadAssertTrue(inForkJoinPool());
462 return NoResult;
463 }
464 };
465 mainPool.invoke(a);
466 }
467
468 /**
469 * inForkJoinPool of non-FJ task returns false
470 */
471 public void testInForkJoinPool2() {
472 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
473 public Integer compute() {
474 threadAssertTrue(!inForkJoinPool());
475 return NoResult;
476 }
477 };
478 a.invoke();
479 }
480
481 /**
482 * setRawResult(null) succeeds
483 */
484 public void testSetRawResult() {
485 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
486 public Integer compute() {
487 setRawResult(NoResult);
488 return NoResult;
489 }
490 };
491 assertEquals(a.invoke(), NoResult);
492 }
493
494 /**
495 * A reinitialized task may be re-invoked
496 */
497 public void testReinitialize() {
498 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
499 public Integer compute() {
500 FibTask f = new FibTask(8);
501 Integer r = f.invoke();
502 threadAssertTrue(r == 21);
503 threadAssertTrue(f.isDone());
504 threadAssertFalse(f.isCancelled());
505 threadAssertFalse(f.isCompletedAbnormally());
506 f.reinitialize();
507 r = f.invoke();
508 threadAssertTrue(r == 21);
509 return NoResult;
510 }
511 };
512 mainPool.invoke(a);
513 }
514
515 /**
516 * invoke task throws exception after invoking completeExceptionally
517 */
518 public void testCompleteExceptionally() {
519 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
520 public Integer compute() {
521 try {
522 FibTask f = new FibTask(8);
523 f.completeExceptionally(new FJException());
524 Integer r = f.invoke();
525 shouldThrow();
526 return r;
527 } catch (FJException success) {
528 }
529 return NoResult;
530 }
531 };
532 mainPool.invoke(a);
533 }
534
535 /**
536 * invoke task suppresses execution invoking complete
537 */
538 public void testComplete() {
539 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
540 public Integer compute() {
541 FibTask f = new FibTask(8);
542 f.complete(NoResult);
543 Integer r = f.invoke();
544 threadAssertTrue(f.isDone());
545 threadAssertTrue(r == NoResult);
546 return r;
547 }
548 };
549 mainPool.invoke(a);
550 }
551
552 /**
553 * invokeAll(t1, t2) invokes all task arguments
554 */
555 public void testInvokeAll2() {
556 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
557 public Integer compute() {
558 FibTask f = new FibTask(8);
559 FibTask g = new FibTask(9);
560 invokeAll(f, g);
561 threadAssertTrue(f.isDone());
562 threadAssertTrue(f.join() == 21);
563 threadAssertTrue(g.isDone());
564 threadAssertTrue(g.join() == 34);
565 return NoResult;
566 }
567 };
568 mainPool.invoke(a);
569 }
570
571 /**
572 * invokeAll(tasks) with 1 argument invokes task
573 */
574 public void testInvokeAll1() {
575 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
576 public Integer compute() {
577 FibTask f = new FibTask(8);
578 invokeAll(f);
579 threadAssertTrue(f.isDone());
580 threadAssertTrue(f.join() == 21);
581 return NoResult;
582 }
583 };
584 mainPool.invoke(a);
585 }
586
587 /**
588 * invokeAll(tasks) with > 2 argument invokes tasks
589 */
590 public void testInvokeAll3() {
591 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
592 public Integer compute() {
593 FibTask f = new FibTask(8);
594 FibTask g = new FibTask(9);
595 FibTask h = new FibTask(7);
596 invokeAll(f, g, h);
597 threadAssertTrue(f.isDone());
598 threadAssertTrue(f.join() == 21);
599 threadAssertTrue(g.isDone());
600 threadAssertTrue(g.join() == 34);
601 threadAssertTrue(h.isDone());
602 threadAssertTrue(h.join() == 13);
603 return NoResult;
604 }
605 };
606 mainPool.invoke(a);
607 }
608
609 /**
610 * invokeAll(collection) invokes all tasks in the collection
611 */
612 public void testInvokeAllCollection() {
613 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
614 public Integer compute() {
615 FibTask f = new FibTask(8);
616 FibTask g = new FibTask(9);
617 FibTask h = new FibTask(7);
618 HashSet set = new HashSet();
619 set.add(f);
620 set.add(g);
621 set.add(h);
622 invokeAll(set);
623 threadAssertTrue(f.isDone());
624 threadAssertTrue(f.join() == 21);
625 threadAssertTrue(g.isDone());
626 threadAssertTrue(g.join() == 34);
627 threadAssertTrue(h.isDone());
628 threadAssertTrue(h.join() == 13);
629 return NoResult;
630 }
631 };
632 mainPool.invoke(a);
633 }
634
635
636 /**
637 * invokeAll(t1, t2) throw exception if any task does
638 */
639 public void testAbnormalInvokeAll2() {
640 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
641 public Integer compute() {
642 try {
643 FibTask f = new FibTask(8);
644 FailingFibTask g = new FailingFibTask(9);
645 invokeAll(f, g);
646 shouldThrow();
647 return NoResult;
648 } catch (FJException success) {
649 }
650 return NoResult;
651 }
652 };
653 mainPool.invoke(a);
654 }
655
656 /**
657 * invokeAll(tasks) with 1 argument throws exception if task does
658 */
659 public void testAbnormalInvokeAll1() {
660 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
661 public Integer compute() {
662 try {
663 FailingFibTask g = new FailingFibTask(9);
664 invokeAll(g);
665 shouldThrow();
666 return NoResult;
667 } catch (FJException success) {
668 }
669 return NoResult;
670 }
671 };
672 mainPool.invoke(a);
673 }
674
675 /**
676 * invokeAll(tasks) with > 2 argument throws exception if any task does
677 */
678 public void testAbnormalInvokeAll3() {
679 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
680 public Integer compute() {
681 try {
682 FibTask f = new FibTask(8);
683 FailingFibTask g = new FailingFibTask(9);
684 FibTask h = new FibTask(7);
685 invokeAll(f, g, h);
686 shouldThrow();
687 return NoResult;
688 } catch (FJException success) {
689 }
690 return NoResult;
691 }
692 };
693 mainPool.invoke(a);
694 }
695
696 /**
697 * invokeAll(collection) throws exception if any task does
698 */
699 public void testAbnormalInvokeAllCollection() {
700 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
701 public Integer compute() {
702 try {
703 FailingFibTask f = new FailingFibTask(8);
704 FibTask g = new FibTask(9);
705 FibTask h = new FibTask(7);
706 HashSet set = new HashSet();
707 set.add(f);
708 set.add(g);
709 set.add(h);
710 invokeAll(set);
711 shouldThrow();
712 return NoResult;
713 } catch (FJException success) {
714 }
715 return NoResult;
716 }
717 };
718 mainPool.invoke(a);
719 }
720
721 /**
722 * tryUnfork returns true for most recent unexecuted task,
723 * and suppresses execution
724 */
725 public void testTryUnfork() {
726 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
727 public Integer compute() {
728 FibTask g = new FibTask(9);
729 g.fork();
730 FibTask f = new FibTask(8);
731 f.fork();
732 threadAssertTrue(f.tryUnfork());
733 helpQuiesce();
734 threadAssertFalse(f.isDone());
735 threadAssertTrue(g.isDone());
736 return NoResult;
737 }
738 };
739 singletonPool.invoke(a);
740 }
741
742 /**
743 * getSurplusQueuedTaskCount returns > 0 when
744 * there are more tasks than threads
745 */
746 public void testGetSurplusQueuedTaskCount() {
747 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
748 public Integer compute() {
749 FibTask h = new FibTask(7);
750 h.fork();
751 FibTask g = new FibTask(9);
752 g.fork();
753 FibTask f = new FibTask(8);
754 f.fork();
755 threadAssertTrue(getSurplusQueuedTaskCount() > 0);
756 helpQuiesce();
757 return NoResult;
758 }
759 };
760 singletonPool.invoke(a);
761 }
762
763 /**
764 * peekNextLocalTask returns most recent unexecuted task.
765 */
766 public void testPeekNextLocalTask() {
767 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
768 public Integer compute() {
769 FibTask g = new FibTask(9);
770 g.fork();
771 FibTask f = new FibTask(8);
772 f.fork();
773 threadAssertTrue(peekNextLocalTask() == f);
774 f.join();
775 threadAssertTrue(f.isDone());
776 helpQuiesce();
777 return NoResult;
778 }
779 };
780 singletonPool.invoke(a);
781 }
782
783 /**
784 * pollNextLocalTask returns most recent unexecuted task
785 * without executing it
786 */
787 public void testPollNextLocalTask() {
788 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
789 public Integer compute() {
790 FibTask g = new FibTask(9);
791 g.fork();
792 FibTask f = new FibTask(8);
793 f.fork();
794 threadAssertTrue(pollNextLocalTask() == f);
795 helpQuiesce();
796 threadAssertFalse(f.isDone());
797 return NoResult;
798 }
799 };
800 singletonPool.invoke(a);
801 }
802
803 /**
804 * pollTask returns an unexecuted task
805 * without executing it
806 */
807 public void testPollTask() {
808 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
809 public Integer compute() {
810 FibTask g = new FibTask(9);
811 g.fork();
812 FibTask f = new FibTask(8);
813 f.fork();
814 threadAssertTrue(pollTask() == f);
815 helpQuiesce();
816 threadAssertFalse(f.isDone());
817 threadAssertTrue(g.isDone());
818 return NoResult;
819 }
820 };
821 singletonPool.invoke(a);
822 }
823
824 /**
825 * peekNextLocalTask returns least recent unexecuted task in async mode
826 */
827 public void testPeekNextLocalTaskAsync() {
828 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
829 public Integer compute() {
830 FibTask g = new FibTask(9);
831 g.fork();
832 FibTask f = new FibTask(8);
833 f.fork();
834 threadAssertTrue(peekNextLocalTask() == g);
835 f.join();
836 helpQuiesce();
837 threadAssertTrue(f.isDone());
838 return NoResult;
839 }
840 };
841 asyncSingletonPool.invoke(a);
842 }
843
844 /**
845 * pollNextLocalTask returns least recent unexecuted task
846 * without executing it, in async mode
847 */
848 public void testPollNextLocalTaskAsync() {
849 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
850 public Integer compute() {
851 FibTask g = new FibTask(9);
852 g.fork();
853 FibTask f = new FibTask(8);
854 f.fork();
855 threadAssertTrue(pollNextLocalTask() == g);
856 helpQuiesce();
857 threadAssertTrue(f.isDone());
858 threadAssertFalse(g.isDone());
859 return NoResult;
860 }
861 };
862 asyncSingletonPool.invoke(a);
863 }
864
865 /**
866 * pollTask returns an unexecuted task
867 * without executing it, in async mode
868 */
869 public void testPollTaskAsync() {
870 RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
871 public Integer compute() {
872 FibTask g = new FibTask(9);
873 g.fork();
874 FibTask f = new FibTask(8);
875 f.fork();
876 threadAssertTrue(pollTask() == g);
877 helpQuiesce();
878 threadAssertTrue(f.isDone());
879 threadAssertFalse(g.isDone());
880 return NoResult;
881 }
882 };
883 asyncSingletonPool.invoke(a);
884 }
885
886 }