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

Comparing jsr166/src/test/tck/ForkJoinPool8Test.java (file contents):
Revision 1.4 by dl, Thu Mar 21 19:06:54 2013 UTC vs.
Revision 1.30 by jsr166, Sat Apr 25 04:55:30 2015 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import junit.framework.*;
7 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 > import static java.util.concurrent.TimeUnit.SECONDS;
9 >
10 > import java.util.HashSet;
11   import java.util.concurrent.CancellationException;
12 + import java.util.concurrent.CountedCompleter;
13   import java.util.concurrent.ExecutionException;
14   import java.util.concurrent.ForkJoinPool;
15   import java.util.concurrent.ForkJoinTask;
12 import java.util.concurrent.ForkJoinWorkerThread;
16   import java.util.concurrent.RecursiveAction;
14 import java.util.concurrent.CountedCompleter;
15 import java.util.concurrent.ThreadLocalRandom;
16 import java.util.concurrent.TimeUnit;
17   import java.util.concurrent.TimeoutException;
18 < import static java.util.concurrent.TimeUnit.SECONDS;
19 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
20 < import java.util.Arrays;
21 < import java.util.HashSet;
18 >
19 > import junit.framework.Test;
20 > import junit.framework.TestSuite;
21  
22   public class ForkJoinPool8Test extends JSR166TestCase {
23      public static void main(String[] args) {
24 <        junit.textui.TestRunner.run(suite());
24 >        main(suite(), args);
25      }
26  
27      public static Test suite() {
# Line 59 | Line 58 | public class ForkJoinPool8Test extends J
58       * RecursiveAction and CountedCompleter, but with all actions
59       * executed in the common pool, generally implicitly via
60       * checkInvoke.
61 <     */
61 >     */
62  
63      private void checkInvoke(ForkJoinTask a) {
64          checkNotDone(a);
# Line 185 | Line 184 | public class ForkJoinPool8Test extends J
184          final int number;
185          int result;
186          FibAction(int n) { number = n; }
187 <        public void realCompute() {
187 >        protected void realCompute() {
188              int n = number;
189              if (n <= 1)
190                  result = n;
# Line 223 | Line 222 | public class ForkJoinPool8Test extends J
222       */
223      public void testInvoke() {
224          RecursiveAction a = new CheckedRecursiveAction() {
225 <            public void realCompute() {
225 >            protected void realCompute() {
226                  FibAction f = new FibAction(8);
227                  assertNull(f.invoke());
228                  assertEquals(21, f.result);
# Line 239 | Line 238 | public class ForkJoinPool8Test extends J
238       */
239      public void testQuietlyInvoke() {
240          RecursiveAction a = new CheckedRecursiveAction() {
241 <            public void realCompute() {
241 >            protected void realCompute() {
242                  FibAction f = new FibAction(8);
243                  f.quietlyInvoke();
244                  assertEquals(21, f.result);
# Line 253 | Line 252 | public class ForkJoinPool8Test extends J
252       */
253      public void testForkJoin() {
254          RecursiveAction a = new CheckedRecursiveAction() {
255 <            public void realCompute() {
255 >            protected void realCompute() {
256                  FibAction f = new FibAction(8);
257                  assertSame(f, f.fork());
258                  assertNull(f.join());
# Line 268 | Line 267 | public class ForkJoinPool8Test extends J
267       */
268      public void testJoinIgnoresInterrupts() {
269          RecursiveAction a = new CheckedRecursiveAction() {
270 <            public void realCompute() {
270 >            protected void realCompute() {
271                  FibAction f = new FibAction(8);
272                  final Thread myself = Thread.currentThread();
273  
# Line 340 | Line 339 | public class ForkJoinPool8Test extends J
339          checkInvoke(a);
340      }
341  
343
342      /**
343       * get of a forked task returns when task completes
344       */
345      public void testForkGet() {
346          RecursiveAction a = new CheckedRecursiveAction() {
347 <            public void realCompute() throws Exception {
347 >            protected void realCompute() throws Exception {
348                  FibAction f = new FibAction(8);
349                  assertSame(f, f.fork());
350                  assertNull(f.get());
# Line 361 | Line 359 | public class ForkJoinPool8Test extends J
359       */
360      public void testForkTimedGet() {
361          RecursiveAction a = new CheckedRecursiveAction() {
362 <            public void realCompute() throws Exception {
362 >            protected void realCompute() throws Exception {
363                  FibAction f = new FibAction(8);
364                  assertSame(f, f.fork());
365                  assertNull(f.get(5L, SECONDS));
# Line 376 | Line 374 | public class ForkJoinPool8Test extends J
374       */
375      public void testForkTimedGetNPE() {
376          RecursiveAction a = new CheckedRecursiveAction() {
377 <            public void realCompute() throws Exception {
377 >            protected void realCompute() throws Exception {
378                  FibAction f = new FibAction(8);
379                  assertSame(f, f.fork());
380                  try {
# Line 392 | Line 390 | public class ForkJoinPool8Test extends J
390       */
391      public void testForkQuietlyJoin() {
392          RecursiveAction a = new CheckedRecursiveAction() {
393 <            public void realCompute() {
393 >            protected void realCompute() {
394                  FibAction f = new FibAction(8);
395                  assertSame(f, f.fork());
396                  f.quietlyJoin();
# Line 403 | Line 401 | public class ForkJoinPool8Test extends J
401      }
402  
403      /**
406     * helpQuiesce returns when tasks are complete.
407     * getQueuedTaskCount returns 0 when quiescent
408     */
409    public void testForkHelpQuiesce() {
410        RecursiveAction a = new CheckedRecursiveAction() {
411            public void realCompute() {
412                FibAction f = new FibAction(8);
413                assertSame(f, f.fork());
414                helpQuiesce();
415                assertEquals(21, f.result);
416                assertEquals(0, getQueuedTaskCount());
417                checkCompletedNormally(f);
418            }};
419        checkInvoke(a);
420    }
421
422    /**
404       * invoke task throws exception when task completes abnormally
405       */
406      public void testAbnormalInvoke() {
407          RecursiveAction a = new CheckedRecursiveAction() {
408 <            public void realCompute() {
408 >            protected void realCompute() {
409                  FailingFibAction f = new FailingFibAction(8);
410                  try {
411                      f.invoke();
# Line 441 | Line 422 | public class ForkJoinPool8Test extends J
422       */
423      public void testAbnormalQuietlyInvoke() {
424          RecursiveAction a = new CheckedRecursiveAction() {
425 <            public void realCompute() {
425 >            protected void realCompute() {
426                  FailingFibAction f = new FailingFibAction(8);
427                  f.quietlyInvoke();
428                  assertTrue(f.getException() instanceof FJException);
# Line 455 | Line 436 | public class ForkJoinPool8Test extends J
436       */
437      public void testAbnormalForkJoin() {
438          RecursiveAction a = new CheckedRecursiveAction() {
439 <            public void realCompute() {
439 >            protected void realCompute() {
440                  FailingFibAction f = new FailingFibAction(8);
441                  assertSame(f, f.fork());
442                  try {
# Line 473 | Line 454 | public class ForkJoinPool8Test extends J
454       */
455      public void testAbnormalForkGet() {
456          RecursiveAction a = new CheckedRecursiveAction() {
457 <            public void realCompute() throws Exception {
457 >            protected void realCompute() throws Exception {
458                  FailingFibAction f = new FailingFibAction(8);
459                  assertSame(f, f.fork());
460                  try {
# Line 493 | Line 474 | public class ForkJoinPool8Test extends J
474       */
475      public void testAbnormalForkTimedGet() {
476          RecursiveAction a = new CheckedRecursiveAction() {
477 <            public void realCompute() throws Exception {
477 >            protected void realCompute() throws Exception {
478                  FailingFibAction f = new FailingFibAction(8);
479                  assertSame(f, f.fork());
480                  try {
481 <                    f.get(5L, TimeUnit.SECONDS);
481 >                    f.get(5L, SECONDS);
482                      shouldThrow();
483                  } catch (ExecutionException success) {
484                      Throwable cause = success.getCause();
# Line 513 | Line 494 | public class ForkJoinPool8Test extends J
494       */
495      public void testAbnormalForkQuietlyJoin() {
496          RecursiveAction a = new CheckedRecursiveAction() {
497 <            public void realCompute() {
497 >            protected void realCompute() {
498                  FailingFibAction f = new FailingFibAction(8);
499                  assertSame(f, f.fork());
500                  f.quietlyJoin();
# Line 528 | Line 509 | public class ForkJoinPool8Test extends J
509       */
510      public void testCancelledInvoke() {
511          RecursiveAction a = new CheckedRecursiveAction() {
512 <            public void realCompute() {
512 >            protected void realCompute() {
513                  FibAction f = new FibAction(8);
514                  assertTrue(f.cancel(true));
515                  try {
# Line 546 | Line 527 | public class ForkJoinPool8Test extends J
527       */
528      public void testCancelledForkJoin() {
529          RecursiveAction a = new CheckedRecursiveAction() {
530 <            public void realCompute() {
530 >            protected void realCompute() {
531                  FibAction f = new FibAction(8);
532                  assertTrue(f.cancel(true));
533                  assertSame(f, f.fork());
# Line 565 | Line 546 | public class ForkJoinPool8Test extends J
546       */
547      public void testCancelledForkGet() {
548          RecursiveAction a = new CheckedRecursiveAction() {
549 <            public void realCompute() throws Exception {
549 >            protected void realCompute() throws Exception {
550                  FibAction f = new FibAction(8);
551                  assertTrue(f.cancel(true));
552                  assertSame(f, f.fork());
# Line 584 | Line 565 | public class ForkJoinPool8Test extends J
565       */
566      public void testCancelledForkTimedGet() {
567          RecursiveAction a = new CheckedRecursiveAction() {
568 <            public void realCompute() throws Exception {
568 >            protected void realCompute() throws Exception {
569                  FibAction f = new FibAction(8);
570                  assertTrue(f.cancel(true));
571                  assertSame(f, f.fork());
# Line 603 | Line 584 | public class ForkJoinPool8Test extends J
584       */
585      public void testCancelledForkQuietlyJoin() {
586          RecursiveAction a = new CheckedRecursiveAction() {
587 <            public void realCompute() {
587 >            protected void realCompute() {
588                  FibAction f = new FibAction(8);
589                  assertTrue(f.cancel(true));
590                  assertSame(f, f.fork());
# Line 618 | Line 599 | public class ForkJoinPool8Test extends J
599       */
600      public void testInForkJoinPool2() {
601          RecursiveAction a = new CheckedRecursiveAction() {
602 <            public void realCompute() {
602 >            protected void realCompute() {
603                  assertFalse(inForkJoinPool());
604              }};
605          assertNull(a.invoke());
# Line 629 | Line 610 | public class ForkJoinPool8Test extends J
610       */
611      public void testReinitialize() {
612          RecursiveAction a = new CheckedRecursiveAction() {
613 <            public void realCompute() {
613 >            protected void realCompute() {
614                  FibAction f = new FibAction(8);
615                  checkNotDone(f);
616  
# Line 649 | Line 630 | public class ForkJoinPool8Test extends J
630       */
631      public void testReinitializeAbnormal() {
632          RecursiveAction a = new CheckedRecursiveAction() {
633 <            public void realCompute() {
633 >            protected void realCompute() {
634                  FailingFibAction f = new FailingFibAction(8);
635                  checkNotDone(f);
636  
# Line 672 | Line 653 | public class ForkJoinPool8Test extends J
653       */
654      public void testCompleteExceptionally() {
655          RecursiveAction a = new CheckedRecursiveAction() {
656 <            public void realCompute() {
656 >            protected void realCompute() {
657                  FibAction f = new FibAction(8);
658                  f.completeExceptionally(new FJException());
659                  try {
# Line 690 | Line 671 | public class ForkJoinPool8Test extends J
671       */
672      public void testComplete() {
673          RecursiveAction a = new CheckedRecursiveAction() {
674 <            public void realCompute() {
674 >            protected void realCompute() {
675                  FibAction f = new FibAction(8);
676                  f.complete(null);
677                  assertNull(f.invoke());
# Line 705 | Line 686 | public class ForkJoinPool8Test extends J
686       */
687      public void testInvokeAll2() {
688          RecursiveAction a = new CheckedRecursiveAction() {
689 <            public void realCompute() {
689 >            protected void realCompute() {
690                  FibAction f = new FibAction(8);
691                  FibAction g = new FibAction(9);
692                  invokeAll(f, g);
# Line 722 | Line 703 | public class ForkJoinPool8Test extends J
703       */
704      public void testInvokeAll1() {
705          RecursiveAction a = new CheckedRecursiveAction() {
706 <            public void realCompute() {
706 >            protected void realCompute() {
707                  FibAction f = new FibAction(8);
708                  invokeAll(f);
709                  checkCompletedNormally(f);
# Line 736 | Line 717 | public class ForkJoinPool8Test extends J
717       */
718      public void testInvokeAll3() {
719          RecursiveAction a = new CheckedRecursiveAction() {
720 <            public void realCompute() {
720 >            protected void realCompute() {
721                  FibAction f = new FibAction(8);
722                  FibAction g = new FibAction(9);
723                  FibAction h = new FibAction(7);
# Line 759 | Line 740 | public class ForkJoinPool8Test extends J
740       */
741      public void testInvokeAllCollection() {
742          RecursiveAction a = new CheckedRecursiveAction() {
743 <            public void realCompute() {
743 >            protected void realCompute() {
744                  FibAction f = new FibAction(8);
745                  FibAction g = new FibAction(9);
746                  FibAction h = new FibAction(7);
# Line 786 | Line 767 | public class ForkJoinPool8Test extends J
767       */
768      public void testInvokeAllNPE() {
769          RecursiveAction a = new CheckedRecursiveAction() {
770 <            public void realCompute() {
770 >            protected void realCompute() {
771                  FibAction f = new FibAction(8);
772                  FibAction g = new FibAction(9);
773                  FibAction h = null;
# Line 803 | Line 784 | public class ForkJoinPool8Test extends J
784       */
785      public void testAbnormalInvokeAll2() {
786          RecursiveAction a = new CheckedRecursiveAction() {
787 <            public void realCompute() {
787 >            protected void realCompute() {
788                  FibAction f = new FibAction(8);
789                  FailingFibAction g = new FailingFibAction(9);
790                  try {
# Line 821 | Line 802 | public class ForkJoinPool8Test extends J
802       */
803      public void testAbnormalInvokeAll1() {
804          RecursiveAction a = new CheckedRecursiveAction() {
805 <            public void realCompute() {
805 >            protected void realCompute() {
806                  FailingFibAction g = new FailingFibAction(9);
807                  try {
808                      invokeAll(g);
# Line 838 | Line 819 | public class ForkJoinPool8Test extends J
819       */
820      public void testAbnormalInvokeAll3() {
821          RecursiveAction a = new CheckedRecursiveAction() {
822 <            public void realCompute() {
822 >            protected void realCompute() {
823                  FibAction f = new FibAction(8);
824                  FailingFibAction g = new FailingFibAction(9);
825                  FibAction h = new FibAction(7);
# Line 857 | Line 838 | public class ForkJoinPool8Test extends J
838       */
839      public void testAbnormalInvokeAllCollection() {
840          RecursiveAction a = new CheckedRecursiveAction() {
841 <            public void realCompute() {
841 >            protected void realCompute() {
842                  FailingFibAction f = new FailingFibAction(8);
843                  FibAction g = new FibAction(9);
844                  FibAction h = new FibAction(7);
# Line 877 | Line 858 | public class ForkJoinPool8Test extends J
858  
859      // CountedCompleter versions
860  
861 <    public abstract class CheckedFJTask extends RecursiveAction {
881 <        protected abstract void realCompute() throws Throwable;
882 <
883 <        public final void compute() {
884 <            try {
885 <                realCompute();
886 <            } catch (Throwable t) {
887 <                threadUnexpectedException(t);
888 <            }
889 <        }
890 <    }
891 <
892 <    static abstract class CCF extends CountedCompleter {
861 >    abstract static class CCF extends CountedCompleter {
862          int number;
863          int rnumber;
864  
# Line 910 | Line 879 | public class ForkJoinPool8Test extends J
879              f.onCompletion(f);
880              if ((p = f.getCompleter()) != null)
881                  p.tryComplete();
882 <            else
883 <                f.quietlyComplete();
882 >            else
883 >                f.quietlyComplete();
884          }
885      }
886  
# Line 943 | Line 912 | public class ForkJoinPool8Test extends J
912      }
913  
914      // Version of CCF with forced failure in left completions
915 <    static abstract class FailingCCF extends CountedCompleter {
915 >    abstract static class FailingCCF extends CountedCompleter {
916          int number;
917          int rnumber;
918  
# Line 964 | Line 933 | public class ForkJoinPool8Test extends J
933              f.onCompletion(f);
934              if ((p = f.getCompleter()) != null)
935                  p.tryComplete();
936 <            else
937 <                f.quietlyComplete();
936 >            else
937 >                f.quietlyComplete();
938          }
939      }
940  
# Line 990 | Line 959 | public class ForkJoinPool8Test extends J
959              completeExceptionally(new FJException());
960          }
961      }
962 <    
962 >
963      /**
964       * invoke returns when task completes normally.
965       * isCompletedAbnormally and isCancelled return false for normally
966       * completed tasks; getRawResult returns null.
967       */
968      public void testInvokeCC() {
969 <       ForkJoinTask a =  new CheckedFJTask() {
970 <            public void realCompute() {
969 >        ForkJoinTask a = new CheckedRecursiveAction() {
970 >            protected void realCompute() {
971                  CCF f = new LCCF(null, 8);
972                  assertNull(f.invoke());
973                  assertEquals(21, f.number);
# Line 1013 | Line 982 | public class ForkJoinPool8Test extends J
982       * completed tasks
983       */
984      public void testQuietlyInvokeCC() {
985 <       ForkJoinTask a =  new CheckedFJTask() {
986 <            public void realCompute() {
985 >        ForkJoinTask a = new CheckedRecursiveAction() {
986 >            protected void realCompute() {
987                  CCF f = new LCCF(null, 8);
988                  f.quietlyInvoke();
989                  assertEquals(21, f.number);
# Line 1027 | Line 996 | public class ForkJoinPool8Test extends J
996       * join of a forked task returns when task completes
997       */
998      public void testForkJoinCC() {
999 <       ForkJoinTask a =  new CheckedFJTask() {
1000 <            public void realCompute() {
999 >        ForkJoinTask a = new CheckedRecursiveAction() {
1000 >            protected void realCompute() {
1001                  CCF f = new LCCF(null, 8);
1002                  assertSame(f, f.fork());
1003                  assertNull(f.join());
# Line 1042 | Line 1011 | public class ForkJoinPool8Test extends J
1011       * get of a forked task returns when task completes
1012       */
1013      public void testForkGetCC() {
1014 <       ForkJoinTask a =  new CheckedFJTask() {
1015 <            public void realCompute() throws Exception {
1014 >        ForkJoinTask a = new CheckedRecursiveAction() {
1015 >            protected void realCompute() throws Exception {
1016                  CCF f = new LCCF(null, 8);
1017                  assertSame(f, f.fork());
1018                  assertNull(f.get());
# Line 1057 | Line 1026 | public class ForkJoinPool8Test extends J
1026       * timed get of a forked task returns when task completes
1027       */
1028      public void testForkTimedGetCC() {
1029 <       ForkJoinTask a =  new CheckedFJTask() {
1030 <            public void realCompute() throws Exception {
1029 >        ForkJoinTask a = new CheckedRecursiveAction() {
1030 >            protected void realCompute() throws Exception {
1031                  CCF f = new LCCF(null, 8);
1032                  assertSame(f, f.fork());
1033                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
# Line 1072 | Line 1041 | public class ForkJoinPool8Test extends J
1041       * timed get with null time unit throws NPE
1042       */
1043      public void testForkTimedGetNPECC() {
1044 <       ForkJoinTask a =  new CheckedFJTask() {
1045 <            public void realCompute() throws Exception {
1044 >        ForkJoinTask a = new CheckedRecursiveAction() {
1045 >            protected void realCompute() throws Exception {
1046                  CCF f = new LCCF(null, 8);
1047                  assertSame(f, f.fork());
1048                  try {
# Line 1088 | Line 1057 | public class ForkJoinPool8Test extends J
1057       * quietlyJoin of a forked task returns when task completes
1058       */
1059      public void testForkQuietlyJoinCC() {
1060 <       ForkJoinTask a =  new CheckedFJTask() {
1061 <            public void realCompute() {
1060 >        ForkJoinTask a = new CheckedRecursiveAction() {
1061 >            protected void realCompute() {
1062                  CCF f = new LCCF(null, 8);
1063                  assertSame(f, f.fork());
1064                  f.quietlyJoin();
# Line 1100 | Line 1069 | public class ForkJoinPool8Test extends J
1069      }
1070  
1071      /**
1103     * helpQuiesce returns when tasks are complete.
1104     * getQueuedTaskCount returns 0 when quiescent
1105     */
1106    public void testForkHelpQuiesceCC() {
1107       ForkJoinTask a =  new CheckedFJTask() {
1108            public void realCompute() {
1109                CCF f = new LCCF(null, 8);
1110                assertSame(f, f.fork());
1111                helpQuiesce();
1112                assertEquals(21, f.number);
1113                assertEquals(0, getQueuedTaskCount());
1114                checkCompletedNormally(f);
1115            }};
1116        checkInvoke(a);
1117    }
1118
1119    /**
1072       * invoke task throws exception when task completes abnormally
1073       */
1074      public void testAbnormalInvokeCC() {
1075 <       ForkJoinTask a =  new CheckedFJTask() {
1076 <            public void realCompute() {
1075 >        ForkJoinTask a = new CheckedRecursiveAction() {
1076 >            protected void realCompute() {
1077                  FailingCCF f = new LFCCF(null, 8);
1078                  try {
1079                      f.invoke();
# Line 1137 | Line 1089 | public class ForkJoinPool8Test extends J
1089       * quietlyInvoke task returns when task completes abnormally
1090       */
1091      public void testAbnormalQuietlyInvokeCC() {
1092 <       ForkJoinTask a =  new CheckedFJTask() {
1093 <            public void realCompute() {
1092 >        ForkJoinTask a = new CheckedRecursiveAction() {
1093 >            protected void realCompute() {
1094                  FailingCCF f = new LFCCF(null, 8);
1095                  f.quietlyInvoke();
1096                  assertTrue(f.getException() instanceof FJException);
# Line 1151 | Line 1103 | public class ForkJoinPool8Test extends J
1103       * join of a forked task throws exception when task completes abnormally
1104       */
1105      public void testAbnormalForkJoinCC() {
1106 <       ForkJoinTask a =  new CheckedFJTask() {
1107 <            public void realCompute() {
1106 >        ForkJoinTask a = new CheckedRecursiveAction() {
1107 >            protected void realCompute() {
1108                  FailingCCF f = new LFCCF(null, 8);
1109                  assertSame(f, f.fork());
1110                  try {
# Line 1169 | Line 1121 | public class ForkJoinPool8Test extends J
1121       * get of a forked task throws exception when task completes abnormally
1122       */
1123      public void testAbnormalForkGetCC() {
1124 <       ForkJoinTask a =  new CheckedFJTask() {
1125 <            public void realCompute() throws Exception {
1124 >        ForkJoinTask a = new CheckedRecursiveAction() {
1125 >            protected void realCompute() throws Exception {
1126                  FailingCCF f = new LFCCF(null, 8);
1127                  assertSame(f, f.fork());
1128                  try {
# Line 1189 | Line 1141 | public class ForkJoinPool8Test extends J
1141       * timed get of a forked task throws exception when task completes abnormally
1142       */
1143      public void testAbnormalForkTimedGetCC() {
1144 <       ForkJoinTask a =  new CheckedFJTask() {
1145 <            public void realCompute() throws Exception {
1144 >        ForkJoinTask a = new CheckedRecursiveAction() {
1145 >            protected void realCompute() throws Exception {
1146                  FailingCCF f = new LFCCF(null, 8);
1147                  assertSame(f, f.fork());
1148                  try {
# Line 1209 | Line 1161 | public class ForkJoinPool8Test extends J
1161       * quietlyJoin of a forked task returns when task completes abnormally
1162       */
1163      public void testAbnormalForkQuietlyJoinCC() {
1164 <       ForkJoinTask a =  new CheckedFJTask() {
1165 <            public void realCompute() {
1164 >        ForkJoinTask a = new CheckedRecursiveAction() {
1165 >            protected void realCompute() {
1166                  FailingCCF f = new LFCCF(null, 8);
1167                  assertSame(f, f.fork());
1168                  f.quietlyJoin();
# Line 1224 | Line 1176 | public class ForkJoinPool8Test extends J
1176       * invoke task throws exception when task cancelled
1177       */
1178      public void testCancelledInvokeCC() {
1179 <       ForkJoinTask a =  new CheckedFJTask() {
1180 <            public void realCompute() {
1179 >        ForkJoinTask a = new CheckedRecursiveAction() {
1180 >            protected void realCompute() {
1181                  CCF f = new LCCF(null, 8);
1182                  assertTrue(f.cancel(true));
1183                  try {
# Line 1242 | Line 1194 | public class ForkJoinPool8Test extends J
1194       * join of a forked task throws exception when task cancelled
1195       */
1196      public void testCancelledForkJoinCC() {
1197 <       ForkJoinTask a =  new CheckedFJTask() {
1198 <            public void realCompute() {
1197 >        ForkJoinTask a = new CheckedRecursiveAction() {
1198 >            protected void realCompute() {
1199                  CCF f = new LCCF(null, 8);
1200                  assertTrue(f.cancel(true));
1201                  assertSame(f, f.fork());
# Line 1261 | Line 1213 | public class ForkJoinPool8Test extends J
1213       * get of a forked task throws exception when task cancelled
1214       */
1215      public void testCancelledForkGetCC() {
1216 <       ForkJoinTask a =  new CheckedFJTask() {
1217 <            public void realCompute() throws Exception {
1216 >        ForkJoinTask a = new CheckedRecursiveAction() {
1217 >            protected void realCompute() throws Exception {
1218                  CCF f = new LCCF(null, 8);
1219                  assertTrue(f.cancel(true));
1220                  assertSame(f, f.fork());
# Line 1280 | Line 1232 | public class ForkJoinPool8Test extends J
1232       * timed get of a forked task throws exception when task cancelled
1233       */
1234      public void testCancelledForkTimedGetCC() throws Exception {
1235 <       ForkJoinTask a =  new CheckedFJTask() {
1236 <            public void realCompute() throws Exception {
1235 >        ForkJoinTask a = new CheckedRecursiveAction() {
1236 >            protected void realCompute() throws Exception {
1237                  CCF f = new LCCF(null, 8);
1238                  assertTrue(f.cancel(true));
1239                  assertSame(f, f.fork());
# Line 1299 | Line 1251 | public class ForkJoinPool8Test extends J
1251       * quietlyJoin of a forked task returns when task cancelled
1252       */
1253      public void testCancelledForkQuietlyJoinCC() {
1254 <       ForkJoinTask a =  new CheckedFJTask() {
1255 <            public void realCompute() {
1254 >        ForkJoinTask a = new CheckedRecursiveAction() {
1255 >            protected void realCompute() {
1256                  CCF f = new LCCF(null, 8);
1257                  assertTrue(f.cancel(true));
1258                  assertSame(f, f.fork());
# Line 1314 | Line 1266 | public class ForkJoinPool8Test extends J
1266       * getPool of non-FJ task returns null
1267       */
1268      public void testGetPool2CC() {
1269 <       ForkJoinTask a =  new CheckedFJTask() {
1270 <            public void realCompute() {
1269 >        ForkJoinTask a = new CheckedRecursiveAction() {
1270 >            protected void realCompute() {
1271                  assertNull(getPool());
1272              }};
1273          assertNull(a.invoke());
# Line 1325 | Line 1277 | public class ForkJoinPool8Test extends J
1277       * inForkJoinPool of non-FJ task returns false
1278       */
1279      public void testInForkJoinPool2CC() {
1280 <       ForkJoinTask a =  new CheckedFJTask() {
1281 <            public void realCompute() {
1280 >        ForkJoinTask a = new CheckedRecursiveAction() {
1281 >            protected void realCompute() {
1282                  assertFalse(inForkJoinPool());
1283              }};
1284          assertNull(a.invoke());
# Line 1336 | Line 1288 | public class ForkJoinPool8Test extends J
1288       * setRawResult(null) succeeds
1289       */
1290      public void testSetRawResultCC() {
1291 <       ForkJoinTask a =  new CheckedFJTask() {
1292 <            public void realCompute() {
1291 >        ForkJoinTask a = new CheckedRecursiveAction() {
1292 >            protected void realCompute() {
1293                  setRawResult(null);
1294                  assertNull(getRawResult());
1295              }};
# Line 1348 | Line 1300 | public class ForkJoinPool8Test extends J
1300       * invoke task throws exception after invoking completeExceptionally
1301       */
1302      public void testCompleteExceptionally2CC() {
1303 <       ForkJoinTask a =  new CheckedFJTask() {
1304 <            public void realCompute() {
1303 >        ForkJoinTask a = new CheckedRecursiveAction() {
1304 >            protected void realCompute() {
1305                  CCF f = new LCCF(null, 8);
1306                  f.completeExceptionally(new FJException());
1307                  try {
# Line 1366 | Line 1318 | public class ForkJoinPool8Test extends J
1318       * invokeAll(t1, t2) invokes all task arguments
1319       */
1320      public void testInvokeAll2CC() {
1321 <       ForkJoinTask a =  new CheckedFJTask() {
1322 <            public void realCompute() {
1321 >        ForkJoinTask a = new CheckedRecursiveAction() {
1322 >            protected void realCompute() {
1323                  CCF f = new LCCF(null, 8);
1324                  CCF g = new LCCF(null, 9);
1325                  invokeAll(f, g);
# Line 1383 | Line 1335 | public class ForkJoinPool8Test extends J
1335       * invokeAll(tasks) with 1 argument invokes task
1336       */
1337      public void testInvokeAll1CC() {
1338 <       ForkJoinTask a =  new CheckedFJTask() {
1339 <            public void realCompute() {
1338 >        ForkJoinTask a = new CheckedRecursiveAction() {
1339 >            protected void realCompute() {
1340                  CCF f = new LCCF(null, 8);
1341                  invokeAll(f);
1342                  checkCompletedNormally(f);
# Line 1397 | Line 1349 | public class ForkJoinPool8Test extends J
1349       * invokeAll(tasks) with > 2 argument invokes tasks
1350       */
1351      public void testInvokeAll3CC() {
1352 <       ForkJoinTask a =  new CheckedFJTask() {
1353 <            public void realCompute() {
1352 >        ForkJoinTask a = new CheckedRecursiveAction() {
1353 >            protected void realCompute() {
1354                  CCF f = new LCCF(null, 8);
1355                  CCF g = new LCCF(null, 9);
1356                  CCF h = new LCCF(null, 7);
# Line 1417 | Line 1369 | public class ForkJoinPool8Test extends J
1369       * invokeAll(collection) invokes all tasks in the collection
1370       */
1371      public void testInvokeAllCollectionCC() {
1372 <       ForkJoinTask a =  new CheckedFJTask() {
1373 <            public void realCompute() {
1372 >        ForkJoinTask a = new CheckedRecursiveAction() {
1373 >            protected void realCompute() {
1374                  CCF f = new LCCF(null, 8);
1375                  CCF g = new LCCF(null, 9);
1376                  CCF h = new LCCF(null, 7);
# Line 1441 | Line 1393 | public class ForkJoinPool8Test extends J
1393       * invokeAll(tasks) with any null task throws NPE
1394       */
1395      public void testInvokeAllNPECC() {
1396 <       ForkJoinTask a =  new CheckedFJTask() {
1397 <            public void realCompute() {
1396 >        ForkJoinTask a = new CheckedRecursiveAction() {
1397 >            protected void realCompute() {
1398                  CCF f = new LCCF(null, 8);
1399                  CCF g = new LCCF(null, 9);
1400                  CCF h = null;
# Line 1458 | Line 1410 | public class ForkJoinPool8Test extends J
1410       * invokeAll(t1, t2) throw exception if any task does
1411       */
1412      public void testAbnormalInvokeAll2CC() {
1413 <       ForkJoinTask a =  new CheckedFJTask() {
1414 <            public void realCompute() {
1413 >        ForkJoinTask a = new CheckedRecursiveAction() {
1414 >            protected void realCompute() {
1415                  CCF f = new LCCF(null, 8);
1416                  FailingCCF g = new LFCCF(null, 9);
1417                  try {
# Line 1476 | Line 1428 | public class ForkJoinPool8Test extends J
1428       * invokeAll(tasks) with 1 argument throws exception if task does
1429       */
1430      public void testAbnormalInvokeAll1CC() {
1431 <       ForkJoinTask a =  new CheckedFJTask() {
1432 <            public void realCompute() {
1431 >        ForkJoinTask a = new CheckedRecursiveAction() {
1432 >            protected void realCompute() {
1433                  FailingCCF g = new LFCCF(null, 9);
1434                  try {
1435                      invokeAll(g);
# Line 1493 | Line 1445 | public class ForkJoinPool8Test extends J
1445       * invokeAll(tasks) with > 2 argument throws exception if any task does
1446       */
1447      public void testAbnormalInvokeAll3CC() {
1448 <       ForkJoinTask a =  new CheckedFJTask() {
1449 <            public void realCompute() {
1448 >        ForkJoinTask a = new CheckedRecursiveAction() {
1449 >            protected void realCompute() {
1450                  CCF f = new LCCF(null, 8);
1451                  FailingCCF g = new LFCCF(null, 9);
1452                  CCF h = new LCCF(null, 7);
# Line 1509 | Line 1461 | public class ForkJoinPool8Test extends J
1461      }
1462  
1463      /**
1464 <     * invokeAll(collection)  throws exception if any task does
1464 >     * invokeAll(collection) throws exception if any task does
1465       */
1466      public void testAbnormalInvokeAllCollectionCC() {
1467 <       ForkJoinTask a =  new CheckedFJTask() {
1468 <            public void realCompute() {
1467 >        ForkJoinTask a = new CheckedRecursiveAction() {
1468 >            protected void realCompute() {
1469                  FailingCCF f = new LFCCF(null, 8);
1470                  CCF g = new LCCF(null, 9);
1471                  CCF h = new LCCF(null, 7);
# Line 1531 | Line 1483 | public class ForkJoinPool8Test extends J
1483          checkInvoke(a);
1484      }
1485  
1486 +    /**
1487 +     * awaitQuiescence by a worker is equivalent in effect to
1488 +     * ForkJoinTask.helpQuiesce()
1489 +     */
1490 +    public void testAwaitQuiescence1() throws Exception {
1491 +        final ForkJoinPool p = new ForkJoinPool();
1492 +        try {
1493 +            final long startTime = System.nanoTime();
1494 +            assertTrue(p.isQuiescent());
1495 +            ForkJoinTask a = new CheckedRecursiveAction() {
1496 +                protected void realCompute() {
1497 +                    FibAction f = new FibAction(8);
1498 +                    assertSame(f, f.fork());
1499 +                    assertSame(p, ForkJoinTask.getPool());
1500 +                    boolean quiescent = p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS);
1501 +                    assertTrue(quiescent);
1502 +                    assertFalse(p.isQuiescent());
1503 +                    while (!f.isDone()) {
1504 +                        assertFalse(p.getAsyncMode());
1505 +                        assertFalse(p.isShutdown());
1506 +                        assertFalse(p.isTerminating());
1507 +                        assertFalse(p.isTerminated());
1508 +                        Thread.yield();
1509 +                    }
1510 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1511 +                    assertFalse(p.isQuiescent());
1512 +                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1513 +                    assertEquals(21, f.result);
1514 +                }};
1515 +            p.execute(a);
1516 +            while (!a.isDone() || !p.isQuiescent()) {
1517 +                assertFalse(p.getAsyncMode());
1518 +                assertFalse(p.isShutdown());
1519 +                assertFalse(p.isTerminating());
1520 +                assertFalse(p.isTerminated());
1521 +                Thread.yield();
1522 +            }
1523 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1524 +            assertEquals(0, p.getQueuedTaskCount());
1525 +            assertFalse(p.getAsyncMode());
1526 +            assertEquals(0, p.getActiveThreadCount());
1527 +            assertEquals(0, p.getQueuedTaskCount());
1528 +            assertEquals(0, p.getQueuedSubmissionCount());
1529 +            assertFalse(p.hasQueuedSubmissions());
1530 +            assertFalse(p.isShutdown());
1531 +            assertFalse(p.isTerminating());
1532 +            assertFalse(p.isTerminated());
1533 +        } finally {
1534 +            joinPool(p);
1535 +        }
1536 +    }
1537 +
1538 +    /**
1539 +     * awaitQuiescence returns when pool isQuiescent() or the indicated
1540 +     * timeout elapsed
1541 +     */
1542 +    public void testAwaitQuiescence2() throws Exception {
1543 +        /**
1544 +         * """It is possible to disable or limit the use of threads in the
1545 +         * common pool by setting the parallelism property to zero. However
1546 +         * doing so may cause unjoined tasks to never be executed."""
1547 +         */
1548 +        if ("0".equals(System.getProperty(
1549 +             "java.util.concurrent.ForkJoinPool.common.parallelism")))
1550 +            return;
1551 +        final ForkJoinPool p = new ForkJoinPool();
1552 +        try {
1553 +            assertTrue(p.isQuiescent());
1554 +            final long startTime = System.nanoTime();
1555 +            ForkJoinTask a = new CheckedRecursiveAction() {
1556 +                protected void realCompute() {
1557 +                    FibAction f = new FibAction(8);
1558 +                    assertSame(f, f.fork());
1559 +                    while (!f.isDone()
1560 +                           && millisElapsedSince(startTime) < LONG_DELAY_MS) {
1561 +                        assertFalse(p.getAsyncMode());
1562 +                        assertFalse(p.isShutdown());
1563 +                        assertFalse(p.isTerminating());
1564 +                        assertFalse(p.isTerminated());
1565 +                        Thread.yield();
1566 +                    }
1567 +                    assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1568 +                    assertEquals(0, ForkJoinTask.getQueuedTaskCount());
1569 +                    assertEquals(21, f.result);
1570 +                }};
1571 +            p.execute(a);
1572 +            assertTrue(p.awaitQuiescence(LONG_DELAY_MS, MILLISECONDS));
1573 +            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
1574 +            assertTrue(p.isQuiescent());
1575 +            assertTrue(a.isDone());
1576 +            assertEquals(0, p.getQueuedTaskCount());
1577 +            assertFalse(p.getAsyncMode());
1578 +            assertEquals(0, p.getActiveThreadCount());
1579 +            assertEquals(0, p.getQueuedTaskCount());
1580 +            assertEquals(0, p.getQueuedSubmissionCount());
1581 +            assertFalse(p.hasQueuedSubmissions());
1582 +            assertFalse(p.isShutdown());
1583 +            assertFalse(p.isTerminating());
1584 +            assertFalse(p.isTerminated());
1585 +        } finally {
1586 +            joinPool(p);
1587 +        }
1588 +    }
1589 +
1590   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines