You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/04/23 12:08:16 UTC

[shardingsphere] branch master updated: Add scaling manual it test (#17017)

This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new d81b1d5d8c0 Add scaling manual it test (#17017)
d81b1d5d8c0 is described below

commit d81b1d5d8c0807de7c5e8705bafe790b2a130a0f
Author: azexcy <10...@users.noreply.github.com>
AuthorDate: Sat Apr 23 20:08:10 2022 +0800

    Add scaling manual it test (#17017)
---
 .../core/metadata/node/PipelineMetaDataNode.java   |  11 ++
 .../integration/data/pipline/cases/BaseITCase.java | 104 -----------
 .../data/pipline/cases/BaseScalingITCase.java      | 197 +++++++++++++++++++++
 .../pipline/cases/command/CommonSQLCommand.java    |  37 +++-
 .../pipline/cases/command/mysql/MySQLCommand.java  |   6 +
 .../pipline/cases/mysql/MySQLAutoRuleScaling.java  | 104 -----------
 .../cases/mysql/MySQLManualScalingCase.java        | 127 +++++++++++++
 .../container/compose/BaseComposedContainer.java   |   5 +-
 .../container/compose/DockerComposedContainer.java |   4 +-
 .../container/compose/LocalComposedContainer.java  |   4 +-
 .../src/test/resources/env/common/command.xml      |  82 ++++++++-
 .../src/test/resources/env/mysql/sql.xml           |  22 ++-
 12 files changed, 474 insertions(+), 229 deletions(-)

diff --git a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/node/PipelineMetaDataNode.java b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/node/PipelineMetaDataNode.java
index d2be0ff20a7..0efc61d4ae3 100644
--- a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/node/PipelineMetaDataNode.java
+++ b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/node/PipelineMetaDataNode.java
@@ -47,4 +47,15 @@ public final class PipelineMetaDataNode {
     public static String getScalingRootPath() {
         return "/" + ROOT_NODE;
     }
+    
+    /**
+     * Get scaling job offset path.
+     *
+     * @param jobId job id.
+     * @param shardingItem sharding item.
+     * @return job offset path.
+     */
+    public static String getScalingJobOffsetPath(final String jobId, final int shardingItem) {
+        return Joiner.on("/").join(getScalingRootPath(), jobId, "offset", shardingItem);
+    }
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/BaseITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/BaseITCase.java
deleted file mode 100644
index 1ec7ff03787..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/BaseITCase.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.integration.data.pipline.cases;
-
-import com.google.common.base.Joiner;
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.SneakyThrows;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.integration.data.pipline.container.compose.BaseComposedContainer;
-import org.apache.shardingsphere.integration.data.pipline.container.compose.DockerComposedContainer;
-import org.apache.shardingsphere.integration.data.pipline.container.compose.LocalComposedContainer;
-import org.apache.shardingsphere.integration.data.pipline.env.IntegrationTestEnvironment;
-import org.apache.shardingsphere.integration.data.pipline.env.enums.ITEnvTypeEnum;
-import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
-import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepositoryConfiguration;
-import org.apache.shardingsphere.mode.repository.cluster.zookeeper.CuratorZookeeperRepository;
-import org.junit.Before;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.List;
-import java.util.Properties;
-
-@Getter(AccessLevel.PROTECTED)
-public abstract class BaseITCase {
-    
-    @Getter(AccessLevel.NONE)
-    private final BaseComposedContainer composedContainer;
-    
-    private ClusterPersistRepository clusterPersistRepository;
-    
-    public BaseITCase(final DatabaseType databaseType) {
-        if (StringUtils.equalsIgnoreCase(IntegrationTestEnvironment.getInstance().getItEnvType(), ITEnvTypeEnum.DOCKER.name())) {
-            composedContainer = new DockerComposedContainer(databaseType);
-        } else {
-            composedContainer = new LocalComposedContainer(databaseType);
-        }
-    }
-    
-    @Before
-    public void setUp() {
-        composedContainer.start();
-        clusterPersistRepository = new CuratorZookeeperRepository();
-        clusterPersistRepository.init(new ClusterPersistRepositoryConfiguration("ZooKeeper", "it_db", composedContainer.getGovernanceContainer().getServerLists(), new Properties()));
-    }
-    
-    /**
-     * Get proxy database connection.
-     *
-     * @return proxy database connection
-     */
-    @SneakyThrows(SQLException.class)
-    public Connection getProxyConnection() {
-        return composedContainer.getProxyConnection();
-    }
-    
-    /**
-     * Get database url, such as  ip:port.
-     *
-     * @return database url
-     */
-    public String getDatabaseUrl() {
-        if (StringUtils.equalsIgnoreCase(IntegrationTestEnvironment.getInstance().getItEnvType(), ITEnvTypeEnum.DOCKER.name())) {
-            return Joiner.on(":").join("db.host", composedContainer.getDatabaseContainer().getPort());
-        } else {
-            return Joiner.on(":").join(composedContainer.getDatabaseContainer().getHost(), composedContainer.getDatabaseContainer().getFirstMappedPort());
-        }
-    }
-    
-    /**
-     * Query actual source database name.
-     *
-     * @return actual source database name list
-     */
-    public List<String> listSourceDatabaseName() {
-        return composedContainer.getDatabaseContainer().getSourceDatabaseNames();
-    }
-    
-    /**
-     * Query actual target database name.
-     *
-     * @return actual target database name list
-     */
-    public List<String> listTargetDatabaseName() {
-        return composedContainer.getDatabaseContainer().getTargetDatabaseNames();
-    }
-}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/BaseScalingITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/BaseScalingITCase.java
new file mode 100644
index 00000000000..7517b3bc22f
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/BaseScalingITCase.java
@@ -0,0 +1,197 @@
+/*
+ * 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.integration.data.pipline.cases;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.Lists;
+import lombok.AccessLevel;
+import lombok.Getter;
+import lombok.SneakyThrows;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shardingsphere.data.pipeline.api.job.JobStatus;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.integration.data.pipline.cases.command.CommonSQLCommand;
+import org.apache.shardingsphere.integration.data.pipline.container.compose.BaseComposedContainer;
+import org.apache.shardingsphere.integration.data.pipline.container.compose.DockerComposedContainer;
+import org.apache.shardingsphere.integration.data.pipline.container.compose.LocalComposedContainer;
+import org.apache.shardingsphere.integration.data.pipline.env.IntegrationTestEnvironment;
+import org.apache.shardingsphere.integration.data.pipline.env.enums.ITEnvTypeEnum;
+import org.junit.Before;
+import org.testcontainers.shaded.com.google.common.base.Splitter;
+
+import javax.xml.bind.JAXB;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+@Getter(AccessLevel.PROTECTED)
+public abstract class BaseScalingITCase {
+    
+    @Getter(AccessLevel.NONE)
+    private final BaseComposedContainer composedContainer;
+    
+    @Getter(AccessLevel.PROTECTED)
+    private CommonSQLCommand commonSQLCommand;
+    
+    public BaseScalingITCase(final DatabaseType databaseType) {
+        if (StringUtils.equalsIgnoreCase(IntegrationTestEnvironment.getInstance().getItEnvType(), ITEnvTypeEnum.DOCKER.name())) {
+            composedContainer = new DockerComposedContainer(databaseType);
+        } else {
+            composedContainer = new LocalComposedContainer(databaseType);
+        }
+    }
+    
+    @Before
+    public void init() throws SQLException {
+        composedContainer.start();
+        commonSQLCommand = JAXB.unmarshal(BaseScalingITCase.class.getClassLoader().getResource("env/common/command.xml"), CommonSQLCommand.class);
+        initScalingEnvironment();
+    }
+    
+    @SneakyThrows
+    protected void initScalingEnvironment() {
+        try (Connection connection = getProxyConnection("")) {
+            connection.createStatement().execute(commonSQLCommand.getCreateDatabase());
+            connection.createStatement().execute(commonSQLCommand.getUseDatabase());
+            int dbIndex = 0;
+            for (String dbName : listSourceDatabaseName()) {
+                connection.createStatement().execute(String.format(commonSQLCommand.getAddResource(), dbIndex, getDatabaseUrl(), dbName));
+                dbIndex++;
+            }
+            for (String value : listTargetDatabaseName()) {
+                connection.createStatement().execute(String.format(commonSQLCommand.getAddResource(), dbIndex, getDatabaseUrl(), value));
+                dbIndex++;
+            }
+            for (String sql : Splitter.on(";").splitToList(commonSQLCommand.getCreateShardingAlgorithm())) {
+                connection.createStatement().execute(sql);
+            }
+            // TODO sleep to wait for sharding algorithm table created,otherwise, the next sql will fail.
+            TimeUnit.SECONDS.sleep(1);
+            connection.createStatement().execute(commonSQLCommand.getCreateShardingTable());
+            connection.createStatement().execute(commonSQLCommand.getCreateShardingBinding());
+            connection.createStatement().execute(commonSQLCommand.getCreateShardingScalingRule());
+        }
+    }
+    
+    /**
+     * Get proxy database connection.
+     *
+     * @param dataSourceName data source names
+     * @return proxy database connection
+     */
+    @SneakyThrows(SQLException.class)
+    public Connection getProxyConnection(final String dataSourceName) {
+        return composedContainer.getProxyConnection(dataSourceName);
+    }
+    
+    /**
+     * Get database url, such as  ip:port.
+     *
+     * @return database url
+     */
+    public String getDatabaseUrl() {
+        if (StringUtils.equalsIgnoreCase(IntegrationTestEnvironment.getInstance().getItEnvType(), ITEnvTypeEnum.DOCKER.name())) {
+            return Joiner.on(":").join("db.host", composedContainer.getDatabaseContainer().getPort());
+        } else {
+            return Joiner.on(":").join(composedContainer.getDatabaseContainer().getHost(), composedContainer.getDatabaseContainer().getFirstMappedPort());
+        }
+    }
+    
+    /**
+     * Query actual source database name.
+     *
+     * @return actual source database name list
+     */
+    public List<String> listSourceDatabaseName() {
+        return composedContainer.getDatabaseContainer().getSourceDatabaseNames();
+    }
+    
+    /**
+     * Query actual target database name.
+     *
+     * @return actual target database name list
+     */
+    public List<String> listTargetDatabaseName() {
+        return composedContainer.getDatabaseContainer().getTargetDatabaseNames();
+    }
+    
+    /**
+     * Check data match consistency.
+     * @param connection proxy database connection
+     * @param jobId job id
+     * @throws InterruptedException if interrupted
+     * @throws SQLException if any SQL exception
+     */
+    protected void checkMatchConsistency(final Connection connection, final String jobId) throws InterruptedException, SQLException {
+        Map<String, String> actualStatusMap = new HashMap<>(2, 1);
+        for (int i = 0; i < 100; i++) {
+            ResultSet statusResult = connection.createStatement().executeQuery(String.format(commonSQLCommand.getShowScalingStatus(), jobId));
+            boolean finished = true;
+            while (statusResult.next()) {
+                String datasourceName = statusResult.getString(2);
+                String status = statusResult.getString(3);
+                actualStatusMap.put(datasourceName, status);
+                assertThat(status, not(JobStatus.PREPARING_FAILURE.name()));
+                assertThat(status, not(JobStatus.EXECUTE_INVENTORY_TASK_FAILURE.name()));
+                assertThat(status, not(JobStatus.EXECUTE_INCREMENTAL_TASK_FAILURE.name()));
+                if (!Objects.equals(status, JobStatus.EXECUTE_INCREMENTAL_TASK.name())) {
+                    finished = false;
+                    break;
+                }
+            }
+            if (finished) {
+                break;
+            } else {
+                TimeUnit.SECONDS.sleep(2);
+            }
+        }
+        assertThat(actualStatusMap.values().stream().filter(StringUtils::isNotBlank).collect(Collectors.toSet()).size(), is(1));
+        connection.createStatement().execute(String.format(getCommonSQLCommand().getStopScalingSourceWriting(), jobId));
+        ResultSet checkScalingResult = connection.createStatement().executeQuery(String.format(commonSQLCommand.getCheckScalingDataMatch(), jobId));
+        while (checkScalingResult.next()) {
+            assertTrue(checkScalingResult.getBoolean(5));
+        }
+        connection.createStatement().execute(String.format(getCommonSQLCommand().getApplyScaling(), jobId));
+        ResultSet previewResult = connection.createStatement().executeQuery(getCommonSQLCommand().getPreviewSelectOrder());
+        List<String> actualTargetNodes = Lists.newLinkedList();
+        while (previewResult.next()) {
+            actualTargetNodes.add(previewResult.getString(1));
+        }
+        assertThat(actualTargetNodes, is(Lists.newArrayList("ds_2", "ds_3", "ds_4")));
+    }
+    
+    /**
+     * Initialize table data.
+     * @param connection proxy database connection
+     * @param insertOrderSQL insert order sql
+     * @param insertOrderItemSQL insert order item sql
+     * @throws SQLException if any SQL exception
+     */
+    protected abstract void initTableData(Connection connection, String insertOrderSQL, String insertOrderItemSQL) throws SQLException;
+}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/command/CommonSQLCommand.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/command/CommonSQLCommand.java
index 4c36d4e13fd..641c8a57513 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/command/CommonSQLCommand.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/command/CommonSQLCommand.java
@@ -38,6 +38,39 @@ public final class CommonSQLCommand {
     @XmlElement(name = "use-database")
     private String useDatabase;
     
-    @XmlElement(name = "create-sharding-table-rule")
-    private String createShardingTableRule;
+    @XmlElement(name = "create-sharding-algorithm")
+    private String createShardingAlgorithm;
+    
+    @XmlElement(name = "create-sharding-table")
+    private String createShardingTable;
+    
+    @XmlElement(name = "create-sharding-binding")
+    private String createShardingBinding;
+    
+    @XmlElement(name = "create-sharding-scaling-rule")
+    private String createShardingScalingRule;
+    
+    @XmlElement(name = "alter-sharding-algorithm")
+    private String alterShardingAlgorithm;
+    
+    @XmlElement(name = "alter-sharding-table-rule")
+    private String alterShardingTableRule;
+    
+    @XmlElement(name = "preview-select-order")
+    private String previewSelectOrder;
+    
+    @XmlElement(name = "show-scaling-status")
+    private String showScalingStatus;
+    
+    @XmlElement(name = "show-scaling-list")
+    private String showScalingList;
+    
+    @XmlElement(name = "stop-scaling-source-writing")
+    private String stopScalingSourceWriting;
+    
+    @XmlElement(name = "check-scaling-data-match")
+    private String checkScalingDataMatch;
+    
+    @XmlElement(name = "apply-scaling")
+    private String applyScaling;
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/command/mysql/MySQLCommand.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/command/mysql/MySQLCommand.java
index c15d57d2b31..f2b5f36cd40 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/command/mysql/MySQLCommand.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/command/mysql/MySQLCommand.java
@@ -32,6 +32,12 @@ public final class MySQLCommand {
     @XmlElement(name = "create-table-order")
     private String createTableOrder;
     
+    @XmlElement(name = "create-table-orderitem")
+    private String createTableOrderItem;
+    
     @XmlElement(name = "insert-order")
     private String insertOrder;
+    
+    @XmlElement(name = "insert-order-item")
+    private String insertOrderItem;
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/mysql/MySQLAutoRuleScaling.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/mysql/MySQLAutoRuleScaling.java
deleted file mode 100644
index c6a1e1fd572..00000000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/mysql/MySQLAutoRuleScaling.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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.integration.data.pipline.cases.mysql;
-
-import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.integration.data.pipline.cases.BaseITCase;
-import org.apache.shardingsphere.integration.data.pipline.cases.command.CommonSQLCommand;
-import org.apache.shardingsphere.integration.data.pipline.cases.command.mysql.MySQLCommand;
-import org.apache.shardingsphere.sharding.algorithm.keygen.SnowflakeKeyGenerateAlgorithm;
-import org.junit.Before;
-import org.junit.Test;
-
-import javax.xml.bind.JAXB;
-import java.math.BigDecimal;
-import java.nio.charset.StandardCharsets;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.Timestamp;
-import java.util.Objects;
-
-/**
- * MySQL auto rule scaling test case.
- */
-public final class MySQLAutoRuleScaling extends BaseITCase {
-    
-    private static final SnowflakeKeyGenerateAlgorithm SNOWFLAKE_GENERATE = new SnowflakeKeyGenerateAlgorithm();
-    
-    public MySQLAutoRuleScaling() {
-        super(new MySQLDatabaseType());
-    }
-    
-    @SneakyThrows
-    @Before
-    public void setUp() {
-        super.setUp();
-        CommonSQLCommand commonSQLCommand = JAXB.unmarshal(Objects.requireNonNull(getClass().getClassLoader().getResource("env/common/command.xml")), CommonSQLCommand.class);
-        MySQLCommand mysqlCommand = JAXB.unmarshal(Objects.requireNonNull(getClass().getClassLoader().getResource("env/mysql/sql.xml")), MySQLCommand.class);
-        try (Connection connection = getProxyConnection()) {
-            connection.createStatement().execute(commonSQLCommand.getCreateDatabase());
-            connection.createStatement().execute(commonSQLCommand.getUseDatabase());
-            int dbIndex = 0;
-            for (String dbName : listSourceDatabaseName()) {
-                connection.createStatement().execute(String.format(commonSQLCommand.getAddResource(), dbIndex, getDatabaseUrl(), dbName));
-                dbIndex++;
-            }
-            for (String value : listTargetDatabaseName()) {
-                connection.createStatement().execute(String.format(commonSQLCommand.getAddResource(), dbIndex, getDatabaseUrl(), value));
-                dbIndex++;
-            }
-            connection.createStatement().execute(commonSQLCommand.getCreateShardingTableRule());
-            connection.createStatement().execute(mysqlCommand.getCreateTableOrder());
-            // init date, need more than 3000 rows, in order to test certain conditions
-            initTableDataOfOrder(connection, mysqlCommand.getInsertOrder(), 1000);
-        }
-    }
-    
-    private void initTableDataOfOrder(final Connection connection, final String insertSQL, final int batchSize) throws Exception {
-        connection.setAutoCommit(false);
-        PreparedStatement statement = connection.prepareStatement(insertSQL);
-        for (int i = 1; i <= 5000; i++) {
-            statement.setLong(1, (Long) SNOWFLAKE_GENERATE.generateKey());
-            statement.setString(2, "varchar" + i);
-            statement.setByte(3, (byte) 1);
-            statement.setInt(4, 100);
-            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
-            statement.setTimestamp(5, timestamp);
-            statement.setTimestamp(6, timestamp);
-            statement.setBytes(7, "hello".getBytes(StandardCharsets.UTF_8));
-            statement.setBinaryStream(8, null);
-            statement.setBigDecimal(9, new BigDecimal("100.00"));
-            statement.setString(10, "test");
-            statement.setDouble(11, Math.random());
-            statement.setString(12, "{}");
-            statement.addBatch();
-            if (i % batchSize == 0) {
-                statement.executeBatch();
-                statement.clearParameters();
-            }
-        }
-        connection.commit();
-        connection.setAutoCommit(true);
-    }
-    
-    @Test
-    public void test() {
-        
-    }
-}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/mysql/MySQLManualScalingCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/mysql/MySQLManualScalingCase.java
new file mode 100644
index 00000000000..6cc9a1a610c
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/cases/mysql/MySQLManualScalingCase.java
@@ -0,0 +1,127 @@
+/*
+ * 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.integration.data.pipline.cases.mysql;
+
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.integration.data.pipline.cases.BaseScalingITCase;
+import org.apache.shardingsphere.integration.data.pipline.cases.command.mysql.MySQLCommand;
+import org.apache.shardingsphere.sharding.algorithm.keygen.SnowflakeKeyGenerateAlgorithm;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import javax.xml.bind.JAXB;
+import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * MySQL auto rule scaling test case.
+ */
+@Slf4j
+public final class MySQLManualScalingCase extends BaseScalingITCase {
+    
+    private static final SnowflakeKeyGenerateAlgorithm SNOWFLAKE_GENERATE = new SnowflakeKeyGenerateAlgorithm();
+    
+    private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current();
+    
+    private static MySQLCommand mySQLCommand;
+    
+    public MySQLManualScalingCase() {
+        super(new MySQLDatabaseType());
+    }
+    
+    @BeforeClass
+    public static void beforeClass() {
+        mySQLCommand = JAXB.unmarshal(MySQLManualScalingCase.class.getClassLoader().getResource("env/mysql/sql.xml"), MySQLCommand.class);
+    }
+    
+    @Before
+    public void init() throws SQLException {
+        super.init();
+        try (Connection connection = getProxyConnection("sharding_db")) {
+            connection.createStatement().execute(mySQLCommand.getCreateTableOrder());
+            connection.createStatement().execute(mySQLCommand.getCreateTableOrderItem());
+            // init date, need more than 3000 rows, in order to test certain conditions
+            initTableData(connection, mySQLCommand.getInsertOrder(), mySQLCommand.getInsertOrderItem());
+        }
+    }
+    
+    @Override
+    protected void initTableData(final Connection connection, final String insertOrderSQL, final String insertOrderItemSQL) throws SQLException {
+        PreparedStatement orderStatement = connection.prepareStatement(insertOrderSQL);
+        PreparedStatement itemStatement = connection.prepareStatement(insertOrderItemSQL);
+        for (int i = 1; i <= 3000; i++) {
+            orderStatement.setLong(1, (Long) SNOWFLAKE_GENERATE.generateKey());
+            int orderId = RANDOM.nextInt(0, 5);
+            orderStatement.setInt(2, orderId);
+            int userId = RANDOM.nextInt(0, 5);
+            orderStatement.setInt(3, userId);
+            orderStatement.setString(4, "varchar" + i);
+            orderStatement.setByte(5, (byte) 1);
+            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
+            orderStatement.setTimestamp(6, timestamp);
+            orderStatement.setTimestamp(7, timestamp);
+            orderStatement.setBytes(8, "hello".getBytes(StandardCharsets.UTF_8));
+            orderStatement.setBinaryStream(9, null);
+            orderStatement.setBigDecimal(10, new BigDecimal("100.00"));
+            orderStatement.setString(11, "test");
+            orderStatement.setDouble(12, Math.random());
+            orderStatement.setString(13, "{}");
+            orderStatement.addBatch();
+            itemStatement.setLong(1, (Long) SNOWFLAKE_GENERATE.generateKey());
+            itemStatement.setInt(2, orderId);
+            itemStatement.setInt(3, userId);
+            itemStatement.setString(4, "SUCCESS");
+            itemStatement.addBatch();
+        }
+        orderStatement.executeBatch();
+        itemStatement.executeBatch();
+    }
+    
+    @Test
+    public void test() throws SQLException, InterruptedException {
+        try (Connection connection = getProxyConnection("sharding_db")) {
+            ResultSet previewResult = connection.createStatement().executeQuery(getCommonSQLCommand().getPreviewSelectOrder());
+            List<String> actualSourceNodes = Lists.newLinkedList();
+            while (previewResult.next()) {
+                actualSourceNodes.add(previewResult.getString(1));
+            }
+            assertThat(actualSourceNodes, is(Lists.newArrayList("ds_0", "ds_1")));
+            connection.createStatement().execute(getCommonSQLCommand().getAlterShardingAlgorithm());
+            connection.createStatement().execute(getCommonSQLCommand().getAlterShardingTableRule());
+            ResultSet scalingList = connection.createStatement().executeQuery(getCommonSQLCommand().getShowScalingList());
+            assertTrue(scalingList.next());
+            String jobId = scalingList.getString(1);
+            checkMatchConsistency(connection, jobId);
+        }
+    }
+}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/BaseComposedContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/BaseComposedContainer.java
index 1fdb0e4473f..bee6137569d 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/BaseComposedContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/BaseComposedContainer.java
@@ -47,11 +47,12 @@ public abstract class BaseComposedContainer implements Startable {
     
     /**
      * Get proxy connection.
-     *
+     * 
+     * @param databaseName database name
      * @return sql connection.
      * @throws SQLException sql exception
      */
-    public abstract Connection getProxyConnection() throws SQLException;
+    public abstract Connection getProxyConnection(String databaseName) throws SQLException;
     
     @Override
     public void start() {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/DockerComposedContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/DockerComposedContainer.java
index 8ca9677f39f..b3259fa1af8 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/DockerComposedContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/DockerComposedContainer.java
@@ -50,8 +50,8 @@ public final class DockerComposedContainer extends BaseComposedContainer {
     }
     
     @Override
-    public Connection getProxyConnection() throws SQLException {
+    public Connection getProxyConnection(final String databaseName) throws SQLException {
         return DriverManager.getConnection(DataSourceEnvironment.getURL(getDatabaseContainer().getDatabaseType(),
-                getProxyContainer().getHost(), getProxyContainer().getFirstMappedPort(), ""), "root", "root");
+                getProxyContainer().getHost(), getProxyContainer().getFirstMappedPort(), databaseName), "root", "root");
     }
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/LocalComposedContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/LocalComposedContainer.java
index 91e681dc615..851d64098fa 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/LocalComposedContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipline/container/compose/LocalComposedContainer.java
@@ -46,7 +46,7 @@ public final class LocalComposedContainer extends BaseComposedContainer {
     }
     
     @Override
-    public Connection getProxyConnection() throws SQLException {
-        return DriverManager.getConnection(DataSourceEnvironment.getURL(getDatabaseContainer().getDatabaseType(), "localhost", 3307, ""), "root", "root");
+    public Connection getProxyConnection(final String databaseName) throws SQLException {
+        return DriverManager.getConnection(DataSourceEnvironment.getURL(getDatabaseContainer().getDatabaseType(), "localhost", 3307, databaseName), "root", "root");
     }
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/common/command.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/common/command.xml
index 01571e2b82f..42928ed29db 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/common/command.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/common/command.xml
@@ -17,20 +17,86 @@
 
 <command>
     <create-database>
-        CREATE DATABASE sharding_db;
+        CREATE DATABASE sharding_db
     </create-database>
     
     <use-database>
-        USE sharding_db;
+        USE sharding_db
     </use-database>
     
     <add-resource>
-        ADD RESOURCE ds_%s (URL="jdbc:mysql://%s/%s?serverTimezone=UTC&amp;useSSL=false&amp;rewriteBatchedStatements=true",USER=root,PASSWORD=root);
+        ADD RESOURCE ds_%s (URL="jdbc:mysql://%s/%s?serverTimezone=UTC&amp;useSSL=false&amp;rewriteBatchedStatements=true",USER=root,PASSWORD=root)
     </add-resource>
     
-    <create-sharding-table-rule>
-        CREATE SHARDING TABLE RULE
-        t_order(RESOURCES(ds_0,ds_1),SHARDING_COLUMN=order_id,TYPE(NAME=hash_mod,PROPERTIES("sharding-count"=4)),KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=snowflake))),
-        t_order_item(RESOURCES(ds_0,ds_1),SHARDING_COLUMN=order_id,TYPE(NAME=hash_mod,PROPERTIES("sharding-count"=4)),KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=snowflake)));
-    </create-sharding-table-rule>
+    <create-sharding-algorithm>
+        CREATE SHARDING ALGORITHM database_inline (
+        TYPE(NAME=INLINE,PROPERTIES("algorithm-expression"="ds_${user_id % 2}")));
+        CREATE SHARDING ALGORITHM t_order_inline (
+        TYPE(NAME=INLINE,PROPERTIES("algorithm-expression"="t_order_${order_id % 2}")));
+        CREATE SHARDING ALGORITHM t_order_item_inline (
+        TYPE(NAME=INLINE,PROPERTIES("algorithm-expression"="t_order_item_${order_id % 2}")))
+    </create-sharding-algorithm>
+    
+    <create-sharding-table>
+        CREATE SHARDING TABLE RULE t_order (
+        DATANODES("ds_${0..1}.t_order_${0..1}"),
+        DATABASE_STRATEGY(TYPE=standard,SHARDING_COLUMN=user_id,SHARDING_ALGORITHM=database_inline),
+        TABLE_STRATEGY(TYPE=standard,SHARDING_COLUMN=order_id,SHARDING_ALGORITHM=t_order_inline),
+        KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=snowflake))
+        ), t_order_item (
+        DATANODES("ds_${0..1}.t_order_item_${0..1}"),
+        DATABASE_STRATEGY(TYPE=standard,SHARDING_COLUMN=user_id,SHARDING_ALGORITHM=database_inline),
+        TABLE_STRATEGY(TYPE=standard,SHARDING_COLUMN=order_id,SHARDING_ALGORITHM=t_order_item_inline),
+        KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME=snowflake)))
+    </create-sharding-table>
+    
+    <create-sharding-binding>
+        CREATE SHARDING BINDING TABLE RULES (t_order,t_order_item)
+    </create-sharding-binding>
+    
+    <create-sharding-scaling-rule>
+        CREATE SHARDING SCALING RULE scaling_manual (DATA_CONSISTENCY_CHECKER(TYPE(NAME=CRC32_MATCH)))
+    </create-sharding-scaling-rule>
+    
+    <alter-sharding-algorithm>
+        ALTER SHARDING ALGORITHM database_inline (
+        TYPE(NAME=INLINE,PROPERTIES("algorithm-expression"="ds_${user_id % 3 + 2}")));
+    </alter-sharding-algorithm>
+    
+    <alter-sharding-table-rule>
+        ALTER SHARDING TABLE RULE t_order (
+        DATANODES("ds_${2..4}.t_order_${0..1}"),
+        DATABASE_STRATEGY(TYPE=standard,SHARDING_COLUMN=user_id,SHARDING_ALGORITHM=database_inline),
+        TABLE_STRATEGY(TYPE=standard,SHARDING_COLUMN=order_id,SHARDING_ALGORITHM=t_order_inline),
+        KEY_GENERATE_STRATEGY(COLUMN=order_id,TYPE(NAME=snowflake))
+        ), t_order_item (
+        DATANODES("ds_${2..4}.t_order_item_${0..1}"),
+        DATABASE_STRATEGY(TYPE=standard,SHARDING_COLUMN=user_id,SHARDING_ALGORITHM=database_inline),
+        TABLE_STRATEGY(TYPE=standard,SHARDING_COLUMN=order_id,SHARDING_ALGORITHM=t_order_item_inline),
+        KEY_GENERATE_STRATEGY(COLUMN=order_item_id,TYPE(NAME=snowflake)));
+    </alter-sharding-table-rule>
+    
+    <preview-select-order>
+        PREVIEW SELECT COUNT(1) FROM t_order;
+    </preview-select-order>
+    
+    <show-scaling-list>
+        SHOW SCALING LIST
+    </show-scaling-list>
+    
+    <show-scaling-status>
+        SHOW SCALING STATUS %s
+    </show-scaling-status>
+    
+    <stop-scaling-source-writing>
+        STOP SCALING SOURCE WRITING %s;
+    </stop-scaling-source-writing>
+    
+    <check-scaling-data-match>
+        CHECK SCALING %s BY TYPE (NAME=CRC32_MATCH);
+    </check-scaling-data-match>
+    
+    <apply-scaling>
+        APPLY SCALING %s;
+    </apply-scaling>
 </command>
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/mysql/sql.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/mysql/sql.xml
index 07a2b012acd..b78cd9be48c 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/mysql/sql.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/mysql/sql.xml
@@ -18,9 +18,10 @@
     <create-table-order>
         CREATE TABLE `t_order` (
         `id` BIGINT NOT NULL COMMENT 'pk id',
+        `order_id` INT NOT NULL,
+        `user_id` INT NOT NULL,
         `t_varchar` VARCHAR ( 255 ) NOT NULL,
         `t_tinyint` TINYINT ( 1 ) NULL,
-        `order_id` INT NULL,
         `t_timestamp` TIMESTAMP NULL,
         `t_datetime` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
         `t_binary` BINARY(255) NULL,
@@ -32,15 +33,16 @@
         PRIMARY KEY ( `id` ),
         UNIQUE INDEX ( `t_varchar` ),
         INDEX ( `order_id` )
-        );
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
     </create-table-order>
     
     <insert-order>
         INSERT INTO `t_order` (
         `id`,
+        `order_id`,
+        `user_id`,
         `t_varchar`,
         `t_tinyint`,
-        `order_id`,
         `t_timestamp`,
         `t_datetime`,
         `t_binary`,
@@ -50,10 +52,20 @@
         `t_double`,
         `t_json`
         )
-        VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );
+        VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?);
     </insert-order>
     
     <create-table-orderitem>
-    
+        CREATE TABLE t_order_item (
+        item_id bigint NOT NULL,
+        order_id int NOT NULL,
+        user_id int NOT NULL,
+        status varchar(50) DEFAULT NULL,
+        PRIMARY KEY (item_id)
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
     </create-table-orderitem>
+    
+    <insert-order-item>
+        INSERT INTO t_order_item(item_id, order_id, user_id, status) VALUES(?,?,?,?);
+    </insert-order-item>
 </command>