Search in sources :

Example 56 with ForkJoinPool

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

the class ForkJoinPoolTest method testInvokeAny3.

/**
 * invokeAny(c) throws NullPointerException if c has a single null element
 */
public void testInvokeAny3() throws Throwable {
    ExecutorService e = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(e);
        List<Callable<String>> l = new ArrayList<>();
        l.add(null);
        try {
            e.invokeAny(l);
            shouldThrow();
        } catch (NullPointerException success) {
        }
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Example 57 with ForkJoinPool

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

the class ForkJoinPoolTest method testSubmitRunnable.

/**
 * Completed submit(runnable) returns successfully
 */
public void testSubmitRunnable() throws Throwable {
    ExecutorService e = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(e);
        Future<?> future = e.submit(new NoOpRunnable());
        assertNull(future.get());
        assertTrue(future.isDone());
        assertFalse(future.isCancelled());
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Example 58 with ForkJoinPool

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

the class ForkJoinPoolTest method testSubmitAfterShutdown.

/**
 * A task submitted after shutdown is rejected
 */
public void testSubmitAfterShutdown() {
    ForkJoinPool p = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(p);
        p.shutdown();
        assertTrue(p.isShutdown());
        try {
            @SuppressWarnings("unused") ForkJoinTask<Integer> f = p.submit(new FibTask(8));
            shouldThrow();
        } catch (RejectedExecutionException success) {
        }
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Example 59 with ForkJoinPool

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

the class ForkJoinPoolTest method testTimedInvokeAll4.

/**
 * get of returned element of invokeAll(c) throws exception on failed task
 */
public void testTimedInvokeAll4() throws Throwable {
    ExecutorService e = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(e);
        List<Callable<String>> l = new ArrayList<>();
        l.add(new NPETask());
        List<Future<String>> futures = e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
        assertEquals(1, futures.size());
        try {
            futures.get(0).get();
            shouldThrow();
        } catch (ExecutionException success) {
            assertTrue(success.getCause() instanceof NullPointerException);
        }
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Callable(java.util.concurrent.Callable) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Example 60 with ForkJoinPool

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

the class ForkJoinPoolTest method testTimedInvokeAny2.

/**
 * timed invokeAny(empty collection) throws IllegalArgumentException
 */
public void testTimedInvokeAny2() throws Throwable {
    ExecutorService e = new ForkJoinPool(1);
    PoolCleaner cleaner = null;
    try {
        cleaner = cleaner(e);
        try {
            e.invokeAny(new ArrayList<Callable<String>>(), randomTimeout(), randomTimeUnit());
            shouldThrow();
        } catch (IllegalArgumentException success) {
        }
    } finally {
        if (cleaner != null) {
            cleaner.close();
        }
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) Callable(java.util.concurrent.Callable) ForkJoinPool(java8.util.concurrent.ForkJoinPool)

Aggregations

ForkJoinPool (java8.util.concurrent.ForkJoinPool)55 ExecutorService (java.util.concurrent.ExecutorService)32 RecursiveAction (java8.util.concurrent.RecursiveAction)32 Callable (java.util.concurrent.Callable)20 ArrayList (java.util.ArrayList)15 ExecutionException (java.util.concurrent.ExecutionException)10 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)9 Future (java.util.concurrent.Future)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ForkJoinWorkerThread (java8.util.concurrent.ForkJoinWorkerThread)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ForkJoinTask (java8.util.concurrent.ForkJoinTask)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CancellationException (java.util.concurrent.CancellationException)1 SynchronousQueue (java.util.concurrent.SynchronousQueue)1 TimeoutException (java.util.concurrent.TimeoutException)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Predicate (java8.util.function.Predicate)1