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.33 by jsr166, Fri May 27 19:42:42 2011 UTC vs.
Revision 1.45 by jsr166, Wed Oct 7 22:39:31 2015 UTC

# Line 3 | Line 3
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6 < import java.util.concurrent.ExecutionException;
6 >
7 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 > import static java.util.concurrent.TimeUnit.SECONDS;
9 >
10 > import java.util.Arrays;
11 > import java.util.Collections;
12 > import java.util.HashSet;
13 > import java.util.List;
14   import java.util.concurrent.CancellationException;
15 + import java.util.concurrent.ExecutionException;
16   import java.util.concurrent.ForkJoinPool;
17   import java.util.concurrent.ForkJoinTask;
10 import java.util.concurrent.ForkJoinWorkerThread;
18   import java.util.concurrent.RecursiveAction;
12 import java.util.concurrent.TimeUnit;
19   import java.util.concurrent.TimeoutException;
20   import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
21 < import static java.util.concurrent.TimeUnit.MILLISECONDS;
22 < import static java.util.concurrent.TimeUnit.SECONDS;
23 < import java.util.HashSet;
18 < import junit.framework.*;
21 >
22 > import junit.framework.Test;
23 > import junit.framework.TestSuite;
24  
25   public class ForkJoinTaskTest extends JSR166TestCase {
26  
27      public static void main(String[] args) {
28 <        junit.textui.TestRunner.run(suite());
28 >        main(suite(), args);
29      }
30  
31      public static Test suite() {
# Line 46 | Line 51 | public class ForkJoinTaskTest extends JS
51      }
52  
53      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
54 <        try {
54 >        try (PoolCleaner cleaner = cleaner(pool)) {
55              assertFalse(a.isDone());
56              assertFalse(a.isCompletedNormally());
57              assertFalse(a.isCompletedAbnormally());
# Line 62 | Line 67 | public class ForkJoinTaskTest extends JS
67              assertFalse(a.isCancelled());
68              assertNull(a.getException());
69              assertNull(a.getRawResult());
65        } finally {
66            joinPool(pool);
70          }
71      }
72  
# Line 96 | Line 99 | public class ForkJoinTaskTest extends JS
99  
100          {
101              Thread.currentThread().interrupt();
102 <            long t0 = System.nanoTime();
102 >            long startTime = System.nanoTime();
103              assertSame(expected, a.join());
104 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
104 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
105              Thread.interrupted();
106          }
107  
108          {
109              Thread.currentThread().interrupt();
110 <            long t0 = System.nanoTime();
110 >            long startTime = System.nanoTime();
111              a.quietlyJoin();        // should be no-op
112 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
112 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
113              Thread.interrupted();
114          }
115  
# Line 139 | Line 142 | public class ForkJoinTaskTest extends JS
142          Thread.interrupted();
143  
144          {
145 <            long t0 = System.nanoTime();
145 >            long startTime = System.nanoTime();
146              a.quietlyJoin();        // should be no-op
147 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
147 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
148          }
149  
150          try {
# Line 177 | Line 180 | public class ForkJoinTaskTest extends JS
180          Thread.interrupted();
181  
182          {
183 <            long t0 = System.nanoTime();
183 >            long startTime = System.nanoTime();
184              a.quietlyJoin();        // should be no-op
185 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
185 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
186          }
187  
188          try {
# Line 216 | Line 219 | public class ForkJoinTaskTest extends JS
219              AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
220                                                   "controlState");
221  
222 <        private BinaryAsyncAction parent;
222 >        private volatile BinaryAsyncAction parent;
223  
224 <        private BinaryAsyncAction sibling;
224 >        private volatile BinaryAsyncAction sibling;
225  
226          protected BinaryAsyncAction() {
227          }
# Line 384 | Line 387 | public class ForkJoinTaskTest extends JS
387       */
388      public void testInvoke() {
389          RecursiveAction a = new CheckedRecursiveAction() {
390 <            public void realCompute() {
390 >            protected void realCompute() {
391                  AsyncFib f = new AsyncFib(8);
392                  assertNull(f.invoke());
393                  assertEquals(21, f.number);
# Line 400 | Line 403 | public class ForkJoinTaskTest extends JS
403       */
404      public void testQuietlyInvoke() {
405          RecursiveAction a = new CheckedRecursiveAction() {
406 <            public void realCompute() {
406 >            protected void realCompute() {
407                  AsyncFib f = new AsyncFib(8);
408                  f.quietlyInvoke();
409                  assertEquals(21, f.number);
# Line 414 | Line 417 | public class ForkJoinTaskTest extends JS
417       */
418      public void testForkJoin() {
419          RecursiveAction a = new CheckedRecursiveAction() {
420 <            public void realCompute() {
420 >            protected void realCompute() {
421                  AsyncFib f = new AsyncFib(8);
422                  assertSame(f, f.fork());
423                  assertNull(f.join());
# Line 429 | Line 432 | public class ForkJoinTaskTest extends JS
432       */
433      public void testForkGet() {
434          RecursiveAction a = new CheckedRecursiveAction() {
435 <            public void realCompute() throws Exception {
435 >            protected void realCompute() throws Exception {
436                  AsyncFib f = new AsyncFib(8);
437                  assertSame(f, f.fork());
438                  assertNull(f.get());
# Line 444 | Line 447 | public class ForkJoinTaskTest extends JS
447       */
448      public void testForkTimedGet() {
449          RecursiveAction a = new CheckedRecursiveAction() {
450 <            public void realCompute() throws Exception {
450 >            protected void realCompute() throws Exception {
451                  AsyncFib f = new AsyncFib(8);
452                  assertSame(f, f.fork());
453                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
# Line 459 | Line 462 | public class ForkJoinTaskTest extends JS
462       */
463      public void testForkTimedGetNPE() {
464          RecursiveAction a = new CheckedRecursiveAction() {
465 <            public void realCompute() throws Exception {
465 >            protected void realCompute() throws Exception {
466                  AsyncFib f = new AsyncFib(8);
467                  assertSame(f, f.fork());
468                  try {
# Line 475 | Line 478 | public class ForkJoinTaskTest extends JS
478       */
479      public void testForkQuietlyJoin() {
480          RecursiveAction a = new CheckedRecursiveAction() {
481 <            public void realCompute() {
481 >            protected void realCompute() {
482                  AsyncFib f = new AsyncFib(8);
483                  assertSame(f, f.fork());
484                  f.quietlyJoin();
# Line 491 | Line 494 | public class ForkJoinTaskTest extends JS
494       */
495      public void testForkHelpQuiesce() {
496          RecursiveAction a = new CheckedRecursiveAction() {
497 <            public void realCompute() {
497 >            protected void realCompute() {
498                  AsyncFib f = new AsyncFib(8);
499                  assertSame(f, f.fork());
500                  helpQuiesce();
# Line 507 | Line 510 | public class ForkJoinTaskTest extends JS
510       */
511      public void testAbnormalInvoke() {
512          RecursiveAction a = new CheckedRecursiveAction() {
513 <            public void realCompute() {
513 >            protected void realCompute() {
514                  FailingAsyncFib f = new FailingAsyncFib(8);
515                  try {
516                      f.invoke();
# Line 524 | Line 527 | public class ForkJoinTaskTest extends JS
527       */
528      public void testAbnormalQuietlyInvoke() {
529          RecursiveAction a = new CheckedRecursiveAction() {
530 <            public void realCompute() {
530 >            protected void realCompute() {
531                  FailingAsyncFib f = new FailingAsyncFib(8);
532                  f.quietlyInvoke();
533                  assertTrue(f.getException() instanceof FJException);
# Line 538 | Line 541 | public class ForkJoinTaskTest extends JS
541       */
542      public void testAbnormalForkJoin() {
543          RecursiveAction a = new CheckedRecursiveAction() {
544 <            public void realCompute() {
544 >            protected void realCompute() {
545                  FailingAsyncFib f = new FailingAsyncFib(8);
546                  assertSame(f, f.fork());
547                  try {
# Line 556 | Line 559 | public class ForkJoinTaskTest extends JS
559       */
560      public void testAbnormalForkGet() {
561          RecursiveAction a = new CheckedRecursiveAction() {
562 <            public void realCompute() throws Exception {
562 >            protected void realCompute() throws Exception {
563                  FailingAsyncFib f = new FailingAsyncFib(8);
564                  assertSame(f, f.fork());
565                  try {
# Line 576 | Line 579 | public class ForkJoinTaskTest extends JS
579       */
580      public void testAbnormalForkTimedGet() {
581          RecursiveAction a = new CheckedRecursiveAction() {
582 <            public void realCompute() throws Exception {
582 >            protected void realCompute() throws Exception {
583                  FailingAsyncFib f = new FailingAsyncFib(8);
584                  assertSame(f, f.fork());
585                  try {
# Line 596 | Line 599 | public class ForkJoinTaskTest extends JS
599       */
600      public void testAbnormalForkQuietlyJoin() {
601          RecursiveAction a = new CheckedRecursiveAction() {
602 <            public void realCompute() {
602 >            protected void realCompute() {
603                  FailingAsyncFib f = new FailingAsyncFib(8);
604                  assertSame(f, f.fork());
605                  f.quietlyJoin();
# Line 611 | Line 614 | public class ForkJoinTaskTest extends JS
614       */
615      public void testCancelledInvoke() {
616          RecursiveAction a = new CheckedRecursiveAction() {
617 <            public void realCompute() {
617 >            protected void realCompute() {
618                  AsyncFib f = new AsyncFib(8);
619                  assertTrue(f.cancel(true));
620                  try {
# Line 629 | Line 632 | public class ForkJoinTaskTest extends JS
632       */
633      public void testCancelledForkJoin() {
634          RecursiveAction a = new CheckedRecursiveAction() {
635 <            public void realCompute() {
635 >            protected void realCompute() {
636                  AsyncFib f = new AsyncFib(8);
637                  assertTrue(f.cancel(true));
638                  assertSame(f, f.fork());
# Line 648 | Line 651 | public class ForkJoinTaskTest extends JS
651       */
652      public void testCancelledForkGet() {
653          RecursiveAction a = new CheckedRecursiveAction() {
654 <            public void realCompute() throws Exception {
654 >            protected void realCompute() throws Exception {
655                  AsyncFib f = new AsyncFib(8);
656                  assertTrue(f.cancel(true));
657                  assertSame(f, f.fork());
# Line 667 | Line 670 | public class ForkJoinTaskTest extends JS
670       */
671      public void testCancelledForkTimedGet() throws Exception {
672          RecursiveAction a = new CheckedRecursiveAction() {
673 <            public void realCompute() throws Exception {
673 >            protected void realCompute() throws Exception {
674                  AsyncFib f = new AsyncFib(8);
675                  assertTrue(f.cancel(true));
676                  assertSame(f, f.fork());
# Line 686 | Line 689 | public class ForkJoinTaskTest extends JS
689       */
690      public void testCancelledForkQuietlyJoin() {
691          RecursiveAction a = new CheckedRecursiveAction() {
692 <            public void realCompute() {
692 >            protected void realCompute() {
693                  AsyncFib f = new AsyncFib(8);
694                  assertTrue(f.cancel(true));
695                  assertSame(f, f.fork());
# Line 702 | Line 705 | public class ForkJoinTaskTest extends JS
705      public void testGetPool() {
706          final ForkJoinPool mainPool = mainPool();
707          RecursiveAction a = new CheckedRecursiveAction() {
708 <            public void realCompute() {
708 >            protected void realCompute() {
709                  assertSame(mainPool, getPool());
710              }};
711          testInvokeOnPool(mainPool, a);
# Line 713 | Line 716 | public class ForkJoinTaskTest extends JS
716       */
717      public void testGetPool2() {
718          RecursiveAction a = new CheckedRecursiveAction() {
719 <            public void realCompute() {
719 >            protected void realCompute() {
720                  assertNull(getPool());
721              }};
722          assertNull(a.invoke());
# Line 724 | Line 727 | public class ForkJoinTaskTest extends JS
727       */
728      public void testInForkJoinPool() {
729          RecursiveAction a = new CheckedRecursiveAction() {
730 <            public void realCompute() {
730 >            protected void realCompute() {
731                  assertTrue(inForkJoinPool());
732              }};
733          testInvokeOnPool(mainPool(), a);
# Line 735 | Line 738 | public class ForkJoinTaskTest extends JS
738       */
739      public void testInForkJoinPool2() {
740          RecursiveAction a = new CheckedRecursiveAction() {
741 <            public void realCompute() {
741 >            protected void realCompute() {
742                  assertFalse(inForkJoinPool());
743              }};
744          assertNull(a.invoke());
# Line 746 | Line 749 | public class ForkJoinTaskTest extends JS
749       */
750      public void testSetRawResult() {
751          RecursiveAction a = new CheckedRecursiveAction() {
752 <            public void realCompute() {
752 >            protected void realCompute() {
753                  setRawResult(null);
754                  assertNull(getRawResult());
755              }};
# Line 758 | Line 761 | public class ForkJoinTaskTest extends JS
761       */
762      public void testCompleteExceptionally() {
763          RecursiveAction a = new CheckedRecursiveAction() {
764 <            public void realCompute() {
764 >            protected void realCompute() {
765                  AsyncFib f = new AsyncFib(8);
766                  f.completeExceptionally(new FJException());
767                  try {
# Line 776 | Line 779 | public class ForkJoinTaskTest extends JS
779       */
780      public void testInvokeAll2() {
781          RecursiveAction a = new CheckedRecursiveAction() {
782 <            public void realCompute() {
782 >            protected void realCompute() {
783                  AsyncFib f = new AsyncFib(8);
784                  AsyncFib g = new AsyncFib(9);
785                  invokeAll(f, g);
# Line 793 | Line 796 | public class ForkJoinTaskTest extends JS
796       */
797      public void testInvokeAll1() {
798          RecursiveAction a = new CheckedRecursiveAction() {
799 <            public void realCompute() {
799 >            protected void realCompute() {
800                  AsyncFib f = new AsyncFib(8);
801                  invokeAll(f);
802                  checkCompletedNormally(f);
# Line 807 | Line 810 | public class ForkJoinTaskTest extends JS
810       */
811      public void testInvokeAll3() {
812          RecursiveAction a = new CheckedRecursiveAction() {
813 <            public void realCompute() {
813 >            protected void realCompute() {
814                  AsyncFib f = new AsyncFib(8);
815                  AsyncFib g = new AsyncFib(9);
816                  AsyncFib h = new AsyncFib(7);
# Line 827 | Line 830 | public class ForkJoinTaskTest extends JS
830       */
831      public void testInvokeAllCollection() {
832          RecursiveAction a = new CheckedRecursiveAction() {
833 <            public void realCompute() {
833 >            protected void realCompute() {
834                  AsyncFib f = new AsyncFib(8);
835                  AsyncFib g = new AsyncFib(9);
836                  AsyncFib h = new AsyncFib(7);
# Line 851 | Line 854 | public class ForkJoinTaskTest extends JS
854       */
855      public void testInvokeAllNPE() {
856          RecursiveAction a = new CheckedRecursiveAction() {
857 <            public void realCompute() {
857 >            protected void realCompute() {
858                  AsyncFib f = new AsyncFib(8);
859                  AsyncFib g = new AsyncFib(9);
860                  AsyncFib h = null;
# Line 868 | Line 871 | public class ForkJoinTaskTest extends JS
871       */
872      public void testAbnormalInvokeAll2() {
873          RecursiveAction a = new CheckedRecursiveAction() {
874 <            public void realCompute() {
874 >            protected void realCompute() {
875                  AsyncFib f = new AsyncFib(8);
876                  FailingAsyncFib g = new FailingAsyncFib(9);
877 +                ForkJoinTask[] tasks = { f, g };
878 +                Collections.shuffle(Arrays.asList(tasks));
879                  try {
880 <                    invokeAll(f, g);
880 >                    invokeAll(tasks);
881                      shouldThrow();
882                  } catch (FJException success) {
883                      checkCompletedAbnormally(g, success);
# Line 886 | Line 891 | public class ForkJoinTaskTest extends JS
891       */
892      public void testAbnormalInvokeAll1() {
893          RecursiveAction a = new CheckedRecursiveAction() {
894 <            public void realCompute() {
894 >            protected void realCompute() {
895                  FailingAsyncFib g = new FailingAsyncFib(9);
896                  try {
897                      invokeAll(g);
# Line 903 | Line 908 | public class ForkJoinTaskTest extends JS
908       */
909      public void testAbnormalInvokeAll3() {
910          RecursiveAction a = new CheckedRecursiveAction() {
911 <            public void realCompute() {
911 >            protected void realCompute() {
912                  AsyncFib f = new AsyncFib(8);
913                  FailingAsyncFib g = new FailingAsyncFib(9);
914                  AsyncFib h = new AsyncFib(7);
915 +                ForkJoinTask[] tasks = { f, g, h };
916 +                Collections.shuffle(Arrays.asList(tasks));
917                  try {
918 <                    invokeAll(f, g, h);
918 >                    invokeAll(tasks);
919                      shouldThrow();
920                  } catch (FJException success) {
921                      checkCompletedAbnormally(g, success);
# Line 918 | Line 925 | public class ForkJoinTaskTest extends JS
925      }
926  
927      /**
928 <     * invokeAll(collection)  throws exception if any task does
928 >     * invokeAll(collection) throws exception if any task does
929       */
930      public void testAbnormalInvokeAllCollection() {
931          RecursiveAction a = new CheckedRecursiveAction() {
932 <            public void realCompute() {
932 >            protected void realCompute() {
933                  FailingAsyncFib f = new FailingAsyncFib(8);
934                  AsyncFib g = new AsyncFib(9);
935                  AsyncFib h = new AsyncFib(7);
936 <                HashSet set = new HashSet();
937 <                set.add(f);
938 <                set.add(g);
932 <                set.add(h);
936 >                ForkJoinTask[] tasks = { f, g, h };
937 >                List taskList = Arrays.asList(tasks);
938 >                Collections.shuffle(taskList);
939                  try {
940 <                    invokeAll(set);
940 >                    invokeAll(taskList);
941                      shouldThrow();
942                  } catch (FJException success) {
943                      checkCompletedAbnormally(f, success);
# Line 946 | Line 952 | public class ForkJoinTaskTest extends JS
952       */
953      public void testTryUnfork() {
954          RecursiveAction a = new CheckedRecursiveAction() {
955 <            public void realCompute() {
955 >            protected void realCompute() {
956                  AsyncFib g = new AsyncFib(9);
957                  assertSame(g, g.fork());
958                  AsyncFib f = new AsyncFib(8);
# Line 965 | Line 971 | public class ForkJoinTaskTest extends JS
971       */
972      public void testGetSurplusQueuedTaskCount() {
973          RecursiveAction a = new CheckedRecursiveAction() {
974 <            public void realCompute() {
974 >            protected void realCompute() {
975                  AsyncFib h = new AsyncFib(7);
976                  assertSame(h, h.fork());
977                  AsyncFib g = new AsyncFib(9);
# Line 987 | Line 993 | public class ForkJoinTaskTest extends JS
993       */
994      public void testPeekNextLocalTask() {
995          RecursiveAction a = new CheckedRecursiveAction() {
996 <            public void realCompute() {
996 >            protected void realCompute() {
997                  AsyncFib g = new AsyncFib(9);
998                  assertSame(g, g.fork());
999                  AsyncFib f = new AsyncFib(8);
# Line 1007 | Line 1013 | public class ForkJoinTaskTest extends JS
1013       */
1014      public void testPollNextLocalTask() {
1015          RecursiveAction a = new CheckedRecursiveAction() {
1016 <            public void realCompute() {
1016 >            protected void realCompute() {
1017                  AsyncFib g = new AsyncFib(9);
1018                  assertSame(g, g.fork());
1019                  AsyncFib f = new AsyncFib(8);
# Line 1026 | Line 1032 | public class ForkJoinTaskTest extends JS
1032       */
1033      public void testPollTask() {
1034          RecursiveAction a = new CheckedRecursiveAction() {
1035 <            public void realCompute() {
1035 >            protected void realCompute() {
1036                  AsyncFib g = new AsyncFib(9);
1037                  assertSame(g, g.fork());
1038                  AsyncFib f = new AsyncFib(8);
# Line 1044 | Line 1050 | public class ForkJoinTaskTest extends JS
1050       */
1051      public void testPeekNextLocalTaskAsync() {
1052          RecursiveAction a = new CheckedRecursiveAction() {
1053 <            public void realCompute() {
1053 >            protected void realCompute() {
1054                  AsyncFib g = new AsyncFib(9);
1055                  assertSame(g, g.fork());
1056                  AsyncFib f = new AsyncFib(8);
# Line 1065 | Line 1071 | public class ForkJoinTaskTest extends JS
1071       */
1072      public void testPollNextLocalTaskAsync() {
1073          RecursiveAction a = new CheckedRecursiveAction() {
1074 <            public void realCompute() {
1074 >            protected void realCompute() {
1075                  AsyncFib g = new AsyncFib(9);
1076                  assertSame(g, g.fork());
1077                  AsyncFib f = new AsyncFib(8);
# Line 1085 | Line 1091 | public class ForkJoinTaskTest extends JS
1091       */
1092      public void testPollTaskAsync() {
1093          RecursiveAction a = new CheckedRecursiveAction() {
1094 <            public void realCompute() {
1094 >            protected void realCompute() {
1095                  AsyncFib g = new AsyncFib(9);
1096                  assertSame(g, g.fork());
1097                  AsyncFib f = new AsyncFib(8);
# Line 1108 | Line 1114 | public class ForkJoinTaskTest extends JS
1114       */
1115      public void testInvokeSingleton() {
1116          RecursiveAction a = new CheckedRecursiveAction() {
1117 <            public void realCompute() {
1117 >            protected void realCompute() {
1118                  AsyncFib f = new AsyncFib(8);
1119                  assertNull(f.invoke());
1120                  assertEquals(21, f.number);
# Line 1124 | Line 1130 | public class ForkJoinTaskTest extends JS
1130       */
1131      public void testQuietlyInvokeSingleton() {
1132          RecursiveAction a = new CheckedRecursiveAction() {
1133 <            public void realCompute() {
1133 >            protected void realCompute() {
1134                  AsyncFib f = new AsyncFib(8);
1135                  f.quietlyInvoke();
1136                  assertEquals(21, f.number);
# Line 1138 | Line 1144 | public class ForkJoinTaskTest extends JS
1144       */
1145      public void testForkJoinSingleton() {
1146          RecursiveAction a = new CheckedRecursiveAction() {
1147 <            public void realCompute() {
1147 >            protected void realCompute() {
1148                  AsyncFib f = new AsyncFib(8);
1149                  assertSame(f, f.fork());
1150                  assertNull(f.join());
# Line 1153 | Line 1159 | public class ForkJoinTaskTest extends JS
1159       */
1160      public void testForkGetSingleton() {
1161          RecursiveAction a = new CheckedRecursiveAction() {
1162 <            public void realCompute() throws Exception {
1162 >            protected void realCompute() throws Exception {
1163                  AsyncFib f = new AsyncFib(8);
1164                  assertSame(f, f.fork());
1165                  assertNull(f.get());
# Line 1168 | Line 1174 | public class ForkJoinTaskTest extends JS
1174       */
1175      public void testForkTimedGetSingleton() {
1176          RecursiveAction a = new CheckedRecursiveAction() {
1177 <            public void realCompute() throws Exception {
1177 >            protected void realCompute() throws Exception {
1178                  AsyncFib f = new AsyncFib(8);
1179                  assertSame(f, f.fork());
1180                  assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
# Line 1183 | Line 1189 | public class ForkJoinTaskTest extends JS
1189       */
1190      public void testForkTimedGetNPESingleton() {
1191          RecursiveAction a = new CheckedRecursiveAction() {
1192 <            public void realCompute() throws Exception {
1192 >            protected void realCompute() throws Exception {
1193                  AsyncFib f = new AsyncFib(8);
1194                  assertSame(f, f.fork());
1195                  try {
# Line 1199 | Line 1205 | public class ForkJoinTaskTest extends JS
1205       */
1206      public void testForkQuietlyJoinSingleton() {
1207          RecursiveAction a = new CheckedRecursiveAction() {
1208 <            public void realCompute() {
1208 >            protected void realCompute() {
1209                  AsyncFib f = new AsyncFib(8);
1210                  assertSame(f, f.fork());
1211                  f.quietlyJoin();
# Line 1215 | Line 1221 | public class ForkJoinTaskTest extends JS
1221       */
1222      public void testForkHelpQuiesceSingleton() {
1223          RecursiveAction a = new CheckedRecursiveAction() {
1224 <            public void realCompute() {
1224 >            protected void realCompute() {
1225                  AsyncFib f = new AsyncFib(8);
1226                  assertSame(f, f.fork());
1227                  helpQuiesce();
# Line 1231 | Line 1237 | public class ForkJoinTaskTest extends JS
1237       */
1238      public void testAbnormalInvokeSingleton() {
1239          RecursiveAction a = new CheckedRecursiveAction() {
1240 <            public void realCompute() {
1240 >            protected void realCompute() {
1241                  FailingAsyncFib f = new FailingAsyncFib(8);
1242                  try {
1243                      f.invoke();
# Line 1248 | Line 1254 | public class ForkJoinTaskTest extends JS
1254       */
1255      public void testAbnormalQuietlyInvokeSingleton() {
1256          RecursiveAction a = new CheckedRecursiveAction() {
1257 <            public void realCompute() {
1257 >            protected void realCompute() {
1258                  FailingAsyncFib f = new FailingAsyncFib(8);
1259                  f.quietlyInvoke();
1260                  assertTrue(f.getException() instanceof FJException);
# Line 1262 | Line 1268 | public class ForkJoinTaskTest extends JS
1268       */
1269      public void testAbnormalForkJoinSingleton() {
1270          RecursiveAction a = new CheckedRecursiveAction() {
1271 <            public void realCompute() {
1271 >            protected void realCompute() {
1272                  FailingAsyncFib f = new FailingAsyncFib(8);
1273                  assertSame(f, f.fork());
1274                  try {
# Line 1280 | Line 1286 | public class ForkJoinTaskTest extends JS
1286       */
1287      public void testAbnormalForkGetSingleton() {
1288          RecursiveAction a = new CheckedRecursiveAction() {
1289 <            public void realCompute() throws Exception {
1289 >            protected void realCompute() throws Exception {
1290                  FailingAsyncFib f = new FailingAsyncFib(8);
1291                  assertSame(f, f.fork());
1292                  try {
# Line 1300 | Line 1306 | public class ForkJoinTaskTest extends JS
1306       */
1307      public void testAbnormalForkTimedGetSingleton() {
1308          RecursiveAction a = new CheckedRecursiveAction() {
1309 <            public void realCompute() throws Exception {
1309 >            protected void realCompute() throws Exception {
1310                  FailingAsyncFib f = new FailingAsyncFib(8);
1311                  assertSame(f, f.fork());
1312                  try {
# Line 1320 | Line 1326 | public class ForkJoinTaskTest extends JS
1326       */
1327      public void testAbnormalForkQuietlyJoinSingleton() {
1328          RecursiveAction a = new CheckedRecursiveAction() {
1329 <            public void realCompute() {
1329 >            protected void realCompute() {
1330                  FailingAsyncFib f = new FailingAsyncFib(8);
1331                  assertSame(f, f.fork());
1332                  f.quietlyJoin();
# Line 1335 | Line 1341 | public class ForkJoinTaskTest extends JS
1341       */
1342      public void testCancelledInvokeSingleton() {
1343          RecursiveAction a = new CheckedRecursiveAction() {
1344 <            public void realCompute() {
1344 >            protected void realCompute() {
1345                  AsyncFib f = new AsyncFib(8);
1346                  assertTrue(f.cancel(true));
1347                  try {
# Line 1353 | Line 1359 | public class ForkJoinTaskTest extends JS
1359       */
1360      public void testCancelledForkJoinSingleton() {
1361          RecursiveAction a = new CheckedRecursiveAction() {
1362 <            public void realCompute() {
1362 >            protected void realCompute() {
1363                  AsyncFib f = new AsyncFib(8);
1364                  assertTrue(f.cancel(true));
1365                  assertSame(f, f.fork());
# Line 1372 | Line 1378 | public class ForkJoinTaskTest extends JS
1378       */
1379      public void testCancelledForkGetSingleton() {
1380          RecursiveAction a = new CheckedRecursiveAction() {
1381 <            public void realCompute() throws Exception {
1381 >            protected void realCompute() throws Exception {
1382                  AsyncFib f = new AsyncFib(8);
1383                  assertTrue(f.cancel(true));
1384                  assertSame(f, f.fork());
# Line 1391 | Line 1397 | public class ForkJoinTaskTest extends JS
1397       */
1398      public void testCancelledForkTimedGetSingleton() throws Exception {
1399          RecursiveAction a = new CheckedRecursiveAction() {
1400 <            public void realCompute() throws Exception {
1400 >            protected void realCompute() throws Exception {
1401                  AsyncFib f = new AsyncFib(8);
1402                  assertTrue(f.cancel(true));
1403                  assertSame(f, f.fork());
# Line 1410 | Line 1416 | public class ForkJoinTaskTest extends JS
1416       */
1417      public void testCancelledForkQuietlyJoinSingleton() {
1418          RecursiveAction a = new CheckedRecursiveAction() {
1419 <            public void realCompute() {
1419 >            protected void realCompute() {
1420                  AsyncFib f = new AsyncFib(8);
1421                  assertTrue(f.cancel(true));
1422                  assertSame(f, f.fork());
# Line 1425 | Line 1431 | public class ForkJoinTaskTest extends JS
1431       */
1432      public void testCompleteExceptionallySingleton() {
1433          RecursiveAction a = new CheckedRecursiveAction() {
1434 <            public void realCompute() {
1434 >            protected void realCompute() {
1435                  AsyncFib f = new AsyncFib(8);
1436                  f.completeExceptionally(new FJException());
1437                  try {
# Line 1443 | Line 1449 | public class ForkJoinTaskTest extends JS
1449       */
1450      public void testInvokeAll2Singleton() {
1451          RecursiveAction a = new CheckedRecursiveAction() {
1452 <            public void realCompute() {
1452 >            protected void realCompute() {
1453                  AsyncFib f = new AsyncFib(8);
1454                  AsyncFib g = new AsyncFib(9);
1455                  invokeAll(f, g);
# Line 1460 | Line 1466 | public class ForkJoinTaskTest extends JS
1466       */
1467      public void testInvokeAll1Singleton() {
1468          RecursiveAction a = new CheckedRecursiveAction() {
1469 <            public void realCompute() {
1469 >            protected void realCompute() {
1470                  AsyncFib f = new AsyncFib(8);
1471                  invokeAll(f);
1472                  checkCompletedNormally(f);
# Line 1474 | Line 1480 | public class ForkJoinTaskTest extends JS
1480       */
1481      public void testInvokeAll3Singleton() {
1482          RecursiveAction a = new CheckedRecursiveAction() {
1483 <            public void realCompute() {
1483 >            protected void realCompute() {
1484                  AsyncFib f = new AsyncFib(8);
1485                  AsyncFib g = new AsyncFib(9);
1486                  AsyncFib h = new AsyncFib(7);
# Line 1494 | Line 1500 | public class ForkJoinTaskTest extends JS
1500       */
1501      public void testInvokeAllCollectionSingleton() {
1502          RecursiveAction a = new CheckedRecursiveAction() {
1503 <            public void realCompute() {
1503 >            protected void realCompute() {
1504                  AsyncFib f = new AsyncFib(8);
1505                  AsyncFib g = new AsyncFib(9);
1506                  AsyncFib h = new AsyncFib(7);
# Line 1518 | Line 1524 | public class ForkJoinTaskTest extends JS
1524       */
1525      public void testInvokeAllNPESingleton() {
1526          RecursiveAction a = new CheckedRecursiveAction() {
1527 <            public void realCompute() {
1527 >            protected void realCompute() {
1528                  AsyncFib f = new AsyncFib(8);
1529                  AsyncFib g = new AsyncFib(9);
1530                  AsyncFib h = null;
# Line 1535 | Line 1541 | public class ForkJoinTaskTest extends JS
1541       */
1542      public void testAbnormalInvokeAll2Singleton() {
1543          RecursiveAction a = new CheckedRecursiveAction() {
1544 <            public void realCompute() {
1544 >            protected void realCompute() {
1545                  AsyncFib f = new AsyncFib(8);
1546                  FailingAsyncFib g = new FailingAsyncFib(9);
1547 +                ForkJoinTask[] tasks = { f, g };
1548 +                Collections.shuffle(Arrays.asList(tasks));
1549                  try {
1550 <                    invokeAll(f, g);
1550 >                    invokeAll(tasks);
1551                      shouldThrow();
1552                  } catch (FJException success) {
1553                      checkCompletedAbnormally(g, success);
# Line 1553 | Line 1561 | public class ForkJoinTaskTest extends JS
1561       */
1562      public void testAbnormalInvokeAll1Singleton() {
1563          RecursiveAction a = new CheckedRecursiveAction() {
1564 <            public void realCompute() {
1564 >            protected void realCompute() {
1565                  FailingAsyncFib g = new FailingAsyncFib(9);
1566                  try {
1567                      invokeAll(g);
# Line 1570 | Line 1578 | public class ForkJoinTaskTest extends JS
1578       */
1579      public void testAbnormalInvokeAll3Singleton() {
1580          RecursiveAction a = new CheckedRecursiveAction() {
1581 <            public void realCompute() {
1581 >            protected void realCompute() {
1582                  AsyncFib f = new AsyncFib(8);
1583                  FailingAsyncFib g = new FailingAsyncFib(9);
1584                  AsyncFib h = new AsyncFib(7);
1585 +                ForkJoinTask[] tasks = { f, g, h };
1586 +                Collections.shuffle(Arrays.asList(tasks));
1587                  try {
1588 <                    invokeAll(f, g, h);
1588 >                    invokeAll(tasks);
1589                      shouldThrow();
1590                  } catch (FJException success) {
1591                      checkCompletedAbnormally(g, success);
# Line 1585 | Line 1595 | public class ForkJoinTaskTest extends JS
1595      }
1596  
1597      /**
1598 <     * invokeAll(collection)  throws exception if any task does
1598 >     * invokeAll(collection) throws exception if any task does
1599       */
1600      public void testAbnormalInvokeAllCollectionSingleton() {
1601          RecursiveAction a = new CheckedRecursiveAction() {
1602 <            public void realCompute() {
1602 >            protected void realCompute() {
1603                  FailingAsyncFib f = new FailingAsyncFib(8);
1604                  AsyncFib g = new AsyncFib(9);
1605                  AsyncFib h = new AsyncFib(7);
1606 <                HashSet set = new HashSet();
1607 <                set.add(f);
1608 <                set.add(g);
1599 <                set.add(h);
1606 >                ForkJoinTask[] tasks = { f, g, h };
1607 >                List taskList = Arrays.asList(tasks);
1608 >                Collections.shuffle(taskList);
1609                  try {
1610 <                    invokeAll(set);
1610 >                    invokeAll(taskList);
1611                      shouldThrow();
1612                  } catch (FJException success) {
1613                      checkCompletedAbnormally(f, success);
# Line 1607 | Line 1616 | public class ForkJoinTaskTest extends JS
1616          testInvokeOnPool(singletonPool(), a);
1617      }
1618  
1619 +    /**
1620 +     * ForkJoinTask.quietlyComplete returns when task completes
1621 +     * normally without setting a value. The most recent value
1622 +     * established by setRawResult(V) (or null by default) is returned
1623 +     * from invoke.
1624 +     */
1625 +    public void testQuietlyComplete() {
1626 +        RecursiveAction a = new CheckedRecursiveAction() {
1627 +                protected void realCompute() {
1628 +                    AsyncFib f = new AsyncFib(8);
1629 +                    f.quietlyComplete();
1630 +                    assertEquals(8, f.number);
1631 +                    checkCompletedNormally(f);
1632 +                }};
1633 +        testInvokeOnPool(mainPool(), a);
1634 +    }
1635 +
1636   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines