wenshao commented on code in PR #4320:
URL: https://github.com/apache/flink-cdc/pull/4320#discussion_r3042810753


##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-sqlserver/src/test/java/org/apache/flink/cdc/connectors/sqlserver/source/SqlServerOnlineSchemaMigrationITCase.java:
##########
@@ -0,0 +1,276 @@
+/*
+ * 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.cdc.connectors.sqlserver.source;
+
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.cdc.common.data.binary.BinaryRecordData;
+import org.apache.flink.cdc.common.data.binary.BinaryStringData;
+import org.apache.flink.cdc.common.event.AddColumnEvent;
+import org.apache.flink.cdc.common.event.AlterColumnTypeEvent;
+import org.apache.flink.cdc.common.event.CreateTableEvent;
+import org.apache.flink.cdc.common.event.DataChangeEvent;
+import org.apache.flink.cdc.common.event.DropColumnEvent;
+import org.apache.flink.cdc.common.event.Event;
+import org.apache.flink.cdc.common.event.TableId;
+import org.apache.flink.cdc.common.schema.PhysicalColumn;
+import org.apache.flink.cdc.common.schema.Schema;
+import org.apache.flink.cdc.common.source.FlinkSourceProvider;
+import org.apache.flink.cdc.common.types.DataType;
+import org.apache.flink.cdc.common.types.DataTypes;
+import org.apache.flink.cdc.connectors.base.options.StartupOptions;
+import org.apache.flink.cdc.connectors.sqlserver.SqlServerTestBase;
+import 
org.apache.flink.cdc.connectors.sqlserver.factory.SqlServerDataSourceFactory;
+import 
org.apache.flink.cdc.connectors.sqlserver.source.config.SqlServerSourceConfigFactory;
+import org.apache.flink.cdc.runtime.typeutils.BinaryRecordDataGenerator;
+import org.apache.flink.cdc.runtime.typeutils.EventTypeInfo;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.planner.factories.TestValuesTableFactory;
+import org.apache.flink.util.CloseableIterator;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static 
org.apache.flink.cdc.connectors.sqlserver.testutils.SqlServerSourceTestUtils.fetchResults;
+import static 
org.testcontainers.containers.MSSQLServerContainer.MS_SQL_SERVER_PORT;
+
+/** IT case for evolving SQL Server schema during online migration. The flow 
mirrors */
+class SqlServerOnlineSchemaMigrationITCase extends SqlServerTestBase {
+
+    private static final String DATABASE_NAME = "customer";
+    private static final StreamExecutionEnvironment env =
+            StreamExecutionEnvironment.getExecutionEnvironment();
+
+    @SuppressWarnings("deprecation")
+    @BeforeEach
+    void before() {
+        initializeSqlServerTable(DATABASE_NAME);
+        TestValuesTableFactory.clearAllData();
+        env.setParallelism(4);
+        env.enableCheckpointing(200);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+    }
+
+    @Test
+    void testSchemaMigrationFromScratch() throws Exception {
+        env.setParallelism(1);
+
+        TableId tableId = TableId.tableId(DATABASE_NAME, "dbo", "customers");
+        SqlServerSourceConfigFactory configFactory =
+                (SqlServerSourceConfigFactory)
+                        new SqlServerSourceConfigFactory()
+                                .hostname(MSSQL_SERVER_CONTAINER.getHost())
+                                
.port(MSSQL_SERVER_CONTAINER.getMappedPort(MS_SQL_SERVER_PORT))
+                                .username(MSSQL_SERVER_CONTAINER.getUsername())
+                                .password(MSSQL_SERVER_CONTAINER.getPassword())
+                                .databaseList(DATABASE_NAME)
+                                .tableList("dbo.customers")
+                                .startupOptions(StartupOptions.initial())
+                                .includeSchemaChanges(true)
+                                .serverTimeZone("UTC");
+
+        FlinkSourceProvider sourceProvider =
+                (FlinkSourceProvider)
+                        new 
SqlServerDataSource(configFactory).getEventSourceProvider();
+        CloseableIterator<Event> events =
+                env.fromSource(
+                                sourceProvider.getSource(),
+                                WatermarkStrategy.noWatermarks(),
+                                SqlServerDataSourceFactory.IDENTIFIER,
+                                new EventTypeInfo())
+                        .executeAndCollect();
+
+        Thread.sleep(5_000);

Review Comment:
   **[Suggestion]** `Thread.sleep(5_000)` is used as a synchronization barrier 
without any condition check. If the source hasn't finished the snapshot within 
5 seconds, subsequent operations may read events out of order. Conversely, on 
fast machines this wastes time. The same pattern appears at line 128 and in 
`SqlServerPipelineNewlyAddedTableITCase.java:327` with `Thread.sleep(1000L)`.
   
   **Suggested fix:** Replace with a polling loop (e.g., 
`SqlServerSourceTestUtils.loopCheck`) that waits until the expected condition 
is met, similar to the pattern already used in 
`SqlServerParallelizedPipelineITCase`.
   
   _— glm-5.1_
   



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