dawidwys commented on a change in pull request #13891:
URL: https://github.com/apache/flink/pull/13891#discussion_r516034264



##########
File path: 
flink-tests/src/test/java/org/apache/flink/api/datastream/DataStreamBatchExecutionITCase.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.api.datastream;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.contains;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Integration test for {@link 
org.apache.flink.api.common.RuntimeExecutionMode#BATCH} execution on
+ * the DataStream API.
+ *
+ * <p>We use a {@link MiniClusterWithClientResource} with a single TaskManager 
with 1 slot to verify
+ * that programs in BATCH execution mode can be executed in stages.
+ */
+public class DataStreamBatchExecutionITCase {
+       private static final int DEFAULT_PARALLELISM = 1;
+
+       @ClassRule
+       public static MiniClusterWithClientResource miniClusterResource = new 
MiniClusterWithClientResource(
+                       new MiniClusterResourceConfiguration.Builder()
+                                       .setNumberTaskManagers(1)
+                                       
.setNumberSlotsPerTaskManager(DEFAULT_PARALLELISM)
+                                       .build());
+
+       /**
+        * We induce a failure in the last mapper. In BATCH execution mode the 
part of the pipeline
+        * before the key-by should not be re-executed. Only the part after 
that will restart. We check
+        * that by suffixing the attempt number to records and asserting the 
correct number.
+        */
+       @Test
+       public void batchFailoverWithKeyByBarrier() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .keyBy(in -> in)
+                               .map(new SuffixAttemptId("c"))
+                               .map(new OnceFailingMapper("d"));
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"
+               // suffix
+               assertThat(result, contains("ciao-a0-b0-c1-d1", 
"ciao-a0-b0-c1-d1"));
+       }
+
+       @Ignore
+       @Test
+       public void stagedExecutionWithDifferentSlotGroups() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .map(new SuffixAttemptId("c"))
+                               .slotSharingGroup("foo")
+                               .map(new SuffixAttemptId("d"))
+                               .slotSharingGroup("bar");
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"
+               // suffix
+               assertThat(result, contains("ciao-a0-b0-c0-d0", 
"ciao-a0-b0-c0-d0"));
+       }
+
+       private StreamExecutionEnvironment getExecutionEnvironment() {
+               final StreamExecutionEnvironment env = 
StreamExecutionEnvironment.getExecutionEnvironment();
+
+               Configuration config = new Configuration();
+               config.set(ExecutionOptions.RUNTIME_MODE, 
RuntimeExecutionMode.BATCH);
+               env.configure(config, 
DataStreamBatchExecutionITCase.class.getClassLoader());
+
+               env.setParallelism(1);
+               env.setRestartStrategy(RestartStrategies.fixedDelayRestart(10, 
Time.milliseconds(1)));
+
+               // trick the collecting sink into working even in the face of 
failures 🙏

Review comment:
       huh, emojis in comments, that's new ;) didn't know you can do that, nice

##########
File path: 
flink-tests/src/test/java/org/apache/flink/api/datastream/DataStreamBatchExecutionITCase.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.api.datastream;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.contains;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Integration test for {@link 
org.apache.flink.api.common.RuntimeExecutionMode#BATCH} execution on
+ * the DataStream API.
+ *
+ * <p>We use a {@link MiniClusterWithClientResource} with a single TaskManager 
with 1 slot to verify
+ * that programs in BATCH execution mode can be executed in stages.
+ */
+public class DataStreamBatchExecutionITCase {
+       private static final int DEFAULT_PARALLELISM = 1;
+
+       @ClassRule
+       public static MiniClusterWithClientResource miniClusterResource = new 
MiniClusterWithClientResource(
+                       new MiniClusterResourceConfiguration.Builder()
+                                       .setNumberTaskManagers(1)
+                                       
.setNumberSlotsPerTaskManager(DEFAULT_PARALLELISM)
+                                       .build());
+
+       /**
+        * We induce a failure in the last mapper. In BATCH execution mode the 
part of the pipeline
+        * before the key-by should not be re-executed. Only the part after 
that will restart. We check
+        * that by suffixing the attempt number to records and asserting the 
correct number.
+        */
+       @Test
+       public void batchFailoverWithKeyByBarrier() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .keyBy(in -> in)
+                               .map(new SuffixAttemptId("c"))
+                               .map(new OnceFailingMapper("d"));
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"
+               // suffix
+               assertThat(result, contains("ciao-a0-b0-c1-d1", 
"ciao-a0-b0-c1-d1"));
+       }
+
+       @Ignore
+       @Test
+       public void stagedExecutionWithDifferentSlotGroups() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .map(new SuffixAttemptId("c"))
+                               .slotSharingGroup("foo")
+                               .map(new SuffixAttemptId("d"))
+                               .slotSharingGroup("bar");
+
+               List<String> result = mapped.executeAndCollect(2);

Review comment:
       nit: Do we need to add the limit? I think it's an unnecessary trap, if 
we add more incoming records in the test.

##########
File path: 
flink-tests/src/test/java/org/apache/flink/api/datastream/DataStreamBatchExecutionITCase.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.api.datastream;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.contains;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Integration test for {@link 
org.apache.flink.api.common.RuntimeExecutionMode#BATCH} execution on

Review comment:
       nit: Personally I prefer to import links. 
   ```suggestion
    * Integration test for {@link RuntimeExecutionMode#BATCH} execution on
   ```

##########
File path: 
flink-tests/src/test/java/org/apache/flink/api/datastream/DataStreamBatchExecutionITCase.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.api.datastream;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.contains;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Integration test for {@link 
org.apache.flink.api.common.RuntimeExecutionMode#BATCH} execution on
+ * the DataStream API.
+ *
+ * <p>We use a {@link MiniClusterWithClientResource} with a single TaskManager 
with 1 slot to verify
+ * that programs in BATCH execution mode can be executed in stages.
+ */
+public class DataStreamBatchExecutionITCase {
+       private static final int DEFAULT_PARALLELISM = 1;
+
+       @ClassRule
+       public static MiniClusterWithClientResource miniClusterResource = new 
MiniClusterWithClientResource(
+                       new MiniClusterResourceConfiguration.Builder()
+                                       .setNumberTaskManagers(1)
+                                       
.setNumberSlotsPerTaskManager(DEFAULT_PARALLELISM)
+                                       .build());
+
+       /**
+        * We induce a failure in the last mapper. In BATCH execution mode the 
part of the pipeline
+        * before the key-by should not be re-executed. Only the part after 
that will restart. We check
+        * that by suffixing the attempt number to records and asserting the 
correct number.
+        */
+       @Test
+       public void batchFailoverWithKeyByBarrier() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .keyBy(in -> in)
+                               .map(new SuffixAttemptId("c"))
+                               .map(new OnceFailingMapper("d"));
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"
+               // suffix
+               assertThat(result, contains("ciao-a0-b0-c1-d1", 
"ciao-a0-b0-c1-d1"));
+       }
+
+       @Ignore
+       @Test
+       public void stagedExecutionWithDifferentSlotGroups() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .map(new SuffixAttemptId("c"))
+                               .slotSharingGroup("foo")
+                               .map(new SuffixAttemptId("d"))
+                               .slotSharingGroup("bar");
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"

Review comment:
       The comment is definitely incorrect.
   
   What's this test verifying? 

##########
File path: 
flink-tests/src/test/java/org/apache/flink/api/datastream/DataStreamBatchExecutionITCase.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.api.datastream;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.contains;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Integration test for {@link 
org.apache.flink.api.common.RuntimeExecutionMode#BATCH} execution on
+ * the DataStream API.
+ *
+ * <p>We use a {@link MiniClusterWithClientResource} with a single TaskManager 
with 1 slot to verify
+ * that programs in BATCH execution mode can be executed in stages.
+ */
+public class DataStreamBatchExecutionITCase {
+       private static final int DEFAULT_PARALLELISM = 1;
+
+       @ClassRule
+       public static MiniClusterWithClientResource miniClusterResource = new 
MiniClusterWithClientResource(
+                       new MiniClusterResourceConfiguration.Builder()
+                                       .setNumberTaskManagers(1)
+                                       
.setNumberSlotsPerTaskManager(DEFAULT_PARALLELISM)
+                                       .build());
+
+       /**
+        * We induce a failure in the last mapper. In BATCH execution mode the 
part of the pipeline
+        * before the key-by should not be re-executed. Only the part after 
that will restart. We check
+        * that by suffixing the attempt number to records and asserting the 
correct number.
+        */
+       @Test
+       public void batchFailoverWithKeyByBarrier() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .keyBy(in -> in)
+                               .map(new SuffixAttemptId("c"))
+                               .map(new OnceFailingMapper("d"));
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"
+               // suffix
+               assertThat(result, contains("ciao-a0-b0-c1-d1", 
"ciao-a0-b0-c1-d1"));
+       }
+
+       @Ignore
+       @Test
+       public void stagedExecutionWithDifferentSlotGroups() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .map(new SuffixAttemptId("c"))
+                               .slotSharingGroup("foo")
+                               .map(new SuffixAttemptId("d"))
+                               .slotSharingGroup("bar");
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"

Review comment:
       The comment is definitely incorrect, there's no `keyBy`.
   
   What's this test verifying? 

##########
File path: 
flink-tests/src/test/java/org/apache/flink/api/datastream/DataStreamBatchExecutionITCase.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.api.datastream;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.contains;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Integration test for {@link 
org.apache.flink.api.common.RuntimeExecutionMode#BATCH} execution on
+ * the DataStream API.
+ *
+ * <p>We use a {@link MiniClusterWithClientResource} with a single TaskManager 
with 1 slot to verify
+ * that programs in BATCH execution mode can be executed in stages.
+ */
+public class DataStreamBatchExecutionITCase {
+       private static final int DEFAULT_PARALLELISM = 1;
+
+       @ClassRule
+       public static MiniClusterWithClientResource miniClusterResource = new 
MiniClusterWithClientResource(
+                       new MiniClusterResourceConfiguration.Builder()
+                                       .setNumberTaskManagers(1)
+                                       
.setNumberSlotsPerTaskManager(DEFAULT_PARALLELISM)
+                                       .build());
+
+       /**
+        * We induce a failure in the last mapper. In BATCH execution mode the 
part of the pipeline
+        * before the key-by should not be re-executed. Only the part after 
that will restart. We check
+        * that by suffixing the attempt number to records and asserting the 
correct number.
+        */
+       @Test
+       public void batchFailoverWithKeyByBarrier() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .keyBy(in -> in)
+                               .map(new SuffixAttemptId("c"))
+                               .map(new OnceFailingMapper("d"));
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"
+               // suffix
+               assertThat(result, contains("ciao-a0-b0-c1-d1", 
"ciao-a0-b0-c1-d1"));
+       }
+
+       @Ignore
+       @Test
+       public void stagedExecutionWithDifferentSlotGroups() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .map(new SuffixAttemptId("c"))
+                               .slotSharingGroup("foo")
+                               .map(new SuffixAttemptId("d"))
+                               .slotSharingGroup("bar");
+
+               List<String> result = mapped.executeAndCollect(2);

Review comment:
       Ah, ok I have missed the different return type. I am fine with using the 
limit then.
   
   Another option is to use `CollectionUtil.iteratorToList()`

##########
File path: 
flink-tests/src/test/java/org/apache/flink/api/datastream/DataStreamBatchExecutionITCase.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.api.datastream;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.contains;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Integration test for {@link 
org.apache.flink.api.common.RuntimeExecutionMode#BATCH} execution on
+ * the DataStream API.
+ *
+ * <p>We use a {@link MiniClusterWithClientResource} with a single TaskManager 
with 1 slot to verify
+ * that programs in BATCH execution mode can be executed in stages.
+ */
+public class DataStreamBatchExecutionITCase {
+       private static final int DEFAULT_PARALLELISM = 1;
+
+       @ClassRule
+       public static MiniClusterWithClientResource miniClusterResource = new 
MiniClusterWithClientResource(
+                       new MiniClusterResourceConfiguration.Builder()
+                                       .setNumberTaskManagers(1)
+                                       
.setNumberSlotsPerTaskManager(DEFAULT_PARALLELISM)
+                                       .build());
+
+       /**
+        * We induce a failure in the last mapper. In BATCH execution mode the 
part of the pipeline
+        * before the key-by should not be re-executed. Only the part after 
that will restart. We check
+        * that by suffixing the attempt number to records and asserting the 
correct number.
+        */
+       @Test
+       public void batchFailoverWithKeyByBarrier() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .keyBy(in -> in)
+                               .map(new SuffixAttemptId("c"))
+                               .map(new OnceFailingMapper("d"));
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"
+               // suffix
+               assertThat(result, contains("ciao-a0-b0-c1-d1", 
"ciao-a0-b0-c1-d1"));
+       }
+
+       @Ignore
+       @Test
+       public void stagedExecutionWithDifferentSlotGroups() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .map(new SuffixAttemptId("c"))
+                               .slotSharingGroup("foo")
+                               .map(new SuffixAttemptId("d"))
+                               .slotSharingGroup("bar");
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"

Review comment:
       sorry, missed the description... will look into the test again

##########
File path: 
flink-tests/src/test/java/org/apache/flink/api/datastream/DataStreamBatchExecutionITCase.java
##########
@@ -0,0 +1,159 @@
+/*
+ * 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.api.datastream;
+
+import org.apache.flink.api.common.RuntimeExecutionMode;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.ExecutionOptions;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.test.util.MiniClusterWithClientResource;
+
+import org.junit.ClassRule;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.contains;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Integration test for {@link 
org.apache.flink.api.common.RuntimeExecutionMode#BATCH} execution on
+ * the DataStream API.
+ *
+ * <p>We use a {@link MiniClusterWithClientResource} with a single TaskManager 
with 1 slot to verify
+ * that programs in BATCH execution mode can be executed in stages.
+ */
+public class DataStreamBatchExecutionITCase {
+       private static final int DEFAULT_PARALLELISM = 1;
+
+       @ClassRule
+       public static MiniClusterWithClientResource miniClusterResource = new 
MiniClusterWithClientResource(
+                       new MiniClusterResourceConfiguration.Builder()
+                                       .setNumberTaskManagers(1)
+                                       
.setNumberSlotsPerTaskManager(DEFAULT_PARALLELISM)
+                                       .build());
+
+       /**
+        * We induce a failure in the last mapper. In BATCH execution mode the 
part of the pipeline
+        * before the key-by should not be re-executed. Only the part after 
that will restart. We check
+        * that by suffixing the attempt number to records and asserting the 
correct number.
+        */
+       @Test
+       public void batchFailoverWithKeyByBarrier() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .keyBy(in -> in)
+                               .map(new SuffixAttemptId("c"))
+                               .map(new OnceFailingMapper("d"));
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"
+               // suffix
+               assertThat(result, contains("ciao-a0-b0-c1-d1", 
"ciao-a0-b0-c1-d1"));
+       }
+
+       @Ignore
+       @Test
+       public void stagedExecutionWithDifferentSlotGroups() throws Exception {
+
+               final StreamExecutionEnvironment env = 
getExecutionEnvironment();
+
+               DataStreamSource<String> source = env.fromElements("ciao", 
"ciao");
+
+               SingleOutputStreamOperator<String> mapped = source
+                               .map(new SuffixAttemptId("a"))
+                               .map(new SuffixAttemptId("b"))
+                               .map(new SuffixAttemptId("c"))
+                               .slotSharingGroup("foo")
+                               .map(new SuffixAttemptId("d"))
+                               .slotSharingGroup("bar");
+
+               List<String> result = mapped.executeAndCollect(2);
+
+               // only the operators after the key-by "barrier" are restarted 
and will have the "attempt 1"

Review comment:
       Ok, now I understand the second test. I am not sure though we should do 
something about it now.
   
   I think it highly depends on the communication with the ResourceManager. I 
think it would require the changes from 
[FLIP-138](https://cwiki.apache.org/confluence/display/FLINK/FLIP-138%3A+Declarative+Resource+management).
 A proper way I see it is that if the `Scheduler` is notified there is not 
enough resources available, it should split the graph by replacing some of the 
`PIPELINED` shuffles with `BLOCKING` shuffles at the same time introducing new 
scheduling regions.
   
   In the current codebase, imo, it is an expected behaviour.




----------------------------------------------------------------
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:
[email protected]


Reply via email to