Search in sources :

Example 6 with SupplierWithException

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) BUFFER_DEBLOAT_TARGET(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_TARGET) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) FunctionWithException(org.apache.flink.util.function.FunctionWithException) AsynchronousException(org.apache.flink.runtime.taskmanager.AsynchronousException) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) RunnableWithException(org.apache.flink.util.function.RunnableWithException) TimeoutException(java.util.concurrent.TimeoutException) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) SupplierWithException(org.apache.flink.util.function.SupplierWithException) BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) ExpectedException(org.junit.rules.ExpectedException)

Aggregations

SupplierWithException (org.apache.flink.util.function.SupplierWithException)6 IOException (java.io.IOException)5 Map (java.util.Map)3 List (java.util.List)2 TimeoutException (java.util.concurrent.TimeoutException)2 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)2 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 Serializable (java.io.Serializable)1 StringWriter (java.io.StringWriter)1 String.format (java.lang.String.format)1 ManagementFactory (java.lang.management.ManagementFactory)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 URLClassLoader (java.net.URLClassLoader)1 ByteBuffer (java.nio.ByteBuffer)1 Duration (java.time.Duration)1