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

Comparing jsr166/src/test/tck/RecursiveTaskTest.java (file contents):
Revision 1.23 by jsr166, Sun Nov 21 20:32:15 2010 UTC vs.
Revision 1.33 by jsr166, Sun Oct 4 18:28:51 2015 UTC

# Line 1 | Line 1
1   /*
2   * Written by Doug Lea with assistance from members of JCP JSR-166
3   * Expert Group and released to the public domain, as explained at
4 < * http://creativecommons.org/licenses/publicdomain
4 > * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import junit.framework.*;
7 > import static java.util.concurrent.TimeUnit.SECONDS;
8 >
9 > import java.util.HashSet;
10   import java.util.concurrent.CancellationException;
11   import java.util.concurrent.ExecutionException;
12   import java.util.concurrent.ForkJoinPool;
13 < import java.util.concurrent.ForkJoinWorkerThread;
13 > import java.util.concurrent.ForkJoinTask;
14   import java.util.concurrent.RecursiveTask;
13 import java.util.concurrent.TimeUnit;
15   import java.util.concurrent.TimeoutException;
16 < import static java.util.concurrent.TimeUnit.SECONDS;
17 < import java.util.HashSet;
16 >
17 > import junit.framework.Test;
18 > import junit.framework.TestSuite;
19  
20   public class RecursiveTaskTest extends JSR166TestCase {
21  
22      public static void main(String[] args) {
23 <        junit.textui.TestRunner.run(suite());
23 >        main(suite(), args);
24      }
25      public static Test suite() {
26          return new TestSuite(RecursiveTaskTest.class);
# Line 39 | Line 41 | public class RecursiveTaskTest extends J
41      }
42  
43      private <T> T testInvokeOnPool(ForkJoinPool pool, RecursiveTask<T> a) {
44 <        try {
44 >        try (PoolCleaner cleaner = cleaner(pool)) {
45              checkNotDone(a);
46  
47              T result = pool.invoke(a);
48  
49              checkCompletedNormally(a, result);
50              return result;
49        } finally {
50            joinPool(pool);
51          }
52      }
53  
# Line 59 | Line 59 | public class RecursiveTaskTest extends J
59          assertNull(a.getException());
60          assertNull(a.getRawResult());
61  
62 <        if (! (Thread.currentThread() instanceof ForkJoinWorkerThread)) {
62 >        if (! ForkJoinTask.inForkJoinPool()) {
63              Thread.currentThread().interrupt();
64              try {
65                  a.get();
# Line 152 | Line 152 | public class RecursiveTaskTest extends J
152          assertFalse(a.isCancelled());
153          assertFalse(a.isCompletedNormally());
154          assertTrue(a.isCompletedAbnormally());
155 <        assertSame(t, a.getException());
155 >        assertSame(t.getClass(), a.getException().getClass());
156          assertNull(a.getRawResult());
157          assertFalse(a.cancel(false));
158          assertFalse(a.cancel(true));
# Line 161 | Line 161 | public class RecursiveTaskTest extends J
161              a.join();
162              shouldThrow();
163          } catch (Throwable expected) {
164 <            assertSame(t, expected);
164 >            assertSame(t.getClass(), expected.getClass());
165          }
166  
167          try {
168              a.get();
169              shouldThrow();
170          } catch (ExecutionException success) {
171 <            assertSame(t, success.getCause());
171 >            assertSame(t.getClass(), success.getCause().getClass());
172          } catch (Throwable fail) { threadUnexpectedException(fail); }
173  
174          try {
175              a.get(5L, SECONDS);
176              shouldThrow();
177          } catch (ExecutionException success) {
178 <            assertSame(t, success.getCause());
178 >            assertSame(t.getClass(), success.getCause().getClass());
179          } catch (Throwable fail) { threadUnexpectedException(fail); }
180      }
181  
182 <    static final class FJException extends RuntimeException {
183 <        FJException() { super(); }
182 >    public static final class FJException extends RuntimeException {
183 >        public FJException() { super(); }
184      }
185  
186      // An invalid return value for Fib
# Line 318 | Line 318 | public class RecursiveTaskTest extends J
318          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
319      }
320  
321
321      /**
322       * helpQuiesce returns when tasks are complete.
323       * getQueuedTaskCount returns 0 when quiescent
# Line 328 | Line 327 | public class RecursiveTaskTest extends J
327              public Integer realCompute() {
328                  FibTask f = new FibTask(8);
329                  assertSame(f, f.fork());
330 <                f.helpQuiesce();
330 >                helpQuiesce();
331                  assertEquals(0, getQueuedTaskCount());
332                  checkCompletedNormally(f, 21);
333                  return NoResult;
# Line 336 | Line 335 | public class RecursiveTaskTest extends J
335          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
336      }
337  
339
338      /**
339       * invoke task throws exception when task completes abnormally
340       */
# Line 602 | Line 600 | public class RecursiveTaskTest extends J
600                  return NoResult;
601              }
602          };
603 <        a.invoke();
603 >        assertSame(NoResult, a.invoke());
604      }
605  
606      /**
# Line 762 | Line 760 | public class RecursiveTaskTest extends J
760          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
761      }
762  
765
763      /**
764       * invokeAll(tasks) with any null task throws NPE
765       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines