yuxiqian commented on code in PR #3683:
URL: https://github.com/apache/flink-cdc/pull/3683#discussion_r1849772522


##########
flink-cdc-connect/flink-cdc-source-connectors/flink-connector-mysql-cdc/src/test/java/org/apache/flink/cdc/connectors/mysql/table/MySqlConnectorShardingTableITCase.java:
##########
@@ -0,0 +1,359 @@
+/*
+ * 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.mysql.table;
+
+import org.apache.flink.cdc.connectors.mysql.source.MySqlSourceTestBase;
+import org.apache.flink.cdc.connectors.mysql.testutils.MySqlContainer;
+import org.apache.flink.cdc.connectors.mysql.testutils.MySqlVersion;
+import org.apache.flink.cdc.connectors.mysql.testutils.UniqueDatabase;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.TableResult;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.table.planner.factories.TestValuesTableFactory;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.CloseableIterator;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.lifecycle.Startables;
+
+import java.sql.Connection;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.util.stream.Stream;
+
+/** Integration tests for MySQL shardding tables. */
+@RunWith(Parameterized.class)
+public class MySqlConnectorShardingTableITCase extends MySqlSourceTestBase {
+
+    private static final Logger LOG =
+            LoggerFactory.getLogger(MySqlConnectorShardingTableITCase.class);
+
+    private static final String TEST_USER = "mysqluser";
+    private static final String TEST_PASSWORD = "mysqlpw";
+
+    private static final MySqlContainer MYSQL8_CONTAINER =
+            createMySqlContainer(MySqlVersion.V8_0, 
"docker/server-gtids/expire-seconds/my.cnf");
+
+    private final UniqueDatabase fullTypesMySql57Database =
+            new UniqueDatabase(MYSQL_CONTAINER, "column_type_test", TEST_USER, 
TEST_PASSWORD);
+
+    private final UniqueDatabase userDatabase1 =
+            new UniqueDatabase(MYSQL_CONTAINER, "user_1", TEST_USER, 
TEST_PASSWORD);
+    private final UniqueDatabase userDatabase2 =
+            new UniqueDatabase(MYSQL_CONTAINER, "user_2", TEST_USER, 
TEST_PASSWORD);
+
+    private final StreamExecutionEnvironment env =
+            StreamExecutionEnvironment.getExecutionEnvironment();
+    private final StreamTableEnvironment tEnv =
+            StreamTableEnvironment.create(
+                    env, 
EnvironmentSettings.newInstance().inStreamingMode().build());
+
+    // enable the incrementalSnapshot (i.e: The new source MySqlParallelSource)
+    private final boolean incrementalSnapshot;
+
+    public MySqlConnectorShardingTableITCase(boolean incrementalSnapshot) {
+        this.incrementalSnapshot = incrementalSnapshot;
+    }
+
+    @Parameterized.Parameters(name = "incrementalSnapshot: {0}")
+    public static Object[] parameters() {
+        return new Object[][] {new Object[] {false}, new Object[] {true}};
+    }
+
+    @BeforeClass
+    public static void beforeClass() {
+        LOG.info("Starting MySql8 containers...");
+        Startables.deepStart(Stream.of(MYSQL8_CONTAINER)).join();
+        LOG.info("Container MySql8 is started.");
+    }
+
+    @AfterClass
+    public static void afterClass() {
+        LOG.info("Stopping MySql8 containers...");
+        MYSQL8_CONTAINER.stop();
+        LOG.info("Container MySql8 is stopped.");
+    }
+
+    @Before
+    public void before() {
+        TestValuesTableFactory.clearAllData();
+        if (incrementalSnapshot) {
+            env.setParallelism(DEFAULT_PARALLELISM);
+            env.enableCheckpointing(200);
+        } else {
+            env.setParallelism(1);
+        }
+    }
+
+    @Test
+    public void testShardingTablesWithTinyInt1() throws Exception {
+        fullTypesMySql57Database.createAndInitialize();
+        try (Connection connection = 
fullTypesMySql57Database.getJdbcConnection();
+                Statement statement = connection.createStatement()) {
+            statement.execute(String.format("USE %s", 
fullTypesMySql57Database.getDatabaseName()));
+            statement.execute(
+                    "CREATE TABLE sharding_table_1("
+                            + "id BIGINT,"
+                            + "status BOOLEAN," // will be recognized as 
tinyint(1) in debezium as
+                            // it comes from show table command
+                            + " PRIMARY KEY (id) "
+                            + ")");
+            statement.execute("INSERT INTO sharding_table_1 values(1, 
true),(2, false)");
+        }
+
+        String sourceDDL =
+                String.format(
+                        "CREATE TABLE sharding_tables (\n"
+                                + "`id` BIGINT,"
+                                + "status TINYINT,"
+                                + "primary key (`id`) not enforced"
+                                + ") WITH ("
+                                + " 'connector' = 'mysql-cdc',"
+                                + " 'hostname' = '%s',"
+                                + " 'port' = '%s',"
+                                + " 'username' = '%s',"
+                                + " 'password' = '%s',"
+                                + " 'database-name' = '%s',"
+                                + " 'table-name' = '%s',"
+                                + " 'scan.incremental.snapshot.enabled' = 
'%s',"
+                                + " 'server-id' = '%s',"
+                                + " 'server-time-zone' = 'UTC',"
+                                + " 'scan.incremental.snapshot.chunk.size' = 
'%s'"
+                                + ")",
+                        MYSQL_CONTAINER.getHost(),
+                        MYSQL_CONTAINER.getDatabasePort(),
+                        fullTypesMySql57Database.getUsername(),
+                        fullTypesMySql57Database.getPassword(),
+                        fullTypesMySql57Database.getDatabaseName(),
+                        "sharding_table_.*",
+                        incrementalSnapshot,
+                        getServerId(),
+                        getSplitSize());
+        String sinkDDL =
+                "CREATE TABLE sink ("
+                        + " `id` BIGINT NOT NULL,"
+                        + " status TINYINT,"
+                        + " primary key (`id`) not enforced"
+                        + ") WITH ("
+                        + " 'connector' = 'values',"
+                        + " 'sink-insert-only' = 'false'"
+                        + ")";
+        tEnv.executeSql(sourceDDL);
+        tEnv.executeSql(sinkDDL);
+
+        // async submit job
+        TableResult result = tEnv.executeSql("INSERT INTO sink SELECT * FROM 
sharding_tables");
+
+        try (Connection connection = 
fullTypesMySql57Database.getJdbcConnection();
+                Statement statement = connection.createStatement()) {
+            statement.execute("INSERT INTO sharding_table_1 values(3, 
true),(4, false)");
+        }
+        // wait for snapshot finished and begin binlog
+        waitForSinkSize("sink", 4);
+
+        try (Connection connection = 
fullTypesMySql57Database.getJdbcConnection();
+                Statement statement = connection.createStatement()) {
+            statement.execute(String.format("USE %s", 
fullTypesMySql57Database.getDatabaseName()));
+            statement.execute(
+                    "CREATE TABLE sharding_table_2("
+                            + "id BIGINT,"
+                            + "status BOOLEAN," // will be recognized as 
boolean in debezium as it
+                            // comes from binlog
+                            + " PRIMARY KEY (id) "
+                            + ")");
+            statement.execute("INSERT INTO sharding_table_2 values(5, 
true),(6, false)");
+        }
+
+        waitForSinkSize("sink", 6);
+        String[] expected =
+                new String[] {
+                    "+I[1, 1]", "+I[2, 0]", "+I[3, 1]", "+I[4, 0]", "+I[5, 
1]", "+I[6, 0]",
+                };
+        List<String> actual = TestValuesTableFactory.getResults("sink");

Review Comment:
   Needs to be renamed to `getResultsAsString` after #3660 or CI will fail



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