Search in sources :

Example 1 with RecreateOnResetOperatorCoordinator

use of org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator in project flink by apache.

the class SourceCoordinatorProviderTest method testCheckpointAndReset.

@Test
public void testCheckpointAndReset() throws Exception {
    final OperatorCoordinator.Context context = new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SPLITS);
    final RecreateOnResetOperatorCoordinator coordinator = (RecreateOnResetOperatorCoordinator) provider.create(context);
    final SourceCoordinator<?, ?> sourceCoordinator = (SourceCoordinator<?, ?>) coordinator.getInternalCoordinator();
    // Start the coordinator.
    coordinator.start();
    // register reader 0 and take a checkpoint.
    coordinator.handleEventFromOperator(0, new ReaderRegistrationEvent(0, "location"));
    CompletableFuture<byte[]> future = new CompletableFuture<>();
    coordinator.checkpointCoordinator(0L, future);
    byte[] bytes = future.get();
    // Register reader 1.
    coordinator.handleEventFromOperator(1, new ReaderRegistrationEvent(1, "location"));
    // Wait until the coordinator context is updated with registration of reader 1.
    while (sourceCoordinator.getContext().registeredReaders().size() < 2) {
        Thread.sleep(1);
    }
    // reset the coordinator to the checkpoint which only contains reader 0.
    coordinator.resetToCheckpoint(0L, bytes);
    final SourceCoordinator<?, ?> restoredSourceCoordinator = (SourceCoordinator<?, ?>) coordinator.getInternalCoordinator();
    assertNotEquals("The restored source coordinator should be a different instance", restoredSourceCoordinator, sourceCoordinator);
    // FLINK-21452: do not (re)store registered readers
    assertEquals("There should be no registered reader.", 0, restoredSourceCoordinator.getContext().registeredReaders().size());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) MockOperatorCoordinatorContext(org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext) RecreateOnResetOperatorCoordinator(org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator) RecreateOnResetOperatorCoordinator(org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator) ReaderRegistrationEvent(org.apache.flink.runtime.source.event.ReaderRegistrationEvent) Test(org.junit.Test)

Example 2 with RecreateOnResetOperatorCoordinator

use of org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator in project flink by apache.

the class SourceCoordinatorProviderTest method testCreate.

@Test
public void testCreate() throws Exception {
    OperatorCoordinator coordinator = provider.create(new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SPLITS));
    assertTrue(coordinator instanceof RecreateOnResetOperatorCoordinator);
}
Also used : MockOperatorCoordinatorContext(org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext) RecreateOnResetOperatorCoordinator(org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator) OperatorCoordinator(org.apache.flink.runtime.operators.coordination.OperatorCoordinator) RecreateOnResetOperatorCoordinator(org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator) Test(org.junit.Test)

Example 3 with RecreateOnResetOperatorCoordinator

use of org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator in project flink by apache.

the class SourceCoordinatorProviderTest method testCallAsyncExceptionFailsJob.

@Test
public void testCallAsyncExceptionFailsJob() throws Exception {
    MockOperatorCoordinatorContext context = new MockOperatorCoordinatorContext(OPERATOR_ID, NUM_SPLITS);
    RecreateOnResetOperatorCoordinator coordinator = (RecreateOnResetOperatorCoordinator) provider.create(context);
    SourceCoordinator<?, ?> sourceCoordinator = (SourceCoordinator<?, ?>) coordinator.getInternalCoordinator();
    sourceCoordinator.getContext().callAsync(() -> null, (ignored, e) -> {
        throw new RuntimeException();
    });
    CommonTestUtils.waitUtil(context::isJobFailed, Duration.ofSeconds(10L), "The job did not fail before timeout.");
}
Also used : MockOperatorCoordinatorContext(org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext) RecreateOnResetOperatorCoordinator(org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator) Test(org.junit.Test)

Aggregations

MockOperatorCoordinatorContext (org.apache.flink.runtime.operators.coordination.MockOperatorCoordinatorContext)3 RecreateOnResetOperatorCoordinator (org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator)3 Test (org.junit.Test)3 OperatorCoordinator (org.apache.flink.runtime.operators.coordination.OperatorCoordinator)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 ReaderRegistrationEvent (org.apache.flink.runtime.source.event.ReaderRegistrationEvent)1