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

Comparing jsr166/src/test/tck/RecursiveActionTest.java (file contents):
Revision 1.49 by jsr166, Sat Mar 18 18:20:00 2017 UTC vs.
Revision 1.56 by dl, Tue Jan 26 13:33:06 2021 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import static java.util.concurrent.TimeUnit.SECONDS;
7 > import static java.util.concurrent.TimeUnit.MILLISECONDS;
8  
9   import java.util.Arrays;
10   import java.util.HashSet;
# Line 73 | Line 73 | public class RecursiveActionTest extends
73  
74              Thread.currentThread().interrupt();
75              try {
76 <                a.get(5L, SECONDS);
76 >                a.get(randomTimeout(), randomTimeUnit());
77                  shouldThrow();
78              } catch (InterruptedException success) {
79              } catch (Throwable fail) { threadUnexpectedException(fail); }
80          }
81  
82          try {
83 <            a.get(0L, SECONDS);
83 >            a.get(randomExpiredTimeout(), randomTimeUnit());
84              shouldThrow();
85          } catch (TimeoutException success) {
86          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 96 | Line 96 | public class RecursiveActionTest extends
96          assertNull(a.join());
97          assertFalse(a.cancel(false));
98          assertFalse(a.cancel(true));
99 +
100 +        Object v1 = null, v2 = null;
101          try {
102 <            assertNull(a.get());
103 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
102 <        try {
103 <            assertNull(a.get(5L, SECONDS));
102 >            v1 = a.get();
103 >            v2 = a.get(randomTimeout(), randomTimeUnit());
104          } catch (Throwable fail) { threadUnexpectedException(fail); }
105 +        assertNull(v1);
106 +        assertNull(v2);
107      }
108  
109      void checkCancelled(RecursiveAction a) {
# Line 125 | Line 127 | public class RecursiveActionTest extends
127          } catch (Throwable fail) { threadUnexpectedException(fail); }
128  
129          try {
130 <            a.get(5L, SECONDS);
130 >            a.get(randomTimeout(), randomTimeUnit());
131              shouldThrow();
132          } catch (CancellationException success) {
133          } catch (Throwable fail) { threadUnexpectedException(fail); }
# Line 156 | Line 158 | public class RecursiveActionTest extends
158          } catch (Throwable fail) { threadUnexpectedException(fail); }
159  
160          try {
161 <            a.get(5L, SECONDS);
161 >            a.get(randomTimeout(), randomTimeUnit());
162              shouldThrow();
163          } catch (ExecutionException success) {
164              assertSame(t.getClass(), success.getCause().getClass());
# Line 327 | Line 329 | public class RecursiveActionTest extends
329       * succeeds in the presence of interrupts
330       */
331      public void testJoinIgnoresInterruptsOutsideForkJoinPool() {
332 <        final SynchronousQueue<FibAction[]> sq =
331 <            new SynchronousQueue<FibAction[]>();
332 >        final SynchronousQueue<FibAction[]> sq = new SynchronousQueue<>();
333          RecursiveAction a = new CheckedRecursiveAction() {
334              protected void realCompute() throws InterruptedException {
335                  FibAction[] fibActions = new FibAction[6];
# Line 340 | Line 341 | public class RecursiveActionTest extends
341                  fibActions[4].cancel(true);
342                  fibActions[5].completeExceptionally(new FJException());
343  
344 <                for (int i = 0; i < fibActions.length; i++)
345 <                    fibActions[i].fork();
344 >                for (FibAction fibAction : fibActions)
345 >                    fibAction.fork();
346  
347                  sq.put(fibActions);
348  
# Line 442 | Line 443 | public class RecursiveActionTest extends
443              protected void realCompute() throws Exception {
444                  FibAction f = new FibAction(8);
445                  assertSame(f, f.fork());
446 <                assertNull(f.get(5L, SECONDS));
446 >                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
447                  assertEquals(21, f.result);
448                  checkCompletedNormally(f);
449              }};
# Line 458 | Line 459 | public class RecursiveActionTest extends
459                  FibAction f = new FibAction(8);
460                  assertSame(f, f.fork());
461                  try {
462 <                    f.get(5L, null);
462 >                    f.get(randomTimeout(), null);
463                      shouldThrow();
464                  } catch (NullPointerException success) {}
465              }};
# Line 577 | Line 578 | public class RecursiveActionTest extends
578                  FailingFibAction f = new FailingFibAction(8);
579                  assertSame(f, f.fork());
580                  try {
581 <                    f.get(5L, SECONDS);
581 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
582                      shouldThrow();
583                  } catch (ExecutionException success) {
584                      Throwable cause = success.getCause();
# Line 669 | Line 670 | public class RecursiveActionTest extends
670                  assertTrue(f.cancel(true));
671                  assertSame(f, f.fork());
672                  try {
673 <                    f.get(5L, SECONDS);
673 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
674                      shouldThrow();
675                  } catch (CancellationException success) {
676                      checkCancelled(f);
# Line 919 | Line 920 | public class RecursiveActionTest extends
920                  FibAction f = new FibAction(8);
921                  FibAction g = new FibAction(9);
922                  FibAction h = new FibAction(7);
923 <                HashSet set = new HashSet();
923 >                HashSet<ForkJoinTask<?>> set = new HashSet<ForkJoinTask<?>>();
924                  set.add(f);
925                  set.add(g);
926                  set.add(h);
# Line 1017 | Line 1018 | public class RecursiveActionTest extends
1018                  FailingFibAction f = new FailingFibAction(8);
1019                  FibAction g = new FibAction(9);
1020                  FibAction h = new FibAction(7);
1021 <                HashSet set = new HashSet();
1021 >                HashSet<ForkJoinTask<?>> set = new HashSet<ForkJoinTask<?>>();
1022                  set.add(f);
1023                  set.add(g);
1024                  set.add(h);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines