Search in sources :

Example 11 with CheckpointMetaData

use of org.apache.flink.runtime.checkpoint.CheckpointMetaData in project flink by apache.

the class StreamTaskExecutionDecorationTest method testTriggerCheckpointOnBarrierIsDecorated.

@Test
public void testTriggerCheckpointOnBarrierIsDecorated() throws Exception {
    task.triggerCheckpointOnBarrier(new CheckpointMetaData(1, 2), new CheckpointOptions(CheckpointType.CHECKPOINT, new CheckpointStorageLocationReference(new byte[] { 1 })), null);
    Assert.assertTrue("execution decorator was not called", decorator.wasCalled());
}
Also used : CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference) Test(org.junit.Test)

Example 12 with CheckpointMetaData

use of org.apache.flink.runtime.checkpoint.CheckpointMetaData in project flink by apache.

the class StreamTaskExecutionDecorationTest method testTriggerCheckpointAsyncIsDecorated.

@Test
public void testTriggerCheckpointAsyncIsDecorated() {
    task.triggerCheckpointAsync(new CheckpointMetaData(1, 2), new CheckpointOptions(CheckpointType.CHECKPOINT, new CheckpointStorageLocationReference(new byte[] { 1 })));
    Assert.assertTrue("mailbox is empty", mailbox.hasMail());
    Assert.assertFalse("execution decorator was called preliminary", decorator.wasCalled());
    mailbox.drain().forEach(m -> {
        try {
            m.run();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    Assert.assertTrue("execution decorator was not called", decorator.wasCalled());
}
Also used : CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) CheckpointStorageLocationReference(org.apache.flink.runtime.state.CheckpointStorageLocationReference) RunnableWithException(org.apache.flink.util.function.RunnableWithException) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) Test(org.junit.Test)

Example 13 with CheckpointMetaData

use of org.apache.flink.runtime.checkpoint.CheckpointMetaData in project flink by apache.

the class RocksDBAsyncSnapshotTest method testFullyAsyncSnapshot.

/**
 * This ensures that asynchronous state handles are actually materialized asynchronously.
 *
 * <p>We use latches to block at various stages and see if the code still continues through the
 * parts that are not asynchronous. If the checkpoint is not done asynchronously the test will
 * simply lock forever.
 */
@Test
public void testFullyAsyncSnapshot() throws Exception {
    final OneInputStreamTaskTestHarness<String, String> testHarness = new OneInputStreamTaskTestHarness<>(OneInputStreamTask::new, BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO);
    testHarness.setupOutputForSingletonOperatorChain();
    testHarness.configureForKeyedStream(new KeySelector<String, String>() {

        @Override
        public String getKey(String value) throws Exception {
            return value;
        }
    }, BasicTypeInfo.STRING_TYPE_INFO);
    StreamConfig streamConfig = testHarness.getStreamConfig();
    File dbDir = temporaryFolder.newFolder();
    RocksDBStateBackend backend = new RocksDBStateBackend(new MemoryStateBackend());
    backend.setDbStoragePath(dbDir.getAbsolutePath());
    streamConfig.setStateBackend(backend);
    streamConfig.setStreamOperator(new AsyncCheckpointOperator());
    streamConfig.setOperatorID(new OperatorID());
    final OneShotLatch delayCheckpointLatch = new OneShotLatch();
    final OneShotLatch ensureCheckpointLatch = new OneShotLatch();
    CheckpointResponder checkpointResponderMock = new CheckpointResponder() {

        @Override
        public void acknowledgeCheckpoint(JobID jobID, ExecutionAttemptID executionAttemptID, long checkpointId, CheckpointMetrics checkpointMetrics, TaskStateSnapshot subtaskState) {
            // even though the async checkpoint would not finish
            try {
                delayCheckpointLatch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            boolean hasManagedKeyedState = false;
            for (Map.Entry<OperatorID, OperatorSubtaskState> entry : subtaskState.getSubtaskStateMappings()) {
                OperatorSubtaskState state = entry.getValue();
                if (state != null) {
                    hasManagedKeyedState |= state.getManagedKeyedState() != null;
                }
            }
            // should be one k/v state
            assertTrue(hasManagedKeyedState);
            // we now know that the checkpoint went through
            ensureCheckpointLatch.trigger();
        }

        @Override
        public void reportCheckpointMetrics(JobID jobID, ExecutionAttemptID executionAttemptID, long checkpointId, CheckpointMetrics checkpointMetrics) {
        }

        @Override
        public void declineCheckpoint(JobID jobID, ExecutionAttemptID executionAttemptID, long checkpointId, CheckpointException checkpointException) {
        }
    };
    JobID jobID = new JobID();
    ExecutionAttemptID executionAttemptID = new ExecutionAttemptID();
    TestTaskStateManager taskStateManagerTestMock = new TestTaskStateManager(jobID, executionAttemptID, checkpointResponderMock, TestLocalRecoveryConfig.disabled(), new InMemoryStateChangelogStorage(), new HashMap<>(), -1L, new OneShotLatch());
    StreamMockEnvironment mockEnv = new StreamMockEnvironment(testHarness.jobConfig, testHarness.taskConfig, testHarness.memorySize, new MockInputSplitProvider(), testHarness.bufferSize, taskStateManagerTestMock);
    AtomicReference<Throwable> errorRef = new AtomicReference<>();
    mockEnv.setExternalExceptionHandler(errorRef::set);
    testHarness.invoke(mockEnv);
    testHarness.waitForTaskRunning();
    final OneInputStreamTask<String, String> task = testHarness.getTask();
    task.triggerCheckpointAsync(new CheckpointMetaData(42, 17), CheckpointOptions.forCheckpointWithDefaultLocation()).get();
    testHarness.processElement(new StreamRecord<>("Wohoo", 0));
    // now we allow the checkpoint
    delayCheckpointLatch.trigger();
    // wait for the checkpoint to go through
    ensureCheckpointLatch.await();
    testHarness.endInput();
    ExecutorService threadPool = task.getAsyncOperationsThreadPool();
    threadPool.shutdown();
    Assert.assertTrue(threadPool.awaitTermination(60_000, TimeUnit.MILLISECONDS));
    testHarness.waitForTaskCompletion();
    if (errorRef.get() != null) {
        fail("Unexpected exception during execution.");
    }
}
Also used : OneInputStreamTask(org.apache.flink.streaming.runtime.tasks.OneInputStreamTask) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) CheckpointMetrics(org.apache.flink.runtime.checkpoint.CheckpointMetrics) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) InMemoryStateChangelogStorage(org.apache.flink.runtime.state.changelog.inmemory.InMemoryStateChangelogStorage) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) StreamMockEnvironment(org.apache.flink.streaming.runtime.tasks.StreamMockEnvironment) MockInputSplitProvider(org.apache.flink.runtime.operators.testutils.MockInputSplitProvider) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) CheckpointResponder(org.apache.flink.runtime.taskmanager.CheckpointResponder) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) AtomicReference(java.util.concurrent.atomic.AtomicReference) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TestTaskStateManager(org.apache.flink.runtime.state.TestTaskStateManager) OneInputStreamTaskTestHarness(org.apache.flink.streaming.runtime.tasks.OneInputStreamTaskTestHarness) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 14 with CheckpointMetaData

use of org.apache.flink.runtime.checkpoint.CheckpointMetaData in project flink by apache.

the class StreamTaskTest method testForceFullSnapshotOnIncompatibleStateBackend.

@Test
public void testForceFullSnapshotOnIncompatibleStateBackend() throws Exception {
    try (StreamTaskMailboxTestHarness<Integer> harness = new StreamTaskMailboxTestHarnessBuilder<>(OneInputStreamTask::new, BasicTypeInfo.INT_TYPE_INFO).modifyStreamConfig(config -> config.setStateBackend(new OnlyIncrementalStateBackend())).addInput(BasicTypeInfo.INT_TYPE_INFO).setupOutputForSingletonOperatorChain(new StreamMap<>(value -> null)).build()) {
        final IllegalStateException exception = assertThrows(IllegalStateException.class, () -> {
            harness.streamTask.triggerCheckpointAsync(new CheckpointMetaData(42L, 1L), CheckpointOptions.forConfig(CheckpointType.FULL_CHECKPOINT, getDefault(), true, false, 0L));
        });
        assertThat(exception.getMessage(), equalTo("Configured state backend (OnlyIncrementalStateBackend) does not" + " support enforcing a full snapshot. If you are restoring in" + " NO_CLAIM mode, please consider choosing either CLAIM or" + " LEGACY restore mode."));
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalTimeServiceManager(org.apache.flink.streaming.api.operators.InternalTimeServiceManager) NettyShuffleDescriptorBuilder(org.apache.flink.runtime.util.NettyShuffleDescriptorBuilder) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) TaskLocalStateStoreImpl(org.apache.flink.runtime.state.TaskLocalStateStoreImpl) Collections.singletonList(java.util.Collections.singletonList) CheckpointException(org.apache.flink.runtime.checkpoint.CheckpointException) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AvailabilityTestResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.AvailabilityTestResultPartitionWriter) FunctionWithException(org.apache.flink.util.function.FunctionWithException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FatalExitExceptionHandler(org.apache.flink.util.FatalExitExceptionHandler) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) AsynchronousException(org.apache.flink.runtime.taskmanager.AsynchronousException) Assert.assertFalse(org.junit.Assert.assertFalse) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) Mockito.mock(org.mockito.Mockito.mock) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ResultPartitionWriter(org.apache.flink.runtime.io.network.api.writer.ResultPartitionWriter) Mockito.spy(org.mockito.Mockito.spy) Answer(org.mockito.stubbing.Answer) OptionalLong(java.util.OptionalLong) MAX_PRIORITY(org.apache.flink.streaming.runtime.tasks.mailbox.TaskMailbox.MAX_PRIORITY) Output(org.apache.flink.streaming.api.operators.Output) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CheckpointableKeyedStateBackend(org.apache.flink.runtime.state.CheckpointableKeyedStateBackend) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) MailboxExecutor(org.apache.flink.api.common.operators.MailboxExecutor) ExecutionState(org.apache.flink.runtime.execution.ExecutionState) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) MockStreamConfig(org.apache.flink.streaming.util.MockStreamConfig) StreamOperator(org.apache.flink.streaming.api.operators.StreamOperator) ExecutionException(java.util.concurrent.ExecutionException) Mockito.never(org.mockito.Mockito.never) JobID(org.apache.flink.api.common.JobID) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) CheckpointStreamFactory(org.apache.flink.runtime.state.CheckpointStreamFactory) Assert.assertEquals(org.junit.Assert.assertEquals) TaskStateManagerImpl(org.apache.flink.runtime.state.TaskStateManagerImpl) TestTaskBuilder(org.apache.flink.runtime.taskmanager.TestTaskBuilder) SystemClock(org.apache.flink.util.clock.SystemClock) ThroughputCalculator(org.apache.flink.runtime.throughput.ThroughputCalculator) ShuffleEnvironment(org.apache.flink.runtime.shuffle.ShuffleEnvironment) ObjectInputStream(java.io.ObjectInputStream) ExceptionUtils(org.apache.flink.util.ExceptionUtils) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) TimerGauge(org.apache.flink.runtime.metrics.TimerGauge) BasicTypeInfo(org.apache.flink.api.common.typeinfo.BasicTypeInfo) ChainingStrategy(org.apache.flink.streaming.api.operators.ChainingStrategy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CheckpointStorageLocationReference.getDefault(org.apache.flink.runtime.state.CheckpointStorageLocationReference.getDefault) Matchers.eq(org.mockito.Matchers.eq) BUFFER_DEBLOAT_ENABLED(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_ENABLED) TaskStateSnapshot(org.apache.flink.runtime.checkpoint.TaskStateSnapshot) CheckpointType(org.apache.flink.runtime.checkpoint.CheckpointType) BUFFER_DEBLOAT_THRESHOLD_PERCENTAGES(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_THRESHOLD_PERCENTAGES) MockStreamTaskBuilder(org.apache.flink.streaming.util.MockStreamTaskBuilder) CheckpointOptions(org.apache.flink.runtime.checkpoint.CheckpointOptions) Preconditions(org.apache.flink.util.Preconditions) AbstractKeyedStateBackend(org.apache.flink.runtime.state.AbstractKeyedStateBackend) CloseableIterable(org.apache.flink.util.CloseableIterable) DEFAULT_OUTPUT_FLUSH_THREAD_NAME(org.apache.flink.runtime.io.network.api.writer.RecordWriter.DEFAULT_OUTPUT_FLUSH_THREAD_NAME) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) CheckpointResponder(org.apache.flink.runtime.taskmanager.CheckpointResponder) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) Assert.assertThrows(org.junit.Assert.assertThrows) CoreMatchers.not(org.hamcrest.CoreMatchers.not) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) OperatorStreamStateHandle(org.apache.flink.runtime.state.OperatorStreamStateHandle) ArgumentCaptor(org.mockito.ArgumentCaptor) StreamRecord(org.apache.flink.streaming.runtime.streamrecord.StreamRecord) StreamTaskStateInitializer(org.apache.flink.streaming.api.operators.StreamTaskStateInitializer) RichParallelSourceFunction(org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction) StreamMap(org.apache.flink.streaming.api.operators.StreamMap) MockEnvironment(org.apache.flink.runtime.operators.testutils.MockEnvironment) StreamInputProcessor(org.apache.flink.streaming.runtime.io.StreamInputProcessor) ExecutorService(java.util.concurrent.ExecutorService) RunnableFuture(java.util.concurrent.RunnableFuture) NettyShuffleEnvironmentBuilder(org.apache.flink.runtime.io.network.NettyShuffleEnvironmentBuilder) Configuration(org.apache.flink.configuration.Configuration) StreamOperatorParameters(org.apache.flink.streaming.api.operators.StreamOperatorParameters) MockEnvironmentBuilder(org.apache.flink.runtime.operators.testutils.MockEnvironmentBuilder) Mockito.when(org.mockito.Mockito.when) Consumer(java.util.function.Consumer) STATE_BACKEND(org.apache.flink.configuration.StateBackendOptions.STATE_BACKEND) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) IndexedInputGate(org.apache.flink.runtime.io.network.partition.consumer.IndexedInputGate) TaskExecutionState(org.apache.flink.runtime.taskmanager.TaskExecutionState) ProcessingTimeCallback(org.apache.flink.api.common.operators.ProcessingTimeService.ProcessingTimeCallback) StreamSource(org.apache.flink.streaming.api.operators.StreamSource) TaskIOMetricGroup(org.apache.flink.runtime.metrics.groups.TaskIOMetricGroup) Arrays(java.util.Arrays) AbstractStreamOperatorFactory(org.apache.flink.streaming.api.operators.AbstractStreamOperatorFactory) CheckpointListener(org.apache.flink.api.common.state.CheckpointListener) OperatorStateBackend(org.apache.flink.runtime.state.OperatorStateBackend) TypeSerializer(org.apache.flink.api.common.typeutils.TypeSerializer) CancelTaskException(org.apache.flink.runtime.execution.CancelTaskException) Executors(java.util.concurrent.Executors) StopMode(org.apache.flink.runtime.io.network.api.StopMode) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) SnapshotType(org.apache.flink.runtime.checkpoint.SnapshotType) TaskStateManager(org.apache.flink.runtime.state.TaskStateManager) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) OneInputStreamOperator(org.apache.flink.streaming.api.operators.OneInputStreamOperator) StateHandleID(org.apache.flink.runtime.state.StateHandleID) RunnableWithException(org.apache.flink.util.function.RunnableWithException) STRING_TYPE_INFO(org.apache.flink.api.common.typeinfo.BasicTypeInfo.STRING_TYPE_INFO) ArrayList(java.util.ArrayList) MEMORY_SEGMENT_SIZE(org.apache.flink.configuration.TaskManagerOptions.MEMORY_SEGMENT_SIZE) Mockito.timeout(org.mockito.Mockito.timeout) OperatorSnapshotFutures(org.apache.flink.streaming.api.operators.OperatorSnapshotFutures) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SourceFunction(org.apache.flink.streaming.api.functions.source.SourceFunction) FutureUtils(org.apache.flink.util.concurrent.FutureUtils) ReadableConfig(org.apache.flink.configuration.ReadableConfig) Matchers.lessThan(org.hamcrest.Matchers.lessThan) ChannelStateWriter(org.apache.flink.runtime.checkpoint.channel.ChannelStateWriter) Nullable(javax.annotation.Nullable) SnapshotResult(org.apache.flink.runtime.state.SnapshotResult) TimeCharacteristic(org.apache.flink.streaming.api.TimeCharacteristic) MailboxDefaultAction(org.apache.flink.streaming.runtime.tasks.mailbox.MailboxDefaultAction) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) StreamStateHandle(org.apache.flink.runtime.state.StreamStateHandle) InMemoryStateChangelogStorage(org.apache.flink.runtime.state.changelog.inmemory.InMemoryStateChangelogStorage) AbstractStreamOperator(org.apache.flink.streaming.api.operators.AbstractStreamOperator) Task(org.apache.flink.runtime.taskmanager.Task) SubtaskState(org.apache.flink.runtime.checkpoint.SubtaskState) TestingUncaughtExceptionHandler(org.apache.flink.util.concurrent.TestingUncaughtExceptionHandler) Assert(org.junit.Assert) CoreMatchers(org.hamcrest.CoreMatchers) CheckpointMetricsBuilder(org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder) SavepointType(org.apache.flink.runtime.checkpoint.SavepointType) SharedStateRegistry(org.apache.flink.runtime.state.SharedStateRegistry) TimeoutException(java.util.concurrent.TimeoutException) StreamTaskUtil.waitTaskIsRunning(org.apache.flink.streaming.util.StreamTaskUtil.waitTaskIsRunning) PartitionDescriptorBuilder(org.apache.flink.runtime.shuffle.PartitionDescriptorBuilder) StringSerializer(org.apache.flink.api.common.typeutils.base.StringSerializer) MapFunction(org.apache.flink.api.common.functions.MapFunction) BUFFER_DEBLOAT_PERIOD(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_PERIOD) DataInputStatus(org.apache.flink.streaming.runtime.io.DataInputStatus) TaskManagerActions(org.apache.flink.runtime.taskmanager.TaskManagerActions) TestLogger(org.apache.flink.util.TestLogger) Assert.fail(org.junit.Assert.fail) MockStateBackend(org.apache.flink.runtime.state.ttl.mock.MockStateBackend) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) TestInputChannel(org.apache.flink.runtime.io.network.partition.consumer.TestInputChannel) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) BUFFER_DEBLOAT_TARGET(org.apache.flink.configuration.TaskManagerOptions.BUFFER_DEBLOAT_TARGET) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) KeyedStateHandle(org.apache.flink.runtime.state.KeyedStateHandle) OperatorSubtaskState(org.apache.flink.runtime.checkpoint.OperatorSubtaskState) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) AbstractStateBackend(org.apache.flink.runtime.state.AbstractStateBackend) StateObjectCollection.singleton(org.apache.flink.runtime.checkpoint.StateObjectCollection.singleton) List(java.util.List) ResultPartitionDeploymentDescriptor(org.apache.flink.runtime.deployment.ResultPartitionDeploymentDescriptor) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) Optional(java.util.Optional) StateBackendFactory(org.apache.flink.runtime.state.StateBackendFactory) CheckpointMetrics(org.apache.flink.runtime.checkpoint.CheckpointMetrics) Environment(org.apache.flink.runtime.execution.Environment) SupplierWithException(org.apache.flink.util.function.SupplierWithException) BiConsumerWithException(org.apache.flink.util.function.BiConsumerWithException) StatePartitionStreamProvider(org.apache.flink.runtime.state.StatePartitionStreamProvider) NoOpTaskManagerActions(org.apache.flink.runtime.taskmanager.NoOpTaskManagerActions) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) SavepointFormatType(org.apache.flink.core.execution.SavepointFormatType) TaskInvokable(org.apache.flink.runtime.jobgraph.tasks.TaskInvokable) UNKNOWN_TASK_CHECKPOINT_NOTIFICATION_FAILURE(org.apache.flink.runtime.checkpoint.CheckpointFailureReason.UNKNOWN_TASK_CHECKPOINT_NOTIFICATION_FAILURE) TestingTaskManagerRuntimeInfo(org.apache.flink.runtime.util.TestingTaskManagerRuntimeInfo) Matchers.anyLong(org.mockito.Matchers.anyLong) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) ExpectedException(org.junit.rules.ExpectedException) InputGate(org.apache.flink.runtime.io.network.partition.consumer.InputGate) Preconditions.checkState(org.apache.flink.util.Preconditions.checkState) StreamOperatorStateContext(org.apache.flink.streaming.api.operators.StreamOperatorStateContext) Matchers(org.hamcrest.Matchers) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) DoneFuture(org.apache.flink.runtime.state.DoneFuture) Rule(org.junit.Rule) Closeable(java.io.Closeable) Collections(java.util.Collections) StateInitializationContext(org.apache.flink.runtime.state.StateInitializationContext) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) StreamMap(org.apache.flink.streaming.api.operators.StreamMap) Test(org.junit.Test)

Example 15 with CheckpointMetaData

use of org.apache.flink.runtime.checkpoint.CheckpointMetaData in project flink by apache.

the class StreamTaskTest method testDecliningCheckpointStreamOperator.

@Test
public void testDecliningCheckpointStreamOperator() throws Exception {
    DummyEnvironment dummyEnvironment = new DummyEnvironment();
    // mock the returned snapshots
    OperatorSnapshotFutures operatorSnapshotResult1 = mock(OperatorSnapshotFutures.class);
    OperatorSnapshotFutures operatorSnapshotResult2 = mock(OperatorSnapshotFutures.class);
    final Exception testException = new ExpectedTestException();
    RunningTask<MockStreamTask> task = runTask(() -> createMockStreamTask(dummyEnvironment, operatorChain(streamOperatorWithSnapshotException(testException), streamOperatorWithSnapshot(operatorSnapshotResult1), streamOperatorWithSnapshot(operatorSnapshotResult2))));
    MockStreamTask streamTask = task.streamTask;
    waitTaskIsRunning(streamTask, task.invocationFuture);
    streamTask.triggerCheckpointAsync(new CheckpointMetaData(42L, 1L), CheckpointOptions.forCheckpointWithDefaultLocation());
    try {
        task.waitForTaskCompletion(false);
    } catch (Exception ex) {
        if (!ExceptionUtils.findThrowable(ex, ExpectedTestException.class).isPresent()) {
            throw ex;
        }
    }
    verify(operatorSnapshotResult1).cancel();
    verify(operatorSnapshotResult2).cancel();
}
Also used : OperatorSnapshotFutures(org.apache.flink.streaming.api.operators.OperatorSnapshotFutures) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) DummyEnvironment(org.apache.flink.runtime.operators.testutils.DummyEnvironment) CheckpointMetaData(org.apache.flink.runtime.checkpoint.CheckpointMetaData) 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) Test(org.junit.Test)

Aggregations

CheckpointMetaData (org.apache.flink.runtime.checkpoint.CheckpointMetaData)47 Test (org.junit.Test)33 CheckpointMetricsBuilder (org.apache.flink.runtime.checkpoint.CheckpointMetricsBuilder)16 CheckpointOptions (org.apache.flink.runtime.checkpoint.CheckpointOptions)15 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)13 IOException (java.io.IOException)12 CheckpointMetrics (org.apache.flink.runtime.checkpoint.CheckpointMetrics)12 MockEnvironment (org.apache.flink.runtime.operators.testutils.MockEnvironment)11 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)11 OperatorSnapshotFutures (org.apache.flink.streaming.api.operators.OperatorSnapshotFutures)11 JobID (org.apache.flink.api.common.JobID)10 CheckpointException (org.apache.flink.runtime.checkpoint.CheckpointException)10 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)10 ExecutionException (java.util.concurrent.ExecutionException)9 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)9 CancelTaskException (org.apache.flink.runtime.execution.CancelTaskException)8 TestTaskStateManager (org.apache.flink.runtime.state.TestTaskStateManager)8 CheckpointResponder (org.apache.flink.runtime.taskmanager.CheckpointResponder)7 FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)7 CompletableFuture (java.util.concurrent.CompletableFuture)6