|
24 | 24 | import org.apache.flink.api.common.SupportsConcurrentExecutionAttempts;
|
25 | 25 | import org.apache.flink.api.common.eventtime.WatermarkStrategy;
|
26 | 26 | import org.apache.flink.api.common.functions.FilterFunction;
|
| 27 | +import org.apache.flink.api.common.functions.FlatMapFunction; |
27 | 28 | import org.apache.flink.api.common.functions.MapFunction;
|
28 | 29 | import org.apache.flink.api.common.functions.ReduceFunction;
|
29 | 30 | import org.apache.flink.api.common.io.InputFormat;
|
|
119 | 120 | import org.apache.flink.streaming.runtime.tasks.SourceOperatorStreamTask;
|
120 | 121 | import org.apache.flink.streaming.util.TestAnyModeReadingStreamOperator;
|
121 | 122 | import org.apache.flink.util.AbstractID;
|
| 123 | +import org.apache.flink.util.Collector; |
122 | 124 | import org.apache.flink.util.SerializedValue;
|
123 | 125 |
|
124 | 126 | import org.apache.flink.shaded.guava33.com.google.common.collect.Iterables;
|
|
155 | 157 | import static org.apache.flink.util.Preconditions.checkNotNull;
|
156 | 158 | import static org.assertj.core.api.Assertions.assertThat;
|
157 | 159 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
| 160 | +import static org.assertj.core.api.Assertions.fail; |
158 | 161 |
|
159 | 162 | /**
|
160 | 163 | * Tests for {@link StreamingJobGraphGenerator} and {@link AdaptiveGraphManager}.
|
@@ -2163,6 +2166,32 @@ void testOutputFormatSupportConcurrentExecutionAttempts() {
|
2163 | 2166 | new TestingOutputFormatSupportConcurrentExecutionAttempts<>(), true);
|
2164 | 2167 | }
|
2165 | 2168 |
|
| 2169 | + @Test |
| 2170 | + void testEnableAsyncStateForSyncOperatorThrowException() throws Exception { |
| 2171 | + final StreamExecutionEnvironment env = |
| 2172 | + StreamExecutionEnvironment.getExecutionEnvironment(new Configuration()); |
| 2173 | + try { |
| 2174 | + env.fromData(1, 2, 3, 4, 5) |
| 2175 | + .keyBy(k -> k) |
| 2176 | + .flatMap( |
| 2177 | + new FlatMapFunction<Integer, Integer>() { |
| 2178 | + @Override |
| 2179 | + public void flatMap(Integer value, Collector<Integer> out) |
| 2180 | + throws Exception { |
| 2181 | + out.collect(value); |
| 2182 | + } |
| 2183 | + }) |
| 2184 | + .enableAsyncState() |
| 2185 | + .print(); |
| 2186 | + fail("Enabling async state for synchronous operators is forbidden."); |
| 2187 | + } catch (UnsupportedOperationException e) { |
| 2188 | + assertThat(e.getMessage()) |
| 2189 | + .isEqualTo( |
| 2190 | + "The transformation does not support " |
| 2191 | + + "async state, or you are enabling the async state without a keyed context (not behind a keyBy())."); |
| 2192 | + } |
| 2193 | + } |
| 2194 | + |
2166 | 2195 | private void testWhetherOutputFormatSupportsConcurrentExecutionAttempts(
|
2167 | 2196 | OutputFormat<Integer> outputFormat, boolean isSupported) {
|
2168 | 2197 | final StreamExecutionEnvironment env =
|
|
0 commit comments