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.2 by jsr166, Fri Jul 31 23:37:31 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 <    /**
263 >    /**
264       * quietelyInvoke task returns when task completes abnormally
265       */
266      public void testAbnormalQuietlyInvoke() {
# 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 (Exception success) {
311                      }
312                      return NoResult;
313                  }
# Line 315 | Line 315 | public class RecursiveTaskTest extends J
315          mainPool.invoke(a);
316      }
317  
318 <    /**
318 >    /**
319       * timed get of a forked task throws exception when task completes abnormally
320       */
321      public void testAbnormalForkTimedGet() {
# Line 327 | Line 327 | public class RecursiveTaskTest extends J
327                          Integer r = f.get(5L, TimeUnit.SECONDS);
328                          shouldThrow();
329                          return r;
330 <                    } catch(Exception success) {
330 >                    } catch (Exception success) {
331                      }
332                      return NoResult;
333                  }
# Line 335 | Line 335 | public class RecursiveTaskTest extends J
335          mainPool.invoke(a);
336      }
337  
338 <    /**
338 >    /**
339       * join of a forked task throws exception when task completes abnormally
340       */
341      public void testAbnormalForkHelpJoin() {
# Line 347 | Line 347 | public class RecursiveTaskTest extends J
347                          Integer r = f.helpJoin();
348                          shouldThrow();
349                          return r;
350 <                    } catch(FJException success) {
350 >                    } catch (FJException success) {
351                      }
352                      return NoResult;
353                  }
# Line 355 | Line 355 | public class RecursiveTaskTest extends J
355          mainPool.invoke(a);
356      }
357  
358 <    /**
358 >    /**
359       * quietlyHelpJoin of a forked task returns when task completes abnormally.
360       * getException of failed task returns its exception.
361       * isCompletedAbnormally of a failed task returns true.
# Line 377 | Line 377 | public class RecursiveTaskTest extends J
377          mainPool.invoke(a);
378      }
379  
380 <    /**
380 >    /**
381       * quietlyJoin of a forked task returns when task completes abnormally
382       */
383      public void testAbnormalForkQuietlyJoin() {
# Line 395 | Line 395 | public class RecursiveTaskTest extends J
395          mainPool.invoke(a);
396      }
397  
398 <    /**
398 >    /**
399       * invoke task throws exception when task cancelled
400       */
401      public void testCancelledInvoke() {
# Line 407 | Line 407 | public class RecursiveTaskTest extends J
407                          Integer r = f.invoke();
408                          shouldThrow();
409                          return r;
410 <                    } catch(CancellationException success) {
410 >                    } catch (CancellationException success) {
411                      }
412                      return NoResult;
413                  }
# Line 415 | Line 415 | public class RecursiveTaskTest extends J
415          mainPool.invoke(a);
416      }
417  
418 <    /**
418 >    /**
419       * join of a forked task throws exception when task cancelled
420       */
421      public void testCancelledForkJoin() {
# Line 428 | Line 428 | public class RecursiveTaskTest extends J
428                          Integer r = f.join();
429                          shouldThrow();
430                          return r;
431 <                    } catch(CancellationException success) {
431 >                    } catch (CancellationException success) {
432                      }
433                      return NoResult;
434                  }
# Line 436 | Line 436 | public class RecursiveTaskTest extends J
436          mainPool.invoke(a);
437      }
438  
439 <    /**
439 >    /**
440       * get of a forked task throws exception when task cancelled
441       */
442      public void testCancelledForkGet() {
# Line 449 | Line 449 | public class RecursiveTaskTest extends J
449                          Integer r = f.get();
450                          shouldThrow();
451                          return r;
452 <                    } catch(Exception success) {
452 >                    } catch (Exception success) {
453                      }
454                      return NoResult;
455                  }
# Line 457 | Line 457 | public class RecursiveTaskTest extends J
457          mainPool.invoke(a);
458      }
459  
460 <    /**
460 >    /**
461       * timed get of a forked task throws exception when task cancelled
462       */
463      public void testCancelledForkTimedGet() {
# Line 470 | Line 470 | public class RecursiveTaskTest extends J
470                          Integer r = f.get(5L, TimeUnit.SECONDS);
471                          shouldThrow();
472                          return r;
473 <                    } catch(Exception success) {
473 >                    } catch (Exception success) {
474                      }
475                      return NoResult;
476                  }
# Line 478 | Line 478 | public class RecursiveTaskTest extends J
478          mainPool.invoke(a);
479      }
480  
481 <    /**
481 >    /**
482       * join of a forked task throws exception when task cancelled
483       */
484      public void testCancelledForkHelpJoin() {
# Line 491 | Line 491 | public class RecursiveTaskTest extends J
491                          Integer r = f.helpJoin();
492                          shouldThrow();
493                          return r;
494 <                    } catch(CancellationException success) {
494 >                    } catch (CancellationException success) {
495                      }
496                      return NoResult;
497                  }
# Line 499 | Line 499 | public class RecursiveTaskTest extends J
499          mainPool.invoke(a);
500      }
501  
502 <    /**
502 >    /**
503       * quietlyHelpJoin of a forked task returns when task cancelled.
504       * getException of cancelled task returns its exception
505       * isCompletedAbnormally of a cancelled task returns true.
# Line 522 | Line 522 | public class RecursiveTaskTest extends J
522          mainPool.invoke(a);
523      }
524  
525 <    /**
525 >    /**
526       * quietlyJoin of a forked task returns when task cancelled
527       */
528      public void testCancelledForkQuietlyJoin() {
# Line 566 | Line 566 | public class RecursiveTaskTest extends J
566          };
567          a.invoke();
568      }
569 <    
569 >
570      /**
571       * inForkJoinPool of executing task returns true
572       */
# Line 606 | Line 606 | public class RecursiveTaskTest extends J
606          assertEquals(a.invoke(), NoResult);
607      }
608  
609 <    /**
609 >    /**
610       * A reinitialized task may be re-invoked
611       */
612      public void testReinitialize() {
# Line 627 | Line 627 | public class RecursiveTaskTest extends J
627          mainPool.invoke(a);
628      }
629  
630 <    /**
630 >    /**
631       * invoke task throws exception after invoking completeExceptionally
632       */
633      public void testCompleteExceptionally() {
# Line 639 | Line 639 | public class RecursiveTaskTest extends J
639                          Integer r = f.invoke();
640                          shouldThrow();
641                          return r;
642 <                    } catch(FJException success) {
642 >                    } catch (FJException success) {
643                      }
644                      return NoResult;
645                  }
# Line 647 | Line 647 | public class RecursiveTaskTest extends J
647          mainPool.invoke(a);
648      }
649  
650 <    /**
650 >    /**
651       * invoke task suppresses execution invoking complete
652       */
653      public void testComplete() {
# Line 664 | Line 664 | public class RecursiveTaskTest extends J
664          mainPool.invoke(a);
665      }
666  
667 <    /**
667 >    /**
668       * invokeAll(t1, t2) invokes all task arguments
669       */
670      public void testInvokeAll2() {
# Line 683 | Line 683 | public class RecursiveTaskTest extends J
683          mainPool.invoke(a);
684      }
685  
686 <    /**
686 >    /**
687       * invokeAll(tasks) with 1 argument invokes task
688       */
689      public void testInvokeAll1() {
# Line 699 | Line 699 | public class RecursiveTaskTest extends J
699          mainPool.invoke(a);
700      }
701  
702 <    /**
702 >    /**
703       * invokeAll(tasks) with > 2 argument invokes tasks
704       */
705      public void testInvokeAll3() {
# Line 721 | Line 721 | public class RecursiveTaskTest extends J
721          mainPool.invoke(a);
722      }
723  
724 <    /**
724 >    /**
725       * invokeAll(collection) invokes all tasks in the collection
726       */
727      public void testInvokeAllCollection() {
# Line 748 | Line 748 | public class RecursiveTaskTest extends J
748      }
749  
750  
751 <    /**
751 >    /**
752       * invokeAll(t1, t2) throw exception if any task does
753       */
754      public void testAbnormalInvokeAll2() {
# Line 760 | Line 760 | public class RecursiveTaskTest extends J
760                          invokeAll(f, g);
761                          shouldThrow();
762                          return NoResult;
763 <                    } catch(FJException success) {
763 >                    } catch (FJException success) {
764                      }
765                      return NoResult;
766                  }
# Line 768 | Line 768 | public class RecursiveTaskTest extends J
768          mainPool.invoke(a);
769      }
770  
771 <    /**
771 >    /**
772       * invokeAll(tasks) with 1 argument throws exception if task does
773       */
774      public void testAbnormalInvokeAll1() {
# Line 779 | Line 779 | public class RecursiveTaskTest extends J
779                          invokeAll(g);
780                          shouldThrow();
781                          return NoResult;
782 <                    } catch(FJException success) {
782 >                    } catch (FJException success) {
783                      }
784                      return NoResult;
785                  }
# Line 787 | Line 787 | public class RecursiveTaskTest extends J
787          mainPool.invoke(a);
788      }
789  
790 <    /**
790 >    /**
791       * invokeAll(tasks) with > 2 argument throws exception if any task does
792       */
793      public void testAbnormalInvokeAll3() {
# Line 800 | Line 800 | public class RecursiveTaskTest extends J
800                          invokeAll(f, g, h);
801                          shouldThrow();
802                          return NoResult;
803 <                    } catch(FJException success) {
803 >                    } catch (FJException success) {
804                      }
805                      return NoResult;
806                  }
# Line 808 | Line 808 | public class RecursiveTaskTest extends J
808          mainPool.invoke(a);
809      }
810  
811 <    /**
811 >    /**
812       * invokeAll(collection)  throws exception if any task does
813       */
814      public void testAbnormalInvokeAllCollection() {
# Line 825 | Line 825 | public class RecursiveTaskTest extends J
825                          invokeAll(set);
826                          shouldThrow();
827                          return NoResult;
828 <                    } catch(FJException success) {
828 >                    } catch (FJException success) {
829                      }
830                      return NoResult;
831                  }
# Line 833 | Line 833 | public class RecursiveTaskTest extends J
833          mainPool.invoke(a);
834      }
835  
836 <    /**
836 >    /**
837       * tryUnfork returns true for most recent unexecuted task,
838       * and suppresses execution
839       */
# Line 854 | Line 854 | public class RecursiveTaskTest extends J
854          singletonPool.invoke(a);
855      }
856  
857 <    /**
857 >    /**
858       * getSurplusQueuedTaskCount returns > 0 when
859       * there are more tasks than threads
860       */
# Line 875 | Line 875 | public class RecursiveTaskTest extends J
875          singletonPool.invoke(a);
876      }
877  
878 <    /**
878 >    /**
879       * peekNextLocalTask returns most recent unexecuted task.
880       */
881      public void testPeekNextLocalTask() {
# Line 895 | Line 895 | public class RecursiveTaskTest extends J
895          singletonPool.invoke(a);
896      }
897  
898 <    /**
898 >    /**
899       * pollNextLocalTask returns most recent unexecuted task
900       * without executing it
901       */
# Line 915 | Line 915 | public class RecursiveTaskTest extends J
915          singletonPool.invoke(a);
916      }
917  
918 <    /**
918 >    /**
919       * pollTask returns an unexecuted task
920       * without executing it
921       */
# Line 936 | Line 936 | public class RecursiveTaskTest extends J
936          singletonPool.invoke(a);
937      }
938  
939 <    /**
939 >    /**
940       * peekNextLocalTask returns least recent unexecuted task in async mode
941       */
942      public void testPeekNextLocalTaskAsync() {
# Line 956 | Line 956 | public class RecursiveTaskTest extends J
956          asyncSingletonPool.invoke(a);
957      }
958  
959 <    /**
959 >    /**
960       * pollNextLocalTask returns least recent unexecuted task
961       * without executing it, in async mode
962       */
# Line 977 | Line 977 | public class RecursiveTaskTest extends J
977          asyncSingletonPool.invoke(a);
978      }
979  
980 <    /**
980 >    /**
981       * pollTask returns an unexecuted task
982       * without executing it, in async mode
983       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines