jiangxin369 commented on code in PR #22670: URL: https://github.com/apache/flink/pull/22670#discussion_r1245014083
########## flink-tests/src/test/java/org/apache/flink/test/checkpointing/ImmediateCheckpointingAfterAllTasksFinishedITCase.java: ########## @@ -0,0 +1,202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.test.checkpointing; + +import org.apache.flink.api.common.restartstrategy.RestartStrategies; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.connector.sink2.Sink; +import org.apache.flink.api.connector.sink2.SinkWriter; +import org.apache.flink.core.execution.SavepointFormatType; +import org.apache.flink.runtime.jobgraph.JobGraph; +import org.apache.flink.runtime.jobgraph.JobVertex; +import org.apache.flink.runtime.jobgraph.SavepointRestoreSettings; +import org.apache.flink.runtime.minicluster.MiniCluster; +import org.apache.flink.runtime.minicluster.MiniClusterConfiguration; +import org.apache.flink.runtime.state.StateSnapshotContext; +import org.apache.flink.runtime.testutils.CommonTestUtils; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.RichSourceFunction; +import org.apache.flink.streaming.api.graph.StreamGraph; +import org.apache.flink.streaming.api.operators.AbstractStreamOperator; +import org.apache.flink.streaming.api.operators.OneInputStreamOperator; +import org.apache.flink.streaming.runtime.streamrecord.StreamRecord; +import org.apache.flink.test.util.AbstractTestBase; + +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +/** + * Tests an immediate checkpoint should be triggered right after all tasks reached the end of data. + */ +public class ImmediateCheckpointingAfterAllTasksFinishedITCase extends AbstractTestBase { + private static final int SMALL_SOURCE_NUM_RECORDS = 20; + private static final int BIG_SOURCE_NUM_RECORDS = 100; + + private StreamExecutionEnvironment env; + + @TempDir private java.nio.file.Path tmpDir; + + @BeforeEach + public void setUp() { + env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setRestartStrategy(RestartStrategies.noRestart()); + env.enableCheckpointing(Long.MAX_VALUE - 1); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + public void testImmediateCheckpointing(int parallelism) throws Exception { + env.setParallelism(parallelism); + StreamGraph streamGraph = getStreamGraph(env); + env.execute(streamGraph); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4}) + public void testRestoreAfterSomeTasksFinished(int parallelism) throws Exception { + env.setParallelism(parallelism); + + final MiniClusterConfiguration cfg = + new MiniClusterConfiguration.Builder() + .withRandomPorts() + .setNumTaskManagers(1) + .setNumSlotsPerTaskManager(4) + .build(); + try (MiniCluster miniCluster = new MiniCluster(cfg)) { + miniCluster.start(); + + env.enableCheckpointing(100); Review Comment: The case is to test the recovery when some tasks are finished. Note that a task can be finished only if it completes the final checkpoint if we keep the checkpointing interval as Long.MAX, these tasks can never finished. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
