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.28 by jsr166, Sat Mar 18 20:42:20 2017 UTC vs.
Revision 1.35 by dl, Tue Jan 26 13:33:06 2021 UTC

# Line 5 | Line 5
5   */
6  
7   import static java.util.concurrent.TimeUnit.MILLISECONDS;
8 import static java.util.concurrent.TimeUnit.SECONDS;
8  
9   import java.util.Arrays;
10   import java.util.concurrent.CountDownLatch;
# Line 92 | Line 91 | public class ForkJoinTask8Test extends J
91          }
92      }
93  
94 <    void checkNotDone(ForkJoinTask a) {
94 >    void checkNotDone(ForkJoinTask<?> a) {
95          assertFalse(a.isDone());
96          assertFalse(a.isCompletedNormally());
97          assertFalse(a.isCompletedAbnormally());
# Line 104 | Line 103 | public class ForkJoinTask8Test extends J
103                           ((BinaryAsyncAction)a).getForkJoinTaskTag());
104  
105          try {
106 <            a.get(0L, SECONDS);
106 >            a.get(randomExpiredTimeout(), randomTimeUnit());
107              shouldThrow();
108          } catch (TimeoutException success) {
109          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 114 | Line 113 | public class ForkJoinTask8Test extends J
113          checkCompletedNormally(a, null);
114      }
115  
116 <    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
116 >    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expectedValue) {
117          assertTrue(a.isDone());
118          assertFalse(a.isCancelled());
119          assertTrue(a.isCompletedNormally());
120          assertFalse(a.isCompletedAbnormally());
121          assertNull(a.getException());
122 <        assertSame(expected, a.getRawResult());
122 >        assertSame(expectedValue, a.getRawResult());
123          if (a instanceof BinaryAsyncAction)
124              assertEquals(COMPLETE_STATE,
125                           ((BinaryAsyncAction)a).getForkJoinTaskTag());
# Line 128 | Line 127 | public class ForkJoinTask8Test extends J
127          {
128              Thread.currentThread().interrupt();
129              long startTime = System.nanoTime();
130 <            assertSame(expected, a.join());
131 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
130 >            assertSame(expectedValue, a.join());
131 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
132              Thread.interrupted();
133          }
134  
# Line 137 | Line 136 | public class ForkJoinTask8Test extends J
136              Thread.currentThread().interrupt();
137              long startTime = System.nanoTime();
138              a.quietlyJoin();        // should be no-op
139 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
139 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
140              Thread.interrupted();
141          }
142  
143          assertFalse(a.cancel(false));
144          assertFalse(a.cancel(true));
145 +
146 +        T v1 = null, v2 = null;
147          try {
148 <            assertSame(expected, a.get());
149 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
149 <        try {
150 <            assertSame(expected, a.get(5L, SECONDS));
148 >            v1 = a.get();
149 >            v2 = a.get(randomTimeout(), randomTimeUnit());
150          } catch (Throwable fail) { threadUnexpectedException(fail); }
151 +        assertSame(expectedValue, v1);
152 +        assertSame(expectedValue, v2);
153      }
154  
155 <    void checkCompletedAbnormally(ForkJoinTask a, Throwable t) {
155 >    void checkCompletedAbnormally(ForkJoinTask<?> a, Throwable t) {
156          assertTrue(a.isDone());
157          assertFalse(a.isCancelled());
158          assertFalse(a.isCompletedNormally());
# Line 175 | Line 176 | public class ForkJoinTask8Test extends J
176          {
177              long startTime = System.nanoTime();
178              a.quietlyJoin();        // should be no-op
179 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
179 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
180          }
181  
182          try {
# Line 186 | Line 187 | public class ForkJoinTask8Test extends J
187          } catch (Throwable fail) { threadUnexpectedException(fail); }
188  
189          try {
190 <            a.get(5L, SECONDS);
190 >            a.get(randomTimeout(), randomTimeUnit());
191              shouldThrow();
192          } catch (ExecutionException success) {
193              assertSame(t.getClass(), success.getCause().getClass());
# Line 488 | Line 489 | public class ForkJoinTask8Test extends J
489                  AsyncFib f = new AsyncFib(8);
490                  assertSame(f, f.fork());
491                  try {
492 <                    f.get(5L, null);
492 >                    f.get(randomTimeout(), null);
493                      shouldThrow();
494                  } catch (NullPointerException success) {}
495              }};
# Line 531 | Line 532 | public class ForkJoinTask8Test extends J
532                  AsyncFib f = new AsyncFib(8);
533                  assertSame(f, f.fork());
534                  helpQuiesce();
535 +                while (!f.isDone()) // wait out race
536 +                    ;
537                  assertEquals(0, getQueuedTaskCount());
538                  f.checkCompletedNormally();
539              }};
# Line 872 | Line 875 | public class ForkJoinTask8Test extends J
875          RecursiveAction a = new CheckedRecursiveAction() {
876              protected void realCompute() {
877                  AsyncFib nul = null;
878 <                Runnable[] throwingActions = {
878 >                assertThrows(
879 >                    NullPointerException.class,
880                      () -> invokeAll(nul),
881                      () -> invokeAll(nul, nul),
882                      () -> invokeAll(new AsyncFib(8), new AsyncFib(9), nul),
883                      () -> invokeAll(new AsyncFib(8), nul, new AsyncFib(9)),
884 <                    () -> invokeAll(nul, new AsyncFib(8), new AsyncFib(9)),
881 <                };
882 <                assertThrows(NullPointerException.class, throwingActions);
884 >                    () -> invokeAll(nul, new AsyncFib(8), new AsyncFib(9)));
885              }};
886          testInvokeOnPool(pool, a);
887      }
# Line 921 | Line 923 | public class ForkJoinTask8Test extends J
923              protected void realCompute() {
924                  AsyncFib f = new AsyncFib(8);
925                  FailingAsyncFib g = new FailingAsyncFib(9);
926 <                ForkJoinTask[] tasks = { f, g };
926 >                ForkJoinTask<?>[] tasks = { f, g };
927                  shuffle(tasks);
928                  try {
929                      invokeAll(tasks[0], tasks[1]);
# Line 948 | Line 950 | public class ForkJoinTask8Test extends J
950                  AsyncFib f = new AsyncFib(8);
951                  FailingAsyncFib g = new FailingAsyncFib(9);
952                  AsyncFib h = new AsyncFib(7);
953 <                ForkJoinTask[] tasks = { f, g, h };
953 >                ForkJoinTask<?>[] tasks = { f, g, h };
954                  shuffle(tasks);
955                  try {
956                      invokeAll(tasks[0], tasks[1], tasks[2]);
# Line 975 | Line 977 | public class ForkJoinTask8Test extends J
977                  FailingAsyncFib f = new FailingAsyncFib(8);
978                  AsyncFib g = new AsyncFib(9);
979                  AsyncFib h = new AsyncFib(7);
980 <                ForkJoinTask[] tasks = { f, g, h };
980 >                ForkJoinTask<?>[] tasks = { f, g, h };
981                  shuffle(tasks);
982                  try {
983                      invokeAll(Arrays.asList(tasks));
# Line 1170 | Line 1172 | public class ForkJoinTask8Test extends J
1172       */
1173      public void testPollSubmission() {
1174          final CountDownLatch done = new CountDownLatch(1);
1175 <        final ForkJoinTask a = ForkJoinTask.adapt(awaiter(done));
1176 <        final ForkJoinTask b = ForkJoinTask.adapt(awaiter(done));
1177 <        final ForkJoinTask c = ForkJoinTask.adapt(awaiter(done));
1175 >        final ForkJoinTask<?> a = ForkJoinTask.adapt(awaiter(done));
1176 >        final ForkJoinTask<?> b = ForkJoinTask.adapt(awaiter(done));
1177 >        final ForkJoinTask<?> c = ForkJoinTask.adapt(awaiter(done));
1178          final ForkJoinPool p = singletonPool();
1179          try (PoolCleaner cleaner = cleaner(p, done)) {
1180              Thread external = new Thread(new CheckedRunnable() {
# Line 1191 | Line 1193 | public class ForkJoinTask8Test extends J
1193                      }
1194                      assertTrue(p.hasQueuedSubmissions());
1195                      assertTrue(Thread.currentThread() instanceof ForkJoinWorkerThread);
1196 <                    ForkJoinTask r = ForkJoinTask.pollSubmission();
1196 >                    ForkJoinTask<?> r = ForkJoinTask.pollSubmission();
1197                      assertTrue(r == a || r == b || r == c);
1198                      assertFalse(r.isDone());
1199                  }};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines