Search in sources :

Example 51 with RecursiveAction

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

the class RecursiveActionTest method testAbnormalInvokeAllCollection.

/**
 * invokeAll(collection) throws exception if any task does
 */
public void testAbnormalInvokeAllCollection() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FailingFibAction f = new FailingFibAction(8);
            FibAction g = new FibAction(9);
            FibAction h = new FibAction(7);
            HashSet<RecursiveAction> set = new HashSet<>();
            set.add(f);
            set.add(g);
            set.add(h);
            try {
                invokeAll(set);
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(f, success);
            }
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction) HashSet(java.util.HashSet)

Example 52 with RecursiveAction

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

the class RecursiveActionTest 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);
            }
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : CancellationException(java.util.concurrent.CancellationException) RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 53 with RecursiveAction

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

the class RecursiveActionTest method testPollNextLocalTask.

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

        protected void realCompute() {
            FibAction g = new FibAction(9);
            assertSame(g, g.fork());
            FibAction f = new FibAction(8);
            assertSame(f, f.fork());
            assertSame(f, pollNextLocalTask());
            helpQuiesce();
            checkNotDone(f);
            checkCompletedNormally(g);
        }
    };
    testInvokeOnPool(singletonPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 54 with RecursiveAction

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

the class RecursiveActionTest method testPollTaskAsync.

/**
 * pollTask returns an unexecuted task without executing it, in
 * async mode
 */
public void testPollTaskAsync() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FibAction g = new FibAction(9);
            assertSame(g, g.fork());
            FibAction f = new FibAction(8);
            assertSame(f, f.fork());
            assertSame(g, pollTask());
            helpQuiesce();
            checkCompletedNormally(f);
            checkNotDone(g);
        }
    };
    testInvokeOnPool(asyncSingletonPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 55 with RecursiveAction

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

the class RecursiveActionTest method testAbnormalInvokeAll2.

/**
 * invokeAll(t1, t2) throw exception if any task does
 */
public void testAbnormalInvokeAll2() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FibAction f = new FibAction(8);
            FailingFibAction g = new FailingFibAction(9);
            try {
                invokeAll(f, g);
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(g, success);
            }
        }
    };
    testInvokeOnPool(mainPool(), 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