ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/RecursiveTaskTest.java
(Generate patch)

Comparing jsr166/src/test/tck/RecursiveTaskTest.java (file contents):
Revision 1.1 by dl, Fri Jul 31 23:02:50 2009 UTC vs.
Revision 1.5 by jsr166, Tue Aug 4 10:00:15 2009 UTC

# Line 11 | Line 11 | import java.util.*;
11   public class RecursiveTaskTest extends JSR166TestCase {
12  
13      public static void main(String[] args) {
14 <        junit.textui.TestRunner.run (suite());  
14 >        junit.textui.TestRunner.run (suite());
15      }
16      public static Test suite() {
17          return new TestSuite(RecursiveTaskTest.class);
# Line 32 | Line 32 | public class RecursiveTaskTest extends J
32      static final Integer NoResult = Integer.valueOf(-17);
33  
34      // A simple recursive task for testing
35 <    static final class FibTask extends RecursiveTask<Integer> {
35 >    static final class FibTask extends RecursiveTask<Integer> {
36          final int number;
37          FibTask(int n) { number = n; }
38          public Integer compute() {
# Line 46 | Line 46 | public class RecursiveTaskTest extends J
46      }
47  
48      // A recursive action failing in base case
49 <    static final class FailingFibTask extends RecursiveTask<Integer> {
49 >    static final class FailingFibTask extends RecursiveTask<Integer> {
50          final int number;
51          int result;
52          FailingFibTask(int n) { number = n; }
# Line 60 | Line 60 | public class RecursiveTaskTest extends J
60          }
61      }
62  
63 <    /**
63 >    /**
64       * invoke returns value when task completes normally.
65       * isCompletedAbnormally and isCancelled return false for normally
66       * completed tasks. getRawResult of a completed non-null task
67       * returns value;
68 <     *
68 >     *
69       */
70      public void testInvoke() {
71          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
# Line 83 | Line 83 | public class RecursiveTaskTest extends J
83          assertTrue(mainPool.invoke(a) == 21);
84      }
85  
86 <    /**
86 >    /**
87       * quietlyInvoke task returns when task completes normally.
88       * isCompletedAbnormally and isCancelled return false for normally
89       * completed tasks
# Line 104 | Line 104 | public class RecursiveTaskTest extends J
104          assertTrue(mainPool.invoke(a) == 21);
105      }
106  
107 <    /**
107 >    /**
108       * join of a forked task returns when task completes
109       */
110      public void testForkJoin() {
# Line 121 | Line 121 | public class RecursiveTaskTest extends J
121          assertTrue(mainPool.invoke(a) == 21);
122      }
123  
124 <    /**
124 >    /**
125       * get of a forked task returns when task completes
126       */
127      public void testForkGet() {
# Line 134 | Line 134 | public class RecursiveTaskTest extends J
134                          threadAssertTrue(r == 21);
135                          threadAssertTrue(f.isDone());
136                          return r;
137 <                    } catch(Exception ex) {
137 >                    } catch (Exception ex) {
138                          unexpectedException();
139                      }
140                      return NoResult;
# Line 143 | Line 143 | public class RecursiveTaskTest extends J
143          assertTrue(mainPool.invoke(a) == 21);
144      }
145  
146 <    /**
146 >    /**
147       * timed get of a forked task returns when task completes
148       */
149      public void testForkTimedGet() {
# Line 156 | Line 156 | public class RecursiveTaskTest extends J
156                          threadAssertTrue(r == 21);
157                          threadAssertTrue(f.isDone());
158                          return r;
159 <                    } catch(Exception ex) {
159 >                    } catch (Exception ex) {
160                          unexpectedException();
161                      }
162                      return NoResult;
# Line 165 | Line 165 | public class RecursiveTaskTest extends J
165          assertTrue(mainPool.invoke(a) == 21);
166      }
167  
168 <    /**
168 >    /**
169       * helpJoin of a forked task returns when task completes
170       */
171      public void testForkHelpJoin() {
# Line 182 | Line 182 | public class RecursiveTaskTest extends J
182          assertTrue(mainPool.invoke(a) == 21);
183      }
184  
185 <    /**
185 >    /**
186       * quietlyJoin of a forked task returns when task completes
187       */
188      public void testForkQuietlyJoin() {
# Line 201 | Line 201 | public class RecursiveTaskTest extends J
201      }
202  
203  
204 <    /**
204 >    /**
205       * quietlyHelpJoin of a forked task returns when task completes
206       */
207      public void testForkQuietlyHelpJoin() {
# Line 220 | Line 220 | public class RecursiveTaskTest extends J
220      }
221  
222  
223 <    /**
223 >    /**
224       * helpQuiesce returns when tasks are complete.
225       * getQueuedTaskCount returns 0 when quiescent
226       */
# Line 241 | Line 241 | public class RecursiveTaskTest extends J
241      }
242  
243  
244 <    /**
244 >    /**
245       * invoke task throws exception when task completes abnormally
246       */
247      public void testAbnormalInvoke() {
# Line 252 | Line 252 | public class RecursiveTaskTest extends J
252                          f.invoke();
253                          shouldThrow();
254                          return NoResult;
255 <                    } catch(FJException success) {
255 >                    } catch (FJException success) {
256                      }
257                      return NoResult;
258                  }
# Line 260 | Line 260 | public class RecursiveTaskTest extends J
260          mainPool.invoke(a);
261      }
262  
263 <    /**
264 <     * quietelyInvoke task returns when task completes abnormally
263 >    /**
264 >     * quietlyInvoke task returns when task completes abnormally
265       */
266      public void testAbnormalQuietlyInvoke() {
267          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
# Line 275 | Line 275 | public class RecursiveTaskTest extends J
275          mainPool.invoke(a);
276      }
277  
278 <    /**
278 >    /**
279       * join of a forked task throws exception when task completes abnormally
280       */
281      public void testAbnormalForkJoin() {
# Line 287 | Line 287 | public class RecursiveTaskTest extends J
287                          Integer r = f.join();
288                          shouldThrow();
289                          return r;
290 <                    } catch(FJException success) {
290 >                    } catch (FJException success) {
291                      }
292                      return NoResult;
293                  }
# Line 295 | Line 295 | public class RecursiveTaskTest extends J
295          mainPool.invoke(a);
296      }
297  
298 <    /**
298 >    /**
299       * get of a forked task throws exception when task completes abnormally
300       */
301      public void testAbnormalForkGet() {
# Line 307 | Line 307 | public class RecursiveTaskTest extends J
307                          Integer r = f.get();
308                          shouldThrow();
309                          return r;
310 <                    } catch(Exception success) {
310 >                    } catch (ExecutionException success) {
311 >                    } catch (Exception ex) {
312 >                        unexpectedException(ex);
313                      }
314                      return NoResult;
315                  }
# Line 315 | Line 317 | public class RecursiveTaskTest extends J
317          mainPool.invoke(a);
318      }
319  
320 <    /**
320 >    /**
321       * timed get of a forked task throws exception when task completes abnormally
322       */
323      public void testAbnormalForkTimedGet() {
# Line 327 | Line 329 | public class RecursiveTaskTest extends J
329                          Integer r = f.get(5L, TimeUnit.SECONDS);
330                          shouldThrow();
331                          return r;
332 <                    } catch(Exception success) {
332 >                    } catch (ExecutionException success) {
333 >                    } catch (Exception ex) {
334 >                        unexpectedException(ex);
335                      }
336                      return NoResult;
337                  }
# Line 335 | Line 339 | public class RecursiveTaskTest extends J
339          mainPool.invoke(a);
340      }
341  
342 <    /**
342 >    /**
343       * join of a forked task throws exception when task completes abnormally
344       */
345      public void testAbnormalForkHelpJoin() {
# Line 347 | Line 351 | public class RecursiveTaskTest extends J
351                          Integer r = f.helpJoin();
352                          shouldThrow();
353                          return r;
354 <                    } catch(FJException success) {
354 >                    } catch (FJException success) {
355                      }
356                      return NoResult;
357                  }
# Line 355 | Line 359 | public class RecursiveTaskTest extends J
359          mainPool.invoke(a);
360      }
361  
362 <    /**
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.
# Line 377 | Line 381 | public class RecursiveTaskTest extends J
381          mainPool.invoke(a);
382      }
383  
384 <    /**
384 >    /**
385       * quietlyJoin of a forked task returns when task completes abnormally
386       */
387      public void testAbnormalForkQuietlyJoin() {
# Line 395 | Line 399 | public class RecursiveTaskTest extends J
399          mainPool.invoke(a);
400      }
401  
402 <    /**
402 >    /**
403       * invoke task throws exception when task cancelled
404       */
405      public void testCancelledInvoke() {
# Line 407 | Line 411 | public class RecursiveTaskTest extends J
411                          Integer r = f.invoke();
412                          shouldThrow();
413                          return r;
414 <                    } catch(CancellationException success) {
414 >                    } catch (CancellationException success) {
415                      }
416                      return NoResult;
417                  }
# Line 415 | Line 419 | public class RecursiveTaskTest extends J
419          mainPool.invoke(a);
420      }
421  
422 <    /**
422 >    /**
423       * join of a forked task throws exception when task cancelled
424       */
425      public void testCancelledForkJoin() {
# Line 428 | Line 432 | public class RecursiveTaskTest extends J
432                          Integer r = f.join();
433                          shouldThrow();
434                          return r;
435 <                    } catch(CancellationException success) {
435 >                    } catch (CancellationException success) {
436                      }
437                      return NoResult;
438                  }
# Line 436 | Line 440 | public class RecursiveTaskTest extends J
440          mainPool.invoke(a);
441      }
442  
443 <    /**
443 >    /**
444       * get of a forked task throws exception when task cancelled
445       */
446      public void testCancelledForkGet() {
# Line 449 | Line 453 | public class RecursiveTaskTest extends J
453                          Integer r = f.get();
454                          shouldThrow();
455                          return r;
456 <                    } catch(Exception success) {
456 >                    } catch (CancellationException success) {
457 >                    } catch (Exception ex) {
458 >                        unexpectedException(ex);
459                      }
460                      return NoResult;
461                  }
# Line 457 | Line 463 | public class RecursiveTaskTest extends J
463          mainPool.invoke(a);
464      }
465  
466 <    /**
466 >    /**
467       * timed get of a forked task throws exception when task cancelled
468       */
469      public void testCancelledForkTimedGet() {
# Line 470 | Line 476 | public class RecursiveTaskTest extends J
476                          Integer r = f.get(5L, TimeUnit.SECONDS);
477                          shouldThrow();
478                          return r;
479 <                    } catch(Exception success) {
479 >                    } catch (CancellationException success) {
480 >                    } catch (Exception ex) {
481 >                        unexpectedException(ex);
482                      }
483                      return NoResult;
484                  }
# Line 478 | Line 486 | public class RecursiveTaskTest extends J
486          mainPool.invoke(a);
487      }
488  
489 <    /**
489 >    /**
490       * join of a forked task throws exception when task cancelled
491       */
492      public void testCancelledForkHelpJoin() {
# Line 491 | Line 499 | public class RecursiveTaskTest extends J
499                          Integer r = f.helpJoin();
500                          shouldThrow();
501                          return r;
502 <                    } catch(CancellationException success) {
502 >                    } catch (CancellationException success) {
503                      }
504                      return NoResult;
505                  }
# Line 499 | Line 507 | public class RecursiveTaskTest extends J
507          mainPool.invoke(a);
508      }
509  
510 <    /**
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.
# Line 522 | Line 530 | public class RecursiveTaskTest extends J
530          mainPool.invoke(a);
531      }
532  
533 <    /**
533 >    /**
534       * quietlyJoin of a forked task returns when task cancelled
535       */
536      public void testCancelledForkQuietlyJoin() {
# Line 566 | Line 574 | public class RecursiveTaskTest extends J
574          };
575          a.invoke();
576      }
577 <    
577 >
578      /**
579       * inForkJoinPool of executing task returns true
580       */
# Line 606 | Line 614 | public class RecursiveTaskTest extends J
614          assertEquals(a.invoke(), NoResult);
615      }
616  
617 <    /**
617 >    /**
618       * A reinitialized task may be re-invoked
619       */
620      public void testReinitialize() {
# Line 627 | Line 635 | public class RecursiveTaskTest extends J
635          mainPool.invoke(a);
636      }
637  
638 <    /**
638 >    /**
639       * invoke task throws exception after invoking completeExceptionally
640       */
641      public void testCompleteExceptionally() {
# Line 639 | Line 647 | public class RecursiveTaskTest extends J
647                          Integer r = f.invoke();
648                          shouldThrow();
649                          return r;
650 <                    } catch(FJException success) {
650 >                    } catch (FJException success) {
651                      }
652                      return NoResult;
653                  }
# Line 647 | Line 655 | public class RecursiveTaskTest extends J
655          mainPool.invoke(a);
656      }
657  
658 <    /**
658 >    /**
659       * invoke task suppresses execution invoking complete
660       */
661      public void testComplete() {
# Line 664 | Line 672 | public class RecursiveTaskTest extends J
672          mainPool.invoke(a);
673      }
674  
675 <    /**
675 >    /**
676       * invokeAll(t1, t2) invokes all task arguments
677       */
678      public void testInvokeAll2() {
# Line 683 | Line 691 | public class RecursiveTaskTest extends J
691          mainPool.invoke(a);
692      }
693  
694 <    /**
694 >    /**
695       * invokeAll(tasks) with 1 argument invokes task
696       */
697      public void testInvokeAll1() {
# Line 699 | Line 707 | public class RecursiveTaskTest extends J
707          mainPool.invoke(a);
708      }
709  
710 <    /**
710 >    /**
711       * invokeAll(tasks) with > 2 argument invokes tasks
712       */
713      public void testInvokeAll3() {
# Line 721 | Line 729 | public class RecursiveTaskTest extends J
729          mainPool.invoke(a);
730      }
731  
732 <    /**
732 >    /**
733       * invokeAll(collection) invokes all tasks in the collection
734       */
735      public void testInvokeAllCollection() {
# Line 748 | Line 756 | public class RecursiveTaskTest extends J
756      }
757  
758  
759 <    /**
759 >    /**
760       * invokeAll(t1, t2) throw exception if any task does
761       */
762      public void testAbnormalInvokeAll2() {
# Line 760 | Line 768 | public class RecursiveTaskTest extends J
768                          invokeAll(f, g);
769                          shouldThrow();
770                          return NoResult;
771 <                    } catch(FJException success) {
771 >                    } catch (FJException success) {
772                      }
773                      return NoResult;
774                  }
# Line 768 | Line 776 | public class RecursiveTaskTest extends J
776          mainPool.invoke(a);
777      }
778  
779 <    /**
779 >    /**
780       * invokeAll(tasks) with 1 argument throws exception if task does
781       */
782      public void testAbnormalInvokeAll1() {
# Line 779 | Line 787 | public class RecursiveTaskTest extends J
787                          invokeAll(g);
788                          shouldThrow();
789                          return NoResult;
790 <                    } catch(FJException success) {
790 >                    } catch (FJException success) {
791                      }
792                      return NoResult;
793                  }
# Line 787 | Line 795 | public class RecursiveTaskTest extends J
795          mainPool.invoke(a);
796      }
797  
798 <    /**
798 >    /**
799       * invokeAll(tasks) with > 2 argument throws exception if any task does
800       */
801      public void testAbnormalInvokeAll3() {
# Line 800 | Line 808 | public class RecursiveTaskTest extends J
808                          invokeAll(f, g, h);
809                          shouldThrow();
810                          return NoResult;
811 <                    } catch(FJException success) {
811 >                    } catch (FJException success) {
812                      }
813                      return NoResult;
814                  }
# Line 808 | Line 816 | public class RecursiveTaskTest extends J
816          mainPool.invoke(a);
817      }
818  
819 <    /**
820 <     * invokeAll(collection)  throws exception if any task does
819 >    /**
820 >     * invokeAll(collection) throws exception if any task does
821       */
822      public void testAbnormalInvokeAllCollection() {
823          RecursiveTask<Integer> a = new RecursiveTask<Integer>() {
# Line 825 | Line 833 | public class RecursiveTaskTest extends J
833                          invokeAll(set);
834                          shouldThrow();
835                          return NoResult;
836 <                    } catch(FJException success) {
836 >                    } catch (FJException success) {
837                      }
838                      return NoResult;
839                  }
# Line 833 | Line 841 | public class RecursiveTaskTest extends J
841          mainPool.invoke(a);
842      }
843  
844 <    /**
844 >    /**
845       * tryUnfork returns true for most recent unexecuted task,
846       * and suppresses execution
847       */
# Line 854 | Line 862 | public class RecursiveTaskTest extends J
862          singletonPool.invoke(a);
863      }
864  
865 <    /**
865 >    /**
866       * getSurplusQueuedTaskCount returns > 0 when
867       * there are more tasks than threads
868       */
# Line 875 | Line 883 | public class RecursiveTaskTest extends J
883          singletonPool.invoke(a);
884      }
885  
886 <    /**
886 >    /**
887       * peekNextLocalTask returns most recent unexecuted task.
888       */
889      public void testPeekNextLocalTask() {
# Line 895 | Line 903 | public class RecursiveTaskTest extends J
903          singletonPool.invoke(a);
904      }
905  
906 <    /**
906 >    /**
907       * pollNextLocalTask returns most recent unexecuted task
908       * without executing it
909       */
# Line 915 | Line 923 | public class RecursiveTaskTest extends J
923          singletonPool.invoke(a);
924      }
925  
926 <    /**
926 >    /**
927       * pollTask returns an unexecuted task
928       * without executing it
929       */
# Line 936 | Line 944 | public class RecursiveTaskTest extends J
944          singletonPool.invoke(a);
945      }
946  
947 <    /**
947 >    /**
948       * peekNextLocalTask returns least recent unexecuted task in async mode
949       */
950      public void testPeekNextLocalTaskAsync() {
# Line 956 | Line 964 | public class RecursiveTaskTest extends J
964          asyncSingletonPool.invoke(a);
965      }
966  
967 <    /**
967 >    /**
968       * pollNextLocalTask returns least recent unexecuted task
969       * without executing it, in async mode
970       */
# Line 977 | Line 985 | public class RecursiveTaskTest extends J
985          asyncSingletonPool.invoke(a);
986      }
987  
988 <    /**
988 >    /**
989       * pollTask returns an unexecuted task
990       * without executing it, in async mode
991       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines