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

Comparing jsr166/src/test/tck/ForkJoinTaskTest.java (file contents):
Revision 1.49 by jsr166, Sun Oct 18 16:40:57 2015 UTC vs.
Revision 1.53 by jsr166, Wed Aug 16 17:18:34 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.HashSet;
11 < import java.util.List;
11 > import java.util.concurrent.Callable;
12   import java.util.concurrent.CancellationException;
13   import java.util.concurrent.ExecutionException;
14   import java.util.concurrent.ForkJoinPool;
# Line 79 | Line 77 | public class ForkJoinTaskTest extends JS
77          assertNull(a.getRawResult());
78  
79          try {
80 <            a.get(0L, SECONDS);
80 >            a.get(randomExpiredTimeout(), randomTimeUnit());
81              shouldThrow();
82          } catch (TimeoutException success) {
83          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 101 | Line 99 | public class ForkJoinTaskTest extends JS
99              Thread.currentThread().interrupt();
100              long startTime = System.nanoTime();
101              assertSame(expected, a.join());
102 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
102 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
103              Thread.interrupted();
104          }
105  
# Line 109 | Line 107 | public class ForkJoinTaskTest extends JS
107              Thread.currentThread().interrupt();
108              long startTime = System.nanoTime();
109              a.quietlyJoin();        // should be no-op
110 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
110 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
111              Thread.interrupted();
112          }
113  
# Line 117 | Line 115 | public class ForkJoinTaskTest extends JS
115          assertFalse(a.cancel(true));
116          try {
117              assertSame(expected, a.get());
118 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
121 <        try {
122 <            assertSame(expected, a.get(5L, SECONDS));
118 >            assertSame(expected, a.get(randomTimeout(), randomTimeUnit()));
119          } catch (Throwable fail) { threadUnexpectedException(fail); }
120      }
121  
# Line 144 | Line 140 | public class ForkJoinTaskTest extends JS
140          {
141              long startTime = System.nanoTime();
142              a.quietlyJoin();        // should be no-op
143 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
143 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
144          }
145  
146          try {
# Line 154 | Line 150 | public class ForkJoinTaskTest extends JS
150          } catch (Throwable fail) { threadUnexpectedException(fail); }
151  
152          try {
153 <            a.get(5L, SECONDS);
153 >            a.get(randomTimeout(), randomTimeUnit());
154              shouldThrow();
155          } catch (CancellationException success) {
156          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 182 | Line 178 | public class ForkJoinTaskTest extends JS
178          {
179              long startTime = System.nanoTime();
180              a.quietlyJoin();        // should be no-op
181 <            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
181 >            assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
182          }
183  
184          try {
# Line 193 | Line 189 | public class ForkJoinTaskTest extends JS
189          } catch (Throwable fail) { threadUnexpectedException(fail); }
190  
191          try {
192 <            a.get(5L, SECONDS);
192 >            a.get(randomTimeout(), randomTimeUnit());
193              shouldThrow();
194          } catch (ExecutionException success) {
195              assertSame(t.getClass(), success.getCause().getClass());
# Line 467 | Line 463 | public class ForkJoinTaskTest extends JS
463                  AsyncFib f = new AsyncFib(8);
464                  assertSame(f, f.fork());
465                  try {
466 <                    f.get(5L, null);
466 >                    f.get(randomTimeout(), null);
467                      shouldThrow();
468                  } catch (NullPointerException success) {}
469              }};
# Line 897 | Line 893 | public class ForkJoinTaskTest extends JS
893                  AsyncFib f = new AsyncFib(8);
894                  FailingAsyncFib g = new FailingAsyncFib(9);
895                  ForkJoinTask[] tasks = { f, g };
896 <                Collections.shuffle(Arrays.asList(tasks));
896 >                shuffle(tasks);
897                  try {
898                      invokeAll(tasks);
899                      shouldThrow();
# Line 935 | Line 931 | public class ForkJoinTaskTest extends JS
931                  FailingAsyncFib g = new FailingAsyncFib(9);
932                  AsyncFib h = new AsyncFib(7);
933                  ForkJoinTask[] tasks = { f, g, h };
934 <                Collections.shuffle(Arrays.asList(tasks));
934 >                shuffle(tasks);
935                  try {
936                      invokeAll(tasks);
937                      shouldThrow();
# Line 956 | Line 952 | public class ForkJoinTaskTest extends JS
952                  AsyncFib g = new AsyncFib(9);
953                  AsyncFib h = new AsyncFib(7);
954                  ForkJoinTask[] tasks = { f, g, h };
955 <                List taskList = Arrays.asList(tasks);
960 <                Collections.shuffle(taskList);
955 >                shuffle(tasks);
956                  try {
957 <                    invokeAll(taskList);
957 >                    invokeAll(Arrays.asList(tasks));
958                      shouldThrow();
959                  } catch (FJException success) {
960                      checkCompletedAbnormally(f, success);
# Line 1215 | Line 1210 | public class ForkJoinTaskTest extends JS
1210                  AsyncFib f = new AsyncFib(8);
1211                  assertSame(f, f.fork());
1212                  try {
1213 <                    f.get(5L, null);
1213 >                    f.get(randomTimeout(), null);
1214                      shouldThrow();
1215                  } catch (NullPointerException success) {}
1216              }};
# Line 1567 | Line 1562 | public class ForkJoinTaskTest extends JS
1562                  AsyncFib f = new AsyncFib(8);
1563                  FailingAsyncFib g = new FailingAsyncFib(9);
1564                  ForkJoinTask[] tasks = { f, g };
1565 <                Collections.shuffle(Arrays.asList(tasks));
1565 >                shuffle(tasks);
1566                  try {
1567                      invokeAll(tasks);
1568                      shouldThrow();
# Line 1605 | Line 1600 | public class ForkJoinTaskTest extends JS
1600                  FailingAsyncFib g = new FailingAsyncFib(9);
1601                  AsyncFib h = new AsyncFib(7);
1602                  ForkJoinTask[] tasks = { f, g, h };
1603 <                Collections.shuffle(Arrays.asList(tasks));
1603 >                shuffle(tasks);
1604                  try {
1605                      invokeAll(tasks);
1606                      shouldThrow();
# Line 1626 | Line 1621 | public class ForkJoinTaskTest extends JS
1621                  AsyncFib g = new AsyncFib(9);
1622                  AsyncFib h = new AsyncFib(7);
1623                  ForkJoinTask[] tasks = { f, g, h };
1624 <                List taskList = Arrays.asList(tasks);
1630 <                Collections.shuffle(taskList);
1624 >                shuffle(tasks);
1625                  try {
1626 <                    invokeAll(taskList);
1626 >                    invokeAll(Arrays.asList(tasks));
1627                      shouldThrow();
1628                  } catch (FJException success) {
1629                      checkCompletedAbnormally(f, success);
# Line 1655 | Line 1649 | public class ForkJoinTaskTest extends JS
1649          testInvokeOnPool(mainPool(), a);
1650      }
1651  
1652 +    /**
1653 +     * adapt(runnable).toString() contains toString of wrapped task
1654 +     */
1655 +    public void testAdapt_Runnable_toString() {
1656 +        if (testImplementationDetails) {
1657 +            Runnable r = () -> {};
1658 +            ForkJoinTask<?> task = ForkJoinTask.adapt(r);
1659 +            assertEquals(
1660 +                identityString(task) + "[Wrapped task = " + r.toString() + "]",
1661 +                task.toString());
1662 +        }
1663 +    }
1664 +
1665 +    /**
1666 +     * adapt(runnable, x).toString() contains toString of wrapped task
1667 +     */
1668 +    public void testAdapt_Runnable_withResult_toString() {
1669 +        if (testImplementationDetails) {
1670 +            Runnable r = () -> {};
1671 +            ForkJoinTask<String> task = ForkJoinTask.adapt(r, "");
1672 +            assertEquals(
1673 +                identityString(task) + "[Wrapped task = " + r.toString() + "]",
1674 +                task.toString());
1675 +        }
1676 +    }
1677 +
1678 +    /**
1679 +     * adapt(callable).toString() contains toString of wrapped task
1680 +     */
1681 +    public void testAdapt_Callable_toString() {
1682 +        if (testImplementationDetails) {
1683 +            Callable<String> c = () -> "";
1684 +            ForkJoinTask<String> task = ForkJoinTask.adapt(c);
1685 +            assertEquals(
1686 +                identityString(task) + "[Wrapped task = " + c.toString() + "]",
1687 +                task.toString());
1688 +        }
1689 +    }
1690   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines