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.31 by jsr166, Wed Nov 8 02:21:43 2017 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 122 | Line 121 | public class ForkJoinTask8Test extends J
121          assertNull(a.getException());
122          assertSame(expected, 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);
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  
# Line 144 | Line 144 | public class ForkJoinTask8Test extends J
144          assertFalse(a.cancel(true));
145          try {
146              assertSame(expected, a.get());
147 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
148 <        try {
149 <            assertSame(expected, a.get(5L, SECONDS));
147 >            assertSame(expected, a.get(randomTimeout(), randomTimeUnit()));
148          } catch (Throwable fail) { threadUnexpectedException(fail); }
149      }
150  
# Line 174 | Line 172 | public class ForkJoinTask8Test extends J
172          {
173              long startTime = System.nanoTime();
174              a.quietlyJoin();        // should be no-op
175 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
175 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
176          }
177  
178          try {
# Line 185 | Line 183 | public class ForkJoinTask8Test extends J
183          } catch (Throwable fail) { threadUnexpectedException(fail); }
184  
185          try {
186 <            a.get(5L, SECONDS);
186 >            a.get(randomTimeout(), randomTimeUnit());
187              shouldThrow();
188          } catch (ExecutionException success) {
189              assertSame(t.getClass(), success.getCause().getClass());
# Line 310 | Line 308 | public class ForkJoinTask8Test extends J
308              try {
309                  AsyncFib f = this;
310                  int n = f.number;
311 <                if (n > 1) {
312 <                    while (n > 1) {
313 <                        AsyncFib p = f;
314 <                        AsyncFib r = new AsyncFib(n - 2);
315 <                        f = new AsyncFib(--n);
316 <                        p.linkSubtasks(r, f);
319 <                        r.fork();
320 <                    }
321 <                    f.number = n;
311 >                while (n > 1) {
312 >                    AsyncFib p = f;
313 >                    AsyncFib r = new AsyncFib(n - 2);
314 >                    f = new AsyncFib(--n);
315 >                    p.linkSubtasks(r, f);
316 >                    r.fork();
317                  }
318                  f.complete();
319              }
# Line 351 | Line 346 | public class ForkJoinTask8Test extends J
346              try {
347                  FailingAsyncFib f = this;
348                  int n = f.number;
349 <                if (n > 1) {
350 <                    while (n > 1) {
351 <                        FailingAsyncFib p = f;
352 <                        FailingAsyncFib r = new FailingAsyncFib(n - 2);
353 <                        f = new FailingAsyncFib(--n);
354 <                        p.linkSubtasks(r, f);
360 <                        r.fork();
361 <                    }
362 <                    f.number = n;
349 >                while (n > 1) {
350 >                    FailingAsyncFib p = f;
351 >                    FailingAsyncFib r = new FailingAsyncFib(n - 2);
352 >                    f = new FailingAsyncFib(--n);
353 >                    p.linkSubtasks(r, f);
354 >                    r.fork();
355                  }
356                  f.complete();
357              }
# Line 493 | Line 485 | public class ForkJoinTask8Test extends J
485                  AsyncFib f = new AsyncFib(8);
486                  assertSame(f, f.fork());
487                  try {
488 <                    f.get(5L, null);
488 >                    f.get(randomTimeout(), null);
489                      shouldThrow();
490                  } catch (NullPointerException success) {}
491              }};
# Line 927 | Line 919 | public class ForkJoinTask8Test extends J
919                  AsyncFib f = new AsyncFib(8);
920                  FailingAsyncFib g = new FailingAsyncFib(9);
921                  ForkJoinTask[] tasks = { f, g };
922 <                Collections.shuffle(Arrays.asList(tasks));
922 >                shuffle(tasks);
923                  try {
924                      invokeAll(tasks[0], tasks[1]);
925                      shouldThrow();
# Line 954 | Line 946 | public class ForkJoinTask8Test extends J
946                  FailingAsyncFib g = new FailingAsyncFib(9);
947                  AsyncFib h = new AsyncFib(7);
948                  ForkJoinTask[] tasks = { f, g, h };
949 <                Collections.shuffle(Arrays.asList(tasks));
949 >                shuffle(tasks);
950                  try {
951                      invokeAll(tasks[0], tasks[1], tasks[2]);
952                      shouldThrow();
# Line 981 | Line 973 | public class ForkJoinTask8Test extends J
973                  AsyncFib g = new AsyncFib(9);
974                  AsyncFib h = new AsyncFib(7);
975                  ForkJoinTask[] tasks = { f, g, h };
976 <                Collections.shuffle(Arrays.asList(tasks));
976 >                shuffle(tasks);
977                  try {
978                      invokeAll(Arrays.asList(tasks));
979                      shouldThrow();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines