StefanRRichter commented on a change in pull request #7813: [FLINK-10712] 
Support to restore state when using RestartPipelinedRegionStrategy
URL: https://github.com/apache/flink/pull/7813#discussion_r259846633
 
 

 ##########
 File path: 
flink-tests/src/test/java/org/apache/flink/test/checkpointing/RegionFailoverITCase.java
 ##########
 @@ -0,0 +1,307 @@
+/*
+ * 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.functions.MapFunction;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.state.ListState;
+import org.apache.flink.api.common.state.ListStateDescriptor;
+import org.apache.flink.client.program.ClusterClient;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.runtime.jobgraph.JobGraph;
+import org.apache.flink.runtime.state.CheckpointListener;
+import org.apache.flink.runtime.state.FunctionInitializationContext;
+import org.apache.flink.runtime.state.FunctionSnapshotContext;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.CheckpointingMode;
+import org.apache.flink.streaming.api.checkpoint.CheckpointedFunction;
+import org.apache.flink.streaming.api.environment.CheckpointConfig;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import 
org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+import org.apache.flink.util.TestLogger;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import java.util.stream.StreamSupport;
+
+/**
+ * Tests for region failover with multi regions.
+ */
+public class RegionFailoverITCase extends TestLogger {
+
+       private static final int FAIL_BASE = 1000;
+       private static final int NUM_OF_REGIONS = 3;
+       private static final Set<Integer> EXPECTED_INDICES = IntStream.range(0, 
NUM_OF_REGIONS).boxed().collect(Collectors.toSet());
+       private static final int NUM_OF_RESTARTS = 3;
+       private static final int NUM_ELEMENTS = FAIL_BASE * 10;
+
+       private static volatile long lastCompletedCheckpointId = 0;
+       private static volatile int numCompletedCheckpoints = 0;
+       private static volatile AtomicInteger jobFailedCnt = new 
AtomicInteger(0);
+
+       private static Map<Long, Integer> snapshotIndicesOfSubTask = new 
HashMap<>();
+
+       private static MiniClusterWithClientResource cluster;
+
+       private static boolean restoredState = false;
+
+       @ClassRule
+       public static final TemporaryFolder TEMPORARY_FOLDER = new 
TemporaryFolder();
+
+       @Before
+       public void setup() throws Exception {
+               Configuration configuration = new Configuration();
+               
configuration.setString(JobManagerOptions.EXECUTION_FAILOVER_STRATEGY, 
"region");
+
+               cluster = new MiniClusterWithClientResource(
+                       new MiniClusterResourceConfiguration.Builder()
+                               .setConfiguration(configuration)
+                               .setNumberTaskManagers(2)
+                               .setNumberSlotsPerTaskManager(2).build());
+               cluster.before();
+               jobFailedCnt.set(0);
+               numCompletedCheckpoints = 0;
+       }
+
+       @AfterClass
+       public static void shutDownExistingCluster() {
+               if (cluster != null) {
+                       cluster.after();
+                       cluster = null;
+               }
+       }
+
+       /**
+        * Tests that a simple job (Source -> Map) with multi regions could 
restore with operator state.
 
 Review comment:
   This test does not check for restore of keyed state. Maybe we can easily 
also include keyed state if we use `DataStreamUtils::reinterpretAsKeyedStream` 
and soures that make sure they follow the right subtask index assignment 
pattern, e.g. only produce elements with the right hash code to be routed to 
their downstream task.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to