danny0405 commented on code in PR #19392:
URL: https://github.com/apache/hudi/pull/19392#discussion_r3670924587


##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/streamer/TestFlinkStreamerConfig.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.hudi.streamer;
+
+import org.apache.hudi.common.model.WriteOperationType;
+import org.apache.hudi.configuration.FlinkOptions;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.ParameterException;
+import org.apache.flink.configuration.Configuration;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests for {@link FlinkStreamerConfig}.
+ */
+class TestFlinkStreamerConfig {
+
+  @TempDir
+  Path tempDir;
+
+  @Test
+  void testParseAndDeriveFlinkConfiguration() {
+    FlinkStreamerConfig config = parse(
+        "--kafka-topic", "orders",
+        "--kafka-group-id", "flink-writers",
+        "--kafka-bootstrap-servers", "broker:9092",
+        "--target-base-path", tempDir.toString(),
+        "--target-table", "orders_hudi",
+        "--table-type", "merge_on_read",
+        "--op", "INSERT",
+        "--record-key-field", "order_id",
+        "--partition-path-field", "order_date",
+        "--source-ordering-fields", "event_ts,seq_no",
+        "--instant-retry-times", "7",
+        "--instant-retry-interval", "250",
+        "--filter-dupes",
+        "--commit-on-errors",
+        "--metadata-enabled",
+        "--write-rate-limit", "500",
+        "--write-task-num", "6",
+        "--bucket-assign-num", "5",
+        "--index-bootstrap-num", "4",
+        "--source-avro-schema-path", "file:///tmp/source.avsc",
+        "--source-avro-schema", 
"{\"type\":\"record\",\"name\":\"order\",\"fields\":[]}",
+        "--compaction-tasks", "3",
+        "--clustering-tasks", "2",
+        "--hive-sync-enable",
+        "--hive-sync-db", "analytics",
+        "--hive-sync-table", "orders",
+        "--hoodie-conf", 
"hoodie.datasource.write.drop.partition.columns=true");
+
+    Configuration conf = FlinkStreamerConfig.toFlinkConfig(config);
+
+    assertEquals(tempDir.toString(), conf.get(FlinkOptions.PATH));
+    assertEquals("orders_hudi", conf.get(FlinkOptions.TABLE_NAME));
+    assertEquals("MERGE_ON_READ", conf.get(FlinkOptions.TABLE_TYPE));
+    assertEquals(WriteOperationType.INSERT.value(), 
conf.get(FlinkOptions.OPERATION));
+    assertEquals("order_id", conf.get(FlinkOptions.RECORD_KEY_FIELD));
+    assertEquals("order_date", conf.get(FlinkOptions.PARTITION_PATH_FIELD));
+    assertEquals("event_ts,seq_no", conf.get(FlinkOptions.ORDERING_FIELDS));
+    assertEquals(7, conf.get(FlinkOptions.RETRY_TIMES));
+    assertEquals(250L, conf.get(FlinkOptions.RETRY_INTERVAL_MS));

Review Comment:
   Addressed in e73a5f9748ea. The CLI contract remains seconds, and 
toFlinkConfig now converts it with TimeUnit.SECONDS.toMillis before populating 
RETRY_INTERVAL_MS. The test verifies 2 seconds becomes 2,000 milliseconds.



##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/configuration/TestOptionsInference.java:
##########
@@ -38,6 +47,78 @@ public class TestOptionsInference {
   @TempDir
   File tempFile;
 
+  @Test
+  void testSetupSourceAndSinkTasks() {
+    Configuration conf = new Configuration();
+
+    OptionsInference.setupSourceTasks(conf, 3);
+    OptionsInference.setupSinkTasks(conf, 4);
+
+    assertEquals(3, conf.get(FlinkOptions.READ_TASKS));
+    assertEquals(4, conf.get(FlinkOptions.WRITE_TASKS));
+    assertEquals(4, conf.get(FlinkOptions.BUCKET_ASSIGN_TASKS));
+    assertEquals(4, conf.get(FlinkOptions.COMPACTION_TASKS));
+    assertEquals(4, conf.get(FlinkOptions.CLUSTERING_TASKS));
+    assertEquals(4, conf.get(FlinkOptions.INDEX_WRITE_TASKS));
+
+    conf.set(FlinkOptions.READ_TASKS, 7);
+    conf.set(FlinkOptions.WRITE_TASKS, 8);
+    conf.set(FlinkOptions.BUCKET_ASSIGN_TASKS, 9);
+    conf.set(FlinkOptions.COMPACTION_TASKS, 10);
+    conf.set(FlinkOptions.CLUSTERING_TASKS, 11);
+    conf.set(FlinkOptions.INDEX_WRITE_TASKS, 12);
+
+    OptionsInference.setupSourceTasks(conf, 20);
+    OptionsInference.setupSinkTasks(conf, 20);
+
+    assertEquals(7, conf.get(FlinkOptions.READ_TASKS));
+    assertEquals(8, conf.get(FlinkOptions.WRITE_TASKS));
+    assertEquals(9, conf.get(FlinkOptions.BUCKET_ASSIGN_TASKS));
+    assertEquals(10, conf.get(FlinkOptions.COMPACTION_TASKS));
+    assertEquals(11, conf.get(FlinkOptions.CLUSTERING_TASKS));
+    assertEquals(12, conf.get(FlinkOptions.INDEX_WRITE_TASKS));
+  }
+
+  @Test
+  void testSetupRuntimeConfigurations() {
+    Configuration conf = new Configuration();
+    conf.set(JobManagerOptions.SCHEDULER, 
JobManagerOptions.SchedulerType.AdaptiveBatch);
+    Configuration runtimeConf = new Configuration();
+    runtimeConf.set(ExecutionOptions.RUNTIME_MODE, RuntimeExecutionMode.BATCH);
+
+    OptionsInference.setupRuntimeConfigs(conf, runtimeConf);
+
+    if (FlinkVersion.current().toString().compareTo("2.0") >= 0) {
+      
assertTrue(conf.get(FlinkOptions.WRITE_INCREMENTAL_JOB_GRAPH_GENERATION));
+    } else {
+      
assertFalse(conf.get(FlinkOptions.WRITE_INCREMENTAL_JOB_GRAPH_GENERATION));
+    }
+
+    conf.set(FlinkOptions.WRITE_INCREMENTAL_JOB_GRAPH_GENERATION, false);
+    runtimeConf.set(ExecutionOptions.RUNTIME_MODE, 
RuntimeExecutionMode.STREAMING);
+    OptionsInference.setupRuntimeConfigs(conf, runtimeConf);

Review Comment:
   Addressed in e73a5f9748ea. I removed reflection entirely and now exercise 
the reactive, adaptive, and default scheduler branches through the public 
OptionsInference.setupRuntimeConfigs API, asserting the observable 
incremental-job-graph setting across Flink versions.



##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/streamer/TestHoodieFlinkStreamer.java:
##########
@@ -0,0 +1,160 @@
+/*
+ * 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.hudi.streamer;
+
+import org.apache.hudi.client.model.HoodieFlinkInternalRow;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.configuration.OptionsInference;
+import org.apache.hudi.configuration.OptionsResolver;
+import org.apache.hudi.sink.transform.Transformer;
+import org.apache.hudi.sink.utils.Pipelines;
+import org.apache.hudi.util.StreamerUtil;
+import org.apache.hudi.utils.StreamerUtils;
+
+import org.apache.flink.api.common.ExecutionConfig;
+import org.apache.flink.configuration.CheckpointingOptions;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.StateBackendOptions;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.CheckpointConfig;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.types.logical.RowType;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.CALLS_REAL_METHODS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests the argument and pipeline wiring in {@link HoodieFlinkStreamer}.
+ */
+class TestHoodieFlinkStreamer {
+
+  private static final String SOURCE_SCHEMA =
+      
"{\"type\":\"record\",\"name\":\"Order\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"}]}";
+
+  @Test
+  void testAppendPipelineWiringWithTransformer() throws Exception {
+    StreamExecutionEnvironment env = mockEnvironment();
+    DataStream<RowData> source = mock(DataStream.class);
+    DataStream<RowData> transformed = mock(DataStream.class);
+    DataStream<RowData> pipeline = mock(DataStream.class);
+    Transformer transformer = mock(Transformer.class);
+    when(transformer.apply(source)).thenReturn(transformed);
+    AtomicReference<Configuration> envConf = new AtomicReference<>();
+
+    try (MockedStatic<StreamExecutionEnvironment> environments = 
mockStatic(StreamExecutionEnvironment.class);
+         MockedStatic<StreamerUtils> streamerUtils = 
mockStatic(StreamerUtils.class);
+         MockedStatic<StreamerUtil> streamerUtil = 
mockStatic(StreamerUtil.class, CALLS_REAL_METHODS);
+         MockedStatic<OptionsInference> inference = 
mockStatic(OptionsInference.class);
+         MockedStatic<OptionsResolver> resolver = 
mockStatic(OptionsResolver.class);
+         MockedStatic<Pipelines> pipelines = mockStatic(Pipelines.class)) {
+      environments.when(() -> 
StreamExecutionEnvironment.getExecutionEnvironment(any(Configuration.class)))
+          .thenAnswer(invocation -> {

Review Comment:
   Addressed in e73a5f9748ea. Both entry-point tests now include an inline 
comment explaining that the static mocks intentionally intercept configuration 
inference and resolution so the tests exercise only argument and pipeline 
wiring.



##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/clustering/TestFlinkClusteringConfig.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.hudi.sink.clustering;
+
+import org.apache.hudi.configuration.FlinkOptions;
+import org.apache.hudi.util.StreamerUtil;
+import org.apache.hudi.utils.TestConfigurations;
+
+import com.beust.jcommander.JCommander;
+import org.apache.flink.configuration.Configuration;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests for {@link FlinkClusteringConfig}.
+ */
+class TestFlinkClusteringConfig {
+
+  @TempDir
+  Path tempDir;
+
+  @Test
+  void testParseAndDeriveFlinkConfiguration() throws Exception {
+    Configuration tableConf = 
TestConfigurations.getDefaultConf(tempDir.toString());
+    tableConf.set(FlinkOptions.URL_ENCODE_PARTITIONING, true);
+    tableConf.set(FlinkOptions.HIVE_STYLE_PARTITIONING, true);
+    StreamerUtil.initTableIfNotExists(tableConf);
+
+    FlinkClusteringConfig config = new FlinkClusteringConfig();
+    JCommander.newBuilder().addObject(config).build().parse(
+        "--path", tempDir.toString(),
+        "--clustering-delta-commits", "6",
+        "--clustering-tasks", "4",
+        "--clean-retain-commits", "12",
+        "--clean-retain-hours", "36",
+        "--clean-retain-file-versions", "7",
+        "--archive-min-commits", "25",
+        "--archive-max-commits", "40",
+        "--schedule",
+        "--clean-async-enabled",
+        "--plan-partition-filter-mode", "RECENT_DAYS",
+        "--target-file-max-bytes", "1048576",
+        "--small-file-limit", "524288",
+        "--skip-from-latest-partitions", "2",
+        "--sort-columns", "event_ts,order_id",
+        "--sort-memory", "256",
+        "--max-num-groups", "10",
+        "--target-partitions", "5",
+        "--cluster-begin-partition", "2026-01-01",

Review Comment:
   Addressed in e73a5f9748ea. The clustering test now asserts the derived begin 
partition, end partition, regex pattern, and selected-partitions values in 
addition to the supplied arguments.



##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/configuration/TestOptionsResolver.java:
##########
@@ -270,4 +283,108 @@ void testEstimateFileGroupCountForGlobalRLI() {
     
conf.setString(HoodieMetadataConfig.GLOBAL_RECORD_LEVEL_INDEX_MAX_FILE_GROUP_COUNT_PROP.key(),
 "11");
     assertEquals(11, OptionsResolver.estimateFileGroupCountForRLI(conf));

Review Comment:
   Addressed in e73a5f9748ea. I split the three broad methods into focused 
tests for incremental graph generation, table types, operation types, payload 
and compaction behavior, read options, schema and timestamp options, write 
options, partitioners, conflict strategies, and buffer sizing. The focused 
suite now reports 42 passing tests.



##########
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/streamer/TestFlinkStreamerConfig.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.hudi.streamer;
+
+import org.apache.hudi.common.model.WriteOperationType;
+import org.apache.hudi.configuration.FlinkOptions;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.ParameterException;
+import org.apache.flink.configuration.Configuration;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests for {@link FlinkStreamerConfig}.
+ */
+class TestFlinkStreamerConfig {
+
+  @TempDir
+  Path tempDir;
+
+  @Test
+  void testParseAndDeriveFlinkConfiguration() {
+    FlinkStreamerConfig config = parse(
+        "--kafka-topic", "orders",
+        "--kafka-group-id", "flink-writers",
+        "--kafka-bootstrap-servers", "broker:9092",
+        "--target-base-path", tempDir.toString(),
+        "--target-table", "orders_hudi",
+        "--table-type", "merge_on_read",
+        "--op", "INSERT",
+        "--record-key-field", "order_id",
+        "--partition-path-field", "order_date",
+        "--source-ordering-fields", "event_ts,seq_no",
+        "--instant-retry-times", "7",
+        "--instant-retry-interval", "250",
+        "--filter-dupes",
+        "--commit-on-errors",
+        "--metadata-enabled",
+        "--write-rate-limit", "500",
+        "--write-task-num", "6",
+        "--bucket-assign-num", "5",
+        "--index-bootstrap-num", "4",
+        "--source-avro-schema-path", "file:///tmp/source.avsc",
+        "--source-avro-schema", 
"{\"type\":\"record\",\"name\":\"order\",\"fields\":[]}",
+        "--compaction-tasks", "3",
+        "--clustering-tasks", "2",
+        "--hive-sync-enable",
+        "--hive-sync-db", "analytics",
+        "--hive-sync-table", "orders",
+        "--hoodie-conf", 
"hoodie.datasource.write.drop.partition.columns=true");
+
+    Configuration conf = FlinkStreamerConfig.toFlinkConfig(config);
+
+    assertEquals(tempDir.toString(), conf.get(FlinkOptions.PATH));
+    assertEquals("orders_hudi", conf.get(FlinkOptions.TABLE_NAME));
+    assertEquals("MERGE_ON_READ", conf.get(FlinkOptions.TABLE_TYPE));
+    assertEquals(WriteOperationType.INSERT.value(), 
conf.get(FlinkOptions.OPERATION));
+    assertEquals("order_id", conf.get(FlinkOptions.RECORD_KEY_FIELD));
+    assertEquals("order_date", conf.get(FlinkOptions.PARTITION_PATH_FIELD));
+    assertEquals("event_ts,seq_no", conf.get(FlinkOptions.ORDERING_FIELDS));
+    assertEquals(7, conf.get(FlinkOptions.RETRY_TIMES));
+    assertEquals(250L, conf.get(FlinkOptions.RETRY_INTERVAL_MS));
+    assertTrue(conf.get(FlinkOptions.PRE_COMBINE));
+    assertTrue(conf.get(FlinkOptions.IGNORE_FAILED));
+    assertTrue(conf.get(FlinkOptions.METADATA_ENABLED));
+    assertEquals(500L, conf.get(FlinkOptions.WRITE_RATE_LIMIT));
+    assertEquals(6, conf.get(FlinkOptions.WRITE_TASKS));
+    assertEquals(5, conf.get(FlinkOptions.BUCKET_ASSIGN_TASKS));
+    assertEquals(4, conf.get(FlinkOptions.INDEX_BOOTSTRAP_TASKS));
+    assertEquals("file:///tmp/source.avsc", 
conf.get(FlinkOptions.SOURCE_AVRO_SCHEMA_PATH));
+    assertEquals(3, conf.get(FlinkOptions.COMPACTION_TASKS));
+    assertEquals(2, conf.get(FlinkOptions.CLUSTERING_TASKS));
+    assertTrue(conf.get(FlinkOptions.HIVE_SYNC_ENABLED));
+    assertEquals("analytics", conf.get(FlinkOptions.HIVE_SYNC_DB));
+    assertEquals("orders", conf.get(FlinkOptions.HIVE_SYNC_TABLE));
+    assertEquals("hoodie.datasource.write.drop.partition.columns=true", 
config.configs.get(0));

Review Comment:
   Addressed in e73a5f9748ea. StreamerUtil.getProps now calls buildProperties 
with the CLI overrides when no props file is supplied, and the test asserts 
that hoodie.datasource.write.drop.partition.columns reaches the derived 
Configuration with value true.



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

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to