use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testExecuteNullRunnable.
/**
* execute(null runnable) throws NullPointerException
*/
public void testExecuteNullRunnable() {
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
try {
@SuppressWarnings("unused") Future<?> future = e.submit((Runnable) 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 testAwaitTermination_timesOut.
/**
* awaitTermination on a non-shutdown pool times out
*/
public void testAwaitTermination_timesOut() throws InterruptedException {
ForkJoinPool p = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(p);
assertFalse(p.isTerminated());
assertFalse(p.awaitTermination(Long.MIN_VALUE, NANOSECONDS));
assertFalse(p.awaitTermination(Long.MIN_VALUE, MILLISECONDS));
assertFalse(p.awaitTermination(-1L, NANOSECONDS));
assertFalse(p.awaitTermination(-1L, MILLISECONDS));
assertFalse(p.awaitTermination(randomExpiredTimeout(), randomTimeUnit()));
long timeoutNanos = 999999L;
long startTime = System.nanoTime();
assertFalse(p.awaitTermination(timeoutNanos, NANOSECONDS));
assertTrue(System.nanoTime() - startTime >= timeoutNanos);
assertFalse(p.isTerminated());
startTime = System.nanoTime();
long timeoutMillis = timeoutMillis();
assertFalse(p.awaitTermination(timeoutMillis, MILLISECONDS));
assertTrue(millisElapsedSince(startTime) >= timeoutMillis);
assertFalse(p.isTerminated());
p.shutdown();
assertTrue(p.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
assertTrue(p.isTerminated());
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testSubmitCallable.
/**
* Completed submit(callable) returns result
*/
public void testSubmitCallable() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
Future<String> future = e.submit(new StringTask());
assertSame(TEST_STRING, future.get());
assertTrue(future.isDone());
assertFalse(future.isCancelled());
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testInvokeAny5.
/**
* invokeAny(c) throws ExecutionException if no task in c completes
*/
public void testInvokeAny5() throws Throwable {
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
List<Callable<String>> l = new ArrayList<>();
l.add(new NPETask());
try {
e.invokeAny(l);
shouldThrow();
} catch (ExecutionException success) {
assertTrue(success.getCause() instanceof NullPointerException);
}
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testTimedInvokeAnyNullTimeUnit.
/**
* timed invokeAny(null time unit) throws NullPointerException
*/
public void testTimedInvokeAnyNullTimeUnit() 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.invokeAny(l, randomTimeout(), null);
shouldThrow();
} catch (NullPointerException success) {
}
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
Aggregations