Search in sources :

Example 61 with RecursiveAction

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

the class ForkJoinTaskTest method testAbnormalInvokeAll2Singleton.

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

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            FailingAsyncFib g = new FailingAsyncFib(9);
            ForkJoinTask<?>[] tasks = { f, g };
            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 62 with RecursiveAction

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

the class ForkJoinTaskTest method testAbnormalInvokeAll2.

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

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

Example 63 with RecursiveAction

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

the class ForkJoinTaskTest method testAbnormalInvokeAll3.

/**
 * invokeAll(tasks) with > 2 argument throws exception if any task does
 */
public void testAbnormalInvokeAll3() {
    @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(mainPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction) ForkJoinTask(java8.util.concurrent.ForkJoinTask)

Example 64 with RecursiveAction

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

the class ForkJoinTaskTest method testGetSurplusQueuedTaskCount.

/**
 * getSurplusQueuedTaskCount returns > 0 when
 * there are more tasks than threads
 */
public void testGetSurplusQueuedTaskCount() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            AsyncFib h = new AsyncFib(7);
            assertSame(h, h.fork());
            AsyncFib g = new AsyncFib(9);
            assertSame(g, g.fork());
            AsyncFib f = new AsyncFib(8);
            assertSame(f, f.fork());
            assertTrue(getSurplusQueuedTaskCount() > 0);
            helpQuiesce();
            assertEquals(0, getSurplusQueuedTaskCount());
            checkCompletedNormally(f);
            checkCompletedNormally(g);
            checkCompletedNormally(h);
        }
    };
    testInvokeOnPool(singletonPool(), a);
}
Also used : RecursiveAction(java8.util.concurrent.RecursiveAction)

Example 65 with RecursiveAction

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

the class ForkJoinTaskTest method testInvokeAll2Singleton.

/**
 * invokeAll(t1, t2) invokes all task arguments
 */
public void testInvokeAll2Singleton() {
    @SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {

        protected void realCompute() {
            AsyncFib f = new AsyncFib(8);
            AsyncFib g = new AsyncFib(9);
            invokeAll(f, g);
            assertEquals(21, f.number);
            assertEquals(34, g.number);
            checkCompletedNormally(f);
            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