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.15 by dl, Tue Sep 8 23:56:19 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 873 | Line 876 | public class ForkJoinTask8Test extends J
876      }
877  
878      /**
879 <     * invokeAll(t1, t2) throw exception if any task does
879 >     * invokeAll(tasks) with 1 argument throws exception if task does
880       */
881 <    public void testAbnormalInvokeAll2() {
882 <        testAbnormalInvokeAll2(mainPool());
881 >    public void testAbnormalInvokeAll1() {
882 >        testAbnormalInvokeAll1(mainPool());
883      }
884 <    public void testAbnormalInvokeAll2_Singleton() {
885 <        testAbnormalInvokeAll2(singletonPool());
884 >    public void testAbnormalInvokeAll1_Singleton() {
885 >        testAbnormalInvokeAll1(singletonPool());
886      }
887 <    public void testAbnormalInvokeAll2(ForkJoinPool pool) {
887 >    public void testAbnormalInvokeAll1(ForkJoinPool pool) {
888          RecursiveAction a = new CheckedRecursiveAction() {
889              protected void realCompute() {
887                AsyncFib f = new AsyncFib(8);
890                  FailingAsyncFib g = new FailingAsyncFib(9);
891                  try {
892 <                    invokeAll(f, g);
892 >                    invokeAll(g);
893                      shouldThrow();
894                  } catch (FJException success) {
895                      checkCompletedAbnormally(g, success);
# Line 897 | Line 899 | public class ForkJoinTask8Test extends J
899      }
900  
901      /**
902 <     * invokeAll(tasks) with 1 argument throws exception if task does
902 >     * invokeAll(t1, t2) throw exception if any task does
903       */
904 <    public void testAbnormalInvokeAll1() {
905 <        testAbnormalInvokeAll1(mainPool());
904 >    public void testAbnormalInvokeAll2() {
905 >        testAbnormalInvokeAll2(mainPool());
906      }
907 <    public void testAbnormalInvokeAll1_Singleton() {
908 <        testAbnormalInvokeAll1(singletonPool());
907 >    public void testAbnormalInvokeAll2_Singleton() {
908 >        testAbnormalInvokeAll2(singletonPool());
909      }
910 <    public void testAbnormalInvokeAll1(ForkJoinPool pool) {
910 >    public void testAbnormalInvokeAll2(ForkJoinPool pool) {
911          RecursiveAction a = new CheckedRecursiveAction() {
912              protected void realCompute() {
913 +                AsyncFib f = new AsyncFib(8);
914                  FailingAsyncFib g = new FailingAsyncFib(9);
915 +                ForkJoinTask[] tasks = { f, g };
916 +                Collections.shuffle(Arrays.asList(tasks));
917                  try {
918 <                    invokeAll(g);
918 >                    invokeAll(tasks[0], tasks[1]);
919                      shouldThrow();
920                  } catch (FJException success) {
921                      checkCompletedAbnormally(g, success);
# Line 934 | Line 939 | public class ForkJoinTask8Test extends J
939                  AsyncFib f = new AsyncFib(8);
940                  FailingAsyncFib g = new FailingAsyncFib(9);
941                  AsyncFib h = new AsyncFib(7);
942 +                ForkJoinTask[] tasks = { f, g, h };
943 +                Collections.shuffle(Arrays.asList(tasks));
944                  try {
945 <                    invokeAll(f, g, h);
945 >                    invokeAll(tasks[0], tasks[1], tasks[2]);
946                      shouldThrow();
947                  } catch (FJException success) {
948                      checkCompletedAbnormally(g, success);
# Line 960 | Line 967 | public class ForkJoinTask8Test extends J
967                  AsyncFib g = new AsyncFib(9);
968                  AsyncFib h = new AsyncFib(7);
969                  ForkJoinTask[] tasks = { f, g, h };
970 +                Collections.shuffle(Arrays.asList(tasks));
971                  try {
972                      invokeAll(Arrays.asList(tasks));
973                      shouldThrow();
# Line 1146 | Line 1154 | public class ForkJoinTask8Test extends J
1154          testInvokeOnPool(mainPool(), a);
1155      }
1156  
1157 +    // jdk9
1158 +    
1159 +    /**
1160 +     * pollSubmission returns unexecuted submitted task, if present
1161 +     */
1162 +    public void testPollSubmission() {
1163 +        final CountDownLatch done = new CountDownLatch(1);
1164 +        final ForkJoinTask a = ForkJoinTask.adapt(awaiter(done));
1165 +        final ForkJoinTask b = ForkJoinTask.adapt(awaiter(done));
1166 +        final ForkJoinTask c = ForkJoinTask.adapt(awaiter(done));
1167 +        final ForkJoinPool p = singletonPool();
1168 +        Thread external = new Thread() {
1169 +                public void run() {
1170 +                    p.execute(a);
1171 +                    p.execute(b);
1172 +                    p.execute(c);
1173 +                }};
1174 +        RecursiveAction s = new CheckedRecursiveAction() {
1175 +                protected void realCompute() {
1176 +                    external.start();
1177 +                    try {
1178 +                        external.join();
1179 +                    } catch(Exception ex) {
1180 +                        threadUnexpectedException(ex);
1181 +                    }
1182 +                    assertTrue(p.hasQueuedSubmissions());
1183 +                    assertTrue(Thread.currentThread() instanceof ForkJoinWorkerThread);
1184 +                    ForkJoinTask r = ForkJoinTask.pollSubmission();
1185 +                    assertTrue(r == a || r == b || r == c);
1186 +                    assertFalse(r.isDone());
1187 +                }};
1188 +        try {
1189 +            p.invoke(s);
1190 +        } finally {
1191 +            done.countDown();
1192 +            joinPool(p);
1193 +        }
1194 +    }
1195 +
1196 +    
1197   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines