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.12 by jsr166, Mon Sep 13 07:22:29 2010 UTC vs.
Revision 1.19 by jsr166, Mon Sep 27 19:15:16 2010 UTC

# Line 3 | Line 3
3   * Expert Group and released to the public domain, as explained at
4   * http://creativecommons.org/licenses/publicdomain
5   */
6 import java.util.*;
7 import java.util.concurrent.Executor;
8 import java.util.concurrent.Executors;
9 import java.util.concurrent.ExecutorService;
10 import java.util.concurrent.AbstractExecutorService;
11 import java.util.concurrent.CountDownLatch;
12 import java.util.concurrent.Callable;
13 import java.util.concurrent.Future;
6   import java.util.concurrent.ExecutionException;
7   import java.util.concurrent.CancellationException;
16 import java.util.concurrent.RejectedExecutionException;
8   import java.util.concurrent.ForkJoinPool;
9   import java.util.concurrent.ForkJoinTask;
10   import java.util.concurrent.ForkJoinWorkerThread;
11   import java.util.concurrent.RecursiveAction;
21 import java.util.concurrent.RecursiveTask;
12   import java.util.concurrent.TimeUnit;
13 + import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
14 + import static java.util.concurrent.TimeUnit.MILLISECONDS;
15 + import java.util.HashSet;
16   import junit.framework.*;
24 import java.util.concurrent.TimeUnit;
25 import java.util.concurrent.atomic.*;
26 import java.util.*;
17  
18   public class ForkJoinTaskTest extends JSR166TestCase {
19  
# Line 35 | Line 25 | public class ForkJoinTaskTest extends JS
25          return new TestSuite(ForkJoinTaskTest.class);
26      }
27  
28 <    /**
28 >    private static ForkJoinPool mainPool() {
29 >        return new ForkJoinPool();
30 >    }
31 >
32 >    private static ForkJoinPool singletonPool() {
33 >        return new ForkJoinPool(1);
34 >    }
35 >
36 >    private static ForkJoinPool asyncSingletonPool() {
37 >        return new ForkJoinPool(1,
38 >                                ForkJoinPool.defaultForkJoinWorkerThreadFactory,
39 >                                null, true);
40 >    }
41 >
42 >    private void testInvokeOnPool(ForkJoinPool pool, RecursiveAction a) {
43 >        try {
44 >            assertFalse(a.isDone());
45 >            assertFalse(a.isCompletedNormally());
46 >            assertFalse(a.isCompletedAbnormally());
47 >            assertFalse(a.isCancelled());
48 >            assertNull(a.getException());
49 >
50 >            assertNull(pool.invoke(a));
51 >
52 >            assertTrue(a.isDone());
53 >            assertTrue(a.isCompletedNormally());
54 >            assertFalse(a.isCompletedAbnormally());
55 >            assertFalse(a.isCancelled());
56 >            assertNull(a.getException());
57 >        } finally {
58 >            joinPool(pool);
59 >        }
60 >    }
61 >
62 >    /*
63       * Testing coverage notes:
64       *
65       * To test extension methods and overrides, most tests use
# Line 43 | Line 67 | public class ForkJoinTaskTest extends JS
67       * differently than supplied Recursive forms.
68       */
69  
46    static final ForkJoinPool mainPool = new ForkJoinPool();
47    static final ForkJoinPool singletonPool = new ForkJoinPool(1);
48    static final ForkJoinPool asyncSingletonPool =
49        new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory,
50                         null, true);
70      static final class FJException extends RuntimeException {
71          FJException() { super(); }
72      }
73  
74 <    static abstract class BinaryAsyncAction extends ForkJoinTask<Void> {
74 >    abstract static class BinaryAsyncAction extends ForkJoinTask<Void> {
75          private volatile int controlState;
76  
77          static final AtomicIntegerFieldUpdater<BinaryAsyncAction> controlStateUpdater =
# Line 227 | Line 246 | public class ForkJoinTaskTest extends JS
246       * completed tasks. getRawResult of a RecursiveAction returns null;
247       */
248      public void testInvoke() {
249 <        RecursiveAction a = new RecursiveAction() {
250 <            public void compute() {
249 >        RecursiveAction a = new CheckedRecursiveAction() {
250 >            public void realCompute() {
251                  AsyncFib f = new AsyncFib(8);
252 <                f.invoke();
253 <                threadAssertTrue(f.number == 21);
254 <                threadAssertTrue(f.isDone());
255 <                threadAssertFalse(f.isCancelled());
256 <                threadAssertFalse(f.isCompletedAbnormally());
257 <                threadAssertTrue(f.getRawResult() == null);
252 >                assertNull(f.invoke());
253 >                assertEquals(21, f.number);
254 >                assertTrue(f.isDone());
255 >                assertFalse(f.isCancelled());
256 >                assertFalse(f.isCompletedAbnormally());
257 >                assertNull(f.getRawResult());
258              }};
259 <        mainPool.invoke(a);
259 >        testInvokeOnPool(mainPool(), a);
260      }
261  
262      /**
# Line 246 | Line 265 | public class ForkJoinTaskTest extends JS
265       * completed tasks
266       */
267      public void testQuietlyInvoke() {
268 <        RecursiveAction a = new RecursiveAction() {
269 <            public void compute() {
268 >        RecursiveAction a = new CheckedRecursiveAction() {
269 >            public void realCompute() {
270                  AsyncFib f = new AsyncFib(8);
271                  f.quietlyInvoke();
272 <                threadAssertTrue(f.number == 21);
273 <                threadAssertTrue(f.isDone());
274 <                threadAssertFalse(f.isCancelled());
275 <                threadAssertFalse(f.isCompletedAbnormally());
276 <                threadAssertTrue(f.getRawResult() == null);
272 >                assertEquals(21, f.number);
273 >                assertTrue(f.isDone());
274 >                assertFalse(f.isCancelled());
275 >                assertFalse(f.isCompletedAbnormally());
276 >                assertNull(f.getRawResult());
277              }};
278 <        mainPool.invoke(a);
278 >        testInvokeOnPool(mainPool(), a);
279      }
280  
281      /**
282       * join of a forked task returns when task completes
283       */
284      public void testForkJoin() {
285 <        RecursiveAction a = new RecursiveAction() {
286 <            public void compute() {
285 >        RecursiveAction a = new CheckedRecursiveAction() {
286 >            public void realCompute() {
287                  AsyncFib f = new AsyncFib(8);
288 <                f.fork();
289 <                f.join();
290 <                threadAssertTrue(f.number == 21);
291 <                threadAssertTrue(f.isDone());
292 <                threadAssertTrue(f.getRawResult() == null);
288 >                assertSame(f, f.fork());
289 >                assertNull(f.join());
290 >                assertEquals(21, f.number);
291 >                assertTrue(f.isDone());
292 >                assertNull(f.getRawResult());
293              }};
294 <        mainPool.invoke(a);
294 >        testInvokeOnPool(mainPool(), a);
295      }
296  
297      /**
298       * get of a forked task returns when task completes
299       */
300      public void testForkGet() {
301 <        RecursiveAction a = new RecursiveAction() {
302 <            public void compute() {
303 <                try {
304 <                    AsyncFib f = new AsyncFib(8);
305 <                    f.fork();
306 <                    f.get();
307 <                    threadAssertTrue(f.number == 21);
289 <                    threadAssertTrue(f.isDone());
290 <                } catch (Exception ex) {
291 <                    unexpectedException(ex);
292 <                }
301 >        RecursiveAction a = new CheckedRecursiveAction() {
302 >            public void realCompute() throws Exception {
303 >                AsyncFib f = new AsyncFib(8);
304 >                assertSame(f, f.fork());
305 >                assertNull(f.get());
306 >                assertEquals(21, f.number);
307 >                assertTrue(f.isDone());
308              }};
309 <        mainPool.invoke(a);
309 >        testInvokeOnPool(mainPool(), a);
310      }
311  
312      /**
313       * timed get of a forked task returns when task completes
314       */
315      public void testForkTimedGet() {
316 <        RecursiveAction a = new RecursiveAction() {
317 <            public void compute() {
318 <                try {
319 <                    AsyncFib f = new AsyncFib(8);
320 <                    f.fork();
321 <                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
322 <                    threadAssertTrue(f.number == 21);
308 <                    threadAssertTrue(f.isDone());
309 <                } catch (Exception ex) {
310 <                    unexpectedException(ex);
311 <                }
316 >        RecursiveAction a = new CheckedRecursiveAction() {
317 >            public void realCompute() throws Exception {
318 >                AsyncFib f = new AsyncFib(8);
319 >                assertSame(f, f.fork());
320 >                assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
321 >                assertEquals(21, f.number);
322 >                assertTrue(f.isDone());
323              }};
324 <        mainPool.invoke(a);
324 >        testInvokeOnPool(mainPool(), a);
325      }
326  
327      /**
328       * timed get with null time unit throws NPE
329       */
330      public void testForkTimedGetNPE() {
331 <        RecursiveAction a = new RecursiveAction() {
332 <            public void compute() {
331 >        RecursiveAction a = new CheckedRecursiveAction() {
332 >            public void realCompute() throws Exception {
333 >                AsyncFib f = new AsyncFib(8);
334 >                assertSame(f, f.fork());
335                  try {
323                    AsyncFib f = new AsyncFib(8);
324                    f.fork();
336                      f.get(5L, null);
337                      shouldThrow();
338 <                } catch (NullPointerException success) {
328 <                } catch (Exception ex) {
329 <                    unexpectedException(ex);
330 <                }
338 >                } catch (NullPointerException success) {}
339              }};
340 <        mainPool.invoke(a);
340 >        testInvokeOnPool(mainPool(), a);
341      }
342  
343      /**
344       * quietlyJoin of a forked task returns when task completes
345       */
346      public void testForkQuietlyJoin() {
347 <        RecursiveAction a = new RecursiveAction() {
348 <            public void compute() {
347 >        RecursiveAction a = new CheckedRecursiveAction() {
348 >            public void realCompute() {
349                  AsyncFib f = new AsyncFib(8);
350 <                f.fork();
350 >                assertSame(f, f.fork());
351                  f.quietlyJoin();
352 <                threadAssertTrue(f.number == 21);
353 <                threadAssertTrue(f.isDone());
352 >                assertEquals(21, f.number);
353 >                assertTrue(f.isDone());
354              }};
355 <        mainPool.invoke(a);
355 >        testInvokeOnPool(mainPool(), a);
356      }
357  
358  
# Line 353 | Line 361 | public class ForkJoinTaskTest extends JS
361       * getQueuedTaskCount returns 0 when quiescent
362       */
363      public void testForkHelpQuiesce() {
364 <        RecursiveAction a = new RecursiveAction() {
365 <            public void compute() {
364 >        RecursiveAction a = new CheckedRecursiveAction() {
365 >            public void realCompute() {
366                  AsyncFib f = new AsyncFib(8);
367 <                f.fork();
367 >                assertSame(f, f.fork());
368                  f.helpQuiesce();
369 <                threadAssertTrue(f.number == 21);
370 <                threadAssertTrue(f.isDone());
371 <                threadAssertTrue(getQueuedTaskCount() == 0);
369 >                assertEquals(21, f.number);
370 >                assertTrue(f.isDone());
371 >                assertEquals(0, getQueuedTaskCount());
372              }};
373 <        mainPool.invoke(a);
373 >        testInvokeOnPool(mainPool(), a);
374      }
375  
376  
# Line 370 | Line 378 | public class ForkJoinTaskTest extends JS
378       * invoke task throws exception when task completes abnormally
379       */
380      public void testAbnormalInvoke() {
381 <        RecursiveAction a = new RecursiveAction() {
382 <            public void compute() {
381 >        RecursiveAction a = new CheckedRecursiveAction() {
382 >            public void realCompute() {
383 >                FailingAsyncFib f = new FailingAsyncFib(8);
384                  try {
376                    FailingAsyncFib f = new FailingAsyncFib(8);
385                      f.invoke();
386                      shouldThrow();
387 <                } catch (FJException success) {
380 <                }
387 >                } catch (FJException success) {}
388              }};
389 <        mainPool.invoke(a);
389 >        testInvokeOnPool(mainPool(), a);
390      }
391  
392      /**
393       * quietlyInvoke task returns when task completes abnormally
394       */
395      public void testAbnormalQuietlyInvoke() {
396 <        RecursiveAction a = new RecursiveAction() {
397 <            public void compute() {
396 >        RecursiveAction a = new CheckedRecursiveAction() {
397 >            public void realCompute() {
398                  FailingAsyncFib f = new FailingAsyncFib(8);
399                  f.quietlyInvoke();
400 <                threadAssertTrue(f.isDone());
400 >                assertTrue(f.isDone());
401              }};
402 <        mainPool.invoke(a);
402 >        testInvokeOnPool(mainPool(), a);
403      }
404  
405      /**
406       * join of a forked task throws exception when task completes abnormally
407       */
408      public void testAbnormalForkJoin() {
409 <        RecursiveAction a = new RecursiveAction() {
410 <            public void compute() {
409 >        RecursiveAction a = new CheckedRecursiveAction() {
410 >            public void realCompute() {
411 >                FailingAsyncFib f = new FailingAsyncFib(8);
412 >                assertSame(f, f.fork());
413                  try {
405                    FailingAsyncFib f = new FailingAsyncFib(8);
406                    f.fork();
414                      f.join();
415                      shouldThrow();
416 <                } catch (FJException success) {
410 <                }
416 >                } catch (FJException success) {}
417              }};
418 <        mainPool.invoke(a);
418 >        testInvokeOnPool(mainPool(), a);
419      }
420  
421      /**
422       * get of a forked task throws exception when task completes abnormally
423       */
424      public void testAbnormalForkGet() {
425 <        RecursiveAction a = new RecursiveAction() {
426 <            public void compute() {
425 >        RecursiveAction a = new CheckedRecursiveAction() {
426 >            public void realCompute() throws Exception {
427 >                FailingAsyncFib f = new FailingAsyncFib(8);
428 >                assertSame(f, f.fork());
429                  try {
422                    FailingAsyncFib f = new FailingAsyncFib(8);
423                    f.fork();
430                      f.get();
431                      shouldThrow();
432                  } catch (ExecutionException success) {
433 <                } catch (Exception ex) {
434 <                    unexpectedException(ex);
433 >                    Throwable cause = success.getCause();
434 >                    assertTrue(cause instanceof FJException);
435 >                    assertTrue(f.isDone());
436 >                    assertTrue(f.isCompletedAbnormally());
437 >                    assertSame(cause, f.getException());
438                  }
439              }};
440 <        mainPool.invoke(a);
440 >        testInvokeOnPool(mainPool(), a);
441      }
442  
443      /**
444       * timed get of a forked task throws exception when task completes abnormally
445       */
446      public void testAbnormalForkTimedGet() {
447 <        RecursiveAction a = new RecursiveAction() {
448 <            public void compute() {
447 >        RecursiveAction a = new CheckedRecursiveAction() {
448 >            public void realCompute() throws Exception {
449 >                FailingAsyncFib f = new FailingAsyncFib(8);
450 >                assertSame(f, f.fork());
451                  try {
452 <                    FailingAsyncFib f = new FailingAsyncFib(8);
442 <                    f.fork();
443 <                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
452 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
453                      shouldThrow();
454                  } catch (ExecutionException success) {
455 <                } catch (Exception ex) {
456 <                    unexpectedException(ex);
455 >                    Throwable cause = success.getCause();
456 >                    assertTrue(cause instanceof FJException);
457 >                    assertTrue(f.isDone());
458 >                    assertTrue(f.isCompletedAbnormally());
459 >                    assertSame(cause, f.getException());
460                  }
461              }};
462 <        mainPool.invoke(a);
462 >        testInvokeOnPool(mainPool(), a);
463      }
464  
465      /**
466       * quietlyJoin of a forked task returns when task completes abnormally
467       */
468      public void testAbnormalForkQuietlyJoin() {
469 <        RecursiveAction a = new RecursiveAction() {
470 <            public void compute() {
469 >        RecursiveAction a = new CheckedRecursiveAction() {
470 >            public void realCompute() {
471                  FailingAsyncFib f = new FailingAsyncFib(8);
472 <                f.fork();
472 >                assertSame(f, f.fork());
473                  f.quietlyJoin();
474 <                threadAssertTrue(f.isDone());
475 <                threadAssertTrue(f.isCompletedAbnormally());
476 <                threadAssertTrue(f.getException() instanceof FJException);
474 >                assertTrue(f.isDone());
475 >                assertTrue(f.isCompletedAbnormally());
476 >                assertTrue(f.getException() instanceof FJException);
477              }};
478 <        mainPool.invoke(a);
478 >        testInvokeOnPool(mainPool(), a);
479      }
480  
481      /**
482       * invoke task throws exception when task cancelled
483       */
484      public void testCancelledInvoke() {
485 <        RecursiveAction a = new RecursiveAction() {
486 <            public void compute() {
485 >        RecursiveAction a = new CheckedRecursiveAction() {
486 >            public void realCompute() {
487 >                AsyncFib f = new AsyncFib(8);
488 >                assertTrue(f.cancel(true));
489                  try {
476                    AsyncFib f = new AsyncFib(8);
477                    f.cancel(true);
490                      f.invoke();
491                      shouldThrow();
492                  } catch (CancellationException success) {
493 +                    assertTrue(f.isDone());
494 +                    assertTrue(f.isCancelled());
495 +                    assertTrue(f.isCompletedAbnormally());
496 +                    assertTrue(f.getException() instanceof CancellationException);
497                  }
498              }};
499 <        mainPool.invoke(a);
499 >        testInvokeOnPool(mainPool(), a);
500      }
501  
502      /**
503       * join of a forked task throws exception when task cancelled
504       */
505      public void testCancelledForkJoin() {
506 <        RecursiveAction a = new RecursiveAction() {
507 <            public void compute() {
506 >        RecursiveAction a = new CheckedRecursiveAction() {
507 >            public void realCompute() {
508 >                AsyncFib f = new AsyncFib(8);
509 >                assertTrue(f.cancel(true));
510 >                assertSame(f, f.fork());
511                  try {
493                    AsyncFib f = new AsyncFib(8);
494                    f.cancel(true);
495                    f.fork();
512                      f.join();
513                      shouldThrow();
514                  } catch (CancellationException success) {
515 +                    assertTrue(f.isDone());
516 +                    assertTrue(f.isCancelled());
517 +                    assertTrue(f.isCompletedAbnormally());
518 +                    assertTrue(f.getException() instanceof CancellationException);
519                  }
520              }};
521 <        mainPool.invoke(a);
521 >        testInvokeOnPool(mainPool(), a);
522      }
523  
524      /**
525       * get of a forked task throws exception when task cancelled
526       */
527      public void testCancelledForkGet() {
528 <        RecursiveAction a = new RecursiveAction() {
529 <            public void compute() {
528 >        RecursiveAction a = new CheckedRecursiveAction() {
529 >            public void realCompute() throws Exception {
530 >                AsyncFib f = new AsyncFib(8);
531 >                assertTrue(f.cancel(true));
532 >                assertSame(f, f.fork());
533                  try {
511                    AsyncFib f = new AsyncFib(8);
512                    f.cancel(true);
513                    f.fork();
534                      f.get();
535                      shouldThrow();
536                  } catch (CancellationException success) {
537 <                } catch (Exception ex) {
538 <                    unexpectedException(ex);
537 >                    assertTrue(f.isDone());
538 >                    assertTrue(f.isCancelled());
539 >                    assertTrue(f.isCompletedAbnormally());
540 >                    assertTrue(f.getException() instanceof CancellationException);
541                  }
542              }};
543 <        mainPool.invoke(a);
543 >        testInvokeOnPool(mainPool(), a);
544      }
545  
546      /**
547       * timed get of a forked task throws exception when task cancelled
548       */
549 <    public void testCancelledForkTimedGet() {
550 <        RecursiveAction a = new RecursiveAction() {
551 <            public void compute() {
552 <                try {
553 <                    AsyncFib f = new AsyncFib(8);
554 <                    f.cancel(true);
555 <                    f.fork();
556 <                    f.get(LONG_DELAY_MS, TimeUnit.MILLISECONDS);
549 >    public void testCancelledForkTimedGet() throws Exception {
550 >        RecursiveAction a = new CheckedRecursiveAction() {
551 >            public void realCompute() throws Exception {
552 >                AsyncFib f = new AsyncFib(8);
553 >                assertTrue(f.cancel(true));
554 >                assertSame(f, f.fork());
555 >                try {
556 >                    f.get(LONG_DELAY_MS, MILLISECONDS);
557                      shouldThrow();
558                  } catch (CancellationException success) {
559 <                } catch (Exception ex) {
560 <                    unexpectedException(ex);
559 >                    assertTrue(f.isDone());
560 >                    assertTrue(f.isCancelled());
561 >                    assertTrue(f.isCompletedAbnormally());
562 >                    assertTrue(f.getException() instanceof CancellationException);
563                  }
564              }};
565 <        mainPool.invoke(a);
565 >        testInvokeOnPool(mainPool(), a);
566      }
567  
568      /**
569       * quietlyJoin of a forked task returns when task cancelled
570       */
571      public void testCancelledForkQuietlyJoin() {
572 <        RecursiveAction a = new RecursiveAction() {
573 <            public void compute() {
572 >        RecursiveAction a = new CheckedRecursiveAction() {
573 >            public void realCompute() {
574                  AsyncFib f = new AsyncFib(8);
575 <                f.cancel(true);
576 <                f.fork();
575 >                assertTrue(f.cancel(true));
576 >                assertSame(f, f.fork());
577                  f.quietlyJoin();
578 <                threadAssertTrue(f.isDone());
579 <                threadAssertTrue(f.isCompletedAbnormally());
580 <                threadAssertTrue(f.getException() instanceof CancellationException);
578 >                assertTrue(f.isDone());
579 >                assertTrue(f.isCompletedAbnormally());
580 >                assertTrue(f.isCancelled());
581 >                assertTrue(f.getException() instanceof CancellationException);
582              }};
583 <        mainPool.invoke(a);
583 >        testInvokeOnPool(mainPool(), a);
584      }
585  
586      /**
587       * getPool of executing task returns its pool
588       */
589      public void testGetPool() {
590 <        RecursiveAction a = new RecursiveAction() {
591 <            public void compute() {
592 <                threadAssertTrue(getPool() == mainPool);
590 >        final ForkJoinPool mainPool = mainPool();
591 >        RecursiveAction a = new CheckedRecursiveAction() {
592 >            public void realCompute() {
593 >                assertSame(mainPool, getPool());
594              }};
595 <        mainPool.invoke(a);
595 >        testInvokeOnPool(mainPool, a);
596      }
597  
598      /**
599       * getPool of non-FJ task returns null
600       */
601      public void testGetPool2() {
602 <        RecursiveAction a = new RecursiveAction() {
603 <            public void compute() {
604 <                threadAssertTrue(getPool() == null);
602 >        RecursiveAction a = new CheckedRecursiveAction() {
603 >            public void realCompute() {
604 >                assertNull(getPool());
605              }};
606 <        a.invoke();
606 >        assertNull(a.invoke());
607      }
608  
609      /**
610       * inForkJoinPool of executing task returns true
611       */
612      public void testInForkJoinPool() {
613 <        RecursiveAction a = new RecursiveAction() {
614 <            public void compute() {
615 <                threadAssertTrue(inForkJoinPool());
613 >        RecursiveAction a = new CheckedRecursiveAction() {
614 >            public void realCompute() {
615 >                assertTrue(inForkJoinPool());
616              }};
617 <        mainPool.invoke(a);
617 >        testInvokeOnPool(mainPool(), a);
618      }
619  
620      /**
621       * inForkJoinPool of non-FJ task returns false
622       */
623      public void testInForkJoinPool2() {
624 <        RecursiveAction a = new RecursiveAction() {
625 <            public void compute() {
626 <                threadAssertTrue(!inForkJoinPool());
624 >        RecursiveAction a = new CheckedRecursiveAction() {
625 >            public void realCompute() {
626 >                assertTrue(!inForkJoinPool());
627              }};
628 <        a.invoke();
628 >        assertNull(a.invoke());
629      }
630  
631      /**
632       * setRawResult(null) succeeds
633       */
634      public void testSetRawResult() {
635 <        RecursiveAction a = new RecursiveAction() {
636 <            public void compute() {
635 >        RecursiveAction a = new CheckedRecursiveAction() {
636 >            public void realCompute() {
637                  setRawResult(null);
638              }};
639 <        a.invoke();
639 >        assertNull(a.invoke());
640      }
641  
642      /**
643       * invoke task throws exception after invoking completeExceptionally
644       */
645      public void testCompleteExceptionally() {
646 <        RecursiveAction a = new RecursiveAction() {
647 <            public void compute() {
646 >        RecursiveAction a = new CheckedRecursiveAction() {
647 >            public void realCompute() {
648 >                AsyncFib f = new AsyncFib(8);
649 >                f.completeExceptionally(new FJException());
650                  try {
623                    AsyncFib f = new AsyncFib(8);
624                    f.completeExceptionally(new FJException());
651                      f.invoke();
652                      shouldThrow();
653 <                } catch (FJException success) {
628 <                }
653 >                } catch (FJException success) {}
654              }};
655 <        mainPool.invoke(a);
655 >        testInvokeOnPool(mainPool(), a);
656      }
657  
658      /**
659       * invokeAll(t1, t2) invokes all task arguments
660       */
661      public void testInvokeAll2() {
662 <        RecursiveAction a = new RecursiveAction() {
663 <            public void compute() {
662 >        RecursiveAction a = new CheckedRecursiveAction() {
663 >            public void realCompute() {
664                  AsyncFib f = new AsyncFib(8);
665                  AsyncFib g = new AsyncFib(9);
666                  invokeAll(f, g);
667 <                threadAssertTrue(f.isDone());
668 <                threadAssertTrue(f.number == 21);
669 <                threadAssertTrue(g.isDone());
670 <                threadAssertTrue(g.number == 34);
667 >                assertTrue(f.isDone());
668 >                assertEquals(21, f.number);
669 >                assertTrue(g.isDone());
670 >                assertEquals(34, g.number);
671              }};
672 <        mainPool.invoke(a);
672 >        testInvokeOnPool(mainPool(), a);
673      }
674  
675      /**
676       * invokeAll(tasks) with 1 argument invokes task
677       */
678      public void testInvokeAll1() {
679 <        RecursiveAction a = new RecursiveAction() {
680 <            public void compute() {
679 >        RecursiveAction a = new CheckedRecursiveAction() {
680 >            public void realCompute() {
681                  AsyncFib f = new AsyncFib(8);
682                  invokeAll(f);
683 <                threadAssertTrue(f.isDone());
684 <                threadAssertTrue(f.number == 21);
683 >                assertTrue(f.isDone());
684 >                assertEquals(21, f.number);
685              }};
686 <        mainPool.invoke(a);
686 >        testInvokeOnPool(mainPool(), a);
687      }
688  
689      /**
690       * invokeAll(tasks) with > 2 argument invokes tasks
691       */
692      public void testInvokeAll3() {
693 <        RecursiveAction a = new RecursiveAction() {
694 <            public void compute() {
693 >        RecursiveAction a = new CheckedRecursiveAction() {
694 >            public void realCompute() {
695                  AsyncFib f = new AsyncFib(8);
696                  AsyncFib g = new AsyncFib(9);
697                  AsyncFib h = new AsyncFib(7);
698                  invokeAll(f, g, h);
699 <                threadAssertTrue(f.isDone());
700 <                threadAssertTrue(f.number == 21);
701 <                threadAssertTrue(g.isDone());
702 <                threadAssertTrue(g.number == 34);
703 <                threadAssertTrue(h.isDone());
704 <                threadAssertTrue(h.number == 13);
699 >                assertTrue(f.isDone());
700 >                assertEquals(21, f.number);
701 >                assertTrue(g.isDone());
702 >                assertEquals(34, g.number);
703 >                assertTrue(h.isDone());
704 >                assertEquals(13, h.number);
705              }};
706 <        mainPool.invoke(a);
706 >        testInvokeOnPool(mainPool(), a);
707      }
708  
709      /**
710       * invokeAll(collection) invokes all tasks in the collection
711       */
712      public void testInvokeAllCollection() {
713 <        RecursiveAction a = new RecursiveAction() {
714 <            public void compute() {
713 >        RecursiveAction a = new CheckedRecursiveAction() {
714 >            public void realCompute() {
715                  AsyncFib f = new AsyncFib(8);
716                  AsyncFib g = new AsyncFib(9);
717                  AsyncFib h = new AsyncFib(7);
# Line 695 | Line 720 | public class ForkJoinTaskTest extends JS
720                  set.add(g);
721                  set.add(h);
722                  invokeAll(set);
723 <                threadAssertTrue(f.isDone());
724 <                threadAssertTrue(f.number == 21);
725 <                threadAssertTrue(g.isDone());
726 <                threadAssertTrue(g.number == 34);
727 <                threadAssertTrue(h.isDone());
728 <                threadAssertTrue(h.number == 13);
723 >                assertTrue(f.isDone());
724 >                assertEquals(21, f.number);
725 >                assertTrue(g.isDone());
726 >                assertEquals(34, g.number);
727 >                assertTrue(h.isDone());
728 >                assertEquals(13, h.number);
729              }};
730 <        mainPool.invoke(a);
730 >        testInvokeOnPool(mainPool(), a);
731      }
732  
733  
# Line 710 | Line 735 | public class ForkJoinTaskTest extends JS
735       * invokeAll(tasks) with any null task throws NPE
736       */
737      public void testInvokeAllNPE() {
738 <        RecursiveAction a = new RecursiveAction() {
739 <            public void compute() {
738 >        RecursiveAction a = new CheckedRecursiveAction() {
739 >            public void realCompute() {
740 >                AsyncFib f = new AsyncFib(8);
741 >                AsyncFib g = new AsyncFib(9);
742 >                AsyncFib h = null;
743                  try {
716                    AsyncFib f = new AsyncFib(8);
717                    AsyncFib g = new AsyncFib(9);
718                    AsyncFib h = null;
744                      invokeAll(f, g, h);
745                      shouldThrow();
746 <                } catch (NullPointerException success) {
722 <                }
746 >                } catch (NullPointerException success) {}
747              }};
748 <        mainPool.invoke(a);
748 >        testInvokeOnPool(mainPool(), a);
749      }
750  
751      /**
752       * invokeAll(t1, t2) throw exception if any task does
753       */
754      public void testAbnormalInvokeAll2() {
755 <        RecursiveAction a = new RecursiveAction() {
756 <            public void compute() {
755 >        RecursiveAction a = new CheckedRecursiveAction() {
756 >            public void realCompute() {
757 >                AsyncFib f = new AsyncFib(8);
758 >                FailingAsyncFib g = new FailingAsyncFib(9);
759                  try {
734                    AsyncFib f = new AsyncFib(8);
735                    FailingAsyncFib g = new FailingAsyncFib(9);
760                      invokeAll(f, g);
761                      shouldThrow();
762 <                } catch (FJException success) {
739 <                }
762 >                } catch (FJException success) {}
763              }};
764 <        mainPool.invoke(a);
764 >        testInvokeOnPool(mainPool(), a);
765      }
766  
767      /**
768       * invokeAll(tasks) with 1 argument throws exception if task does
769       */
770      public void testAbnormalInvokeAll1() {
771 <        RecursiveAction a = new RecursiveAction() {
772 <            public void compute() {
771 >        RecursiveAction a = new CheckedRecursiveAction() {
772 >            public void realCompute() {
773 >                FailingAsyncFib g = new FailingAsyncFib(9);
774                  try {
751                    FailingAsyncFib g = new FailingAsyncFib(9);
775                      invokeAll(g);
776                      shouldThrow();
777 <                } catch (FJException success) {
755 <                }
777 >                } catch (FJException success) {}
778              }};
779 <        mainPool.invoke(a);
779 >        testInvokeOnPool(mainPool(), a);
780      }
781  
782      /**
783       * invokeAll(tasks) with > 2 argument throws exception if any task does
784       */
785      public void testAbnormalInvokeAll3() {
786 <        RecursiveAction a = new RecursiveAction() {
787 <            public void compute() {
786 >        RecursiveAction a = new CheckedRecursiveAction() {
787 >            public void realCompute() {
788 >                AsyncFib f = new AsyncFib(8);
789 >                FailingAsyncFib g = new FailingAsyncFib(9);
790 >                AsyncFib h = new AsyncFib(7);
791                  try {
767                    AsyncFib f = new AsyncFib(8);
768                    FailingAsyncFib g = new FailingAsyncFib(9);
769                    AsyncFib h = new AsyncFib(7);
792                      invokeAll(f, g, h);
793                      shouldThrow();
794 <                } catch (FJException success) {
773 <                }
794 >                } catch (FJException success) {}
795              }};
796 <        mainPool.invoke(a);
796 >        testInvokeOnPool(mainPool(), a);
797      }
798  
799      /**
800       * invokeAll(collection)  throws exception if any task does
801       */
802      public void testAbnormalInvokeAllCollection() {
803 <        RecursiveAction a = new RecursiveAction() {
804 <            public void compute() {
803 >        RecursiveAction a = new CheckedRecursiveAction() {
804 >            public void realCompute() {
805 >                FailingAsyncFib f = new FailingAsyncFib(8);
806 >                AsyncFib g = new AsyncFib(9);
807 >                AsyncFib h = new AsyncFib(7);
808 >                HashSet set = new HashSet();
809 >                set.add(f);
810 >                set.add(g);
811 >                set.add(h);
812                  try {
785                    FailingAsyncFib f = new FailingAsyncFib(8);
786                    AsyncFib g = new AsyncFib(9);
787                    AsyncFib h = new AsyncFib(7);
788                    HashSet set = new HashSet();
789                    set.add(f);
790                    set.add(g);
791                    set.add(h);
813                      invokeAll(set);
814                      shouldThrow();
815 <                } catch (FJException success) {
795 <                }
815 >                } catch (FJException success) {}
816              }};
817 <        mainPool.invoke(a);
817 >        testInvokeOnPool(mainPool(), a);
818      }
819  
820      /**
# Line 802 | Line 822 | public class ForkJoinTaskTest extends JS
822       * and suppresses execution
823       */
824      public void testTryUnfork() {
825 <        RecursiveAction a = new RecursiveAction() {
826 <            public void compute() {
825 >        RecursiveAction a = new CheckedRecursiveAction() {
826 >            public void realCompute() {
827                  AsyncFib g = new AsyncFib(9);
828 <                g.fork();
828 >                assertSame(g, g.fork());
829                  AsyncFib f = new AsyncFib(8);
830 <                f.fork();
831 <                threadAssertTrue(f.tryUnfork());
830 >                assertSame(f, f.fork());
831 >                assertTrue(f.tryUnfork());
832                  helpQuiesce();
833 <                threadAssertFalse(f.isDone());
834 <                threadAssertTrue(g.isDone());
833 >                assertFalse(f.isDone());
834 >                assertTrue(g.isDone());
835              }};
836 <        singletonPool.invoke(a);
836 >        testInvokeOnPool(singletonPool(), a);
837      }
838  
839      /**
# Line 821 | Line 841 | public class ForkJoinTaskTest extends JS
841       * there are more tasks than threads
842       */
843      public void testGetSurplusQueuedTaskCount() {
844 <        RecursiveAction a = new RecursiveAction() {
845 <            public void compute() {
844 >        RecursiveAction a = new CheckedRecursiveAction() {
845 >            public void realCompute() {
846                  AsyncFib h = new AsyncFib(7);
847 <                h.fork();
847 >                assertSame(h, h.fork());
848                  AsyncFib g = new AsyncFib(9);
849 <                g.fork();
849 >                assertSame(g, g.fork());
850                  AsyncFib f = new AsyncFib(8);
851 <                f.fork();
852 <                threadAssertTrue(getSurplusQueuedTaskCount() > 0);
851 >                assertSame(f, f.fork());
852 >                assertTrue(getSurplusQueuedTaskCount() > 0);
853                  helpQuiesce();
854              }};
855 <        singletonPool.invoke(a);
855 >        testInvokeOnPool(singletonPool(), a);
856      }
857  
858      /**
859       * peekNextLocalTask returns most recent unexecuted task.
860       */
861      public void testPeekNextLocalTask() {
862 <        RecursiveAction a = new RecursiveAction() {
863 <            public void compute() {
862 >        RecursiveAction a = new CheckedRecursiveAction() {
863 >            public void realCompute() {
864                  AsyncFib g = new AsyncFib(9);
865 <                g.fork();
865 >                assertSame(g, g.fork());
866                  AsyncFib f = new AsyncFib(8);
867 <                f.fork();
868 <                threadAssertTrue(peekNextLocalTask() == f);
869 <                f.join();
870 <                threadAssertTrue(f.isDone());
867 >                assertSame(f, f.fork());
868 >                assertSame(f, peekNextLocalTask());
869 >                assertNull(f.join());
870 >                assertTrue(f.isDone());
871                  helpQuiesce();
872              }};
873 <        singletonPool.invoke(a);
873 >        testInvokeOnPool(singletonPool(), a);
874      }
875  
876      /**
# Line 858 | Line 878 | public class ForkJoinTaskTest extends JS
878       * without executing it
879       */
880      public void testPollNextLocalTask() {
881 <        RecursiveAction a = new RecursiveAction() {
882 <            public void compute() {
881 >        RecursiveAction a = new CheckedRecursiveAction() {
882 >            public void realCompute() {
883                  AsyncFib g = new AsyncFib(9);
884 <                g.fork();
884 >                assertSame(g, g.fork());
885                  AsyncFib f = new AsyncFib(8);
886 <                f.fork();
887 <                threadAssertTrue(pollNextLocalTask() == f);
886 >                assertSame(f, f.fork());
887 >                assertSame(f, pollNextLocalTask());
888                  helpQuiesce();
889 <                threadAssertFalse(f.isDone());
889 >                assertFalse(f.isDone());
890              }};
891 <        singletonPool.invoke(a);
891 >        testInvokeOnPool(singletonPool(), a);
892      }
893  
894      /**
# Line 876 | Line 896 | public class ForkJoinTaskTest extends JS
896       * without executing it
897       */
898      public void testPollTask() {
899 <        RecursiveAction a = new RecursiveAction() {
900 <            public void compute() {
899 >        RecursiveAction a = new CheckedRecursiveAction() {
900 >            public void realCompute() {
901                  AsyncFib g = new AsyncFib(9);
902 <                g.fork();
902 >                assertSame(g, g.fork());
903                  AsyncFib f = new AsyncFib(8);
904 <                f.fork();
905 <                threadAssertTrue(pollTask() == f);
904 >                assertSame(f, f.fork());
905 >                assertSame(f, pollTask());
906                  helpQuiesce();
907 <                threadAssertFalse(f.isDone());
908 <                threadAssertTrue(g.isDone());
907 >                assertFalse(f.isDone());
908 >                assertTrue(g.isDone());
909              }};
910 <        singletonPool.invoke(a);
910 >        testInvokeOnPool(singletonPool(), a);
911      }
912  
913      /**
914       * peekNextLocalTask returns least recent unexecuted task in async mode
915       */
916      public void testPeekNextLocalTaskAsync() {
917 <        RecursiveAction a = new RecursiveAction() {
918 <            public void compute() {
917 >        RecursiveAction a = new CheckedRecursiveAction() {
918 >            public void realCompute() {
919                  AsyncFib g = new AsyncFib(9);
920 <                g.fork();
920 >                assertSame(g, g.fork());
921                  AsyncFib f = new AsyncFib(8);
922 <                f.fork();
923 <                threadAssertTrue(peekNextLocalTask() == g);
924 <                f.join();
922 >                assertSame(f, f.fork());
923 >                assertSame(g, peekNextLocalTask());
924 >                assertNull(f.join());
925                  helpQuiesce();
926 <                threadAssertTrue(f.isDone());
926 >                assertTrue(f.isDone());
927              }};
928 <        asyncSingletonPool.invoke(a);
928 >        testInvokeOnPool(asyncSingletonPool(), a);
929      }
930  
931      /**
# Line 913 | Line 933 | public class ForkJoinTaskTest extends JS
933       * without executing it, in async mode
934       */
935      public void testPollNextLocalTaskAsync() {
936 <        RecursiveAction a = new RecursiveAction() {
937 <            public void compute() {
936 >        RecursiveAction a = new CheckedRecursiveAction() {
937 >            public void realCompute() {
938                  AsyncFib g = new AsyncFib(9);
939 <                g.fork();
939 >                assertSame(g, g.fork());
940                  AsyncFib f = new AsyncFib(8);
941 <                f.fork();
942 <                threadAssertTrue(pollNextLocalTask() == g);
941 >                assertSame(f, f.fork());
942 >                assertSame(g, pollNextLocalTask());
943                  helpQuiesce();
944 <                threadAssertTrue(f.isDone());
945 <                threadAssertFalse(g.isDone());
944 >                assertTrue(f.isDone());
945 >                assertFalse(g.isDone());
946              }};
947 <        asyncSingletonPool.invoke(a);
947 >        testInvokeOnPool(asyncSingletonPool(), a);
948      }
949  
950      /**
# Line 932 | Line 952 | public class ForkJoinTaskTest extends JS
952       * without executing it, in async mode
953       */
954      public void testPollTaskAsync() {
955 <        RecursiveAction a = new RecursiveAction() {
956 <            public void compute() {
955 >        RecursiveAction a = new CheckedRecursiveAction() {
956 >            public void realCompute() {
957                  AsyncFib g = new AsyncFib(9);
958 <                g.fork();
958 >                assertSame(g, g.fork());
959                  AsyncFib f = new AsyncFib(8);
960 <                f.fork();
961 <                threadAssertTrue(pollTask() == g);
960 >                assertSame(f, f.fork());
961 >                assertSame(g, pollTask());
962                  helpQuiesce();
963 <                threadAssertTrue(f.isDone());
964 <                threadAssertFalse(g.isDone());
963 >                assertTrue(f.isDone());
964 >                assertFalse(g.isDone());
965              }};
966 <        asyncSingletonPool.invoke(a);
966 >        testInvokeOnPool(asyncSingletonPool(), a);
967      }
968   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines