Search in sources :

Example 21 with FlinkCompletableFuture

use of org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture in project flink by apache.

the class FutureUtilsTest method testConjunctFutureFailureOnFirst.

@Test
public void testConjunctFutureFailureOnFirst() throws Exception {
    CompletableFuture<Object> future1 = new FlinkCompletableFuture<>();
    CompletableFuture<Object> future2 = new FlinkCompletableFuture<>();
    CompletableFuture<Object> future3 = new FlinkCompletableFuture<>();
    CompletableFuture<Object> future4 = new FlinkCompletableFuture<>();
    // build the conjunct future
    ConjunctFuture result = FutureUtils.combineAll(Arrays.asList(future1, future2, future3, future4));
    Future<Void> resultMapped = result.thenAccept(new AcceptFunction<Void>() {

        @Override
        public void accept(Void value) {
        }
    });
    assertEquals(4, result.getNumFuturesTotal());
    assertEquals(0, result.getNumFuturesCompleted());
    assertFalse(result.isDone());
    assertFalse(resultMapped.isDone());
    future2.completeExceptionally(new IOException());
    assertEquals(0, result.getNumFuturesCompleted());
    assertTrue(result.isDone());
    assertTrue(resultMapped.isDone());
    try {
        result.get();
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof IOException);
    }
    try {
        resultMapped.get();
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof IOException);
    }
}
Also used : ConjunctFuture(org.apache.flink.runtime.concurrent.FutureUtils.ConjunctFuture) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) FlinkCompletableFuture(org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture) Test(org.junit.Test)

Aggregations

FlinkCompletableFuture (org.apache.flink.runtime.concurrent.impl.FlinkCompletableFuture)21 Test (org.junit.Test)17 SimpleSlot (org.apache.flink.runtime.instance.SimpleSlot)10 Time (org.apache.flink.api.common.time.Time)8 JobID (org.apache.flink.api.common.JobID)6 TaskManagerGateway (org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway)6 TaskDeploymentDescriptor (org.apache.flink.runtime.deployment.TaskDeploymentDescriptor)5 Instance (org.apache.flink.runtime.instance.Instance)5 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)5 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)5 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)5 IOException (java.io.IOException)4 ScheduledUnit (org.apache.flink.runtime.jobmanager.scheduler.ScheduledUnit)4 Scheduler (org.apache.flink.runtime.jobmanager.scheduler.Scheduler)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ConjunctFuture (org.apache.flink.runtime.concurrent.FutureUtils.ConjunctFuture)3 ExecutionGraphTestUtils.getExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getExecutionVertex)3 ExecutionGraphTestUtils.getInstance (org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils.getInstance)3 ExecutionVertex (org.apache.flink.runtime.executiongraph.ExecutionVertex)3 Slot (org.apache.flink.runtime.instance.Slot)3