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.2 by jsr166, Fri Jul 31 23:37:31 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) {
137 >                    } catch (Exception ex) {
138                          unexpectedException();
139                      }
140                  }
# Line 142 | Line 142 | public class RecursiveActionTest extends
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) {
157 >                    } catch (Exception ex) {
158                          unexpectedException();
159                      }
160                  }
# Line 162 | Line 162 | public class RecursiveActionTest extends
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) {
175 >                    } catch (NullPointerException success) {
176 >                    } catch (Exception ex) {
177                          unexpectedException();
178                      }
179                  }
# Line 181 | Line 181 | public class RecursiveActionTest extends
181          mainPool.invoke(a);
182      }
183  
184 <    /**
184 >    /**
185       * helpJoin of a forked task returns when task completes
186       */
187      public void testForkHelpJoin() {
# Line 197 | Line 197 | public class RecursiveActionTest extends
197          mainPool.invoke(a);
198      }
199  
200 <    /**
200 >    /**
201       * quietlyJoin of a forked task returns when task completes
202       */
203      public void testForkQuietlyJoin() {
# Line 214 | Line 214 | public class RecursiveActionTest extends
214      }
215  
216  
217 <    /**
217 >    /**
218       * quietlyHelpJoin of a forked task returns when task completes
219       */
220      public void testForkQuietlyHelpJoin() {
# Line 231 | Line 231 | public class RecursiveActionTest extends
231      }
232  
233  
234 <    /**
234 >    /**
235       * helpQuiesce returns when tasks are complete.
236       * getQueuedTaskCount returns 0 when quiescent
237       */
# Line 250 | Line 250 | public class RecursiveActionTest extends
250      }
251  
252  
253 <    /**
253 >    /**
254       * invoke task throws exception when task completes abnormally
255       */
256      public void testAbnormalInvoke() {
# Line 260 | Line 260 | public class RecursiveActionTest extends
260                          FailingFibAction f = new FailingFibAction(8);
261                          f.invoke();
262                          shouldThrow();
263 <                    } catch(FJException success) {
263 >                    } catch (FJException success) {
264                      }
265                  }
266              };
267          mainPool.invoke(a);
268      }
269  
270 <    /**
270 >    /**
271       * quietelyInvoke task returns when task completes abnormally
272       */
273      public void testAbnormalQuietlyInvoke() {
# Line 281 | Line 281 | public class RecursiveActionTest extends
281          mainPool.invoke(a);
282      }
283  
284 <    /**
284 >    /**
285       * join of a forked task throws exception when task completes abnormally
286       */
287      public void testAbnormalForkJoin() {
# Line 292 | Line 292 | public class RecursiveActionTest extends
292                          f.fork();
293                          f.join();
294                          shouldThrow();
295 <                    } catch(FJException success) {
295 >                    } catch (FJException success) {
296                      }
297                  }
298              };
299          mainPool.invoke(a);
300      }
301  
302 <    /**
302 >    /**
303       * get of a forked task throws exception when task completes abnormally
304       */
305      public void testAbnormalForkGet() {
# Line 310 | Line 310 | public class RecursiveActionTest extends
310                          f.fork();
311                          f.get();
312                          shouldThrow();
313 <                    } catch(Exception success) {
313 >                    } catch (Exception success) {
314                      }
315                  }
316              };
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 328 | Line 328 | public class RecursiveActionTest extends
328                          f.fork();
329                          f.get(5L, TimeUnit.SECONDS);
330                          shouldThrow();
331 <                    } catch(Exception success) {
331 >                    } catch (Exception success) {
332                      }
333                  }
334              };
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 346 | Line 346 | public class RecursiveActionTest extends
346                          f.fork();
347                          f.helpJoin();
348                          shouldThrow();
349 <                    } catch(FJException success) {
349 >                    } catch (FJException success) {
350                      }
351                  }
352              };
353          mainPool.invoke(a);
354      }
355  
356 <    /**
356 >    /**
357       * quietlyHelpJoin of a forked task returns when task completes abnormally.
358       * getException of failed task returns its exception.
359       * isCompletedAbnormally of a failed task returns true.
# Line 374 | Line 374 | public class RecursiveActionTest extends
374          mainPool.invoke(a);
375      }
376  
377 <    /**
377 >    /**
378       * quietlyJoin of a forked task returns when task completes abnormally
379       */
380      public void testAbnormalForkQuietlyJoin() {
# Line 391 | Line 391 | public class RecursiveActionTest extends
391          mainPool.invoke(a);
392      }
393  
394 <    /**
394 >    /**
395       * invoke task throws exception when task cancelled
396       */
397      public void testCancelledInvoke() {
# Line 402 | Line 402 | public class RecursiveActionTest extends
402                          f.cancel(true);
403                          f.invoke();
404                          shouldThrow();
405 <                    } catch(CancellationException success) {
405 >                    } catch (CancellationException success) {
406                      }
407                  }
408              };
409          mainPool.invoke(a);
410      }
411  
412 <    /**
412 >    /**
413       * join of a forked task throws exception when task cancelled
414       */
415      public void testCancelledForkJoin() {
# Line 421 | Line 421 | public class RecursiveActionTest extends
421                          f.fork();
422                          f.join();
423                          shouldThrow();
424 <                    } catch(CancellationException success) {
424 >                    } catch (CancellationException success) {
425                      }
426                  }
427              };
428          mainPool.invoke(a);
429      }
430  
431 <    /**
431 >    /**
432       * get of a forked task throws exception when task cancelled
433       */
434      public void testCancelledForkGet() {
# Line 440 | Line 440 | public class RecursiveActionTest extends
440                          f.fork();
441                          f.get();
442                          shouldThrow();
443 <                    } catch(Exception success) {
443 >                    } catch (Exception success) {
444                      }
445                  }
446              };
447          mainPool.invoke(a);
448      }
449  
450 <    /**
450 >    /**
451       * timed get of a forked task throws exception when task cancelled
452       */
453      public void testCancelledForkTimedGet() {
# Line 459 | Line 459 | public class RecursiveActionTest extends
459                          f.fork();
460                          f.get(5L, TimeUnit.SECONDS);
461                          shouldThrow();
462 <                    } catch(Exception success) {
462 >                    } catch (Exception success) {
463                      }
464                  }
465              };
466          mainPool.invoke(a);
467      }
468  
469 <    /**
469 >    /**
470       * join of a forked task throws exception when task cancelled
471       */
472      public void testCancelledForkHelpJoin() {
# Line 478 | Line 478 | public class RecursiveActionTest extends
478                          f.fork();
479                          f.helpJoin();
480                          shouldThrow();
481 <                    } catch(CancellationException success) {
481 >                    } catch (CancellationException success) {
482                      }
483                  }
484              };
485          mainPool.invoke(a);
486      }
487  
488 <    /**
488 >    /**
489       * quietlyHelpJoin of a forked task returns when task cancelled.
490       * getException of cancelled task returns its exception.
491       * isCompletedAbnormally of a cancelled task returns true.
# Line 507 | Line 507 | public class RecursiveActionTest extends
507          mainPool.invoke(a);
508      }
509  
510 <    /**
510 >    /**
511       * quietlyJoin of a forked task returns when task cancelled
512       */
513      public void testCancelledForkQuietlyJoin() {
# Line 589 | Line 589 | public class RecursiveActionTest extends
589  
590      /**
591       * getPoolIndex of current thread in pool returns 0 <= value < poolSize
592 <     *
592 >     *
593       */
594      public void testWorkerGetPoolIndex() {
595          RecursiveAction a = new RecursiveAction() {
# Line 617 | Line 617 | public class RecursiveActionTest extends
617          a.invoke();
618      }
619  
620 <    /**
620 >    /**
621       * A reinitialized task may be re-invoked
622       */
623      public void testReinitialize() {
# Line 637 | Line 637 | public class RecursiveActionTest extends
637          mainPool.invoke(a);
638      }
639  
640 <    /**
640 >    /**
641       * invoke task throws exception after invoking completeExceptionally
642       */
643      public void testCompleteExceptionally() {
# Line 648 | Line 648 | public class RecursiveActionTest extends
648                          f.completeExceptionally(new FJException());
649                          f.invoke();
650                          shouldThrow();
651 <                    } catch(FJException success) {
651 >                    } catch (FJException success) {
652                      }
653                  }
654              };
655          mainPool.invoke(a);
656      }
657  
658 <    /**
658 >    /**
659       * invoke task suppresses execution invoking complete
660       */
661      public void testComplete() {
# Line 671 | Line 671 | public class RecursiveActionTest extends
671          mainPool.invoke(a);
672      }
673  
674 <    /**
674 >    /**
675       * invokeAll(t1, t2) invokes all task arguments
676       */
677      public void testInvokeAll2() {
# Line 689 | Line 689 | public class RecursiveActionTest extends
689          mainPool.invoke(a);
690      }
691  
692 <    /**
692 >    /**
693       * invokeAll(tasks) with 1 argument invokes task
694       */
695      public void testInvokeAll1() {
# Line 704 | Line 704 | public class RecursiveActionTest extends
704          mainPool.invoke(a);
705      }
706  
707 <    /**
707 >    /**
708       * invokeAll(tasks) with > 2 argument invokes tasks
709       */
710      public void testInvokeAll3() {
# Line 725 | Line 725 | public class RecursiveActionTest extends
725          mainPool.invoke(a);
726      }
727  
728 <    /**
728 >    /**
729       * invokeAll(collection) invokes all tasks in the collection
730       */
731      public void testInvokeAllCollection() {
# Line 751 | Line 751 | public class RecursiveActionTest extends
751      }
752  
753  
754 <    /**
754 >    /**
755       * invokeAll(tasks) with any null task throws NPE
756       */
757      public void testInvokeAllNPE() {
# Line 770 | Line 770 | public class RecursiveActionTest extends
770          mainPool.invoke(a);
771      }
772  
773 <    /**
773 >    /**
774       * invokeAll(t1, t2) throw exception if any task does
775       */
776      public void testAbnormalInvokeAll2() {
# Line 781 | Line 781 | public class RecursiveActionTest extends
781                          FailingFibAction g = new FailingFibAction(9);
782                          invokeAll(f, g);
783                          shouldThrow();
784 <                    } catch(FJException success) {
784 >                    } catch (FJException success) {
785                      }
786                  }
787              };
788          mainPool.invoke(a);
789      }
790  
791 <    /**
791 >    /**
792       * invokeAll(tasks) with 1 argument throws exception if task does
793       */
794      public void testAbnormalInvokeAll1() {
# Line 798 | Line 798 | public class RecursiveActionTest extends
798                          FailingFibAction g = new FailingFibAction(9);
799                          invokeAll(g);
800                          shouldThrow();
801 <                    } catch(FJException success) {
801 >                    } catch (FJException success) {
802                      }
803                  }
804              };
805          mainPool.invoke(a);
806      }
807  
808 <    /**
808 >    /**
809       * invokeAll(tasks) with > 2 argument throws exception if any task does
810       */
811      public void testAbnormalInvokeAll3() {
# Line 817 | Line 817 | public class RecursiveActionTest extends
817                          FibAction h = new FibAction(7);
818                          invokeAll(f, g, h);
819                          shouldThrow();
820 <                    } catch(FJException success) {
820 >                    } catch (FJException success) {
821                      }
822                  }
823              };
824          mainPool.invoke(a);
825      }
826  
827 <    /**
827 >    /**
828       * invokeAll(collection)  throws exception if any task does
829       */
830      public void testAbnormalInvokeAllCollection() {
# Line 840 | Line 840 | public class RecursiveActionTest extends
840                          set.add(h);
841                          invokeAll(set);
842                          shouldThrow();
843 <                    } catch(FJException success) {
843 >                    } catch (FJException success) {
844                      }
845                  }
846              };
847          mainPool.invoke(a);
848      }
849  
850 <    /**
850 >    /**
851       * tryUnfork returns true for most recent unexecuted task,
852       * and suppresses execution
853       */
# Line 867 | Line 867 | public class RecursiveActionTest extends
867          singletonPool.invoke(a);
868      }
869  
870 <    /**
870 >    /**
871       * getSurplusQueuedTaskCount returns > 0 when
872       * there are more tasks than threads
873       */
# Line 887 | Line 887 | public class RecursiveActionTest extends
887          singletonPool.invoke(a);
888      }
889  
890 <    /**
890 >    /**
891       * peekNextLocalTask returns most recent unexecuted task.
892       */
893      public void testPeekNextLocalTask() {
# Line 906 | Line 906 | public class RecursiveActionTest extends
906          singletonPool.invoke(a);
907      }
908  
909 <    /**
909 >    /**
910       * pollNextLocalTask returns most recent unexecuted task
911       * without executing it
912       */
# Line 925 | Line 925 | public class RecursiveActionTest extends
925          singletonPool.invoke(a);
926      }
927  
928 <    /**
928 >    /**
929       * pollTask returns an unexecuted task
930       * without executing it
931       */
# Line 945 | Line 945 | public class RecursiveActionTest extends
945          singletonPool.invoke(a);
946      }
947  
948 <    /**
948 >    /**
949       * peekNextLocalTask returns least recent unexecuted task in async mode
950       */
951      public void testPeekNextLocalTaskAsync() {
# Line 964 | Line 964 | public class RecursiveActionTest extends
964          asyncSingletonPool.invoke(a);
965      }
966  
967 <    /**
967 >    /**
968       * pollNextLocalTask returns least recent unexecuted task
969       * without executing it, in async mode
970       */
# Line 984 | Line 984 | public class RecursiveActionTest extends
984          asyncSingletonPool.invoke(a);
985      }
986  
987 <    /**
987 >    /**
988       * pollTask returns an unexecuted task
989       * without executing it, in async mode
990       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines