You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/07/03 13:57:32 UTC

[GitHub] [flink] zentol commented on a change in pull request #8971: [FLINK-13019][coordination][tests] IT test for fine-grained recovery

zentol commented on a change in pull request #8971: [FLINK-13019][coordination][tests] IT test for fine-grained recovery
URL: https://github.com/apache/flink/pull/8971#discussion_r299965541
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/test/recovery/BatchFineGrainedRecoveryITCase.java
 ##########
 @@ -0,0 +1,317 @@
+/*
+ * 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.recovery;
+
+import org.apache.flink.api.common.ExecutionMode;
+import org.apache.flink.api.common.JobExecutionResult;
+import org.apache.flink.api.common.accumulators.Accumulator;
+import org.apache.flink.api.common.accumulators.ListAccumulator;
+import org.apache.flink.api.common.functions.MapPartitionFunction;
+import org.apache.flink.api.common.functions.RichFlatMapFunction;
+import org.apache.flink.api.common.io.NonParallelInput;
+import org.apache.flink.api.common.io.RichOutputFormat;
+import org.apache.flink.api.common.operators.util.NonRichGenericInputFormat;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.api.java.DataSet;
+import org.apache.flink.api.java.ExecutionEnvironment;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.JobManagerOptions;
+import org.apache.flink.runtime.minicluster.TestingMiniCluster;
+import org.apache.flink.runtime.minicluster.TestingMiniClusterConfiguration.Builder;
+import org.apache.flink.test.util.TestEnvironment;
+import org.apache.flink.util.Collector;
+import org.apache.flink.util.FlinkRuntimeException;
+import org.apache.flink.util.TestLogger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.IntStream;
+
+import static org.apache.flink.configuration.JobManagerOptions.FORCE_PARTITION_RELEASE_ON_CONSUMPTION;
+import static org.apache.flink.runtime.executiongraph.failover.FailoverStrategyLoader.PIPELINED_REGION_RESTART_STRATEGY_NAME;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class BatchFineGrainedRecoveryITCase extends TestLogger {
+	private static final int EMITTED_RECORD_NUMBER = 1000;
+	private static final int MAX_FAILURE_NUMBER = 10;
+	private static final int MAP_NUMBER = 3;
+	private static final String CHECK_ACC_NAME = "CHECK_ACC_NAME";
+	private static final int[] EXPECTED_JOB_OUTPUT = IntStream.range(MAP_NUMBER, EMITTED_RECORD_NUMBER + MAP_NUMBER).toArray();
+
+	private static TestingMiniCluster miniCluster;
+
+	@Before
+	public void setup() throws Exception {
+		Configuration configuration = new Configuration();
+		configuration.setBoolean(FORCE_PARTITION_RELEASE_ON_CONSUMPTION, false);
+		configuration.setString(JobManagerOptions.EXECUTION_FAILOVER_STRATEGY, PIPELINED_REGION_RESTART_STRATEGY_NAME);
+
+		miniCluster = new TestingMiniCluster(
+			new Builder()
+				.setNumTaskManagers(MAP_NUMBER)
+				.setNumSlotsPerTaskManager(1)
+				.setConfiguration(configuration)
+				.build(),
+			null);
+
+		miniCluster.start();
+	}
+
+	@After
+	public void teardown() throws Exception {
+		if (miniCluster != null) {
+			miniCluster.close();
+		}
+	}
+
+	@Test
+	public void testProgram() throws Exception {
+		ExecutionEnvironment env = createExecutionEnvironment();
+
+		StaticFailureCounter.reset();
+		StaticMapFailureTracker.reset();
+
+		FailureStrategy failureStrategy = new RandomExceptionFailureStrategy(1, EMITTED_RECORD_NUMBER);
+
+		DataSet<Integer> input = env.createInput(FixedRecordNumberInputFormat.emitFixedRecordNumber());
+		for (int i = 0; i < MAP_NUMBER; i++) {
+			input = input.flatMap(new TestMapper(StaticMapFailureTracker.addNewMap(), failureStrategy));
+			input = disableChaining(input, Integer.class);
+		}
+		input.output(new AccumulatingRichOutputFormat());
+
+		verifyResult(env.execute());
+
+		StaticMapFailureTracker.verify();
+	}
+
+	private static ExecutionEnvironment createExecutionEnvironment() {
+		@SuppressWarnings("StaticVariableUsedBeforeInitialization")
+		ExecutionEnvironment env = new TestEnvironment(miniCluster, 1, true);
+		env.setRestartStrategy(RestartStrategies.fixedDelayRestart(MAX_FAILURE_NUMBER, Time.milliseconds(10)));
+		env.getConfig().setExecutionMode(ExecutionMode.BATCH_FORCED);
+		return env;
+	}
+
+	private static <T> DataSet<T> disableChaining(
+			DataSet<T> input,
+			@SuppressWarnings("SameParameterValue") Class<T> cl) {
+		return input.mapPartition((MapPartitionFunction<T, T>) (ns, out) -> ns.forEach(out::collect)).returns(cl);
+	}
+
+	private static void verifyResult(JobExecutionResult result) {
+		Collection<Integer> accumulatorResult = result.getAccumulatorResult(CHECK_ACC_NAME);
+		int[] output = accumulatorResult.stream().mapToInt(i -> i).toArray();
+		assertThat(output, is(EXPECTED_JOB_OUTPUT));
+	}
+
+	private enum StaticMapFailureTracker {
+		;
+
+		private static final List<AtomicInteger> mapRestarts = new ArrayList<>(10);
+		private static final List<AtomicInteger> expectedMapRestarts = new ArrayList<>(10);
+		private static final List<AtomicInteger> mapFailures = new ArrayList<>(10);
+
+		private static void reset() {
+			mapRestarts.clear();
+			expectedMapRestarts.clear();
 
 Review comment:
   should also reset `mapFailures`

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services