use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testInvokeAll2.
/**
* invokeAll(empty collection) returns empty list
*/
public void testInvokeAll2() throws InterruptedException {
ExecutorService e = new ForkJoinPool(1);
final Collection<Callable<String>> emptyCollection = Collections.emptyList();
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
List<Future<String>> r = e.invokeAll(emptyCollection);
assertTrue(r.isEmpty());
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testSetUncaughtExceptionHandler.
/**
* setUncaughtExceptionHandler changes handler for uncaught exceptions.
*
* Additionally tests: Overriding ForkJoinWorkerThread.onStart
* performs its defined action
*/
public void testSetUncaughtExceptionHandler() throws InterruptedException {
final CountDownLatch uehInvoked = new CountDownLatch(1);
final Thread.UncaughtExceptionHandler ueh = new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
threadAssertTrue(e instanceof MyError);
threadAssertTrue(t instanceof FailingFJWSubclass);
uehInvoked.countDown();
}
};
ForkJoinPool p = new ForkJoinPool(1, new FailingThreadFactory(), ueh, false);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(p);
assertSame(ueh, p.getUncaughtExceptionHandler());
try {
p.execute(new FibTask(8));
await(uehInvoked);
} finally {
// failure might have prevented processing task
p.shutdownNow();
}
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testSubmitForkJoinTask.
/**
* Completed submit(ForkJoinTask) returns result
*/
public void testSubmitForkJoinTask() throws Throwable {
ForkJoinPool p = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(p);
ForkJoinTask<Integer> f = p.submit(new FibTask(8));
assertEquals(21, (int) f.get());
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testTimedInvokeAll1.
/**
* timed invokeAll(null) throws NullPointerException
*/
public void testTimedInvokeAll1() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
try {
e.invokeAll(null, randomTimeout(), randomTimeUnit());
shouldThrow();
} catch (NullPointerException success) {
}
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testInvokeAll4.
/**
* get of returned element of invokeAll(c) throws
* ExecutionException on failed task
*/
public void testInvokeAll4() 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);
assertEquals(1, futures.size());
try {
futures.get(0).get();
shouldThrow();
} catch (ExecutionException success) {
assertTrue(success.getCause() instanceof NullPointerException);
}
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
Aggregations