You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "XComp (via GitHub)" <gi...@apache.org> on 2023/03/16 12:21:37 UTC

[GitHub] [flink] XComp commented on a diff in pull request #21971: [FLINK-31084][connectors/dataGen] Add default value for dataGen seque…

XComp commented on code in PR #21971:
URL: https://github.com/apache/flink/pull/21971#discussion_r1118862415


##########
flink-table/flink-table-api-java-bridge/src/test/java/org/apache/flink/table/factories/DataGenTableSourceFactoryTest.java:
##########
@@ -264,7 +267,68 @@ void testSequenceCheckpointRestore() throws Exception {
     }
 
     @Test
-    void testLackStartForSequence() {
+    void testDefaultValueForSequence() {
+        DescriptorProperties descriptor = new DescriptorProperties();
+        descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
+        descriptor.putString(
+                DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND,
+                DataGenConnectorOptionsUtil.SEQUENCE);
+
+        DataGenTableSource source =
+                (DataGenTableSource)
+                        createTableSource(
+                                ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())),
+                                descriptor.asMap());
+        DataGenerator<?>[] fieldGenerators = source.getFieldGenerators();
+        SequenceGenerator<?> fieldGenerator = (SequenceGenerator<?>) fieldGenerators[0];
+        long start = fieldGenerator.getStart();
+        long end = fieldGenerator.getEnd();
+
+        Assertions.assertThat(0)
+                .describedAs("The default start value should be 0")
+                .isEqualTo(start);
+        Assertions.assertThat(Integer.MAX_VALUE)
+                .describedAs("The default start value should be Integer.MAX_VALUE")
+                .isEqualTo(end);
+    }
+
+    @Test
+    void testStartEndForSequence() {
+        DescriptorProperties descriptor = new DescriptorProperties();
+        descriptor.putString(FactoryUtil.CONNECTOR.key(), "datagen");
+        descriptor.putString(
+                DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.KIND,
+                DataGenConnectorOptionsUtil.SEQUENCE);
+        final int setupStart = 10;
+        descriptor.putLong(
+                DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.START,
+                setupStart);
+        final int setupEnd = 100;
+        descriptor.putLong(
+                DataGenConnectorOptionsUtil.FIELDS + ".f0." + DataGenConnectorOptionsUtil.END,
+                setupEnd);
+
+        DataGenTableSource source =
+                (DataGenTableSource)
+                        createTableSource(
+                                ResolvedSchema.of(Column.physical("f0", DataTypes.BIGINT())),
+                                descriptor.asMap());
+        DataGenerator<?>[] fieldGenerators = source.getFieldGenerators();
+        SequenceGenerator<?> fieldGenerator = (SequenceGenerator<?>) fieldGenerators[0];
+        long start = fieldGenerator.getStart();
+        long end = fieldGenerator.getEnd();
+
+        Assertions.assertThat(setupStart)
+                .describedAs("The default start value should be " + setupStart)
+                .isEqualTo(start);
+        Assertions.assertThat(setupEnd)
+                .describedAs("The default start value should be " + setupEnd)
+                .isEqualTo(end);
+    }
+
+    @Test
+    void testCornerCaseForSequence() {
+        // An example of testing that the end value is greater than the start value

Review Comment:
   We could make two test methods out of this one. A Junit test should usually only test a single issue. On another note, usually, comments are not necessary but should be replaced by assert messages instead. That way, the comment also serves as a description for the assert in case the assert fails.



-- 
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