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.52 by jsr166, Mon May 29 19:15:02 2017 UTC vs.
Revision 1.56 by jsr166, Sun Jul 22 20:47:22 2018 UTC

# Line 8 | Line 8 | import static java.util.concurrent.TimeU
8  
9   import java.util.Arrays;
10   import java.util.HashSet;
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 86 | Line 87 | public class ForkJoinTaskTest extends JS
87          checkCompletedNormally(a, null);
88      }
89  
90 <    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expected) {
90 >    <T> void checkCompletedNormally(ForkJoinTask<T> a, T expectedValue) {
91          assertTrue(a.isDone());
92          assertFalse(a.isCancelled());
93          assertTrue(a.isCompletedNormally());
94          assertFalse(a.isCompletedAbnormally());
95          assertNull(a.getException());
96 <        assertSame(expected, a.getRawResult());
96 >        assertSame(expectedValue, a.getRawResult());
97  
98          {
99              Thread.currentThread().interrupt();
100              long startTime = System.nanoTime();
101 <            assertSame(expected, a.join());
101 >            assertSame(expectedValue, a.join());
102              assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
103              Thread.interrupted();
104          }
# Line 112 | Line 113 | public class ForkJoinTaskTest extends JS
113  
114          assertFalse(a.cancel(false));
115          assertFalse(a.cancel(true));
116 +
117 +        T v1 = null, v2 = null;
118          try {
119 <            assertSame(expected, a.get());
120 <            assertSame(expected, a.get(randomTimeout(), randomTimeUnit()));
119 >            v1 = a.get();
120 >            v2 = a.get(randomTimeout(), randomTimeUnit());
121          } catch (Throwable fail) { threadUnexpectedException(fail); }
122 +        assertSame(expectedValue, v1);
123 +        assertSame(expectedValue, v2);
124      }
125  
126      void checkCancelled(ForkJoinTask a) {
# Line 1648 | Line 1653 | public class ForkJoinTaskTest extends JS
1653          testInvokeOnPool(mainPool(), a);
1654      }
1655  
1656 +    /**
1657 +     * adapt(runnable).toString() contains toString of wrapped task
1658 +     */
1659 +    public void testAdapt_Runnable_toString() {
1660 +        if (testImplementationDetails) {
1661 +            Runnable r = () -> {};
1662 +            ForkJoinTask<?> task = ForkJoinTask.adapt(r);
1663 +            assertEquals(
1664 +                identityString(task) + "[Wrapped task = " + r.toString() + "]",
1665 +                task.toString());
1666 +        }
1667 +    }
1668 +
1669 +    /**
1670 +     * adapt(runnable, x).toString() contains toString of wrapped task
1671 +     */
1672 +    public void testAdapt_Runnable_withResult_toString() {
1673 +        if (testImplementationDetails) {
1674 +            Runnable r = () -> {};
1675 +            ForkJoinTask<String> task = ForkJoinTask.adapt(r, "");
1676 +            assertEquals(
1677 +                identityString(task) + "[Wrapped task = " + r.toString() + "]",
1678 +                task.toString());
1679 +        }
1680 +    }
1681 +
1682 +    /**
1683 +     * adapt(callable).toString() contains toString of wrapped task
1684 +     */
1685 +    public void testAdapt_Callable_toString() {
1686 +        if (testImplementationDetails) {
1687 +            Callable<String> c = () -> "";
1688 +            ForkJoinTask<String> task = ForkJoinTask.adapt(c);
1689 +            assertEquals(
1690 +                identityString(task) + "[Wrapped task = " + c.toString() + "]",
1691 +                task.toString());
1692 +        }
1693 +    }
1694   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines