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

Comparing jsr166/src/test/tck/RecursiveActionTest.java (file contents):
Revision 1.1 by dl, Fri Jul 31 23:02:50 2009 UTC vs.
Revision 1.6 by jsr166, Tue Aug 4 10:13:48 2009 UTC

# Line 11 | Line 11 | import java.util.*;
11   public class RecursiveActionTest 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(RecursiveActionTest.class);
# Line 29 | Line 29 | public class RecursiveActionTest extends
29      }
30  
31      // A simple recursive action for testing
32 <    static final class FibAction extends RecursiveAction {
32 >    static final class FibAction extends RecursiveAction {
33          final int number;
34          int result;
35          FibAction(int n) { number = n; }
# Line 47 | Line 47 | public class RecursiveActionTest extends
47      }
48  
49      // A recursive action failing in base case
50 <    static final class FailingFibAction extends RecursiveAction {
50 >    static final class FailingFibAction extends RecursiveAction {
51          final int number;
52          int result;
53          FailingFibAction(int n) { number = n; }
# Line 64 | Line 64 | public class RecursiveActionTest extends
64          }
65      }
66  
67 <    /**
67 >    /**
68       * invoke returns when task completes normally.
69       * isCompletedAbnormally and isCancelled return false for normally
70       * completed tasks. getRawResult of a RecursiveAction returns null;
71 <     *
71 >     *
72       */
73      public void testInvoke() {
74          RecursiveAction a = new RecursiveAction() {
# Line 85 | Line 85 | public class RecursiveActionTest extends
85          mainPool.invoke(a);
86      }
87  
88 <    /**
88 >    /**
89       * quietlyInvoke task returns when task completes normally.
90       * isCompletedAbnormally and isCancelled return false for normally
91       * completed tasks
# Line 105 | Line 105 | public class RecursiveActionTest extends
105          mainPool.invoke(a);
106      }
107  
108 <    /**
108 >    /**
109       * join of a forked task returns when task completes
110       */
111      public void testForkJoin() {
# Line 122 | Line 122 | public class RecursiveActionTest extends
122          mainPool.invoke(a);
123      }
124  
125 <    /**
125 >    /**
126       * get of a forked task returns when task completes
127       */
128      public void testForkGet() {
# Line 134 | Line 134 | public class RecursiveActionTest extends
134                          f.get();
135                          threadAssertTrue(f.result == 21);
136                          threadAssertTrue(f.isDone());
137 <                    } catch(Exception ex) {
138 <                        unexpectedException();
137 >                    } catch (Exception ex) {
138 >                        unexpectedException(ex);
139                      }
140                  }
141              };
142          mainPool.invoke(a);
143      }
144  
145 <    /**
145 >    /**
146       * timed get of a forked task returns when task completes
147       */
148      public void testForkTimedGet() {
# Line 154 | Line 154 | public class RecursiveActionTest extends
154                          f.get(5L, TimeUnit.SECONDS);
155                          threadAssertTrue(f.result == 21);
156                          threadAssertTrue(f.isDone());
157 <                    } catch(Exception ex) {
158 <                        unexpectedException();
157 >                    } catch (Exception ex) {
158 >                        unexpectedException(ex);
159                      }
160                  }
161              };
162          mainPool.invoke(a);
163      }
164  
165 <    /**
165 >    /**
166       * timed get with null time unit throws NPE
167       */
168      public void testForkTimedGetNPE() {
# Line 172 | Line 172 | public class RecursiveActionTest extends
172                          FibAction f = new FibAction(8);
173                          f.fork();
174                          f.get(5L, null);
175 <                    } catch(NullPointerException success) {
176 <                    } catch(Exception ex) {
177 <                        unexpectedException();
175 >                        shouldThrow();
176 >                    } catch (NullPointerException success) {
177 >                    } catch (Exception ex) {
178 >                        unexpectedException(ex);
179                      }
180                  }
181              };
182          mainPool.invoke(a);
183      }
184  
185 <    /**
185 >    /**
186       * helpJoin of a forked task returns when task completes
187       */
188      public void testForkHelpJoin() {
# Line 197 | Line 198 | public class RecursiveActionTest extends
198          mainPool.invoke(a);
199      }
200  
201 <    /**
201 >    /**
202       * quietlyJoin of a forked task returns when task completes
203       */
204      public void testForkQuietlyJoin() {
# Line 214 | Line 215 | public class RecursiveActionTest extends
215      }
216  
217  
218 <    /**
218 >    /**
219       * quietlyHelpJoin of a forked task returns when task completes
220       */
221      public void testForkQuietlyHelpJoin() {
# Line 231 | Line 232 | public class RecursiveActionTest extends
232      }
233  
234  
235 <    /**
235 >    /**
236       * helpQuiesce returns when tasks are complete.
237       * getQueuedTaskCount returns 0 when quiescent
238       */
# Line 250 | Line 251 | public class RecursiveActionTest extends
251      }
252  
253  
254 <    /**
254 >    /**
255       * invoke task throws exception when task completes abnormally
256       */
257      public void testAbnormalInvoke() {
# Line 260 | Line 261 | public class RecursiveActionTest extends
261                          FailingFibAction f = new FailingFibAction(8);
262                          f.invoke();
263                          shouldThrow();
264 <                    } catch(FJException success) {
264 >                    } catch (FJException success) {
265                      }
266                  }
267              };
268          mainPool.invoke(a);
269      }
270  
271 <    /**
272 <     * quietelyInvoke task returns when task completes abnormally
271 >    /**
272 >     * quietlyInvoke task returns when task completes abnormally
273       */
274      public void testAbnormalQuietlyInvoke() {
275          RecursiveAction a = new RecursiveAction() {
# Line 281 | Line 282 | public class RecursiveActionTest extends
282          mainPool.invoke(a);
283      }
284  
285 <    /**
285 >    /**
286       * join of a forked task throws exception when task completes abnormally
287       */
288      public void testAbnormalForkJoin() {
# Line 292 | Line 293 | public class RecursiveActionTest extends
293                          f.fork();
294                          f.join();
295                          shouldThrow();
296 <                    } catch(FJException success) {
296 >                    } catch (FJException success) {
297                      }
298                  }
299              };
300          mainPool.invoke(a);
301      }
302  
303 <    /**
303 >    /**
304       * get of a forked task throws exception when task completes abnormally
305       */
306      public void testAbnormalForkGet() {
# Line 310 | Line 311 | public class RecursiveActionTest extends
311                          f.fork();
312                          f.get();
313                          shouldThrow();
314 <                    } catch(Exception success) {
314 >                    } catch (ExecutionException success) {
315 >                    } catch (Exception ex) {
316 >                        unexpectedException(ex);
317                      }
318                  }
319              };
320          mainPool.invoke(a);
321      }
322  
323 <    /**
323 >    /**
324       * timed get of a forked task throws exception when task completes abnormally
325       */
326      public void testAbnormalForkTimedGet() {
# Line 328 | Line 331 | public class RecursiveActionTest extends
331                          f.fork();
332                          f.get(5L, TimeUnit.SECONDS);
333                          shouldThrow();
334 <                    } catch(Exception success) {
334 >                    } catch (ExecutionException success) {
335 >                    } catch (Exception ex) {
336 >                        unexpectedException(ex);
337                      }
338                  }
339              };
340          mainPool.invoke(a);
341      }
342  
343 <    /**
343 >    /**
344       * join of a forked task throws exception when task completes abnormally
345       */
346      public void testAbnormalForkHelpJoin() {
# Line 346 | Line 351 | public class RecursiveActionTest extends
351                          f.fork();
352                          f.helpJoin();
353                          shouldThrow();
354 <                    } catch(FJException success) {
354 >                    } catch (FJException success) {
355                      }
356                  }
357              };
358          mainPool.invoke(a);
359      }
360  
361 <    /**
361 >    /**
362       * quietlyHelpJoin of a forked task returns when task completes abnormally.
363       * getException of failed task returns its exception.
364       * isCompletedAbnormally of a failed task returns true.
# Line 374 | Line 379 | public class RecursiveActionTest extends
379          mainPool.invoke(a);
380      }
381  
382 <    /**
382 >    /**
383       * quietlyJoin of a forked task returns when task completes abnormally
384       */
385      public void testAbnormalForkQuietlyJoin() {
# Line 391 | Line 396 | public class RecursiveActionTest extends
396          mainPool.invoke(a);
397      }
398  
399 <    /**
399 >    /**
400       * invoke task throws exception when task cancelled
401       */
402      public void testCancelledInvoke() {
# Line 402 | Line 407 | public class RecursiveActionTest extends
407                          f.cancel(true);
408                          f.invoke();
409                          shouldThrow();
410 <                    } catch(CancellationException success) {
410 >                    } catch (CancellationException success) {
411                      }
412                  }
413              };
414          mainPool.invoke(a);
415      }
416  
417 <    /**
417 >    /**
418       * join of a forked task throws exception when task cancelled
419       */
420      public void testCancelledForkJoin() {
# Line 421 | Line 426 | public class RecursiveActionTest extends
426                          f.fork();
427                          f.join();
428                          shouldThrow();
429 <                    } catch(CancellationException success) {
429 >                    } catch (CancellationException success) {
430                      }
431                  }
432              };
433          mainPool.invoke(a);
434      }
435  
436 <    /**
436 >    /**
437       * get of a forked task throws exception when task cancelled
438       */
439      public void testCancelledForkGet() {
# Line 440 | Line 445 | public class RecursiveActionTest extends
445                          f.fork();
446                          f.get();
447                          shouldThrow();
448 <                    } catch(Exception success) {
448 >                    } catch (CancellationException success) {
449 >                    } catch (Exception ex) {
450 >                        unexpectedException(ex);
451                      }
452                  }
453              };
454          mainPool.invoke(a);
455      }
456  
457 <    /**
457 >    /**
458       * timed get of a forked task throws exception when task cancelled
459       */
460      public void testCancelledForkTimedGet() {
# Line 459 | Line 466 | public class RecursiveActionTest extends
466                          f.fork();
467                          f.get(5L, TimeUnit.SECONDS);
468                          shouldThrow();
469 <                    } catch(Exception success) {
469 >                    } catch (CancellationException success) {
470 >                    } catch (Exception ex) {
471 >                        unexpectedException(ex);
472                      }
473                  }
474              };
475          mainPool.invoke(a);
476      }
477  
478 <    /**
478 >    /**
479       * join of a forked task throws exception when task cancelled
480       */
481      public void testCancelledForkHelpJoin() {
# Line 478 | Line 487 | public class RecursiveActionTest extends
487                          f.fork();
488                          f.helpJoin();
489                          shouldThrow();
490 <                    } catch(CancellationException success) {
490 >                    } catch (CancellationException success) {
491                      }
492                  }
493              };
494          mainPool.invoke(a);
495      }
496  
497 <    /**
497 >    /**
498       * quietlyHelpJoin of a forked task returns when task cancelled.
499       * getException of cancelled task returns its exception.
500       * isCompletedAbnormally of a cancelled task returns true.
# Line 507 | Line 516 | public class RecursiveActionTest extends
516          mainPool.invoke(a);
517      }
518  
519 <    /**
519 >    /**
520       * quietlyJoin of a forked task returns when task cancelled
521       */
522      public void testCancelledForkQuietlyJoin() {
# Line 589 | Line 598 | public class RecursiveActionTest extends
598  
599      /**
600       * getPoolIndex of current thread in pool returns 0 <= value < poolSize
601 <     *
601 >     *
602       */
603      public void testWorkerGetPoolIndex() {
604          RecursiveAction a = new RecursiveAction() {
# Line 617 | Line 626 | public class RecursiveActionTest extends
626          a.invoke();
627      }
628  
629 <    /**
629 >    /**
630       * A reinitialized task may be re-invoked
631       */
632      public void testReinitialize() {
# Line 637 | Line 646 | public class RecursiveActionTest extends
646          mainPool.invoke(a);
647      }
648  
649 <    /**
649 >    /**
650       * invoke task throws exception after invoking completeExceptionally
651       */
652      public void testCompleteExceptionally() {
# Line 648 | Line 657 | public class RecursiveActionTest extends
657                          f.completeExceptionally(new FJException());
658                          f.invoke();
659                          shouldThrow();
660 <                    } catch(FJException success) {
660 >                    } catch (FJException success) {
661                      }
662                  }
663              };
664          mainPool.invoke(a);
665      }
666  
667 <    /**
667 >    /**
668       * invoke task suppresses execution invoking complete
669       */
670      public void testComplete() {
# Line 671 | Line 680 | public class RecursiveActionTest extends
680          mainPool.invoke(a);
681      }
682  
683 <    /**
683 >    /**
684       * invokeAll(t1, t2) invokes all task arguments
685       */
686      public void testInvokeAll2() {
# Line 689 | Line 698 | public class RecursiveActionTest extends
698          mainPool.invoke(a);
699      }
700  
701 <    /**
701 >    /**
702       * invokeAll(tasks) with 1 argument invokes task
703       */
704      public void testInvokeAll1() {
# Line 704 | Line 713 | public class RecursiveActionTest extends
713          mainPool.invoke(a);
714      }
715  
716 <    /**
716 >    /**
717       * invokeAll(tasks) with > 2 argument invokes tasks
718       */
719      public void testInvokeAll3() {
# Line 725 | Line 734 | public class RecursiveActionTest extends
734          mainPool.invoke(a);
735      }
736  
737 <    /**
737 >    /**
738       * invokeAll(collection) invokes all tasks in the collection
739       */
740      public void testInvokeAllCollection() {
# Line 751 | Line 760 | public class RecursiveActionTest extends
760      }
761  
762  
763 <    /**
763 >    /**
764       * invokeAll(tasks) with any null task throws NPE
765       */
766      public void testInvokeAllNPE() {
# Line 770 | Line 779 | public class RecursiveActionTest extends
779          mainPool.invoke(a);
780      }
781  
782 <    /**
782 >    /**
783       * invokeAll(t1, t2) throw exception if any task does
784       */
785      public void testAbnormalInvokeAll2() {
# Line 781 | Line 790 | public class RecursiveActionTest extends
790                          FailingFibAction g = new FailingFibAction(9);
791                          invokeAll(f, g);
792                          shouldThrow();
793 <                    } catch(FJException success) {
793 >                    } catch (FJException success) {
794                      }
795                  }
796              };
797          mainPool.invoke(a);
798      }
799  
800 <    /**
800 >    /**
801       * invokeAll(tasks) with 1 argument throws exception if task does
802       */
803      public void testAbnormalInvokeAll1() {
# Line 798 | Line 807 | public class RecursiveActionTest extends
807                          FailingFibAction g = new FailingFibAction(9);
808                          invokeAll(g);
809                          shouldThrow();
810 <                    } catch(FJException success) {
810 >                    } catch (FJException success) {
811                      }
812                  }
813              };
814          mainPool.invoke(a);
815      }
816  
817 <    /**
817 >    /**
818       * invokeAll(tasks) with > 2 argument throws exception if any task does
819       */
820      public void testAbnormalInvokeAll3() {
# Line 817 | Line 826 | public class RecursiveActionTest extends
826                          FibAction h = new FibAction(7);
827                          invokeAll(f, g, h);
828                          shouldThrow();
829 <                    } catch(FJException success) {
829 >                    } catch (FJException success) {
830                      }
831                  }
832              };
833          mainPool.invoke(a);
834      }
835  
836 <    /**
837 <     * invokeAll(collection)  throws exception if any task does
836 >    /**
837 >     * invokeAll(collection) throws exception if any task does
838       */
839      public void testAbnormalInvokeAllCollection() {
840          RecursiveAction a = new RecursiveAction() {
# Line 840 | Line 849 | public class RecursiveActionTest extends
849                          set.add(h);
850                          invokeAll(set);
851                          shouldThrow();
852 <                    } catch(FJException success) {
852 >                    } catch (FJException success) {
853                      }
854                  }
855              };
856          mainPool.invoke(a);
857      }
858  
859 <    /**
859 >    /**
860       * tryUnfork returns true for most recent unexecuted task,
861       * and suppresses execution
862       */
# Line 867 | Line 876 | public class RecursiveActionTest extends
876          singletonPool.invoke(a);
877      }
878  
879 <    /**
879 >    /**
880       * getSurplusQueuedTaskCount returns > 0 when
881       * there are more tasks than threads
882       */
# Line 887 | Line 896 | public class RecursiveActionTest extends
896          singletonPool.invoke(a);
897      }
898  
899 <    /**
899 >    /**
900       * peekNextLocalTask returns most recent unexecuted task.
901       */
902      public void testPeekNextLocalTask() {
# Line 906 | Line 915 | public class RecursiveActionTest extends
915          singletonPool.invoke(a);
916      }
917  
918 <    /**
918 >    /**
919       * pollNextLocalTask returns most recent unexecuted task
920       * without executing it
921       */
# Line 925 | Line 934 | public class RecursiveActionTest extends
934          singletonPool.invoke(a);
935      }
936  
937 <    /**
937 >    /**
938       * pollTask returns an unexecuted task
939       * without executing it
940       */
# Line 945 | Line 954 | public class RecursiveActionTest extends
954          singletonPool.invoke(a);
955      }
956  
957 <    /**
957 >    /**
958       * peekNextLocalTask returns least recent unexecuted task in async mode
959       */
960      public void testPeekNextLocalTaskAsync() {
# Line 964 | Line 973 | public class RecursiveActionTest extends
973          asyncSingletonPool.invoke(a);
974      }
975  
976 <    /**
976 >    /**
977       * pollNextLocalTask returns least recent unexecuted task
978       * without executing it, in async mode
979       */
# Line 984 | Line 993 | public class RecursiveActionTest extends
993          asyncSingletonPool.invoke(a);
994      }
995  
996 <    /**
996 >    /**
997       * pollTask returns an unexecuted task
998       * without executing it, in async mode
999       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines