Search in sources :

Example 76 with RecursiveAction

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

the class ForkJoinTaskTest method testForkHelpQuiesce.

/**
 * helpQuiesce returns when tasks are complete.
 * getQueuedTaskCount returns 0 when quiescent
 */
public void testForkHelpQuiesce() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

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

Example 77 with RecursiveAction

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

the class ForkJoinTaskTest method testInvokeAllCollection.

/**
 * invokeAll(collection) invokes all tasks in the collection
 */
public void testInvokeAllCollection() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            AsyncFib g = new AsyncFib(9);
            AsyncFib h = new AsyncFib(7);
            HashSet<AsyncFib> set = new HashSet<>();
            set.add(f);
            set.add(g);
            set.add(h);
            invokeAll(set);
            assertEquals(21, f.number);
            assertEquals(34, g.number);
            assertEquals(13, h.number);
            checkCompletedNormally(f);
            checkCompletedNormally(g);
            checkCompletedNormally(h);
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction) HashSet(java.util.HashSet)

Example 78 with RecursiveAction

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

the class ForkJoinTaskTest method testSetRawResult.

/**
 * setRawResult(null) succeeds
 */
public void testSetRawResult() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            setRawResult(null);
            assertNull(getRawResult());
        }
    };
    assertNull(a.invoke());
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 79 with RecursiveAction

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

the class ForkJoinTaskTest method testAbnormalInvokeAllCollectionSingleton.

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

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

Example 80 with RecursiveAction

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

the class ForkJoinTaskTest method testCancelledForkJoin.

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

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            assertTrue(f.cancel(true));
            assertSame(f, f.fork());
            try {
                f.join();
                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