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 2022/10/06 08:12:55 UTC

[GitHub] [flink] afedulov commented on a diff in pull request #20757: [FLINK-27919] Add FLIP-27-based source for data generation (FLIP-238)

afedulov commented on code in PR #20757:
URL: https://github.com/apache/flink/pull/20757#discussion_r988689902


##########
flink-tests/src/test/java/org/apache/flink/api/connector/source/lib/DataGeneratorSourceITCase.java:
##########
@@ -0,0 +1,255 @@
+/*
+ * 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.connector.source.lib;
+
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.common.functions.RichMapFunction;
+import org.apache.flink.api.common.state.CheckpointListener;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.connector.source.SourceReaderContext;
+import org.apache.flink.api.connector.source.SourceReaderFactory;
+import org.apache.flink.api.connector.source.datagen.DataGeneratorSource;
+import org.apache.flink.api.connector.source.datagen.GeneratorFunction;
+import org.apache.flink.api.connector.source.lib.util.GatedRateLimiter;
+import org.apache.flink.api.connector.source.lib.util.GeneratingIteratorSourceReader;
+import org.apache.flink.api.connector.source.lib.util.RateLimitedSourceReader;
+import org.apache.flink.api.connector.source.lib.util.RateLimiter;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.datastream.DataStreamSource;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.test.junit5.MiniClusterExtension;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.LongStream;
+
+import static java.util.stream.Collectors.summingInt;
+import static org.apache.flink.core.testutils.FlinkAssertions.anyCauseMatches;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
+
+/** An integration test for {@code DataGeneratorSource}. */
+public class DataGeneratorSourceITCase extends TestLogger {
+
+    private static final int PARALLELISM = 4;
+
+    @RegisterExtension
+    private static final MiniClusterExtension miniClusterExtension =
+            new MiniClusterExtension(
+                    new MiniClusterResourceConfiguration.Builder()
+                            .setNumberTaskManagers(1)
+                            .setNumberSlotsPerTaskManager(PARALLELISM)
+                            .build());
+
+    // ------------------------------------------------------------------------
+
+    @Test
+    @DisplayName("Combined results of parallel source readers produce the expected sequence.")
+    public void testParallelSourceExecution() throws Exception {
+        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+        env.setParallelism(PARALLELISM);
+
+        final DataStream<Long> stream = getGeneratorSourceStream(index -> index, env, 1_000L);
+
+        final List<Long> result = stream.executeAndCollect(10000);
+
+        assertThat(result).containsExactlyInAnyOrderElementsOf(range(0, 999));
+    }
+
+    @Test
+    @DisplayName("Generator function can be instantiated as an anonymous class.")
+    public void testParallelSourceExecutionWithAnonymousClass() throws Exception {
+        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+        env.setParallelism(PARALLELISM);
+
+        GeneratorFunction<Long, Long> generatorFunction =
+                new GeneratorFunction<Long, Long>() {
+
+                    @Override
+                    public Long map(Long value) {
+                        return value;
+                    }
+                };
+
+        final DataStream<Long> stream = getGeneratorSourceStream(generatorFunction, env, 1_000L);
+
+        final List<Long> result = stream.executeAndCollect(10000);
+
+        assertThat(result).containsExactlyInAnyOrderElementsOf(range(0, 999));
+    }
+
+    @Test
+    @DisplayName("Exceptions from the generator function are not 'swallowed'.")
+    public void testFailingGeneratorFunction() throws Exception {
+        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
+        env.setParallelism(PARALLELISM);
+
+        GeneratorFunction<Long, Long> generatorFunction =
+                value -> {
+                    throw new Exception("boom");
+                };
+
+        final DataStream<Long> stream = getGeneratorSourceStream(generatorFunction, env, 1_000L);
+
+        assertThatThrownBy(
+                        () -> {
+                            stream.executeAndCollect(10000);
+                        })
+                .satisfies(anyCauseMatches("exception on this input:"))
+                .satisfies(anyCauseMatches("boom"));
+    }
+
+    @Test
+    @DisplayName("Exceptions from the generator function initialization are not 'swallowed'.")
+    public void testFailingGeneratorFunctionInitialization() throws Exception {

Review Comment:
   Disabled.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org