Search in sources :

Example 6 with RecursiveAction

use of java8.util.concurrent.RecursiveAction in project streamsupport by stefan-zobel.

the class ForkJoinPool8Test method testInForkJoinPool2.

/**
 * inForkJoinPool of non-FJ task returns false
 */
public void testInForkJoinPool2() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            assertFalse(inForkJoinPool());
        }
    };
    assertNull(a.invoke());
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 7 with RecursiveAction

use of java8.util.concurrent.RecursiveAction in project streamsupport by stefan-zobel.

the class ForkJoinPool8Test method testAbnormalQuietlyInvoke.

/**
 * quietlyInvoke task returns when task completes abnormally
 */
public void testAbnormalQuietlyInvoke() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FailingFibAction f = new FailingFibAction(8);
            f.quietlyInvoke();
            assertTrue(f.getException() instanceof FJException);
            checkCompletedAbnormally(f, f.getException());
        }
    };
    checkInvoke(a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 8 with RecursiveAction

use of java8.util.concurrent.RecursiveAction in project streamsupport by stefan-zobel.

the class ForkJoinPool8Test method testAbnormalForkQuietlyJoin.

/**
 * quietlyJoin of a forked task returns when task completes abnormally
 */
public void testAbnormalForkQuietlyJoin() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FailingFibAction f = new FailingFibAction(8);
            assertSame(f, f.fork());
            f.quietlyJoin();
            assertTrue(f.getException() instanceof FJException);
            checkCompletedAbnormally(f, f.getException());
        }
    };
    checkInvoke(a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 9 with RecursiveAction

use of java8.util.concurrent.RecursiveAction in project streamsupport by stefan-zobel.

the class ForkJoinPool8Test method testCancelledForkGet.

/**
 * get of a forked task throws exception when task cancelled
 */
public void testCancelledForkGet() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() throws Exception {
            FibAction f = new FibAction(8);
            assertTrue(f.cancel(true));
            assertSame(f, f.fork());
            try {
                f.get();
                shouldThrow();
            } catch (CancellationException success) {
                checkCancelled(f);
            }
        }
    };
    checkInvoke(a);
}
Also used : CancellationException(java.util.concurrent.CancellationException) RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 10 with RecursiveAction

use of java8.util.concurrent.RecursiveAction in project streamsupport by stefan-zobel.

the class ForkJoinPool8Test method testReinitializeAbnormal.

/**
 * A reinitialized abnormally completed task may be re-invoked
 */
public void testReinitializeAbnormal() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FailingFibAction f = new FailingFibAction(8);
            checkNotDone(f);
            for (int i = 0; i < 3; i++) {
                try {
                    f.invoke();
                    shouldThrow();
                } catch (FJException success) {
                    checkCompletedAbnormally(f, success);
                }
                f.reinitialize();
                checkNotDone(f);
            }
        }
    };
    checkInvoke(a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Aggregations

RecursiveAction (java8.util.concurrent.RecursiveAction)194 CancellationException (java.util.concurrent.CancellationException)19 ExecutionException (java.util.concurrent.ExecutionException)11 ForkJoinTask (java8.util.concurrent.ForkJoinTask)9 HashSet (java.util.HashSet)6 ForkJoinPool (java8.util.concurrent.ForkJoinPool)5 ForkJoinWorkerThread (java8.util.concurrent.ForkJoinWorkerThread)5 CountDownLatch (java.util.concurrent.CountDownLatch)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 TimeoutException (java.util.concurrent.TimeoutException)1