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.41 by jsr166, Sat Apr 25 04:55:30 2015 UTC vs.
Revision 1.45 by jsr166, Wed Oct 7 22:39:31 2015 UTC

# Line 7 | Line 7
7   import static java.util.concurrent.TimeUnit.MILLISECONDS;
8   import static java.util.concurrent.TimeUnit.SECONDS;
9  
10 + import java.util.Arrays;
11 + import java.util.Collections;
12   import java.util.HashSet;
13 + import java.util.List;
14   import java.util.concurrent.CancellationException;
15   import java.util.concurrent.ExecutionException;
16   import java.util.concurrent.ForkJoinPool;
# Line 48 | Line 51 | public class ForkJoinTaskTest extends JS
51      }
52  
53      private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
54 <        try {
54 >        try (PoolCleaner cleaner = cleaner(pool)) {
55              assertFalse(a.isDone());
56              assertFalse(a.isCompletedNormally());
57              assertFalse(a.isCompletedAbnormally());
# Line 64 | Line 67 | public class ForkJoinTaskTest extends JS
67              assertFalse(a.isCancelled());
68              assertNull(a.getException());
69              assertNull(a.getRawResult());
67        } finally {
68            joinPool(pool);
70          }
71      }
72  
# Line 98 | Line 99 | public class ForkJoinTaskTest extends JS
99  
100          {
101              Thread.currentThread().interrupt();
102 <            long t0 = System.nanoTime();
102 >            long startTime = System.nanoTime();
103              assertSame(expected, a.join());
104 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
104 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
105              Thread.interrupted();
106          }
107  
108          {
109              Thread.currentThread().interrupt();
110 <            long t0 = System.nanoTime();
110 >            long startTime = System.nanoTime();
111              a.quietlyJoin();        // should be no-op
112 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
112 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
113              Thread.interrupted();
114          }
115  
# Line 141 | Line 142 | public class ForkJoinTaskTest extends JS
142          Thread.interrupted();
143  
144          {
145 <            long t0 = System.nanoTime();
145 >            long startTime = System.nanoTime();
146              a.quietlyJoin();        // should be no-op
147 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
147 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
148          }
149  
150          try {
# Line 179 | Line 180 | public class ForkJoinTaskTest extends JS
180          Thread.interrupted();
181  
182          {
183 <            long t0 = System.nanoTime();
183 >            long startTime = System.nanoTime();
184              a.quietlyJoin();        // should be no-op
185 <            assertTrue(millisElapsedSince(t0) < SMALL_DELAY_MS);
185 >            assertTrue(millisElapsedSince(startTime) < SMALL_DELAY_MS);
186          }
187  
188          try {
# Line 218 | Line 219 | public class ForkJoinTaskTest extends JS
219              AtomicIntegerFieldUpdater.newUpdater(BinaryAsyncAction.class,
220                                                   "controlState");
221  
222 <        private BinaryAsyncAction parent;
222 >        private volatile BinaryAsyncAction parent;
223  
224 <        private BinaryAsyncAction sibling;
224 >        private volatile BinaryAsyncAction sibling;
225  
226          protected BinaryAsyncAction() {
227          }
# Line 873 | Line 874 | public class ForkJoinTaskTest extends JS
874              protected void realCompute() {
875                  AsyncFib f = new AsyncFib(8);
876                  FailingAsyncFib g = new FailingAsyncFib(9);
877 +                ForkJoinTask[] tasks = { f, g };
878 +                Collections.shuffle(Arrays.asList(tasks));
879                  try {
880 <                    invokeAll(f, g);
880 >                    invokeAll(tasks);
881                      shouldThrow();
882                  } catch (FJException success) {
883                      checkCompletedAbnormally(g, success);
# Line 909 | Line 912 | public class ForkJoinTaskTest extends JS
912                  AsyncFib f = new AsyncFib(8);
913                  FailingAsyncFib g = new FailingAsyncFib(9);
914                  AsyncFib h = new AsyncFib(7);
915 +                ForkJoinTask[] tasks = { f, g, h };
916 +                Collections.shuffle(Arrays.asList(tasks));
917                  try {
918 <                    invokeAll(f, g, h);
918 >                    invokeAll(tasks);
919                      shouldThrow();
920                  } catch (FJException success) {
921                      checkCompletedAbnormally(g, success);
# Line 928 | Line 933 | public class ForkJoinTaskTest extends JS
933                  FailingAsyncFib f = new FailingAsyncFib(8);
934                  AsyncFib g = new AsyncFib(9);
935                  AsyncFib h = new AsyncFib(7);
936 <                HashSet set = new HashSet();
937 <                set.add(f);
938 <                set.add(g);
934 <                set.add(h);
936 >                ForkJoinTask[] tasks = { f, g, h };
937 >                List taskList = Arrays.asList(tasks);
938 >                Collections.shuffle(taskList);
939                  try {
940 <                    invokeAll(set);
940 >                    invokeAll(taskList);
941                      shouldThrow();
942                  } catch (FJException success) {
943                      checkCompletedAbnormally(f, success);
# Line 1540 | Line 1544 | public class ForkJoinTaskTest extends JS
1544              protected void realCompute() {
1545                  AsyncFib f = new AsyncFib(8);
1546                  FailingAsyncFib g = new FailingAsyncFib(9);
1547 +                ForkJoinTask[] tasks = { f, g };
1548 +                Collections.shuffle(Arrays.asList(tasks));
1549                  try {
1550 <                    invokeAll(f, g);
1550 >                    invokeAll(tasks);
1551                      shouldThrow();
1552                  } catch (FJException success) {
1553                      checkCompletedAbnormally(g, success);
# Line 1576 | Line 1582 | public class ForkJoinTaskTest extends JS
1582                  AsyncFib f = new AsyncFib(8);
1583                  FailingAsyncFib g = new FailingAsyncFib(9);
1584                  AsyncFib h = new AsyncFib(7);
1585 +                ForkJoinTask[] tasks = { f, g, h };
1586 +                Collections.shuffle(Arrays.asList(tasks));
1587                  try {
1588 <                    invokeAll(f, g, h);
1588 >                    invokeAll(tasks);
1589                      shouldThrow();
1590                  } catch (FJException success) {
1591                      checkCompletedAbnormally(g, success);
# Line 1595 | Line 1603 | public class ForkJoinTaskTest extends JS
1603                  FailingAsyncFib f = new FailingAsyncFib(8);
1604                  AsyncFib g = new AsyncFib(9);
1605                  AsyncFib h = new AsyncFib(7);
1606 <                HashSet set = new HashSet();
1607 <                set.add(f);
1608 <                set.add(g);
1601 <                set.add(h);
1606 >                ForkJoinTask[] tasks = { f, g, h };
1607 >                List taskList = Arrays.asList(tasks);
1608 >                Collections.shuffle(taskList);
1609                  try {
1610 <                    invokeAll(set);
1610 >                    invokeAll(taskList);
1611                      shouldThrow();
1612                  } catch (FJException success) {
1613                      checkCompletedAbnormally(f, success);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines