sandynz commented on code in PR #30602: URL: https://github.com/apache/shardingsphere/pull/30602#discussion_r1535245065
########## test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/MySQLToPostgreSQLMigrationE2E.java: ########## @@ -0,0 +1,139 @@ +/* + * 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.migration.general; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.RandomUtils; +import org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobType; +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.test.e2e.data.pipeline.cases.PipelineContainerComposer; +import org.apache.shardingsphere.test.e2e.data.pipeline.cases.migration.AbstractMigrationE2EIT; +import org.apache.shardingsphere.test.e2e.data.pipeline.env.PipelineE2EEnvironment; +import org.apache.shardingsphere.test.e2e.data.pipeline.env.enums.PipelineEnvTypeEnum; +import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ECondition; +import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ESettings; +import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ESettings.PipelineE2EDatabaseSettings; +import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ETestCaseArgumentsProvider; +import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter; +import org.junit.jupiter.api.condition.EnabledIf; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.shaded.org.awaitility.Awaitility; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@Slf4j +@PipelineE2ESettings(fetchSingle = true, database = @PipelineE2EDatabaseSettings(type = "MySQL", scenarioFiles = "env/common/none.xml")) +public class MySQLToPostgreSQLMigrationE2E extends AbstractMigrationE2EIT { Review Comment: Class name could use PostgreSQLToMySQLXxx ########## test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/data/pipeline/cases/migration/general/MySQLToPostgreSQLMigrationE2E.java: ########## @@ -0,0 +1,139 @@ +/* + * 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.migration.general; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.RandomStringUtils; +import org.apache.commons.lang3.RandomUtils; +import org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobType; +import org.apache.shardingsphere.infra.database.core.type.DatabaseType; +import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.test.e2e.data.pipeline.cases.PipelineContainerComposer; +import org.apache.shardingsphere.test.e2e.data.pipeline.cases.migration.AbstractMigrationE2EIT; +import org.apache.shardingsphere.test.e2e.data.pipeline.env.PipelineE2EEnvironment; +import org.apache.shardingsphere.test.e2e.data.pipeline.env.enums.PipelineEnvTypeEnum; +import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ECondition; +import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ESettings; +import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ESettings.PipelineE2EDatabaseSettings; +import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineE2ETestCaseArgumentsProvider; +import org.apache.shardingsphere.test.e2e.data.pipeline.framework.param.PipelineTestParameter; +import org.junit.jupiter.api.condition.EnabledIf; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ArgumentsSource; +import org.testcontainers.containers.PostgreSQLContainer; +import org.testcontainers.shaded.org.awaitility.Awaitility; + +import java.math.BigDecimal; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@Slf4j +@PipelineE2ESettings(fetchSingle = true, database = @PipelineE2EDatabaseSettings(type = "MySQL", scenarioFiles = "env/common/none.xml")) +public class MySQLToPostgreSQLMigrationE2E extends AbstractMigrationE2EIT { + + @ParameterizedTest(name = "{0}") + @EnabledIf("isEnabled") + @ArgumentsSource(PipelineE2ETestCaseArgumentsProvider.class) + void assertMySQLToPostgreSQLMigrationSuccess(final PipelineTestParameter testParam) throws SQLException { + PostgreSQLContainer<?> postgreSQLContainer = null; + try (PipelineContainerComposer containerComposer = new PipelineContainerComposer(testParam, new MigrationJobType())) { + if (PipelineEnvTypeEnum.DOCKER == PipelineE2EEnvironment.getInstance().getItEnvType()) { + postgreSQLContainer = new PostgreSQLContainer<>("postgres:13"); + postgreSQLContainer.withNetwork(containerComposer.getContainerComposer().getContainers().getNetwork()).withNetworkAliases("postgresql.host") + .withDatabaseName("postgres").withUsername("postgres").withPassword("postgres").withCommand("-c wal_level=logical").start(); + } + String jdbcUrl = PipelineE2EEnvironment.getInstance().getItEnvType() == PipelineEnvTypeEnum.DOCKER ? postgreSQLContainer.getJdbcUrl() : "jdbc:postgresql://localhost:5432/postgres"; + initSourceTable(jdbcUrl); + registerMigrationSourceStorageUnit(containerComposer); + containerComposer.registerStorageUnit(PipelineContainerComposer.DS_0); + containerComposer.proxyExecuteWithLog("CREATE SHARDING TABLE RULE t_order(STORAGE_UNITS(pipeline_it_0),SHARDING_COLUMN=order_id,TYPE(NAME='hash_mod',PROPERTIES('sharding-count'='2'))," + + "KEY_GENERATE_STRATEGY(COLUMN=order_id, TYPE(NAME='snowflake')))", 2); + initTargetTable(containerComposer); + containerComposer.proxyExecuteWithLog("MIGRATE TABLE source_ds.t_order INTO t_order", 2); + Awaitility.await().ignoreExceptions().atMost(10, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(() -> !listJobId(containerComposer).isEmpty()); + String jobId = listJobId(containerComposer).get(0); + try (Connection connection = DriverManager.getConnection(jdbcUrl, "postgres", "postgres")) { + connection.createStatement().execute(String.format("INSERT INTO t_order (order_id,user_id,status) VALUES (%s, %s, '%s')", "1000000000", 1, "afterStop")); Review Comment: Wait job status reached could be used to make sure record is updated on incremental stage -- 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]
