You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "sandynz (via GitHub)" <gi...@apache.org> on 2023/02/28 09:01:32 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #24376: Add CDC E2E test case at pipeline

sandynz commented on code in PR #24376:
URL: https://github.com/apache/shardingsphere/pull/24376#discussion_r1119724688


##########
test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/cdc/AbstractCDCE2EIT.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.shardingsphere.test.e2e.data.pipeline.cases.cdc;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.data.pipeline.cdc.client.CDCClient;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.ImportDataSourceParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.StartCDCClientParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.protocol.request.StreamDataRequestBody.SchemaTable;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.base.PipelineBaseE2EIT;
+import org.apache.shardingsphere.test.e2e.data.pipeline.env.enums.PipelineEnvTypeEnum;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.constants.ProxyContainerConstants;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.util.DatabaseTypeUtil;
+import org.junit.After;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Slf4j
+public abstract class AbstractCDCE2EIT extends PipelineBaseE2EIT {
+    
+    private static final String REGISTER_STORAGE_UNIT_SQL = "REGISTER STORAGE UNIT ds_0 ( URL='${ds0}', USER='${user}', PASSWORD='${password}'),"
+            + "ds_1 ( URL='${ds1}', USER='${user}', PASSWORD='${password}')";
+    
+    private static final String CREATE_SHARDING_RULE_SQL = "CREATE SHARDING TABLE RULE t_order("
+            + "STORAGE_UNITS(ds_0,ds_1),"
+            + "SHARDING_COLUMN=user_id,"
+            + "TYPE(NAME='hash_mod',PROPERTIES('sharding-count'='4')),"
+            + "KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='snowflake'))"
+            + ")";

Review Comment:
   Could we reuse current DistSQL in xml for now?



##########
test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/cdc/AbstractCDCE2EIT.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.shardingsphere.test.e2e.data.pipeline.cases.cdc;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.data.pipeline.cdc.client.CDCClient;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.ImportDataSourceParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.StartCDCClientParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.protocol.request.StreamDataRequestBody.SchemaTable;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.base.PipelineBaseE2EIT;
+import org.apache.shardingsphere.test.e2e.data.pipeline.env.enums.PipelineEnvTypeEnum;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.constants.ProxyContainerConstants;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.util.DatabaseTypeUtil;
+import org.junit.After;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Slf4j
+public abstract class AbstractCDCE2EIT extends PipelineBaseE2EIT {
+    
+    private static final String REGISTER_STORAGE_UNIT_SQL = "REGISTER STORAGE UNIT ds_0 ( URL='${ds0}', USER='${user}', PASSWORD='${password}'),"
+            + "ds_1 ( URL='${ds1}', USER='${user}', PASSWORD='${password}')";
+    
+    private static final String CREATE_SHARDING_RULE_SQL = "CREATE SHARDING TABLE RULE t_order("
+            + "STORAGE_UNITS(ds_0,ds_1),"
+            + "SHARDING_COLUMN=user_id,"
+            + "TYPE(NAME='hash_mod',PROPERTIES('sharding-count'='4')),"
+            + "KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='snowflake'))"
+            + ")";
+    
+    private final ExecutorService executor = Executors.newSingleThreadExecutor();
+    
+    public AbstractCDCE2EIT(final PipelineTestParameter testParam) {
+        super(testParam);
+        // if the time zone of the unit test and the time zone of the mirror do not match, CDC will get the wrong timestamp
+        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+    }
+    
+    protected void registerStorageUnit() throws SQLException {
+        String registerStorageUnitTemplate = REGISTER_STORAGE_UNIT_SQL.replace("${user}", getUsername())
+                .replace("${password}", getPassword())
+                .replace("${ds0}", appendExtraParam(getActualJdbcUrlTemplate(DS_0, true)))
+                .replace("${ds1}", appendExtraParam(getActualJdbcUrlTemplate(DS_1, true)));
+        addResource(registerStorageUnitTemplate);
+    }
+    
+    protected void createOrderTableRule() throws SQLException {
+        proxyExecuteWithLog(CREATE_SHARDING_RULE_SQL, 2);
+    }
+    
+    protected void createSchema(final String schemaName) throws SQLException {
+        if (!getDatabaseType().isSchemaAvailable()) {
+            return;
+        }
+        if (DatabaseTypeUtil.isPostgreSQL(getDatabaseType())) {
+            proxyExecuteWithLog(String.format("CREATE SCHEMA IF NOT EXISTS %s", schemaName), 2);
+            return;
+        }
+        if (DatabaseTypeUtil.isOpenGauss(getDatabaseType())) {
+            proxyExecuteWithLog(String.format("CREATE SCHEMA %s", schemaName), 2);
+        }
+    }
+    
+    protected void startCDCClient() {
+        ImportDataSourceParameter importDataSourceParam = new ImportDataSourceParameter(appendExtraParam(getActualJdbcUrlTemplate(DS_4, false, 0)), getUsername(), getPassword());
+        StartCDCClientParameter parameter = new StartCDCClientParameter(importDataSourceParam);
+        parameter.setAddress("localhost");
+        parameter.setPort(getContainerComposer().getProxyCDCPort());
+        parameter.setUsername(PipelineEnvTypeEnum.DOCKER == ENV.getItEnvType() ? ProxyContainerConstants.USERNAME : "root");
+        parameter.setPassword(PipelineEnvTypeEnum.DOCKER == ENV.getItEnvType() ? ProxyContainerConstants.PASSWORD : "root");

Review Comment:
   Could we reuse `username` and `password` in `PipelineBaseE2EIT`? It should not be hard-coded here, it doesn't match configuration in `it-env.properties`



##########
test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/cdc/AbstractCDCE2EIT.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.shardingsphere.test.e2e.data.pipeline.cases.cdc;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.data.pipeline.cdc.client.CDCClient;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.ImportDataSourceParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.StartCDCClientParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.protocol.request.StreamDataRequestBody.SchemaTable;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.base.PipelineBaseE2EIT;
+import org.apache.shardingsphere.test.e2e.data.pipeline.env.enums.PipelineEnvTypeEnum;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.constants.ProxyContainerConstants;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.util.DatabaseTypeUtil;
+import org.junit.After;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Slf4j
+public abstract class AbstractCDCE2EIT extends PipelineBaseE2EIT {
+    
+    private static final String REGISTER_STORAGE_UNIT_SQL = "REGISTER STORAGE UNIT ds_0 ( URL='${ds0}', USER='${user}', PASSWORD='${password}'),"
+            + "ds_1 ( URL='${ds1}', USER='${user}', PASSWORD='${password}')";
+    
+    private static final String CREATE_SHARDING_RULE_SQL = "CREATE SHARDING TABLE RULE t_order("
+            + "STORAGE_UNITS(ds_0,ds_1),"
+            + "SHARDING_COLUMN=user_id,"
+            + "TYPE(NAME='hash_mod',PROPERTIES('sharding-count'='4')),"
+            + "KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='snowflake'))"
+            + ")";
+    
+    private final ExecutorService executor = Executors.newSingleThreadExecutor();
+    
+    public AbstractCDCE2EIT(final PipelineTestParameter testParam) {
+        super(testParam);
+        // if the time zone of the unit test and the time zone of the mirror do not match, CDC will get the wrong timestamp
+        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+    }
+    
+    protected void registerStorageUnit() throws SQLException {
+        String registerStorageUnitTemplate = REGISTER_STORAGE_UNIT_SQL.replace("${user}", getUsername())
+                .replace("${password}", getPassword())
+                .replace("${ds0}", appendExtraParam(getActualJdbcUrlTemplate(DS_0, true)))
+                .replace("${ds1}", appendExtraParam(getActualJdbcUrlTemplate(DS_1, true)));
+        addResource(registerStorageUnitTemplate);
+    }
+    
+    protected void createOrderTableRule() throws SQLException {
+        proxyExecuteWithLog(CREATE_SHARDING_RULE_SQL, 2);
+    }
+    
+    protected void createSchema(final String schemaName) throws SQLException {
+        if (!getDatabaseType().isSchemaAvailable()) {
+            return;
+        }
+        if (DatabaseTypeUtil.isPostgreSQL(getDatabaseType())) {
+            proxyExecuteWithLog(String.format("CREATE SCHEMA IF NOT EXISTS %s", schemaName), 2);
+            return;
+        }
+        if (DatabaseTypeUtil.isOpenGauss(getDatabaseType())) {
+            proxyExecuteWithLog(String.format("CREATE SCHEMA %s", schemaName), 2);
+        }
+    }

Review Comment:
   There's createSourceSchema in AbstractMigrationE2EIT, could we extract similar code block to PipelineBaseE2EIT?



##########
test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/cdc/MySQLCDCE2EIT.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.shardingsphere.test.e2e.data.pipeline.cases.cdc;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.shardingsphere.data.pipeline.cdc.api.job.type.CDCJobType;
+import org.apache.shardingsphere.data.pipeline.core.util.ThreadUtil;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.base.PipelineBaseE2EIT;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.task.CDCIncrementTask;
+import org.apache.shardingsphere.test.e2e.data.pipeline.env.enums.PipelineEnvTypeEnum;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.helper.PipelineCaseHelper;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter;
+import org.apache.shardingsphere.test.e2e.data.pipeline.util.DataSourceExecuteUtil;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.time.LocalDateTime;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * MySQL CDC E2E IT.
+ */
+@RunWith(Parameterized.class)
+@Slf4j
+public final class MySQLCDCE2EIT extends AbstractCDCE2EIT {
+    
+    public MySQLCDCE2EIT(final PipelineTestParameter testParam) {
+        super(testParam);
+    }
+    
+    @Parameters(name = "{0}")
+    public static Collection<PipelineTestParameter> getTestParameters() {
+        Collection<PipelineTestParameter> result = new LinkedList<>();
+        if (PipelineBaseE2EIT.ENV.getItEnvType() == PipelineEnvTypeEnum.NONE) {
+            return result;
+        }
+        MySQLDatabaseType mysqlDatabaseType = new MySQLDatabaseType();
+        for (String each : PipelineBaseE2EIT.ENV.listStorageContainerImages(mysqlDatabaseType)) {
+            result.add(new PipelineTestParameter(mysqlDatabaseType, each, "env/scenario/general/mysql.xml"));
+        }
+        return result;
+    }
+    
+    @Override
+    protected String getSourceTableOrderName() {
+        return "t_order";
+    }
+    
+    @Test
+    public void assertCDCDataImportSuccess() throws SQLException, InterruptedException {
+        initEnvironment(getDatabaseType(), new CDCJobType());
+        registerStorageUnit();
+        createOrderTableRule();
+        proxyExecuteWithLog(getExtraSQLCommand().getCreateTableOrder(getSourceTableOrderName()), 0);
+        Pair<List<Object[]>, List<Object[]>> dataPair = PipelineCaseHelper.generateFullInsertData(getDatabaseType(), 20);
+        log.info("init data begin: {}", LocalDateTime.now());
+        DataSourceExecuteUtil.execute(getProxyDataSource(), getExtraSQLCommand().getFullInsertOrder(getSourceTableOrderName()), dataPair.getLeft());
+        log.info("init data end: {}", LocalDateTime.now());
+        initImporterTable();
+        startCDCClient();
+        startIncrementTask(new CDCIncrementTask(getProxyDataSource(), getSourceTableOrderName(), 0, 20, 3));
+        getIncreaseTaskThread().join(20000);
+        List<Map<String, Object>> actualProxyList;
+        try (Connection connection = getProxyDataSource().getConnection()) {
+            ResultSet resultSet = connection.createStatement().executeQuery(String.format("SELECT * FROM %s ORDER BY order_id ASC", getOrderTableName()));
+            actualProxyList = transformResultSetToList(resultSet);
+        }
+        // TODO wait CDC sync data finished
+        ThreadUtil.sleep(4, TimeUnit.SECONDS);
+        Awaitility.await().atMost(30, TimeUnit.SECONDS).pollInterval(2, TimeUnit.SECONDS).until(() -> listOrderRecords(getSourceTableOrderName()).size() == actualProxyList.size());

Review Comment:
   Could we reuse `waitIncrementTaskFinished` to do it?



##########
test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/cdc/AbstractCDCE2EIT.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.shardingsphere.test.e2e.data.pipeline.cases.cdc;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.data.pipeline.cdc.client.CDCClient;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.ImportDataSourceParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.StartCDCClientParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.protocol.request.StreamDataRequestBody.SchemaTable;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.base.PipelineBaseE2EIT;
+import org.apache.shardingsphere.test.e2e.data.pipeline.env.enums.PipelineEnvTypeEnum;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.constants.ProxyContainerConstants;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.util.DatabaseTypeUtil;
+import org.junit.After;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Slf4j
+public abstract class AbstractCDCE2EIT extends PipelineBaseE2EIT {
+    
+    private static final String REGISTER_STORAGE_UNIT_SQL = "REGISTER STORAGE UNIT ds_0 ( URL='${ds0}', USER='${user}', PASSWORD='${password}'),"
+            + "ds_1 ( URL='${ds1}', USER='${user}', PASSWORD='${password}')";
+    
+    private static final String CREATE_SHARDING_RULE_SQL = "CREATE SHARDING TABLE RULE t_order("
+            + "STORAGE_UNITS(ds_0,ds_1),"
+            + "SHARDING_COLUMN=user_id,"
+            + "TYPE(NAME='hash_mod',PROPERTIES('sharding-count'='4')),"
+            + "KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='snowflake'))"
+            + ")";
+    
+    private final ExecutorService executor = Executors.newSingleThreadExecutor();
+    
+    public AbstractCDCE2EIT(final PipelineTestParameter testParam) {
+        super(testParam);
+        // if the time zone of the unit test and the time zone of the mirror do not match, CDC will get the wrong timestamp
+        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+    }
+    
+    protected void registerStorageUnit() throws SQLException {
+        String registerStorageUnitTemplate = REGISTER_STORAGE_UNIT_SQL.replace("${user}", getUsername())
+                .replace("${password}", getPassword())
+                .replace("${ds0}", appendExtraParam(getActualJdbcUrlTemplate(DS_0, true)))
+                .replace("${ds1}", appendExtraParam(getActualJdbcUrlTemplate(DS_1, true)));
+        addResource(registerStorageUnitTemplate);
+    }
+    
+    protected void createOrderTableRule() throws SQLException {
+        proxyExecuteWithLog(CREATE_SHARDING_RULE_SQL, 2);
+    }
+    
+    protected void createSchema(final String schemaName) throws SQLException {
+        if (!getDatabaseType().isSchemaAvailable()) {
+            return;
+        }
+        if (DatabaseTypeUtil.isPostgreSQL(getDatabaseType())) {
+            proxyExecuteWithLog(String.format("CREATE SCHEMA IF NOT EXISTS %s", schemaName), 2);
+            return;
+        }
+        if (DatabaseTypeUtil.isOpenGauss(getDatabaseType())) {
+            proxyExecuteWithLog(String.format("CREATE SCHEMA %s", schemaName), 2);
+        }
+    }
+    
+    protected void startCDCClient() {
+        ImportDataSourceParameter importDataSourceParam = new ImportDataSourceParameter(appendExtraParam(getActualJdbcUrlTemplate(DS_4, false, 0)), getUsername(), getPassword());
+        StartCDCClientParameter parameter = new StartCDCClientParameter(importDataSourceParam);
+        parameter.setAddress("localhost");
+        parameter.setPort(getContainerComposer().getProxyCDCPort());
+        parameter.setUsername(PipelineEnvTypeEnum.DOCKER == ENV.getItEnvType() ? ProxyContainerConstants.USERNAME : "root");
+        parameter.setPassword(PipelineEnvTypeEnum.DOCKER == ENV.getItEnvType() ? ProxyContainerConstants.PASSWORD : "root");
+        parameter.setDatabase("sharding_db");
+        parameter.setFull(true);
+        String schema = "";
+        if (getDatabaseType().isSchemaAvailable()) {
+            schema = "test";
+        }
+        parameter.setSchemaTables(Collections.singletonList(SchemaTable.newBuilder().setTable(getSourceTableOrderName()).setSchema(schema).build()));
+        parameter.setDatabaseType(getDatabaseType().getType());
+        CompletableFuture.runAsync(() -> new CDCClient(parameter).start(), executor).whenComplete((unused, throwable) -> {
+            if (null != throwable) {
+                log.error("cdc client sync failed, ", throwable);
+            }
+            throw new RuntimeException(throwable);
+        });
+    }
+    
+    protected List<Map<String, Object>> listOrderRecords(final String tableNameWithSchema) throws SQLException {
+        try (Connection connection = DriverManager.getConnection(getActualJdbcUrlTemplate(DS_4, false), getUsername(), getPassword())) {
+            ResultSet resultSet = connection.createStatement().executeQuery(String.format("SELECT * FROM %s ORDER BY order_id ASC", tableNameWithSchema));
+            return transformResultSetToList(resultSet);
+        }
+    }
+    
+    protected void assertDataMatched(final List<Map<String, Object>> actualProxyRecords, final List<Map<String, Object>> actualImportedRecords) {
+        for (int i = 0; i < actualProxyRecords.size(); i++) {
+            Map<String, Object> proxyData = actualProxyRecords.get(i);
+            Map<String, Object> importedData = actualImportedRecords.get(i);
+            Object orderId = proxyData.get("order_id");
+            assertThat(orderId, is(importedData.get("order_id")));
+            assertThat(proxyData.get("user_id"), is(importedData.get("user_id")));
+            assertThat(proxyData.get("status"), is(importedData.get("status")));
+            assertThat(proxyData.get("t_json"), is(importedData.get("t_json")));
+            // TODO the result of openGauss contain more precise value, eg.2023-02-28 21:46:30.828, but proxy result is 2023-02-28 13:46:30.828664, ignore nanos now
+            assertThat(((Timestamp) proxyData.get("t_timestamp")).getTime(), is(((Timestamp) importedData.get("t_timestamp")).getTime()));
+            assertThat(proxyData.get("t_char"), is(importedData.get("t_char")));
+            assertThat(proxyData.get("t_text"), is(importedData.get("t_text")));
+            // TODO the result of PostgreSQL contain more precise value, eg.11:59:37.979Z, but proxy result is 11:59:37
+            assertThat(proxyData.get("t_time").toString(), is(importedData.get("t_time").toString()));
+            assertThat(proxyData.get("t_date"), is(importedData.get("t_date")));
+        }
+    }

Review Comment:
   Could we reuse `SingleTableInventoryDataConsistencyChecker` to do consistency check? There will be much column types need to be tested



##########
test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/cdc/AbstractCDCE2EIT.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.shardingsphere.test.e2e.data.pipeline.cases.cdc;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.data.pipeline.cdc.client.CDCClient;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.ImportDataSourceParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.StartCDCClientParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.protocol.request.StreamDataRequestBody.SchemaTable;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.base.PipelineBaseE2EIT;
+import org.apache.shardingsphere.test.e2e.data.pipeline.env.enums.PipelineEnvTypeEnum;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.constants.ProxyContainerConstants;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.util.DatabaseTypeUtil;
+import org.junit.After;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Slf4j
+public abstract class AbstractCDCE2EIT extends PipelineBaseE2EIT {
+    
+    private static final String REGISTER_STORAGE_UNIT_SQL = "REGISTER STORAGE UNIT ds_0 ( URL='${ds0}', USER='${user}', PASSWORD='${password}'),"
+            + "ds_1 ( URL='${ds1}', USER='${user}', PASSWORD='${password}')";
+    
+    private static final String CREATE_SHARDING_RULE_SQL = "CREATE SHARDING TABLE RULE t_order("
+            + "STORAGE_UNITS(ds_0,ds_1),"
+            + "SHARDING_COLUMN=user_id,"
+            + "TYPE(NAME='hash_mod',PROPERTIES('sharding-count'='4')),"
+            + "KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='snowflake'))"
+            + ")";
+    
+    private final ExecutorService executor = Executors.newSingleThreadExecutor();
+    
+    public AbstractCDCE2EIT(final PipelineTestParameter testParam) {
+        super(testParam);
+        // if the time zone of the unit test and the time zone of the mirror do not match, CDC will get the wrong timestamp
+        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+    }
+    
+    protected void registerStorageUnit() throws SQLException {
+        String registerStorageUnitTemplate = REGISTER_STORAGE_UNIT_SQL.replace("${user}", getUsername())
+                .replace("${password}", getPassword())
+                .replace("${ds0}", appendExtraParam(getActualJdbcUrlTemplate(DS_0, true)))
+                .replace("${ds1}", appendExtraParam(getActualJdbcUrlTemplate(DS_1, true)));
+        addResource(registerStorageUnitTemplate);
+    }
+    
+    protected void createOrderTableRule() throws SQLException {
+        proxyExecuteWithLog(CREATE_SHARDING_RULE_SQL, 2);
+    }
+    
+    protected void createSchema(final String schemaName) throws SQLException {
+        if (!getDatabaseType().isSchemaAvailable()) {
+            return;
+        }
+        if (DatabaseTypeUtil.isPostgreSQL(getDatabaseType())) {
+            proxyExecuteWithLog(String.format("CREATE SCHEMA IF NOT EXISTS %s", schemaName), 2);
+            return;
+        }
+        if (DatabaseTypeUtil.isOpenGauss(getDatabaseType())) {
+            proxyExecuteWithLog(String.format("CREATE SCHEMA %s", schemaName), 2);
+        }
+    }
+    
+    protected void startCDCClient() {
+        ImportDataSourceParameter importDataSourceParam = new ImportDataSourceParameter(appendExtraParam(getActualJdbcUrlTemplate(DS_4, false, 0)), getUsername(), getPassword());
+        StartCDCClientParameter parameter = new StartCDCClientParameter(importDataSourceParam);
+        parameter.setAddress("localhost");
+        parameter.setPort(getContainerComposer().getProxyCDCPort());
+        parameter.setUsername(PipelineEnvTypeEnum.DOCKER == ENV.getItEnvType() ? ProxyContainerConstants.USERNAME : "root");
+        parameter.setPassword(PipelineEnvTypeEnum.DOCKER == ENV.getItEnvType() ? ProxyContainerConstants.PASSWORD : "root");
+        parameter.setDatabase("sharding_db");
+        parameter.setFull(true);

Review Comment:
   TODO is needed here, `full=false` should be tested later



##########
test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/framework/container/compose/DockerContainerComposer.java:
##########
@@ -92,6 +92,11 @@ public String getProxyJdbcUrl(final String databaseName) {
         return DataSourceEnvironment.getURL(databaseType, proxyContainer.getHost(), proxyContainer.getFirstMappedPort(), databaseName);
     }
     
+    @Override

Review Comment:
   Is `proxyContainer.getFirstMappedPort()` equivalent with `proxyContainer.getMappedPort(3307)`?



##########
test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/cdc/OpenGaussCDCE2EIT.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.shardingsphere.test.e2e.data.pipeline.cases.cdc;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.shardingsphere.data.pipeline.cdc.api.job.type.CDCJobType;
+import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.base.PipelineBaseE2EIT;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.task.CDCIncrementTask;
+import org.apache.shardingsphere.test.e2e.data.pipeline.env.enums.PipelineEnvTypeEnum;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.helper.PipelineCaseHelper;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter;
+import org.apache.shardingsphere.test.e2e.data.pipeline.util.DataSourceExecuteUtil;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.testcontainers.shaded.org.awaitility.Awaitility;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.time.LocalDateTime;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * CDC general E2E IT.
+ */
+@RunWith(Parameterized.class)
+@Slf4j
+public final class OpenGaussCDCE2EIT extends AbstractCDCE2EIT {
+    

Review Comment:
   Could we merge `OpenGaussCDCE2EIT` and `MySQLCDCE2EIT`?



##########
test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/cdc/AbstractCDCE2EIT.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.shardingsphere.test.e2e.data.pipeline.cases.cdc;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.data.pipeline.cdc.client.CDCClient;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.ImportDataSourceParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.client.parameter.StartCDCClientParameter;
+import org.apache.shardingsphere.data.pipeline.cdc.protocol.request.StreamDataRequestBody.SchemaTable;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.base.PipelineBaseE2EIT;
+import org.apache.shardingsphere.test.e2e.data.pipeline.env.enums.PipelineEnvTypeEnum;
+import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.constants.ProxyContainerConstants;
+import org.apache.shardingsphere.test.e2e.env.container.atomic.util.DatabaseTypeUtil;
+import org.junit.After;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.TimeZone;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+@Slf4j
+public abstract class AbstractCDCE2EIT extends PipelineBaseE2EIT {
+    
+    private static final String REGISTER_STORAGE_UNIT_SQL = "REGISTER STORAGE UNIT ds_0 ( URL='${ds0}', USER='${user}', PASSWORD='${password}'),"
+            + "ds_1 ( URL='${ds1}', USER='${user}', PASSWORD='${password}')";
+    
+    private static final String CREATE_SHARDING_RULE_SQL = "CREATE SHARDING TABLE RULE t_order("
+            + "STORAGE_UNITS(ds_0,ds_1),"
+            + "SHARDING_COLUMN=user_id,"
+            + "TYPE(NAME='hash_mod',PROPERTIES('sharding-count'='4')),"
+            + "KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME='snowflake'))"
+            + ")";
+    
+    private final ExecutorService executor = Executors.newSingleThreadExecutor();
+    
+    public AbstractCDCE2EIT(final PipelineTestParameter testParam) {
+        super(testParam);
+        // if the time zone of the unit test and the time zone of the mirror do not match, CDC will get the wrong timestamp
+        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

Review Comment:
   It might work around for E2E, but I'm afraid it doesn't work for real world. Could we set timezone in CDC dumper/importer etc?
   Since we don't know users' database timezone, we should supply a way to configure it for users.



##########
test/e2e/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/task/CDCIncrementTask.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.shardingsphere.test.e2e.data.pipeline.cases.task;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.test.e2e.data.pipeline.cases.base.BaseIncrementTask;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.time.LocalDate;
+import java.time.temporal.ChronoUnit;
+import java.util.concurrent.ThreadLocalRandom;
+
+@RequiredArgsConstructor
+@Slf4j
+public final class CDCIncrementTask extends BaseIncrementTask {

Review Comment:
   Could we reuse `MySQLIncrementTask` and `PostgreSQLIncrementTask`?



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org