use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testSubmitFailedPrivilegedExceptionAction.
/**
* A submitted failed privileged exception action reports exception
*/
public void testSubmitFailedPrivilegedExceptionAction() throws Exception {
final Callable<Object> callable = Executors.callable(new PrivilegedExceptionAction<Object>() {
public Object run() {
throw new IndexOutOfBoundsException();
}
});
Runnable r = new CheckedRunnable() {
public void realRun() throws Exception {
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
Future<?> future = e.submit(callable);
try {
future.get();
shouldThrow();
} catch (ExecutionException success) {
assertTrue(success.getCause() instanceof IndexOutOfBoundsException);
}
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
};
runWithPermissions(r, new RuntimePermission("modifyThread"));
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testTimedInvokeAll2.
/**
* timed invokeAll(empty collection) returns empty list
*/
public void testTimedInvokeAll2() throws InterruptedException {
ExecutorService e = new ForkJoinPool(1);
final Collection<Callable<String>> emptyCollection = Collections.emptyList();
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
List<Future<String>> r = e.invokeAll(emptyCollection, randomTimeout(), randomTimeUnit());
assertTrue(r.isEmpty());
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testInvokeAll3.
/**
* invokeAll(c) throws NullPointerException if c has null elements
*/
public void testInvokeAll3() throws InterruptedException {
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
List<Callable<String>> l = new ArrayList<>();
l.add(new StringTask());
l.add(null);
try {
e.invokeAll(l);
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 testSubmitPrivilegedExceptionAction.
/**
* A submitted privileged exception action runs to completion
*/
public void testSubmitPrivilegedExceptionAction() throws Exception {
final Callable<Object> callable = Executors.callable(new PrivilegedExceptionAction<Object>() {
public Object run() {
return TEST_STRING;
}
});
Runnable r = new CheckedRunnable() {
public void realRun() throws Exception {
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
Future<?> future = e.submit(callable);
assertSame(TEST_STRING, future.get());
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
};
runWithPermissions(r, new RuntimePermission("modifyThread"));
}
use of java8.util.concurrent.ForkJoinPool in project streamsupport by stefan-zobel.
the class ForkJoinPoolTest method testSubmitPrivilegedAction.
/**
* A submitted privileged action runs to completion
*/
public void testSubmitPrivilegedAction() throws Exception {
final Callable<Object> callable = Executors.callable(new PrivilegedAction<Object>() {
public Object run() {
return TEST_STRING;
}
});
Runnable r = new CheckedRunnable() {
public void realRun() throws Exception {
ExecutorService e = new ForkJoinPool(1);
PoolCleaner cleaner = null;
try {
cleaner = cleaner(e);
Future<?> future = e.submit(callable);
assertSame(TEST_STRING, future.get());
} finally {
if (cleaner != null) {
cleaner.close();
}
}
}
};
runWithPermissions(r, new RuntimePermission("modifyThread"));
}
Aggregations