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

Comparing jsr166/src/test/tck/ForkJoinTask8Test.java (file contents):
Revision 1.12 by jsr166, Sat Feb 7 22:32:48 2015 UTC vs.
Revision 1.19 by dl, Mon Oct 5 22:59:29 2015 UTC

# Line 8 | Line 8 | import static java.util.concurrent.TimeU
8   import static java.util.concurrent.TimeUnit.SECONDS;
9  
10   import java.util.Arrays;
11 + import java.util.Collections;
12 + import java.util.concurrent.CountDownLatch;
13   import java.util.concurrent.ExecutionException;
14   import java.util.concurrent.ForkJoinPool;
15   import java.util.concurrent.ForkJoinTask;
16 + import java.util.concurrent.ForkJoinWorkerThread;
17   import java.util.concurrent.RecursiveAction;
18   import java.util.concurrent.TimeoutException;
19  
# Line 34 | Line 37 | public class ForkJoinTask8Test extends J
37      static final short EXCEPTION_STATE = 1;
38  
39      public static void main(String[] args) {
40 <        junit.textui.TestRunner.run(suite());
40 >        main(suite(), args);
41      }
42  
43      public static Test suite() {
# Line 71 | Line 74 | public class ForkJoinTask8Test extends J
74      }
75  
76      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
77 <        try {
77 >        try (PoolCleaner cleaner = cleaner(pool)) {
78              assertFalse(a.isDone());
79              assertFalse(a.isCompletedNormally());
80              assertFalse(a.isCompletedAbnormally());
# Line 87 | Line 90 | public class ForkJoinTask8Test extends J
90              assertFalse(a.isCancelled());
91              assertNull(a.getException());
92              assertNull(a.getRawResult());
90        } finally {
91            joinPool(pool);
93          }
94      }
95  
# Line 197 | Line 198 | public class ForkJoinTask8Test extends J
198  
199      abstract static class BinaryAsyncAction extends ForkJoinTask<Void> {
200  
201 <        private BinaryAsyncAction parent;
201 >        private volatile BinaryAsyncAction parent;
202  
203 <        private BinaryAsyncAction sibling;
203 >        private volatile BinaryAsyncAction sibling;
204  
205          protected BinaryAsyncAction() {
206              setForkJoinTaskTag(INITIAL_STATE);
# Line 873 | Line 874 | public class ForkJoinTask8Test extends J
874      }
875  
876      /**
877 <     * invokeAll(t1, t2) throw exception if any task does
877 >     * invokeAll(tasks) with 1 argument throws exception if task does
878       */
879 <    public void testAbnormalInvokeAll2() {
880 <        testAbnormalInvokeAll2(mainPool());
879 >    public void testAbnormalInvokeAll1() {
880 >        testAbnormalInvokeAll1(mainPool());
881      }
882 <    public void testAbnormalInvokeAll2_Singleton() {
883 <        testAbnormalInvokeAll2(singletonPool());
882 >    public void testAbnormalInvokeAll1_Singleton() {
883 >        testAbnormalInvokeAll1(singletonPool());
884      }
885 <    public void testAbnormalInvokeAll2(ForkJoinPool pool) {
885 >    public void testAbnormalInvokeAll1(ForkJoinPool pool) {
886          RecursiveAction a = new CheckedRecursiveAction() {
887              protected void realCompute() {
887                AsyncFib f = new AsyncFib(8);
888                  FailingAsyncFib g = new FailingAsyncFib(9);
889                  try {
890 <                    invokeAll(f, g);
890 >                    invokeAll(g);
891                      shouldThrow();
892                  } catch (FJException success) {
893                      checkCompletedAbnormally(g, success);
# Line 897 | Line 897 | public class ForkJoinTask8Test extends J
897      }
898  
899      /**
900 <     * invokeAll(tasks) with 1 argument throws exception if task does
900 >     * invokeAll(t1, t2) throw exception if any task does
901       */
902 <    public void testAbnormalInvokeAll1() {
903 <        testAbnormalInvokeAll1(mainPool());
902 >    public void testAbnormalInvokeAll2() {
903 >        testAbnormalInvokeAll2(mainPool());
904      }
905 <    public void testAbnormalInvokeAll1_Singleton() {
906 <        testAbnormalInvokeAll1(singletonPool());
905 >    public void testAbnormalInvokeAll2_Singleton() {
906 >        testAbnormalInvokeAll2(singletonPool());
907      }
908 <    public void testAbnormalInvokeAll1(ForkJoinPool pool) {
908 >    public void testAbnormalInvokeAll2(ForkJoinPool pool) {
909          RecursiveAction a = new CheckedRecursiveAction() {
910              protected void realCompute() {
911 +                AsyncFib f = new AsyncFib(8);
912                  FailingAsyncFib g = new FailingAsyncFib(9);
913 +                ForkJoinTask[] tasks = { f, g };
914 +                Collections.shuffle(Arrays.asList(tasks));
915                  try {
916 <                    invokeAll(g);
916 >                    invokeAll(tasks[0], tasks[1]);
917                      shouldThrow();
918                  } catch (FJException success) {
919                      checkCompletedAbnormally(g, success);
# Line 934 | Line 937 | public class ForkJoinTask8Test extends J
937                  AsyncFib f = new AsyncFib(8);
938                  FailingAsyncFib g = new FailingAsyncFib(9);
939                  AsyncFib h = new AsyncFib(7);
940 +                ForkJoinTask[] tasks = { f, g, h };
941 +                Collections.shuffle(Arrays.asList(tasks));
942                  try {
943 <                    invokeAll(f, g, h);
943 >                    invokeAll(tasks[0], tasks[1], tasks[2]);
944                      shouldThrow();
945                  } catch (FJException success) {
946                      checkCompletedAbnormally(g, success);
# Line 960 | Line 965 | public class ForkJoinTask8Test extends J
965                  AsyncFib g = new AsyncFib(9);
966                  AsyncFib h = new AsyncFib(7);
967                  ForkJoinTask[] tasks = { f, g, h };
968 +                Collections.shuffle(Arrays.asList(tasks));
969                  try {
970                      invokeAll(Arrays.asList(tasks));
971                      shouldThrow();
# Line 1146 | Line 1152 | public class ForkJoinTask8Test extends J
1152          testInvokeOnPool(mainPool(), a);
1153      }
1154  
1155 +    // jdk9
1156 +
1157 +    /**
1158 +     * pollSubmission returns unexecuted submitted task, if present
1159 +     */
1160 +    public void testPollSubmission() {
1161 +        final CountDownLatch done = new CountDownLatch(1);
1162 +        final ForkJoinTask a = ForkJoinTask.adapt(awaiter(done));
1163 +        final ForkJoinTask b = ForkJoinTask.adapt(awaiter(done));
1164 +        final ForkJoinTask c = ForkJoinTask.adapt(awaiter(done));
1165 +        final ForkJoinPool p = singletonPool();
1166 +        try (PoolCleaner cleaner = cleaner(p)) {
1167 +            Thread external = new Thread(new CheckedRunnable() {
1168 +                public void realRun() {
1169 +                    p.execute(a);
1170 +                    p.execute(b);
1171 +                    p.execute(c);
1172 +                }});
1173 +            RecursiveAction s = new CheckedRecursiveAction() {
1174 +                protected void realCompute() {
1175 +                    external.start();
1176 +                    try {
1177 +                        external.join();
1178 +                    } catch (Exception ex) {
1179 +                        threadUnexpectedException(ex);
1180 +                    }
1181 +                    assertTrue(p.hasQueuedSubmissions());
1182 +                    assertTrue(Thread.currentThread() instanceof ForkJoinWorkerThread);
1183 +                    ForkJoinTask r = ForkJoinTask.pollSubmission();
1184 +                    assertTrue(r == a || r == b || r == c);
1185 +                    assertFalse(r.isDone());
1186 +                }};
1187 +            p.invoke(s);
1188 +            done.countDown();
1189 +        }
1190 +    }
1191 +
1192   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines