use of org.apache.flink.util.function.SupplierWithException in project flink by apache.
the class StreamTaskTest method runTask.
private static <T extends StreamTask<?, ?>> RunningTask<T> runTask(SupplierWithException<T, Exception> taskFactory) throws Exception {
CompletableFuture<T> taskCreationFuture = new CompletableFuture<>();
CompletableFuture<Void> invocationFuture = CompletableFuture.runAsync(() -> {
T task;
try {
task = taskFactory.get();
taskCreationFuture.complete(task);
} catch (Exception e) {
taskCreationFuture.completeExceptionally(e);
return;
}
try {
task.invoke();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}, Executors.newSingleThreadExecutor());
// Wait until task is created.
return new RunningTask<>(taskCreationFuture.get(), invocationFuture);
}
Aggregations