use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testIsQuiescent.
/**
* After invoking a single task, isQuiescent eventually becomes
* true, at which time queues are empty, threads are not active,
* the task has completed successfully, and construction
* parameters continue to hold
*/
public void testIsQuiescent() throws Exception {
ForkJoinPool p = new ForkJoinPool(2);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(p);
assertTrue(p.isQuiescent());
long startTime = System.nanoTime();
FibTask f = new FibTask(20);
p.invoke(f);
assertSame(ForkJoinPool.defaultForkJoinWorkerThreadFactory, p.getFactory());
while (!p.isQuiescent()) {
if (millisElapsedSince(startTime) > LONG_DELAY_MS)
throw new AssertionError("timed out");
assertFalse(p.getAsyncMode());
assertFalse(p.isShutdown());
assertFalse(p.isTerminating());
assertFalse(p.isTerminated());
Thread.yield();
}
assertTrue(p.isQuiescent());
assertFalse(p.getAsyncMode());
assertEquals(0, p.getQueuedTaskCount());
assertEquals(0, p.getQueuedSubmissionCount());
assertFalse(p.hasQueuedSubmissions());
while (p.getActiveThreadCount() != 0 && millisElapsedSince(startTime) < LONG_DELAY_MS) Thread.yield();
assertFalse(p.isShutdown());
assertFalse(p.isTerminating());
assertFalse(p.isTerminated());
assertTrue(f.isDone());
assertEquals(6765, (int) f.get());
assertTrue(millisElapsedSince(startTime) < LONG_DELAY_MS);
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testInvokeAny4.
/**
* invokeAny(c) throws NullPointerException if c has null elements
*/
public void testInvokeAny4() throws Throwable {
CountDownLatch latch = new CountDownLatch(1);
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
List<Callable<String>> l = new ArrayList<>();
l.add(latchAwaitingStringTask(latch));
l.add(null);
try {
e.invokeAny(l);
shouldThrow();
} catch (NullPointerException success) {
}
latch.countDown();
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testGetPoolSize.
/**
* getPoolSize returns number of started workers.
*/
public void testGetPoolSize() {
final CountDownLatch taskStarted = new CountDownLatch(1);
final CountDownLatch done = new CountDownLatch(1);
final ForkJoinPool p = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(p);
assertEquals(0, p.getActiveThreadCount());
final Runnable task = new CheckedRunnable() {
public void realRun() throws InterruptedException {
taskStarted.countDown();
assertEquals(1, p.getPoolSize());
assertEquals(1, p.getActiveThreadCount());
await(done);
}
};
@SuppressWarnings("unused") Future<?> future = p.submit(task);
await(taskStarted);
assertEquals(1, p.getPoolSize());
assertEquals(1, p.getActiveThreadCount());
done.countDown();
} finally {
if (cleaner != null) {
cleaner.close();
}
}
assertEquals(0, p.getPoolSize());
assertEquals(0, p.getActiveThreadCount());
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinTask8Test method testAbnormalForkJoin.
private void testAbnormalForkJoin(ForkJoinPool pool) {
@SuppressWarnings("serial") RecursiveAction a = new CheckedRecursiveAction() {
protected void realCompute() {
FailingAsyncFib f = new FailingAsyncFib(8);
assertSame(f, f.fork());
try {
f.join();
shouldThrow();
} catch (FJException success) {
checkCompletedAbnormally(f, success);
}
}
};
testInvokeOnPool(pool, a);
}
use of java8.util.concurrent.ForkJoinPool 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);
}
Aggregations