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

Comparing jsr166/src/test/tck/ForkJoinTaskTest.java (file contents):
Revision 1.1 by dl, Fri Jul 31 23:02:49 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 ForkJoinTaskTest 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(ForkJoinTaskTest.class);
# Line 19 | Line 19 | public class ForkJoinTaskTest extends JS
19  
20      /**
21       * Testing coverage notes:
22 <     *
22 >     *
23       * To test extension methods and overrides, most tests use
24       * BinaryAsyncAction extension class that processes joins
25       * differently than supplied Recursive forms.
26 <     */    
26 >     */
27  
28      static final ForkJoinPool mainPool = new ForkJoinPool();
29      static final ForkJoinPool singletonPool = new ForkJoinPool(1);
# Line 40 | Line 40 | public class ForkJoinTaskTest extends JS
40          private volatile int controlState;
41  
42          static final AtomicIntegerFieldUpdater<BinaryAsyncAction> controlStateUpdater =
43 <            AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
43 >            AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
44                                                   "controlState");
45  
46          private BinaryAsyncAction parent;
# Line 92 | Line 92 | public class ForkJoinTaskTest extends JS
92                      break;
93                  try {
94                      p.onComplete(a, s);
95 <                } catch(Throwable rex) {
95 >                } catch (Throwable rex) {
96                      p.completeExceptionally(rex);
97                      return;
98                  }
# Line 129 | Line 129 | public class ForkJoinTaskTest extends JS
129              return controlState;
130          }
131  
132 <        protected final boolean compareAndSetControlState(int expect,
132 >        protected final boolean compareAndSetControlState(int expect,
133                                                            int update) {
134              return controlStateUpdater.compareAndSet(this, expect, update);
135          }
# Line 150 | Line 150 | public class ForkJoinTaskTest extends JS
150  
151      static final class AsyncFib  extends BinaryAsyncAction {
152          int number;
153 <        public AsyncFib(int n) {
153 >        public AsyncFib(int n) {
154              this.number = n;
155          }
156 <        
156 >
157          public final boolean exec() {
158              AsyncFib f = this;
159              int n = f.number;
# Line 179 | Line 179 | public class ForkJoinTaskTest extends JS
179  
180      static final class FailingAsyncFib  extends BinaryAsyncAction {
181          int number;
182 <        public FailingAsyncFib(int n) {
182 >        public FailingAsyncFib(int n) {
183              this.number = n;
184          }
185 <        
185 >
186          public final boolean exec() {
187              FailingAsyncFib f = this;
188              int n = f.number;
# Line 205 | Line 205 | public class ForkJoinTaskTest extends JS
205          }
206      }
207  
208 <    /**
208 >    /**
209       * invoke returns when task completes normally.
210       * isCompletedAbnormally and isCancelled return false for normally
211       * completed tasks. getRawResult of a RecursiveAction returns null;
212 <     *
212 >     *
213       */
214      public void testInvoke() {
215          RecursiveAction a = new RecursiveAction() {
# Line 226 | Line 226 | public class ForkJoinTaskTest extends JS
226          mainPool.invoke(a);
227      }
228  
229 <    /**
229 >    /**
230       * quietlyInvoke task returns when task completes normally.
231       * isCompletedAbnormally and isCancelled return false for normally
232       * completed tasks
# Line 246 | Line 246 | public class ForkJoinTaskTest extends JS
246          mainPool.invoke(a);
247      }
248  
249 <    /**
249 >    /**
250       * join of a forked task returns when task completes
251       */
252      public void testForkJoin() {
# Line 263 | Line 263 | public class ForkJoinTaskTest extends JS
263          mainPool.invoke(a);
264      }
265  
266 <    /**
266 >    /**
267       * get of a forked task returns when task completes
268       */
269      public void testForkGet() {
# Line 275 | Line 275 | public class ForkJoinTaskTest extends JS
275                          f.get();
276                          threadAssertTrue(f.number == 21);
277                          threadAssertTrue(f.isDone());
278 <                    } catch(Exception ex) {
278 >                    } catch (Exception ex) {
279                          unexpectedException();
280                      }
281                  }
# Line 283 | Line 283 | public class ForkJoinTaskTest extends JS
283          mainPool.invoke(a);
284      }
285  
286 <    /**
286 >    /**
287       * timed get of a forked task returns when task completes
288       */
289      public void testForkTimedGet() {
# Line 295 | Line 295 | public class ForkJoinTaskTest extends JS
295                          f.get(5L, TimeUnit.SECONDS);
296                          threadAssertTrue(f.number == 21);
297                          threadAssertTrue(f.isDone());
298 <                    } catch(Exception ex) {
298 >                    } catch (Exception ex) {
299                          unexpectedException();
300                      }
301                  }
# Line 303 | Line 303 | public class ForkJoinTaskTest extends JS
303          mainPool.invoke(a);
304      }
305  
306 <    /**
306 >    /**
307       * timed get with null time unit throws NPE
308       */
309      public void testForkTimedGetNPE() {
# Line 313 | Line 313 | public class ForkJoinTaskTest extends JS
313                          AsyncFib f = new AsyncFib(8);
314                          f.fork();
315                          f.get(5L, null);
316 <                    } catch(NullPointerException success) {
317 <                    } catch(Exception ex) {
316 >                    } catch (NullPointerException success) {
317 >                    } catch (Exception ex) {
318                          unexpectedException();
319                      }
320                  }
# Line 322 | Line 322 | public class ForkJoinTaskTest extends JS
322          mainPool.invoke(a);
323      }
324  
325 <    /**
325 >    /**
326       * helpJoin of a forked task returns when task completes
327       */
328      public void testForkHelpJoin() {
# Line 338 | Line 338 | public class ForkJoinTaskTest extends JS
338          mainPool.invoke(a);
339      }
340  
341 <    /**
341 >    /**
342       * quietlyJoin of a forked task returns when task completes
343       */
344      public void testForkQuietlyJoin() {
# Line 355 | Line 355 | public class ForkJoinTaskTest extends JS
355      }
356  
357  
358 <    /**
358 >    /**
359       * quietlyHelpJoin of a forked task returns when task completes
360       */
361      public void testForkQuietlyHelpJoin() {
# Line 372 | Line 372 | public class ForkJoinTaskTest extends JS
372      }
373  
374  
375 <    /**
375 >    /**
376       * helpQuiesce returns when tasks are complete.
377       * getQueuedTaskCount returns 0 when quiescent
378       */
# Line 391 | Line 391 | public class ForkJoinTaskTest extends JS
391      }
392  
393  
394 <    /**
394 >    /**
395       * invoke task throws exception when task completes abnormally
396       */
397      public void testAbnormalInvoke() {
# Line 401 | Line 401 | public class ForkJoinTaskTest extends JS
401                          FailingAsyncFib f = new FailingAsyncFib(8);
402                          f.invoke();
403                          shouldThrow();
404 <                    } catch(FJException success) {
404 >                    } catch (FJException success) {
405                      }
406                  }
407              };
408          mainPool.invoke(a);
409      }
410  
411 <    /**
411 >    /**
412       * quietelyInvoke task returns when task completes abnormally
413       */
414      public void testAbnormalQuietlyInvoke() {
# Line 422 | Line 422 | public class ForkJoinTaskTest extends JS
422          mainPool.invoke(a);
423      }
424  
425 <    /**
425 >    /**
426       * join of a forked task throws exception when task completes abnormally
427       */
428      public void testAbnormalForkJoin() {
# Line 433 | Line 433 | public class ForkJoinTaskTest extends JS
433                          f.fork();
434                          f.join();
435                          shouldThrow();
436 <                    } catch(FJException success) {
436 >                    } catch (FJException success) {
437                      }
438                  }
439              };
440          mainPool.invoke(a);
441      }
442  
443 <    /**
443 >    /**
444       * get of a forked task throws exception when task completes abnormally
445       */
446      public void testAbnormalForkGet() {
# Line 451 | Line 451 | public class ForkJoinTaskTest extends JS
451                          f.fork();
452                          f.get();
453                          shouldThrow();
454 <                    } catch(Exception success) {
454 >                    } catch (Exception success) {
455                      }
456                  }
457              };
458          mainPool.invoke(a);
459      }
460  
461 <    /**
461 >    /**
462       * timed get of a forked task throws exception when task completes abnormally
463       */
464      public void testAbnormalForkTimedGet() {
# Line 469 | Line 469 | public class ForkJoinTaskTest extends JS
469                          f.fork();
470                          f.get(5L, TimeUnit.SECONDS);
471                          shouldThrow();
472 <                    } catch(Exception success) {
472 >                    } catch (Exception success) {
473                      }
474                  }
475              };
476          mainPool.invoke(a);
477      }
478  
479 <    /**
479 >    /**
480       * join of a forked task throws exception when task completes abnormally
481       */
482      public void testAbnormalForkHelpJoin() {
# Line 487 | Line 487 | public class ForkJoinTaskTest extends JS
487                          f.fork();
488                          f.helpJoin();
489                          shouldThrow();
490 <                    } catch(FJException success) {
490 >                    } catch (FJException success) {
491                      }
492                  }
493              };
494          mainPool.invoke(a);
495      }
496  
497 <    /**
497 >    /**
498       * quietlyHelpJoin of a forked task returns when task completes abnormally.
499       * getException of failed task returns its exception.
500       * isCompletedAbnormally of a failed task returns true.
# Line 515 | Line 515 | public class ForkJoinTaskTest extends JS
515          mainPool.invoke(a);
516      }
517  
518 <    /**
518 >    /**
519       * quietlyJoin of a forked task returns when task completes abnormally
520       */
521      public void testAbnormalForkQuietlyJoin() {
# Line 532 | Line 532 | public class ForkJoinTaskTest extends JS
532          mainPool.invoke(a);
533      }
534  
535 <    /**
535 >    /**
536       * invoke task throws exception when task cancelled
537       */
538      public void testCancelledInvoke() {
# Line 543 | Line 543 | public class ForkJoinTaskTest extends JS
543                          f.cancel(true);
544                          f.invoke();
545                          shouldThrow();
546 <                    } catch(CancellationException success) {
546 >                    } catch (CancellationException success) {
547                      }
548                  }
549              };
550          mainPool.invoke(a);
551      }
552  
553 <    /**
553 >    /**
554       * join of a forked task throws exception when task cancelled
555       */
556      public void testCancelledForkJoin() {
# Line 562 | Line 562 | public class ForkJoinTaskTest extends JS
562                          f.fork();
563                          f.join();
564                          shouldThrow();
565 <                    } catch(CancellationException success) {
565 >                    } catch (CancellationException success) {
566                      }
567                  }
568              };
569          mainPool.invoke(a);
570      }
571  
572 <    /**
572 >    /**
573       * get of a forked task throws exception when task cancelled
574       */
575      public void testCancelledForkGet() {
# Line 581 | Line 581 | public class ForkJoinTaskTest extends JS
581                          f.fork();
582                          f.get();
583                          shouldThrow();
584 <                    } catch(Exception success) {
584 >                    } catch (Exception success) {
585                      }
586                  }
587              };
588          mainPool.invoke(a);
589      }
590  
591 <    /**
591 >    /**
592       * timed get of a forked task throws exception when task cancelled
593       */
594      public void testCancelledForkTimedGet() {
# Line 600 | Line 600 | public class ForkJoinTaskTest extends JS
600                          f.fork();
601                          f.get(5L, TimeUnit.SECONDS);
602                          shouldThrow();
603 <                    } catch(Exception success) {
603 >                    } catch (Exception success) {
604                      }
605                  }
606              };
607          mainPool.invoke(a);
608      }
609  
610 <    /**
610 >    /**
611       * join of a forked task throws exception when task cancelled
612       */
613      public void testCancelledForkHelpJoin() {
# Line 619 | Line 619 | public class ForkJoinTaskTest extends JS
619                          f.fork();
620                          f.helpJoin();
621                          shouldThrow();
622 <                    } catch(CancellationException success) {
622 >                    } catch (CancellationException success) {
623                      }
624                  }
625              };
626          mainPool.invoke(a);
627      }
628  
629 <    /**
629 >    /**
630       * quietlyHelpJoin of a forked task returns when task cancelled.
631       * getException of cancelled task returns its exception.
632       * isCompletedAbnormally of a cancelled task returns true.
# Line 648 | Line 648 | public class ForkJoinTaskTest extends JS
648          mainPool.invoke(a);
649      }
650  
651 <    /**
651 >    /**
652       * quietlyJoin of a forked task returns when task cancelled
653       */
654      public void testCancelledForkQuietlyJoin() {
# Line 726 | Line 726 | public class ForkJoinTaskTest extends JS
726          a.invoke();
727      }
728  
729 <    /**
729 >    /**
730       * invoke task throws exception after invoking completeExceptionally
731       */
732      public void testCompleteExceptionally() {
# Line 737 | Line 737 | public class ForkJoinTaskTest extends JS
737                          f.completeExceptionally(new FJException());
738                          f.invoke();
739                          shouldThrow();
740 <                    } catch(FJException success) {
740 >                    } catch (FJException success) {
741                      }
742                  }
743              };
744          mainPool.invoke(a);
745      }
746  
747 <    /**
747 >    /**
748       * invokeAll(t1, t2) invokes all task arguments
749       */
750      public void testInvokeAll2() {
# Line 762 | Line 762 | public class ForkJoinTaskTest extends JS
762          mainPool.invoke(a);
763      }
764  
765 <    /**
765 >    /**
766       * invokeAll(tasks) with 1 argument invokes task
767       */
768      public void testInvokeAll1() {
# Line 777 | Line 777 | public class ForkJoinTaskTest extends JS
777          mainPool.invoke(a);
778      }
779  
780 <    /**
780 >    /**
781       * invokeAll(tasks) with > 2 argument invokes tasks
782       */
783      public void testInvokeAll3() {
# Line 798 | Line 798 | public class ForkJoinTaskTest extends JS
798          mainPool.invoke(a);
799      }
800  
801 <    /**
801 >    /**
802       * invokeAll(collection) invokes all tasks in the collection
803       */
804      public void testInvokeAllCollection() {
# Line 824 | Line 824 | public class ForkJoinTaskTest extends JS
824      }
825  
826  
827 <    /**
827 >    /**
828       * invokeAll(tasks) with any null task throws NPE
829       */
830      public void testInvokeAllNPE() {
# Line 843 | Line 843 | public class ForkJoinTaskTest extends JS
843          mainPool.invoke(a);
844      }
845  
846 <    /**
846 >    /**
847       * invokeAll(t1, t2) throw exception if any task does
848       */
849      public void testAbnormalInvokeAll2() {
# Line 854 | Line 854 | public class ForkJoinTaskTest extends JS
854                          FailingAsyncFib g = new FailingAsyncFib(9);
855                          invokeAll(f, g);
856                          shouldThrow();
857 <                    } catch(FJException success) {
857 >                    } catch (FJException success) {
858                      }
859                  }
860              };
861          mainPool.invoke(a);
862      }
863  
864 <    /**
864 >    /**
865       * invokeAll(tasks) with 1 argument throws exception if task does
866       */
867      public void testAbnormalInvokeAll1() {
# Line 871 | Line 871 | public class ForkJoinTaskTest extends JS
871                          FailingAsyncFib g = new FailingAsyncFib(9);
872                          invokeAll(g);
873                          shouldThrow();
874 <                    } catch(FJException success) {
874 >                    } catch (FJException success) {
875                      }
876                  }
877              };
878          mainPool.invoke(a);
879      }
880  
881 <    /**
881 >    /**
882       * invokeAll(tasks) with > 2 argument throws exception if any task does
883       */
884      public void testAbnormalInvokeAll3() {
# Line 890 | Line 890 | public class ForkJoinTaskTest extends JS
890                          AsyncFib h = new AsyncFib(7);
891                          invokeAll(f, g, h);
892                          shouldThrow();
893 <                    } catch(FJException success) {
893 >                    } catch (FJException success) {
894                      }
895                  }
896              };
897          mainPool.invoke(a);
898      }
899  
900 <    /**
900 >    /**
901       * invokeAll(collection)  throws exception if any task does
902       */
903      public void testAbnormalInvokeAllCollection() {
# Line 913 | Line 913 | public class ForkJoinTaskTest extends JS
913                          set.add(h);
914                          invokeAll(set);
915                          shouldThrow();
916 <                    } catch(FJException success) {
916 >                    } catch (FJException success) {
917                      }
918                  }
919              };
920          mainPool.invoke(a);
921      }
922  
923 <    /**
923 >    /**
924       * tryUnfork returns true for most recent unexecuted task,
925       * and suppresses execution
926       */
# Line 940 | Line 940 | public class ForkJoinTaskTest extends JS
940          singletonPool.invoke(a);
941      }
942  
943 <    /**
943 >    /**
944       * getSurplusQueuedTaskCount returns > 0 when
945       * there are more tasks than threads
946       */
# Line 960 | Line 960 | public class ForkJoinTaskTest extends JS
960          singletonPool.invoke(a);
961      }
962  
963 <    /**
963 >    /**
964       * peekNextLocalTask returns most recent unexecuted task.
965       */
966      public void testPeekNextLocalTask() {
# Line 979 | Line 979 | public class ForkJoinTaskTest extends JS
979          singletonPool.invoke(a);
980      }
981  
982 <    /**
982 >    /**
983       * pollNextLocalTask returns most recent unexecuted task
984       * without executing it
985       */
# Line 998 | Line 998 | public class ForkJoinTaskTest extends JS
998          singletonPool.invoke(a);
999      }
1000  
1001 <    /**
1001 >    /**
1002       * pollTask returns an unexecuted task
1003       * without executing it
1004       */
# Line 1018 | Line 1018 | public class ForkJoinTaskTest extends JS
1018          singletonPool.invoke(a);
1019      }
1020  
1021 <    /**
1021 >    /**
1022       * peekNextLocalTask returns least recent unexecuted task in async mode
1023       */
1024      public void testPeekNextLocalTaskAsync() {
# Line 1037 | Line 1037 | public class ForkJoinTaskTest extends JS
1037          asyncSingletonPool.invoke(a);
1038      }
1039  
1040 <    /**
1040 >    /**
1041       * pollNextLocalTask returns least recent unexecuted task
1042       * without executing it, in async mode
1043       */
# Line 1057 | Line 1057 | public class ForkJoinTaskTest extends JS
1057          asyncSingletonPool.invoke(a);
1058      }
1059  
1060 <    /**
1060 >    /**
1061       * pollTask returns an unexecuted task
1062       * without executing it, in async mode
1063       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines