hudi-agent commented on code in PR #19392: URL: https://github.com/apache/hudi/pull/19392#discussion_r3664799773
########## 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: 🤖 nit: `inference` (and in the second test, both `inference` and the partially-used `resolver`) are opened in the try-with-resources but no stubs are configured on them. A reader can't tell whether this is intentional (to prevent real static calls) or a forgotten stub. A one-line comment like `// opened to intercept static calls and prevent real execution` would make the intent clear. <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub> ########## 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: 🤖 nit: accessing the private `getSchedulerType` method via reflection makes this test fragile — any rename of the method silently breaks the test at runtime rather than compile time. Have you considered making the method package-private so the test can call it directly, or extracting the logic into a small utility that can be tested without reflection? <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub> ########## 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: 🤖 nit: `testBasicOptionPredicatesAndValues` (and the two methods that follow) each bundle a dozen unrelated assertions — table type, operation, payload class, compaction strategy, etc. — into one test. When any of them fails, the test name gives no hint which scenario broke. Could you split these into a few more focused tests, each named for the specific behavior it exercises (e.g. `testTableTypePredicates`, `testOperationTypePredicates`)? <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag quality.</i></sub> -- 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]
