Search in sources :

Example 31 with RecursiveAction

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

the class ForkJoinTask8Test method testQuietlyInvoke.

private void testQuietlyInvoke(ForkJoinPool pool) {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            f.quietlyInvoke();
            f.checkCompletedNormally();
        }
    };
    testInvokeOnPool(pool, a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 32 with RecursiveAction

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

the class ForkJoinTask8Test method testQuietlyComplete.

/**
 * ForkJoinTask.quietlyComplete returns when task completes
 * normally without setting a value. The most recent value
 * established by setRawResult(V) (or null by default) is returned
 * from invoke.
 */
public void testQuietlyComplete() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            f.quietlyComplete();
            assertEquals(8, f.number);
            assertTrue(f.isDone());
            assertFalse(f.isCancelled());
            assertTrue(f.isCompletedNormally());
            assertFalse(f.isCompletedAbnormally());
            assertNull(f.getException());
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 33 with RecursiveAction

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

the class ForkJoinTask8Test method testInForkJoinPool.

private void testInForkJoinPool(ForkJoinPool pool) {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            assertTrue(inForkJoinPool());
        }
    };
    testInvokeOnPool(pool, a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 34 with RecursiveAction

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

the class ForkJoinTask8Test 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 35 with RecursiveAction

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

the class RecursiveActionTest method testCancelledForkTimedGet.

/**
 * timed get of a forked task throws exception when task cancelled
 */
public void testCancelledForkTimedGet() {
    @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(LONG_DELAY_MS, MILLISECONDS);
                shouldThrow();
            } catch (CancellationException success) {
                checkCancelled(f);
            }
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : CancellationException(java.util.concurrent.CancellationException) 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