Search in sources :

Example 36 with RecursiveAction

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

the class RecursiveActionTest method testWorkerGetPool.

/**
 * getPool of current thread in pool returns its pool
 */
public void testWorkerGetPool() {
    final ForkJoinPool mainPool = mainPool();
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            ForkJoinWorkerThread w = (ForkJoinWorkerThread) Thread.currentThread();
            assertSame(mainPool, w.getPool());
        }
    };
    testInvokeOnPool(mainPool, a);
}
Also used : ForkJoinWorkerThread(java8.util.concurrent.ForkJoinWorkerThread) RecursiveAction(java8.util.concurrent.RecursiveAction) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Example 37 with RecursiveAction

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

the class RecursiveActionTest method testTryUnfork.

/**
 * tryUnfork returns true for most recent unexecuted task,
 * and suppresses execution
 */
public void testTryUnfork() {
    @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());
            assertTrue(f.tryUnfork());
            helpQuiesce();
            checkNotDone(f);
            checkCompletedNormally(g);
        }
    };
    testInvokeOnPool(singletonPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 38 with RecursiveAction

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

the class RecursiveActionTest method testGetPool2.

/**
 * getPool of non-FJ task returns null
 */
public void testGetPool2() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

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

Example 39 with RecursiveAction

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

the class RecursiveActionTest method testForkTimedGetNPE.

/**
 * timed get with null time unit throws NPE
 */
public void testForkTimedGetNPE() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() throws Exception {
            FibAction f = new FibAction(8);
            assertSame(f, f.fork());
            try {
                f.get(randomTimeout(), null);
                shouldThrow();
            } catch (NullPointerException success) {
            }
        }
    };
    testInvokeOnPool(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 40 with RecursiveAction

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

the class RecursiveActionTest method testAbnormalInvoke.

/**
 * invoke task throws exception when task completes abnormally
 */
public void testAbnormalInvoke() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            FailingFibAction f = new FailingFibAction(8);
            try {
                f.invoke();
                shouldThrow();
            } catch (FJException success) {
                checkCompletedAbnormally(f, 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