Search in sources :

Example 86 with RecursiveAction

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

the class ForkJoinTaskTest method testAbnormalInvokeAll3Singleton.

/**
 * invokeAll(tasks) with > 2 argument throws exception if any task does
 */
public void testAbnormalInvokeAll3Singleton() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            FailingAsyncFib g = new FailingAsyncFib(9);
            AsyncFib h = new AsyncFib(7);
            ForkJoinTask<?>[] tasks = { f, g, h };
            shuffle(tasks);
            try {
                invokeAll(tasks);
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(g, success);
            }
        }
    };
    testInvokeOnPool(singletonPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction) ForkJoinTask(java8.util.concurrent.ForkJoinTask)

Example 87 with RecursiveAction

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

the class ForkJoinTaskTest method testForkQuietlyJoinSingleton.

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

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            assertSame(f, f.fork());
            f.quietlyJoin();
            assertEquals(21, f.number);
            checkCompletedNormally(f);
        }
    };
    testInvokeOnPool(singletonPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 88 with RecursiveAction

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

the class ForkJoinTaskTest method testForkTimedGet.

/**
 * timed get of a forked task returns when task completes
 */
public void testForkTimedGet() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() throws Exception {
            AsyncFib f = new AsyncFib(8);
            assertSame(f, f.fork());
            assertNull(f.get(LONG_DELAY_MS, MILLISECONDS));
            assertEquals(21, f.number);
            checkCompletedNormally(f);
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 89 with RecursiveAction

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

the class ForkJoinTaskTest method testForkGet.

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

        protected void realCompute() throws Exception {
            AsyncFib f = new AsyncFib(8);
            assertSame(f, f.fork());
            assertNull(f.get());
            assertEquals(21, f.number);
            checkCompletedNormally(f);
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 90 with RecursiveAction

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

the class ForkJoinTaskTest method testPollNextLocalTask.

/**
 * pollNextLocalTask returns most recent unexecuted task without
 * executing it
 */
public void testPollNextLocalTask() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            AsyncFib g = new AsyncFib(9);
            assertSame(g, g.fork());
            AsyncFib f = new AsyncFib(8);
            assertSame(f, f.fork());
            assertSame(f, pollNextLocalTask());
            helpQuiesce();
            checkNotDone(f);
            assertEquals(34, g.number);
            checkCompletedNormally(g);
        }
    };
    testInvokeOnPool(singletonPool(), 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