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.24 by jsr166, Sun Oct 11 15:34:06 2015 UTC vs.
Revision 1.33 by jsr166, Fri Feb 22 19:27:47 2019 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;
11 import java.util.Collections;
10   import java.util.concurrent.CountDownLatch;
11   import java.util.concurrent.ExecutionException;
12   import java.util.concurrent.ForkJoinPool;
# Line 101 | Line 99 | public class ForkJoinTask8Test extends J
99          assertNull(a.getException());
100          assertNull(a.getRawResult());
101          if (a instanceof BinaryAsyncAction)
102 <            assertTrue(((BinaryAsyncAction)a).getForkJoinTaskTag() == INITIAL_STATE);
102 >            assertEquals(INITIAL_STATE,
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 <            assertTrue(((BinaryAsyncAction)a).getForkJoinTaskTag() == COMPLETE_STATE);
124 >            assertEquals(COMPLETE_STATE,
125 >                         ((BinaryAsyncAction)a).getForkJoinTaskTag());
126  
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 136 | 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); }
148 <        try {
149 <            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) {
# Line 174 | 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 185 | 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 310 | Line 312 | public class ForkJoinTask8Test extends J
312              try {
313                  AsyncFib f = this;
314                  int n = f.number;
315 <                if (n > 1) {
316 <                    while (n > 1) {
317 <                        AsyncFib p = f;
318 <                        AsyncFib r = new AsyncFib(n - 2);
319 <                        f = new AsyncFib(--n);
320 <                        p.linkSubtasks(r, f);
319 <                        r.fork();
320 <                    }
321 <                    f.number = n;
315 >                while (n > 1) {
316 >                    AsyncFib p = f;
317 >                    AsyncFib r = new AsyncFib(n - 2);
318 >                    f = new AsyncFib(--n);
319 >                    p.linkSubtasks(r, f);
320 >                    r.fork();
321                  }
322                  f.complete();
323              }
# Line 351 | Line 350 | public class ForkJoinTask8Test extends J
350              try {
351                  FailingAsyncFib f = this;
352                  int n = f.number;
353 <                if (n > 1) {
354 <                    while (n > 1) {
355 <                        FailingAsyncFib p = f;
356 <                        FailingAsyncFib r = new FailingAsyncFib(n - 2);
357 <                        f = new FailingAsyncFib(--n);
358 <                        p.linkSubtasks(r, f);
360 <                        r.fork();
361 <                    }
362 <                    f.number = n;
353 >                while (n > 1) {
354 >                    FailingAsyncFib p = f;
355 >                    FailingAsyncFib r = new FailingAsyncFib(n - 2);
356 >                    f = new FailingAsyncFib(--n);
357 >                    p.linkSubtasks(r, f);
358 >                    r.fork();
359                  }
360                  f.complete();
361              }
# Line 493 | 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 877 | Line 873 | public class ForkJoinTask8Test extends J
873          RecursiveAction a = new CheckedRecursiveAction() {
874              protected void realCompute() {
875                  AsyncFib nul = null;
876 <                Runnable[] throwingActions = {
876 >                assertThrows(
877 >                    NullPointerException.class,
878                      () -> invokeAll(nul),
879                      () -> invokeAll(nul, nul),
880                      () -> invokeAll(new AsyncFib(8), new AsyncFib(9), nul),
881                      () -> invokeAll(new AsyncFib(8), nul, new AsyncFib(9)),
882 <                    () -> invokeAll(nul, new AsyncFib(8), new AsyncFib(9)),
886 <                };
887 <                assertThrows(NullPointerException.class, throwingActions);
882 >                    () -> invokeAll(nul, new AsyncFib(8), new AsyncFib(9)));
883              }};
884          testInvokeOnPool(pool, a);
885      }
# Line 927 | Line 922 | public class ForkJoinTask8Test extends J
922                  AsyncFib f = new AsyncFib(8);
923                  FailingAsyncFib g = new FailingAsyncFib(9);
924                  ForkJoinTask[] tasks = { f, g };
925 <                Collections.shuffle(Arrays.asList(tasks));
925 >                shuffle(tasks);
926                  try {
927                      invokeAll(tasks[0], tasks[1]);
928                      shouldThrow();
# Line 954 | Line 949 | public class ForkJoinTask8Test extends J
949                  FailingAsyncFib g = new FailingAsyncFib(9);
950                  AsyncFib h = new AsyncFib(7);
951                  ForkJoinTask[] tasks = { f, g, h };
952 <                Collections.shuffle(Arrays.asList(tasks));
952 >                shuffle(tasks);
953                  try {
954                      invokeAll(tasks[0], tasks[1], tasks[2]);
955                      shouldThrow();
# Line 981 | Line 976 | public class ForkJoinTask8Test extends J
976                  AsyncFib g = new AsyncFib(9);
977                  AsyncFib h = new AsyncFib(7);
978                  ForkJoinTask[] tasks = { f, g, h };
979 <                Collections.shuffle(Arrays.asList(tasks));
979 >                shuffle(tasks);
980                  try {
981                      invokeAll(Arrays.asList(tasks));
982                      shouldThrow();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines