use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinTask8Test method testInvokeAllCollection.
private void testInvokeAllCollection(ForkJoinPool pool) {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib[] tasks = { new AsyncFib(8), new AsyncFib(9), new AsyncFib(7) };
invokeAll(Arrays.asList(tasks));
for (AsyncFib task : tasks) assertTrue(task.isDone());
for (AsyncFib task : tasks) task.checkCompletedNormally();
}
};
testInvokeOnPool(pool, a);
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinTask8Test method testAbnormalForkGet.
private void testAbnormalForkGet(ForkJoinPool pool) {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
FailingAsyncFib f = new FailingAsyncFib(8);
assertSame(f, f.fork());
try {
f.get();
shouldThrow();
} catch (ExecutionException success) {
Throwable cause = success.getCause();
assertTrue(cause instanceof FJException);
checkCompletedAbnormally(f, cause);
}
}
};
testInvokeOnPool(pool, a);
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinTask8Test method testForkHelpQuiesce.
private void testForkHelpQuiesce(ForkJoinPool pool) {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib f = new AsyncFib(8);
assertSame(f, f.fork());
helpQuiesce();
assertEquals(0, getQueuedTaskCount());
f.checkCompletedNormally();
}
};
testInvokeOnPool(pool, a);
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinTask8Test method testInvokeAll1.
private void testInvokeAll1(ForkJoinPool pool) {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
AsyncFib f = new AsyncFib(8);
invokeAll(f);
f.checkCompletedNormally();
}
};
testInvokeOnPool(pool, a);
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinTask8Test method testPollSubmission.
// jdk9
/**
* pollSubmission returns unexecuted submitted task, if present
*/
public void testPollSubmission() {
final CountDownLatch done = new CountDownLatch(1);
final ForkJoinTask<?> a = ForkJoinTask.adapt(awaiter(done));
final ForkJoinTask<?> b = ForkJoinTask.adapt(awaiter(done));
final ForkJoinTask<?> c = ForkJoinTask.adapt(awaiter(done));
final ForkJoinPool p = singletonPool();
PoolCleaner cleaner = null;
try {
cleaner = cleaner(p, done);
Thread external = new Thread(new CheckedRunnable() {
public void realRun() {
p.execute(a);
p.execute(b);
p.execute(c);
}
});
@SuppressWarnings("serial") RecursiveAction s = new CheckedRecursiveAction() {
protected void realCompute() {
external.start();
try {
external.join();
} catch (Exception ex) {
threadUnexpectedException(ex);
}
assertTrue(p.hasQueuedSubmissions());
assertTrue(Thread.currentThread() instanceof ForkJoinWorkerThread);
ForkJoinTask<?> r = ForkJoinTask.pollSubmission();
assertTrue(r == a || r == b || r == c);
assertFalse(r.isDone());
}
};
p.invoke(s);
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
Aggregations