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.25 by jsr166, Tue Nov 23 08:48:23 2010 UTC vs.
Revision 1.43 by jsr166, Wed Jan 27 01:57:24 2021 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.MILLISECONDS;
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.ForkJoinTask;
12 import java.util.concurrent.ForkJoinWorkerThread;
14   import java.util.concurrent.RecursiveTask;
14 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 40 | 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;
50        } finally {
51            joinPool(pool);
51          }
52      }
53  
54 <    void checkNotDone(RecursiveTask a) {
54 >    void checkNotDone(RecursiveTask<?> a) {
55          assertFalse(a.isDone());
56          assertFalse(a.isCompletedNormally());
57          assertFalse(a.isCompletedAbnormally());
# Line 70 | Line 69 | public class RecursiveTaskTest extends J
69  
70              Thread.currentThread().interrupt();
71              try {
72 <                a.get(5L, SECONDS);
72 >                a.get(randomTimeout(), randomTimeUnit());
73                  shouldThrow();
74              } catch (InterruptedException success) {
75              } catch (Throwable fail) { threadUnexpectedException(fail); }
76          }
77  
78          try {
79 <            a.get(0L, SECONDS);
79 >            a.get(randomExpiredTimeout(), randomTimeUnit());
80              shouldThrow();
81          } catch (TimeoutException success) {
82          } catch (Throwable fail) { threadUnexpectedException(fail); }
83      }
84  
85 <    <T> void checkCompletedNormally(RecursiveTask<T> a, T expected) {
85 >    <T> void checkCompletedNormally(RecursiveTask<T> a, T expectedValue) {
86          assertTrue(a.isDone());
87          assertFalse(a.isCancelled());
88          assertTrue(a.isCompletedNormally());
89          assertFalse(a.isCompletedAbnormally());
90          assertNull(a.getException());
91 <        assertSame(expected, a.getRawResult());
92 <        assertSame(expected, a.join());
91 >        assertSame(expectedValue, a.getRawResult());
92 >        assertSame(expectedValue, a.join());
93          assertFalse(a.cancel(false));
94          assertFalse(a.cancel(true));
95 +
96 +        T v1 = null, v2 = null;
97          try {
98 <            assertSame(expected, a.get());
99 <        } catch (Throwable fail) { threadUnexpectedException(fail); }
99 <        try {
100 <            assertSame(expected, a.get(5L, SECONDS));
98 >            v1 = a.get();
99 >            v2 = a.get(randomTimeout(), randomTimeUnit());
100          } catch (Throwable fail) { threadUnexpectedException(fail); }
101 +        assertSame(expectedValue, v1);
102 +        assertSame(expectedValue, v2);
103      }
104  
105      /**
106       * Waits for the task to complete, and checks that when it does,
107       * it will have an Integer result equals to the given int.
108       */
109 <    void checkCompletesNormally(RecursiveTask<Integer> a, int expected) {
109 >    void checkCompletesNormally(RecursiveTask<Integer> a, int expectedValue) {
110          Integer r = a.join();
111 <        assertEquals(expected, (int) r);
111 >        assertEquals(expectedValue, (int) r);
112          checkCompletedNormally(a, r);
113      }
114  
# Line 115 | Line 116 | public class RecursiveTaskTest extends J
116       * Like checkCompletesNormally, but verifies that the task has
117       * already completed.
118       */
119 <    void checkCompletedNormally(RecursiveTask<Integer> a, int expected) {
119 >    void checkCompletedNormally(RecursiveTask<Integer> a, int expectedValue) {
120          Integer r = a.getRawResult();
121 <        assertEquals(expected, (int) r);
121 >        assertEquals(expectedValue, (int) r);
122          checkCompletedNormally(a, r);
123      }
124  
125 <    void checkCancelled(RecursiveTask a) {
125 >    void checkCancelled(RecursiveTask<?> a) {
126          assertTrue(a.isDone());
127          assertTrue(a.isCancelled());
128          assertFalse(a.isCompletedNormally());
# Line 142 | Line 143 | public class RecursiveTaskTest extends J
143          } catch (Throwable fail) { threadUnexpectedException(fail); }
144  
145          try {
146 <            a.get(5L, SECONDS);
146 >            a.get(randomTimeout(), randomTimeUnit());
147              shouldThrow();
148          } catch (CancellationException success) {
149          } catch (Throwable fail) { threadUnexpectedException(fail); }
150      }
151  
152 <    void checkCompletedAbnormally(RecursiveTask a, Throwable t) {
152 >    void checkCompletedAbnormally(RecursiveTask<?> a, Throwable t) {
153          assertTrue(a.isDone());
154          assertFalse(a.isCancelled());
155          assertFalse(a.isCompletedNormally());
156          assertTrue(a.isCompletedAbnormally());
157 <        assertSame(t, a.getException());
157 >        assertSame(t.getClass(), a.getException().getClass());
158          assertNull(a.getRawResult());
159          assertFalse(a.cancel(false));
160          assertFalse(a.cancel(true));
# Line 162 | Line 163 | public class RecursiveTaskTest extends J
163              a.join();
164              shouldThrow();
165          } catch (Throwable expected) {
166 <            assertSame(t, expected);
166 >            assertSame(t.getClass(), expected.getClass());
167          }
168  
169          try {
170              a.get();
171              shouldThrow();
172          } catch (ExecutionException success) {
173 <            assertSame(t, success.getCause());
173 >            assertSame(t.getClass(), success.getCause().getClass());
174          } catch (Throwable fail) { threadUnexpectedException(fail); }
175  
176          try {
177 <            a.get(5L, SECONDS);
177 >            a.get(randomTimeout(), randomTimeUnit());
178              shouldThrow();
179          } catch (ExecutionException success) {
180 <            assertSame(t, success.getCause());
180 >            assertSame(t.getClass(), success.getCause().getClass());
181          } catch (Throwable fail) { threadUnexpectedException(fail); }
182      }
183  
184 <    static final class FJException extends RuntimeException {
185 <        FJException() { super(); }
184 >    public static final class FJException extends RuntimeException {
185 >        public FJException() { super(); }
186      }
187  
188 <    // An invalid return value for Fib
188 >    /** An invalid return value for Fib. */
189      static final Integer NoResult = Integer.valueOf(-17);
190  
191 <    // A simple recursive task for testing
191 >    /** A simple recursive task for testing. */
192      final class FibTask extends CheckedRecursiveTask<Integer> {
193          final int number;
194          FibTask(int n) { number = n; }
# Line 197 | Line 198 | public class RecursiveTaskTest extends J
198                  return n;
199              FibTask f1 = new FibTask(n - 1);
200              f1.fork();
201 <            return (new FibTask(n - 2)).compute() + f1.join();
201 >            return new FibTask(n - 2).compute() + f1.join();
202          }
203  
204          public void publicSetRawResult(Integer result) {
# Line 205 | Line 206 | public class RecursiveTaskTest extends J
206          }
207      }
208  
209 <    // A recursive action failing in base case
209 >    /** A recursive action failing in base case. */
210      final class FailingFibTask extends RecursiveTask<Integer> {
211          final int number;
212          int result;
# Line 216 | Line 217 | public class RecursiveTaskTest extends J
217                  throw new FJException();
218              FailingFibTask f1 = new FailingFibTask(n - 1);
219              f1.fork();
220 <            return (new FibTask(n - 2)).compute() + f1.join();
220 >            return new FibTask(n - 2).compute() + f1.join();
221          }
222      }
223  
# Line 227 | Line 228 | public class RecursiveTaskTest extends J
228       * returns value;
229       */
230      public void testInvoke() {
231 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
231 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
232              public Integer realCompute() {
233                  FibTask f = new FibTask(8);
234                  Integer r = f.invoke();
# Line 244 | Line 245 | public class RecursiveTaskTest extends J
245       * completed tasks
246       */
247      public void testQuietlyInvoke() {
248 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
248 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
249              public Integer realCompute() {
250                  FibTask f = new FibTask(8);
251                  f.quietlyInvoke();
# Line 258 | Line 259 | public class RecursiveTaskTest extends J
259       * join of a forked task returns when task completes
260       */
261      public void testForkJoin() {
262 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
262 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
263              public Integer realCompute() {
264                  FibTask f = new FibTask(8);
265                  assertSame(f, f.fork());
# Line 274 | Line 275 | public class RecursiveTaskTest extends J
275       * get of a forked task returns when task completes
276       */
277      public void testForkGet() {
278 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
278 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
279              public Integer realCompute() throws Exception {
280                  FibTask f = new FibTask(8);
281                  assertSame(f, f.fork());
# Line 290 | Line 291 | public class RecursiveTaskTest extends J
291       * timed get of a forked task returns when task completes
292       */
293      public void testForkTimedGet() {
294 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
294 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
295              public Integer realCompute() throws Exception {
296                  FibTask f = new FibTask(8);
297                  assertSame(f, f.fork());
298 <                Integer r = f.get(5L, SECONDS);
298 >                Integer r = f.get(LONG_DELAY_MS, MILLISECONDS);
299                  assertEquals(21, (int) r);
300                  checkCompletedNormally(f, r);
301                  return r;
# Line 306 | Line 307 | public class RecursiveTaskTest extends J
307       * quietlyJoin of a forked task returns when task completes
308       */
309      public void testForkQuietlyJoin() {
310 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
310 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
311              public Integer realCompute() {
312                  FibTask f = new FibTask(8);
313                  assertSame(f, f.fork());
# Line 319 | Line 320 | public class RecursiveTaskTest extends J
320          assertEquals(21, (int) testInvokeOnPool(mainPool(), a));
321      }
322  
322
323      /**
324       * helpQuiesce returns when tasks are complete.
325       * getQueuedTaskCount returns 0 when quiescent
326       */
327      public void testForkHelpQuiesce() {
328 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
328 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
329              public Integer realCompute() {
330                  FibTask f = new FibTask(8);
331                  assertSame(f, f.fork());
332 <                f.helpQuiesce();
332 >                helpQuiesce();
333 >                while (!f.isDone()) // wait out race
334 >                    ;
335                  assertEquals(0, getQueuedTaskCount());
336                  checkCompletedNormally(f, 21);
337                  return NoResult;
# Line 337 | Line 339 | public class RecursiveTaskTest extends J
339          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
340      }
341  
340
342      /**
343       * invoke task throws exception when task completes abnormally
344       */
345      public void testAbnormalInvoke() {
346 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
346 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
347              public Integer realCompute() {
348                  FailingFibTask f = new FailingFibTask(8);
349                  try {
# Line 360 | Line 361 | public class RecursiveTaskTest extends J
361       * quietlyInvoke task returns when task completes abnormally
362       */
363      public void testAbnormalQuietlyInvoke() {
364 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
364 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
365              public Integer realCompute() {
366                  FailingFibTask f = new FailingFibTask(8);
367                  f.quietlyInvoke();
# Line 375 | Line 376 | public class RecursiveTaskTest extends J
376       * join of a forked task throws exception when task completes abnormally
377       */
378      public void testAbnormalForkJoin() {
379 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
379 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
380              public Integer realCompute() {
381                  FailingFibTask f = new FailingFibTask(8);
382                  assertSame(f, f.fork());
383                  try {
384 <                    Integer r = f.join();
384 >                    f.join();
385                      shouldThrow();
386                  } catch (FJException success) {
387                      checkCompletedAbnormally(f, success);
# Line 394 | Line 395 | public class RecursiveTaskTest extends J
395       * get of a forked task throws exception when task completes abnormally
396       */
397      public void testAbnormalForkGet() {
398 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
398 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
399              public Integer realCompute() throws Exception {
400                  FailingFibTask f = new FailingFibTask(8);
401                  assertSame(f, f.fork());
402                  try {
403 <                    Integer r = f.get();
403 >                    f.get();
404                      shouldThrow();
405                  } catch (ExecutionException success) {
406                      Throwable cause = success.getCause();
# Line 415 | Line 416 | public class RecursiveTaskTest extends J
416       * timed get of a forked task throws exception when task completes abnormally
417       */
418      public void testAbnormalForkTimedGet() {
419 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
419 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
420              public Integer realCompute() throws Exception {
421                  FailingFibTask f = new FailingFibTask(8);
422                  assertSame(f, f.fork());
423                  try {
424 <                    Integer r = f.get(5L, SECONDS);
424 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
425                      shouldThrow();
426                  } catch (ExecutionException success) {
427                      Throwable cause = success.getCause();
# Line 436 | Line 437 | public class RecursiveTaskTest extends J
437       * quietlyJoin of a forked task returns when task completes abnormally
438       */
439      public void testAbnormalForkQuietlyJoin() {
440 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
440 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
441              public Integer realCompute() {
442                  FailingFibTask f = new FailingFibTask(8);
443                  assertSame(f, f.fork());
# Line 452 | Line 453 | public class RecursiveTaskTest extends J
453       * invoke task throws exception when task cancelled
454       */
455      public void testCancelledInvoke() {
456 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
456 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
457              public Integer realCompute() {
458                  FibTask f = new FibTask(8);
459                  assertTrue(f.cancel(true));
460                  try {
461 <                    Integer r = f.invoke();
461 >                    f.invoke();
462                      shouldThrow();
463                  } catch (CancellationException success) {
464                      checkCancelled(f);
# Line 471 | Line 472 | public class RecursiveTaskTest extends J
472       * join of a forked task throws exception when task cancelled
473       */
474      public void testCancelledForkJoin() {
475 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
475 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
476              public Integer realCompute() {
477                  FibTask f = new FibTask(8);
478                  assertTrue(f.cancel(true));
479                  assertSame(f, f.fork());
480                  try {
481 <                    Integer r = f.join();
481 >                    f.join();
482                      shouldThrow();
483                  } catch (CancellationException success) {
484                      checkCancelled(f);
# Line 491 | Line 492 | public class RecursiveTaskTest extends J
492       * get of a forked task throws exception when task cancelled
493       */
494      public void testCancelledForkGet() {
495 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
495 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
496              public Integer realCompute() throws Exception {
497                  FibTask f = new FibTask(8);
498                  assertTrue(f.cancel(true));
499                  assertSame(f, f.fork());
500                  try {
501 <                    Integer r = f.get();
501 >                    f.get();
502                      shouldThrow();
503                  } catch (CancellationException success) {
504                      checkCancelled(f);
# Line 511 | Line 512 | public class RecursiveTaskTest extends J
512       * timed get of a forked task throws exception when task cancelled
513       */
514      public void testCancelledForkTimedGet() {
515 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
515 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
516              public Integer realCompute() throws Exception {
517                  FibTask f = new FibTask(8);
518                  assertTrue(f.cancel(true));
519                  assertSame(f, f.fork());
520                  try {
521 <                    Integer r = f.get(5L, SECONDS);
521 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
522                      shouldThrow();
523                  } catch (CancellationException success) {
524                      checkCancelled(f);
# Line 531 | Line 532 | public class RecursiveTaskTest extends J
532       * quietlyJoin of a forked task returns when task cancelled
533       */
534      public void testCancelledForkQuietlyJoin() {
535 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
535 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
536              public Integer realCompute() {
537                  FibTask f = new FibTask(8);
538                  assertTrue(f.cancel(true));
# Line 548 | Line 549 | public class RecursiveTaskTest extends J
549       */
550      public void testGetPool() {
551          final ForkJoinPool mainPool = mainPool();
552 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
552 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
553              public Integer realCompute() {
554                  assertSame(mainPool, getPool());
555                  return NoResult;
# Line 560 | Line 561 | public class RecursiveTaskTest extends J
561       * getPool of non-FJ task returns null
562       */
563      public void testGetPool2() {
564 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
564 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
565              public Integer realCompute() {
566                  assertNull(getPool());
567                  return NoResult;
# Line 572 | Line 573 | public class RecursiveTaskTest extends J
573       * inForkJoinPool of executing task returns true
574       */
575      public void testInForkJoinPool() {
576 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
576 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
577              public Integer realCompute() {
578                  assertTrue(inForkJoinPool());
579                  return NoResult;
# Line 584 | Line 585 | public class RecursiveTaskTest extends J
585       * inForkJoinPool of non-FJ task returns false
586       */
587      public void testInForkJoinPool2() {
588 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
588 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
589              public Integer realCompute() {
590                  assertFalse(inForkJoinPool());
591                  return NoResult;
# Line 596 | Line 597 | public class RecursiveTaskTest extends J
597       * The value set by setRawResult is returned by getRawResult
598       */
599      public void testSetRawResult() {
600 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
600 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
601              public Integer realCompute() {
602                  setRawResult(NoResult);
603                  assertSame(NoResult, getRawResult());
# Line 610 | Line 611 | public class RecursiveTaskTest extends J
611       * A reinitialized normally completed task may be re-invoked
612       */
613      public void testReinitialize() {
614 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
614 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
615              public Integer realCompute() {
616                  FibTask f = new FibTask(8);
617                  checkNotDone(f);
# Line 632 | Line 633 | public class RecursiveTaskTest extends J
633       * A reinitialized abnormally completed task may be re-invoked
634       */
635      public void testReinitializeAbnormal() {
636 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
636 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
637              public Integer realCompute() {
638                  FailingFibTask f = new FailingFibTask(8);
639                  checkNotDone(f);
# Line 656 | Line 657 | public class RecursiveTaskTest extends J
657       * invoke task throws exception after invoking completeExceptionally
658       */
659      public void testCompleteExceptionally() {
660 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
660 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
661              public Integer realCompute() {
662                  FibTask f = new FibTask(8);
663                  f.completeExceptionally(new FJException());
664                  try {
665 <                    Integer r = f.invoke();
665 >                    f.invoke();
666                      shouldThrow();
667                  } catch (FJException success) {
668                      checkCompletedAbnormally(f, success);
# Line 675 | Line 676 | public class RecursiveTaskTest extends J
676       * invoke task suppresses execution invoking complete
677       */
678      public void testComplete() {
679 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
679 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
680              public Integer realCompute() {
681                  FibTask f = new FibTask(8);
682                  f.complete(NoResult);
# Line 691 | Line 692 | public class RecursiveTaskTest extends J
692       * invokeAll(t1, t2) invokes all task arguments
693       */
694      public void testInvokeAll2() {
695 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
695 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
696              public Integer realCompute() {
697                  FibTask f = new FibTask(8);
698                  FibTask g = new FibTask(9);
# Line 707 | Line 708 | public class RecursiveTaskTest extends J
708       * invokeAll(tasks) with 1 argument invokes task
709       */
710      public void testInvokeAll1() {
711 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
711 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
712              public Integer realCompute() {
713                  FibTask f = new FibTask(8);
714                  invokeAll(f);
# Line 721 | Line 722 | public class RecursiveTaskTest extends J
722       * invokeAll(tasks) with > 2 argument invokes tasks
723       */
724      public void testInvokeAll3() {
725 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
725 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
726              public Integer realCompute() {
727                  FibTask f = new FibTask(8);
728                  FibTask g = new FibTask(9);
# Line 742 | Line 743 | public class RecursiveTaskTest extends J
743       * invokeAll(collection) invokes all tasks in the collection
744       */
745      public void testInvokeAllCollection() {
746 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
746 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
747              public Integer realCompute() {
748                  FibTask f = new FibTask(8);
749                  FibTask g = new FibTask(9);
750                  FibTask h = new FibTask(7);
751 <                HashSet set = new HashSet();
751 >                HashSet<ForkJoinTask<?>> set = new HashSet<>();
752                  set.add(f);
753                  set.add(g);
754                  set.add(h);
# Line 763 | Line 764 | public class RecursiveTaskTest extends J
764          assertSame(NoResult, testInvokeOnPool(mainPool(), a));
765      }
766  
766
767      /**
768       * invokeAll(tasks) with any null task throws NPE
769       */
770      public void testInvokeAllNPE() {
771 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
771 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
772              public Integer realCompute() {
773                  FibTask f = new FibTask(8);
774                  FibTask g = new FibTask(9);
# Line 786 | Line 786 | public class RecursiveTaskTest extends J
786       * invokeAll(t1, t2) throw exception if any task does
787       */
788      public void testAbnormalInvokeAll2() {
789 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
789 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
790              public Integer realCompute() {
791                  FibTask f = new FibTask(8);
792                  FailingFibTask g = new FailingFibTask(9);
# Line 805 | Line 805 | public class RecursiveTaskTest extends J
805       * invokeAll(tasks) with 1 argument throws exception if task does
806       */
807      public void testAbnormalInvokeAll1() {
808 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
808 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
809              public Integer realCompute() {
810                  FailingFibTask g = new FailingFibTask(9);
811                  try {
# Line 823 | Line 823 | public class RecursiveTaskTest extends J
823       * invokeAll(tasks) with > 2 argument throws exception if any task does
824       */
825      public void testAbnormalInvokeAll3() {
826 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
826 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
827              public Integer realCompute() {
828                  FibTask f = new FibTask(8);
829                  FailingFibTask g = new FailingFibTask(9);
# Line 843 | Line 843 | public class RecursiveTaskTest extends J
843       * invokeAll(collection) throws exception if any task does
844       */
845      public void testAbnormalInvokeAllCollection() {
846 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
846 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
847              public Integer realCompute() {
848                  FailingFibTask f = new FailingFibTask(8);
849                  FibTask g = new FibTask(9);
850                  FibTask h = new FibTask(7);
851 <                HashSet set = new HashSet();
851 >                HashSet<ForkJoinTask<?>> set = new HashSet<>();
852                  set.add(f);
853                  set.add(g);
854                  set.add(h);
# Line 868 | Line 868 | public class RecursiveTaskTest extends J
868       * and suppresses execution
869       */
870      public void testTryUnfork() {
871 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
871 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
872              public Integer realCompute() {
873                  FibTask g = new FibTask(9);
874                  assertSame(g, g.fork());
# Line 888 | Line 888 | public class RecursiveTaskTest extends J
888       * there are more tasks than threads
889       */
890      public void testGetSurplusQueuedTaskCount() {
891 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
891 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
892              public Integer realCompute() {
893                  FibTask h = new FibTask(7);
894                  assertSame(h, h.fork());
# Line 911 | Line 911 | public class RecursiveTaskTest extends J
911       * peekNextLocalTask returns most recent unexecuted task.
912       */
913      public void testPeekNextLocalTask() {
914 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
914 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
915              public Integer realCompute() {
916                  FibTask g = new FibTask(9);
917                  assertSame(g, g.fork());
# Line 931 | Line 931 | public class RecursiveTaskTest extends J
931       * without executing it
932       */
933      public void testPollNextLocalTask() {
934 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
934 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
935              public Integer realCompute() {
936                  FibTask g = new FibTask(9);
937                  assertSame(g, g.fork());
# Line 950 | Line 950 | public class RecursiveTaskTest extends J
950       * pollTask returns an unexecuted task without executing it
951       */
952      public void testPollTask() {
953 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
953 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
954              public Integer realCompute() {
955                  FibTask g = new FibTask(9);
956                  assertSame(g, g.fork());
# Line 969 | Line 969 | public class RecursiveTaskTest extends J
969       * peekNextLocalTask returns least recent unexecuted task in async mode
970       */
971      public void testPeekNextLocalTaskAsync() {
972 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
972 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
973              public Integer realCompute() {
974                  FibTask g = new FibTask(9);
975                  assertSame(g, g.fork());
# Line 990 | Line 990 | public class RecursiveTaskTest extends J
990       * executing it, in async mode
991       */
992      public void testPollNextLocalTaskAsync() {
993 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
993 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
994              public Integer realCompute() {
995                  FibTask g = new FibTask(9);
996                  assertSame(g, g.fork());
# Line 1010 | Line 1010 | public class RecursiveTaskTest extends J
1010       * async mode
1011       */
1012      public void testPollTaskAsync() {
1013 <        RecursiveTask<Integer> a = new CheckedRecursiveTask<Integer>() {
1013 >        RecursiveTask<Integer> a = new CheckedRecursiveTask<>() {
1014              public Integer realCompute() {
1015                  FibTask g = new FibTask(9);
1016                  assertSame(g, g.fork());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines