use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testTimedInvokeAllNullTimeUnit.
/**
* timed invokeAll(null time unit) throws NullPointerException
*/
public void testTimedInvokeAllNullTimeUnit() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
try {
e.invokeAll(l, randomTimeout(), null);
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 testBlockingForkJoinTask.
/**
* Pool maintains parallelism when using ManagedBlocker
*/
public void testBlockingForkJoinTask() throws Throwable {
ForkJoinPool p = new ForkJoinPool(4);
try {
ReentrantLock lock = new ReentrantLock();
ManagedLocker locker = new ManagedLocker(lock);
ForkJoinTask<Integer> f = new LockingFibTask(20, locker, lock);
p.execute(f);
assertEquals(6765, (int) f.get());
} finally {
// don't wait out shutdown
p.shutdownNow();
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testTimedInvokeAll5.
/**
* timed invokeAll(c) returns results of all completed tasks in c
*/
public void testTimedInvokeAll5() throws Throwable {
ForkJoinPool e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(new StringTask());
List<Future<String>> futures = e.invokeAll(l, LONG_DELAY_MS, MILLISECONDS);
assertEquals(2, futures.size());
for (Future<String> future : futures) assertSame(TEST_STRING, future.get());
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testInterruptedSubmit.
/**
* submit(callable).get() throws InterruptedException if interrupted
*/
public void testInterruptedSubmit() throws InterruptedException {
final CountDownLatch submitted = new CountDownLatch(1);
final CountDownLatch quittingTime = new CountDownLatch(1);
final Callable<Void> awaiter = new CheckedCallable<Void>() {
public Void realCall() throws InterruptedException {
assertTrue(quittingTime.await(2 * LONG_DELAY_MS, MILLISECONDS));
return null;
}
};
final ExecutorService p = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(p, quittingTime);
Thread t = new Thread(new CheckedInterruptedRunnable() {
public void realRun() throws Exception {
Future<Void> future = p.submit(awaiter);
submitted.countDown();
future.get();
}
});
t.start();
await(submitted);
t.interrupt();
awaitTermination(t);
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testExecuteRunnable.
// FJ Versions of AbstractExecutorService tests
/**
* execute(runnable) runs it to completion
*/
public void testExecuteRunnable() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
final AtomicBoolean done = new AtomicBoolean(false);
Future<?> future = e.submit(new CheckedRunnable() {
public void realRun() {
done.set(true);
}
});
assertNull(future.get());
assertNull(future.get(randomExpiredTimeout(), randomTimeUnit()));
assertTrue(done.get());
assertTrue(future.isDone());
assertFalse(future.isCancelled());
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
Aggregations