danny0405 commented on code in PR #19543: URL: https://github.com/apache/hudi/pull/19543#discussion_r3733283271
########## hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/sink/v2/utils/TestPipelinesV2.java: ########## @@ -0,0 +1,200 @@ +/* + * 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.v2.utils; + +import org.apache.hudi.client.model.HoodieFlinkInternalRow; +import org.apache.hudi.configuration.FlinkOptions; +import org.apache.hudi.configuration.OptionsResolver; +import org.apache.hudi.exception.HoodieException; +import org.apache.hudi.sink.utils.Pipelines; +import org.apache.hudi.utils.TestConfigurations; + +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.dag.Transformation; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.datastream.DataStreamSink; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.data.RowData; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.MockedStatic; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.mockStatic; + +/** Tests topology construction and routing in {@link PipelinesV2}. */ +class TestPipelinesV2 { + + private Configuration conf; + private DataStream<RowData> input; + + @BeforeEach + void setUp() { + conf = new Configuration(); + StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); + input = env.fromCollection( + Collections.<RowData>emptyList(), + TypeInformation.of(RowData.class)); + } + + @Test + void testSinkUsesModeSpecificParallelismAndStableIdentity() { + conf.set(FlinkOptions.OPERATION, "bulk_insert"); + conf.set(FlinkOptions.WRITE_TASKS, 4); + + DataStreamSink<RowData> sink = PipelinesV2.sink( + input, conf, TestConfigurations.ROW_TYPE, false, true); + + assertEquals(4, sink.getTransformation().getParallelism()); + assertEquals("sink_v2", sink.getTransformation().getName()); + } + + @Test + void testServiceTopologiesUseExpectedSingletonCommitOperators() { + conf.set(FlinkOptions.CLUSTERING_TASKS, 3); + conf.set(FlinkOptions.COMPACTION_TASKS, 2); + + DataStream<RowData> clean = PipelinesV2.cleanV2(conf, input); + DataStream<RowData> cluster = PipelinesV2.clusterV2( + conf, TestConfigurations.ROW_TYPE, input); + DataStream<RowData> compact = PipelinesV2.compactV2(conf, input); + + assertOperator(clean, "clean_commits", 1, 1); + assertOperator(cluster, "clustering_commit", 1, 1); + assertOperator(compact, "compact_commit", 1, 1); + assertEquals(3, transformation(cluster, "clustering_task").getParallelism()); Review Comment: Done in 1f56ccae1bb9. The test environment now defaults to parallelism 7; both cluster_plan_generate and compact_plan_generate are asserted at parallelism/max parallelism 1; and each plan-to-task route is asserted to contain exactly one Pipelines.IndexPartitioner. The focused Sink V2 suite passes (15/15). -- 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]
