Search in sources :

Example 1 with CheckpointExceptionMatcher

use of org.apache.flink.streaming.runtime.io.checkpointing.AlignedCheckpointsTest.CheckpointExceptionMatcher in project flink by apache.

the class StreamTaskCancellationBarrierTest method testDeclineCallOnCancelBarrierOneInput.

/**
 * This test verifies (for onw input tasks) that the Stream tasks react the following way to
 * receiving a checkpoint cancellation barrier: - send a "decline checkpoint" notification out
 * (to the JobManager) - emit a cancellation barrier downstream.
 */
@Test
public void testDeclineCallOnCancelBarrierOneInput() throws Exception {
    OneInputStreamTaskTestHarness<String, String> testHarness = new OneInputStreamTaskTestHarness<>(OneInputStreamTask::new, 1, 2, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
    testHarness.setupOutputForSingletonOperatorChain();
    StreamConfig streamConfig = testHarness.getStreamConfig();
    StreamMap<String, String> mapOperator = new StreamMap<>(new IdentityMap());
    streamConfig.setStreamOperator(mapOperator);
    streamConfig.setOperatorID(new OperatorID());
    StreamMockEnvironment environment = spy(testHarness.createEnvironment());
    // start the task
    testHarness.invoke(environment);
    testHarness.waitForTaskRunning();
    // emit cancellation barriers
    testHarness.processEvent(new CancelCheckpointMarker(2L), 0, 1);
    testHarness.processEvent(new CancelCheckpointMarker(2L), 0, 0);
    testHarness.waitForInputProcessing();
    // the decline call should go to the coordinator
    verify(environment, times(1)).declineCheckpoint(eq(2L), argThat(new CheckpointExceptionMatcher(CheckpointFailureReason.CHECKPOINT_DECLINED_ON_CANCELLATION_BARRIER)));
    // a cancellation barrier should be downstream
    Object result = testHarness.getOutput().poll();
    assertNotNull("nothing emitted", result);
    assertTrue("wrong type emitted", result instanceof CancelCheckpointMarker);
    assertEquals("wrong checkpoint id", 2L, ((CancelCheckpointMarker) result).getCheckpointId());
    // cancel and shutdown
    testHarness.endInput();
    testHarness.waitForTaskCompletion();
}
Also used : CancelCheckpointMarker(org.apache.flink.runtime.io.network.api.CancelCheckpointMarker) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) CheckpointExceptionMatcher(org.apache.flink.streaming.runtime.io.checkpointing.AlignedCheckpointsTest.CheckpointExceptionMatcher) CoStreamMap(org.apache.flink.streaming.api.operators.co.CoStreamMap) StreamMap(org.apache.flink.streaming.api.operators.StreamMap) Test(org.junit.Test) AlignedCheckpointsTest(org.apache.flink.streaming.runtime.io.checkpointing.AlignedCheckpointsTest)

Aggregations

CancelCheckpointMarker (org.apache.flink.runtime.io.network.api.CancelCheckpointMarker)1 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)1 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)1 StreamMap (org.apache.flink.streaming.api.operators.StreamMap)1 CoStreamMap (org.apache.flink.streaming.api.operators.co.CoStreamMap)1 AlignedCheckpointsTest (org.apache.flink.streaming.runtime.io.checkpointing.AlignedCheckpointsTest)1 CheckpointExceptionMatcher (org.apache.flink.streaming.runtime.io.checkpointing.AlignedCheckpointsTest.CheckpointExceptionMatcher)1 Test (org.junit.Test)1