use of java8.util.concurrent.ForkJoinPool 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);
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinTask8Test method testForkTimedGetNullTimeUnit.
private void testForkTimedGetNullTimeUnit(ForkJoinPool pool) {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws Exception {
AsyncFib f = new AsyncFib(8);
assertSame(f, f.fork());
try {
f.get(randomTimeout(), null);
shouldThrow();
} catch (NullPointerException success) {
}
}
};
testInvokeOnPool(pool, a);
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class RecursiveActionTest method testGetPool.
/**
* getPool of executing task returns its pool
*/
public void testGetPool() {
final ForkJoinPool mainPool = mainPool();
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
assertSame(mainPool, getPool());
}
};
testInvokeOnPool(mainPool, a);
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class RecursiveActionTest method testJoinIgnoresInterruptsOutsideForkJoinPool.
/**
* join/quietlyJoin of a forked task when not in ForkJoinPool
* succeeds in the presence of interrupts
*/
public void testJoinIgnoresInterruptsOutsideForkJoinPool() {
final SynchronousQueue<FibAction[]> sq = new SynchronousQueue<>();
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() throws InterruptedException {
FibAction[] fibActions = new FibAction[6];
for (int i = 0; i < fibActions.length; i++) fibActions[i] = new FibAction(8);
fibActions[1].cancel(false);
fibActions[2].completeExceptionally(new FJException());
fibActions[4].cancel(true);
fibActions[5].completeExceptionally(new FJException());
for (int i = 0; i < fibActions.length; i++) fibActions[i].fork();
sq.put(fibActions);
helpQuiesce();
}
};
Runnable r = new CheckedRunnable() {
public void realRun() throws InterruptedException {
FibAction[] fibActions = sq.take();
FibAction f;
final Thread myself = Thread.currentThread();
// test join() ------------
f = fibActions[0];
assertFalse(ForkJoinTask.inForkJoinPool());
myself.interrupt();
assertTrue(myself.isInterrupted());
assertNull(f.join());
assertTrue(Thread.interrupted());
assertEquals(21, f.result);
checkCompletedNormally(f);
f = fibActions[1];
myself.interrupt();
assertTrue(myself.isInterrupted());
try {
f.join();
shouldThrow();
} catch (CancellationException success) {
assertTrue(Thread.interrupted());
checkCancelled(f);
}
f = fibActions[2];
myself.interrupt();
assertTrue(myself.isInterrupted());
try {
f.join();
shouldThrow();
} catch (FJException success) {
assertTrue(Thread.interrupted());
checkCompletedAbnormally(f, success);
}
// test quietlyJoin() ---------
f = fibActions[3];
myself.interrupt();
assertTrue(myself.isInterrupted());
f.quietlyJoin();
assertTrue(Thread.interrupted());
assertEquals(21, f.result);
checkCompletedNormally(f);
f = fibActions[4];
myself.interrupt();
assertTrue(myself.isInterrupted());
f.quietlyJoin();
assertTrue(Thread.interrupted());
checkCancelled(f);
f = fibActions[5];
myself.interrupt();
assertTrue(myself.isInterrupted());
f.quietlyJoin();
assertTrue(Thread.interrupted());
assertTrue(f.getException() instanceof FJException);
checkCompletedAbnormally(f, f.getException());
}
};
Thread t;
t = newStartedThread(r);
testInvokeOnPool(mainPool(), a);
awaitTermination(t);
a.reinitialize();
t = newStartedThread(r);
testInvokeOnPool(singletonPool(), a);
awaitTermination(t);
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class RecursiveActionTest method testWorkerGetPoolIndex.
/**
* getPoolIndex of current thread in pool returns 0 <= value < poolSize
*/
public void testWorkerGetPoolIndex() {
final ForkJoinPool mainPool = mainPool();
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
ForkJoinWorkerThread w = (ForkJoinWorkerThread) Thread.currentThread();
assertTrue(w.getPoolIndex() >= 0);
// pool size can shrink after assigning index, so cannot check
// assertTrue(w.getPoolIndex() < mainPool.getPoolSize());
}
};
testInvokeOnPool(mainPool, a);
}
Aggregations