use of java8.util.concurrent.ForkJoinTask in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testDrainTasksTo.
/**
* drainTasksTo transfers unexecuted submitted tasks, if present
*/
public void testDrainTasksTo() {
final CountDownLatch done = new CountDownLatch(1);
SubFJP p = new SubFJP();
PoolCleaner cleaner = null;
try {
cleaner = cleaner(p);
ForkJoinTask<?> a = p.submit(awaiter(done));
ForkJoinTask<?> b = p.submit(awaiter(done));
ForkJoinTask<?> c = p.submit(awaiter(done));
ArrayList<ForkJoinTask<?>> al = new ArrayList();
p.drainTasksTo(al);
assertTrue(al.size() > 0);
for (ForkJoinTask<?> r : al) {
assertTrue(r == a || r == b || r == c);
assertFalse(r.isDone());
}
done.countDown();
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinTask 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();
}
}
}
use of java8.util.concurrent.ForkJoinTask in project streamsupport by stefan-zobel.
the class ForkJoinTask8Test method testAbnormalInvokeAll2.
private void testAbnormalInvokeAll2(ForkJoinPool pool) {
@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[0], tasks[1]);
shouldThrow();
} catch (FJException success) {
checkCompletedAbnormally(g, success);
}
}
};
testInvokeOnPool(pool, a);
}
use of java8.util.concurrent.ForkJoinTask 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();
}
}
}
use of java8.util.concurrent.ForkJoinTask in project streamsupport by stefan-zobel.
the class ForkJoinTask8Test method testAbnormalInvokeAll3.
private void testAbnormalInvokeAll3(ForkJoinPool pool) {
@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[0], tasks[1], tasks[2]);
shouldThrow();
} catch (FJException success) {
checkCompletedAbnormally(g, success);
}
}
};
testInvokeOnPool(pool, a);
}
Aggregations