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 2021/01/30 16:02:46 UTC

[shardingsphere] branch master updated: In order to improve the quality of integration testing, we want to introduce embedded MySQL. (#9227)

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

zhangliang 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 1925d8a  In order to improve the quality of integration testing, we want to introduce embedded MySQL. (#9227)
1925d8a is described below

commit 1925d8aa694d27dcb618a8085023720c0c6efa02
Author: AlphaPo <ju...@163.com>
AuthorDate: Sun Jan 31 00:02:25 2021 +0800

    In order to improve the quality of integration testing, we want to introduce embedded MySQL. (#9227)
    
    * Added embedded MySQL support for integration testing
    Fixed multiple database type testing, if H2 is enabled, other database type data sources are not initialized
    Fixed the problem of not closing the target database connection pool after integration testing
    
    * merge untracked file
    
    * Add license
---
 pom.xml                                            |  9 ++-
 .../shardingsphere-integration-test-suite/pom.xml  |  5 ++
 .../test/integration/engine/it/BaseIT.java         | 18 ++++++
 .../env/IntegrationTestEnvironment.java            | 30 ++++++++--
 .../env/database/DatabaseEnvironmentManager.java   | 70 +++++++++++++++++++++-
 .../EmbeddedDatabaseResource.java}                 | 26 ++++----
 .../database/MySQLEmbeddedDatabaseResource.java    | 64 ++++++++++++++++++++
 .../env/datasource/DatabaseEnvironment.java        |  7 ++-
 .../builder/ActualDataSourceBuilder.java           |  2 +-
 .../env/datasource/builder/DataSourceCacheKey.java |  4 +-
 .../datasource/builder/ProxyDataSourceBuilder.java |  2 +-
 .../env/props/DatabaseScenarioProperties.java      | 20 +++++++
 .../test/resources/env/db/scenario-env.properties  |  4 ++
 .../scenario-env.properties                        |  4 ++
 .../src/test/resources/env/engine-env.properties   |  1 +
 .../env/replica_query/scenario-env.properties      |  4 ++
 .../test/resources/env/tbl/scenario-env.properties |  4 ++
 17 files changed, 248 insertions(+), 26 deletions(-)

diff --git a/pom.xml b/pom.xml
index a600b3f..2952b2f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,7 +105,8 @@
         
         <calcite.version>1.26.0</calcite.version>
         <commons-io.version>2.8.0</commons-io.version>
-        
+        <embedded-mysql.version>4.6.1</embedded-mysql.version>
+
         <!-- Plugin versions -->
         <apache-rat-plugin.version>0.12</apache-rat-plugin.version>
         <takari-maven-plugin.version>0.6.1</takari-maven-plugin.version>
@@ -455,6 +456,12 @@
                 <version>${spring-boot.version}</version>
                 <scope>test</scope>
             </dependency>
+            <dependency>
+                <groupId>com.wix</groupId>
+                <artifactId>wix-embedded-mysql</artifactId>
+                <version>${embedded-mysql.version}</version>
+                <scope>test</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
     
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml
index 400d7eb..ea128b1 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/pom.xml
@@ -71,6 +71,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>com.wix</groupId>
+            <artifactId>wix-embedded-mysql</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-dbcp2</artifactId>
             <scope>test</scope>
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BaseIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BaseIT.java
index 4782a40..6b2f0d9 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BaseIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/BaseIT.java
@@ -66,6 +66,13 @@ public abstract class BaseIT {
         this.databaseType = databaseType;
         actualDataSources = ActualDataSourceBuilder.createActualDataSources(scenario, databaseType);
         targetDataSource = createTargetDataSource();
+
+        // TODO maybe use @AfterClass, but targetDataSource should be static
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            if (targetDataSource instanceof ShardingSphereDataSource) {
+                closeTargetDataSource();
+            }
+        }));
     }
     
     private DataSource createTargetDataSource() throws SQLException, IOException {
@@ -92,4 +99,15 @@ public abstract class BaseIT {
             ((ShardingSphereDataSource) targetDataSource).getMetaDataContexts().getExecutorEngine().close();
         }
     }
+
+    private void closeTargetDataSource() {
+        ((ShardingSphereDataSource) targetDataSource).getDataSourceMap().values().forEach(dataSource -> {
+            try {
+                ((AutoCloseable) dataSource).close();
+                //CHECKSTYLE:OFF
+            } catch (Exception ignore) {
+            }
+            //CHECKSTYLE:ON
+        });
+    }
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/IntegrationTestEnvironment.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/IntegrationTestEnvironment.java
index beabbae..ceeb070 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/IntegrationTestEnvironment.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/IntegrationTestEnvironment.java
@@ -21,7 +21,9 @@ import com.google.common.base.Splitter;
 import lombok.Getter;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.test.integration.env.database.DatabaseEnvironmentManager;
 import org.apache.shardingsphere.test.integration.env.datasource.DatabaseEnvironment;
 import org.apache.shardingsphere.test.integration.env.props.DatabaseScenarioProperties;
 import org.apache.shardingsphere.test.integration.env.props.EnvironmentProperties;
@@ -57,15 +59,21 @@ public final class IntegrationTestEnvironment {
     private final Map<DatabaseType, Map<String, DatabaseEnvironment>> databaseEnvironments;
     
     private final Map<String, DatabaseEnvironment> proxyEnvironments;
+
+    private final boolean isDatabasesEmbedded;
     
     private IntegrationTestEnvironment() {
         Properties engineEnvProps = EnvironmentProperties.loadProperties("env/engine-env.properties");
         isEnvironmentPrepared = "docker".equals(engineEnvProps.getProperty("it.env.type"));
         adapters = Splitter.on(",").trimResults().splitToList(engineEnvProps.getProperty("it.adapters"));
         runAdditionalTestCases = Boolean.parseBoolean(engineEnvProps.getProperty("it.run.additional.cases"));
+        isDatabasesEmbedded = Boolean.parseBoolean(engineEnvProps.getProperty("it.databases.embedded"));
         scenarios = getScenarios(engineEnvProps);
         Map<String, DatabaseScenarioProperties> databaseProps = getDatabaseScenarioProperties();
         databaseEnvironments = createDatabaseEnvironments(getDatabaseTypes(engineEnvProps), databaseProps);
+        if (isDatabasesEmbedded) {
+            initEmbeddedDatabaseResources();
+        }
         proxyEnvironments = createProxyEnvironments(databaseProps);
         if (isEnvironmentPrepared) {
             for (String each : scenarios) {
@@ -107,11 +115,22 @@ public final class IntegrationTestEnvironment {
     }
     
     private DatabaseEnvironment createDatabaseEnvironment(final DatabaseType databaseType, final DatabaseScenarioProperties databaseProps) {
-        if ("H2".equals(databaseType.getName())) {
-            return new DatabaseEnvironment(databaseType, "", 0, "sa", ""); 
+        if (databaseType instanceof H2DatabaseType) {
+            return new DatabaseEnvironment(databaseType, "", 0, "sa", "", "", "");
+        }
+        return new DatabaseEnvironment(databaseType, databaseProps.getDatabaseHost(databaseType), databaseProps.getDatabasePort(databaseType),
+                databaseProps.getDatabaseUsername(databaseType), databaseProps.getDatabasePassword(databaseType),
+                databaseProps.getDatabaseDistributionUrl(databaseType), databaseProps.getDatabaseDistributionVersion(databaseType));
+    }
+
+    private void initEmbeddedDatabaseResources() {
+        if (!isEnvironmentPrepared()) {
+            for (Map.Entry<DatabaseType, Map<String, DatabaseEnvironment>> each : getDatabaseEnvironments().entrySet()) {
+                for (Map.Entry<String, DatabaseEnvironment> databaseEnvironmentEntry : each.getValue().entrySet()) {
+                    DatabaseEnvironmentManager.createEmbeddedDatabaseResource(each.getKey(), databaseEnvironmentEntry.getKey(), databaseEnvironmentEntry.getValue());
+                }
+            }
         }
-        return new DatabaseEnvironment(databaseType, databaseProps.getDatabaseHost(databaseType), 
-                databaseProps.getDatabasePort(databaseType), databaseProps.getDatabaseUsername(databaseType), databaseProps.getDatabasePassword(databaseType));
     }
     
     private Map<String, DatabaseEnvironment> createProxyEnvironments(final Map<String, DatabaseScenarioProperties> databaseProps) {
@@ -124,7 +143,8 @@ public final class IntegrationTestEnvironment {
     
     private DatabaseEnvironment createProxyEnvironment(final DatabaseScenarioProperties databaseProps) {
         // TODO hard code for MySQL, should configurable
-        return new DatabaseEnvironment(new MySQLDatabaseType(), databaseProps.getProxyHost(), databaseProps.getProxyPort(), databaseProps.getProxyUsername(), databaseProps.getProxyPassword());
+        return new DatabaseEnvironment(new MySQLDatabaseType(), databaseProps.getProxyHost(), databaseProps.getProxyPort(), databaseProps.getProxyUsername(), databaseProps.getProxyPassword(),
+                "", "");
     }
     
     private void waitForEnvironmentReady(final String scenario) {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironmentManager.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironmentManager.java
index a7c570d..c9155a4 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironmentManager.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/DatabaseEnvironmentManager.java
@@ -20,6 +20,8 @@ package org.apache.shardingsphere.test.integration.env.database;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
 import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
 import org.apache.shardingsphere.test.integration.env.IntegrationTestEnvironment;
 import org.apache.shardingsphere.test.integration.env.datasource.builder.ActualDataSourceBuilder;
@@ -34,12 +36,20 @@ import java.io.IOException;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 /**
  * Schema environment manager.
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class DatabaseEnvironmentManager {
+
+    private static final ConcurrentMap<String, EmbeddedDatabaseResource> DATABASE_RESOURCE_CACHE = new ConcurrentHashMap<>();
+
+    private static final Lock DATABASE_RESOURCE_LOCK = new ReentrantLock();
     
     /**
      * Get database names.
@@ -74,9 +84,9 @@ public final class DatabaseEnvironmentManager {
     
     private static void executeInitSQLs(final String scenario) throws IOException, JAXBException, SQLException {
         for (DatabaseType each : IntegrationTestEnvironment.getInstance().getDatabaseEnvironments().keySet()) {
-            if ("H2".equals(each.getName())) {
+            if (each instanceof H2DatabaseType) {
                 executeInitSQLForSchemaNotSupportedDatabase(scenario, each);
-                return;
+                continue;
             }
             // TODO use multiple threads to improve performance
             DataSource dataSource = ActualDataSourceBuilder.build(null, scenario, each);
@@ -97,7 +107,63 @@ public final class DatabaseEnvironmentManager {
     private static void executeSQLScript(final DataSource dataSource, final File file) throws SQLException, IOException {
         try (Connection connection = dataSource.getConnection();
              FileReader reader = new FileReader(file)) {
+            // TODO If you don't use H2 in the future, you need to implement this method.
             RunScript.execute(connection, reader);
         }
     }
+
+    /**
+     * create embedded database resource by database type and environment.
+     *
+     * @param databaseType database type
+     * @param scenario scenario
+     * @param databaseEnvironment database props
+     */
+    public static void createEmbeddedDatabaseResource(final DatabaseType databaseType,
+                                                      final String scenario,
+                                                      final org.apache.shardingsphere.test.integration.env.datasource.DatabaseEnvironment databaseEnvironment) {
+        if (null == databaseType) {
+            return;
+        }
+        String databaseTypeName = databaseType.getName();
+        String embeddedDatabaseResourceKey = databaseTypeName + "_" + scenario;
+        EmbeddedDatabaseResource embeddedDatabaseResource = DATABASE_RESOURCE_CACHE.get(embeddedDatabaseResourceKey);
+        if (null != embeddedDatabaseResource) {
+            return;
+        }
+        try {
+            DATABASE_RESOURCE_LOCK.lock();
+            embeddedDatabaseResource = DATABASE_RESOURCE_CACHE.get(embeddedDatabaseResourceKey);
+            if (null != embeddedDatabaseResource) {
+                return;
+            }
+            if (databaseType instanceof MySQLDatabaseType) {
+                embeddedDatabaseResource = new MySQLEmbeddedDatabaseResource(databaseEnvironment);
+            } else {
+                // TODO return default database resource
+                embeddedDatabaseResource = new EmbeddedDatabaseResource() {
+
+                    @Override
+                    public void start() {
+                    }
+
+                    @Override
+                    public void stop() {
+                    }
+                };
+            }
+            embeddedDatabaseResource.start();
+            DATABASE_RESOURCE_CACHE.put(embeddedDatabaseResourceKey, embeddedDatabaseResource);
+        } finally {
+            DATABASE_RESOURCE_LOCK.unlock();
+        }
+    }
+
+    /**
+     * drop embedded database resource.
+     */
+    public static void dropEmbeddedDatabaseResource() {
+        DATABASE_RESOURCE_CACHE.values().forEach(EmbeddedDatabaseResource::stop);
+        DATABASE_RESOURCE_CACHE.clear();
+    }
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/EmbeddedDatabaseResource.java
similarity index 65%
copy from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java
copy to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/EmbeddedDatabaseResource.java
index 57e2fd3..251f0c9 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/EmbeddedDatabaseResource.java
@@ -15,20 +15,20 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.test.integration.env.datasource.builder;
-
-import lombok.EqualsAndHashCode;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
+package org.apache.shardingsphere.test.integration.env.database;
 
 /**
- * Data source cache key.
+ * Embedded database resource.
  */
-@RequiredArgsConstructor
-@EqualsAndHashCode
-public final class DataSourceCacheKey {
-    
-    private final String dataSourceName;
-    
-    private final DatabaseType databaseType;
+public interface EmbeddedDatabaseResource {
+
+    /**
+     * start embedded database resource.
+     */
+    void start();
+
+    /**
+     * stop embedded database resource.
+     */
+    void stop();
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/MySQLEmbeddedDatabaseResource.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/MySQLEmbeddedDatabaseResource.java
new file mode 100644
index 0000000..7bfe2d6
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/database/MySQLEmbeddedDatabaseResource.java
@@ -0,0 +1,64 @@
+/*
+ * 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.integration.env.database;
+
+import com.wix.mysql.EmbeddedMysql;
+import com.wix.mysql.config.Charset;
+import com.wix.mysql.config.DownloadConfig;
+import com.wix.mysql.config.MysqldConfig;
+import com.wix.mysql.distribution.Version;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.test.integration.env.datasource.DatabaseEnvironment;
+
+/**
+ * MySQL database resource.
+ */
+@Slf4j
+@RequiredArgsConstructor
+public final class MySQLEmbeddedDatabaseResource implements EmbeddedDatabaseResource {
+
+    private final DatabaseEnvironment databaseEnvironment;
+
+    private EmbeddedMysql embeddedMySQL;
+
+    @Override
+    public void start() {
+        final long t = System.currentTimeMillis();
+        log.info("Test embedded database resources MySQL prepare.");
+        DownloadConfig downloadConfig = DownloadConfig.aDownloadConfig()
+                .withBaseUrl(databaseEnvironment.getDistributionUrl())
+                .build();
+        MysqldConfig mysqldConfig = MysqldConfig.aMysqldConfig(Version.valueOf(databaseEnvironment.getDistributionVersion()))
+                .withCharset(Charset.UTF8MB4)
+                .withPort(databaseEnvironment.getPort())
+                .withUser("test", "test")
+                .withServerVariable("bind-address", "0.0.0.0")
+                .withServerVariable("innodb_flush_log_at_trx_commit", 2)
+                .build();
+        embeddedMySQL = EmbeddedMysql.anEmbeddedMysql(mysqldConfig, downloadConfig).start();
+        log.info("Test embedded database resources MySQL start mysqld elapsed time {}s", (System.currentTimeMillis() - t) / 1000);
+    }
+
+    @Override
+    public void stop() {
+        if (null != embeddedMySQL) {
+            embeddedMySQL.stop();
+        }
+    }
+}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/DatabaseEnvironment.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/DatabaseEnvironment.java
index b363af5..394a248 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/DatabaseEnvironment.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/DatabaseEnvironment.java
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
  * Database environment.
  */
 @RequiredArgsConstructor
+@Getter
 public final class DatabaseEnvironment {
     
     private final DatabaseType databaseType;
@@ -33,11 +34,13 @@ public final class DatabaseEnvironment {
     
     private final int port;
     
-    @Getter
     private final String username;
     
-    @Getter
     private final String password;
+
+    private final String distributionUrl;
+
+    private final String distributionVersion;
     
     /**
      * Get driver class name.
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ActualDataSourceBuilder.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ActualDataSourceBuilder.java
index cea8ab5..8b1e6df 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ActualDataSourceBuilder.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ActualDataSourceBuilder.java
@@ -73,7 +73,7 @@ public final class ActualDataSourceBuilder {
      * @return actual data source
      */
     public static DataSource build(final String name, final String scenario, final DatabaseType databaseType) {
-        DataSourceCacheKey cacheKey = new DataSourceCacheKey(name, databaseType);
+        DataSourceCacheKey cacheKey = new DataSourceCacheKey(scenario, name, databaseType);
         if (CACHE.containsKey(cacheKey)) {
             return CACHE.get(cacheKey);
         }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java
index 57e2fd3..cbdc803 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/DataSourceCacheKey.java
@@ -27,7 +27,9 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
 @RequiredArgsConstructor
 @EqualsAndHashCode
 public final class DataSourceCacheKey {
-    
+
+    private final String scenario;
+
     private final String dataSourceName;
     
     private final DatabaseType databaseType;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ProxyDataSourceBuilder.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ProxyDataSourceBuilder.java
index 22d7af2..5024a19 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ProxyDataSourceBuilder.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/datasource/builder/ProxyDataSourceBuilder.java
@@ -45,7 +45,7 @@ public final class ProxyDataSourceBuilder {
      * @return proxy data source
      */
     public static DataSource build(final String name, final DatabaseType databaseType, final DatabaseEnvironment databaseEnvironment) {
-        DataSourceCacheKey cacheKey = new DataSourceCacheKey(name, databaseType);
+        DataSourceCacheKey cacheKey = new DataSourceCacheKey(name, name, databaseType);
         if (CACHE.containsKey(cacheKey)) {
             return CACHE.get(cacheKey);
         }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/DatabaseScenarioProperties.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/DatabaseScenarioProperties.java
index bee66b8..c219e90 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/DatabaseScenarioProperties.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/props/DatabaseScenarioProperties.java
@@ -107,4 +107,24 @@ public final class DatabaseScenarioProperties {
     public String getProxyPassword() {
         return props.getProperty(String.format("it.%s.proxy.password", scenario));
     }
+
+    /**
+     * Get database distribution url.
+     *
+     * @param databaseType database type
+     * @return database distribution url
+     */
+    public String getDatabaseDistributionUrl(final DatabaseType databaseType) {
+        return props.getProperty(String.format("it.%s.%s.distribution.url", scenario, databaseType.getName().toLowerCase()));
+    }
+
+    /**
+     * Get database distribution version.
+     *
+     * @param databaseType database type
+     * @return database distribution version
+     */
+    public String getDatabaseDistributionVersion(final DatabaseType databaseType) {
+        return props.getProperty(String.format("it.%s.%s.distribution.version", scenario, databaseType.getName().toLowerCase()));
+    }
 }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/db/scenario-env.properties b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/db/scenario-env.properties
index 2af95b8..f318e7d 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/db/scenario-env.properties
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/db/scenario-env.properties
@@ -19,6 +19,10 @@ it.db.mysql.host=127.0.0.1
 it.db.mysql.port=33060
 it.db.mysql.username=root
 it.db.mysql.password=
+#it.db.mysql.distribution.url=http://mirrors.ustc.edu.cn/mysql-ftp/Downloads
+it.db.mysql.distribution.url=https://dev.mysql.com/get/Downloads
+# v5_5_latest | v5_6_latest | v5_7_latest | v8_0_latest
+it.db.mysql.distribution.version=v5_7_latest
 
 it.db.postgresql.host=127.0.0.1
 it.db.postgresql.port=5432
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_replica_query/scenario-env.properties b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_replica_query/scenario-env.properties
index f9c99cc..a0efbad 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_replica_query/scenario-env.properties
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/dbtbl_with_replica_query/scenario-env.properties
@@ -19,6 +19,10 @@ it.dbtbl_with_replica_query.mysql.host=127.0.0.1
 it.dbtbl_with_replica_query.mysql.port=33360
 it.dbtbl_with_replica_query.mysql.username=root
 it.dbtbl_with_replica_query.mysql.password=
+#it.dbtbl_with_replica_query.mysql.distribution.url=http://mirrors.ustc.edu.cn/mysql-ftp/Downloads
+it.dbtbl_with_replica_query.mysql.distribution.url=https://dev.mysql.com/get/Downloads
+# v5_5_latest | v5_6_latest | v5_7_latest | v8_0_latest
+it.dbtbl_with_replica_query.mysql.distribution.version=v5_7_latest
 
 it.dbtbl_with_replica_query.postgresql.host=127.0.0.1
 it.dbtbl_with_replica_query.postgresql.port=5432
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/engine-env.properties b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/engine-env.properties
index 493d701..54fffc5 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/engine-env.properties
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/engine-env.properties
@@ -23,5 +23,6 @@ it.scenarios=db,tbl,dbtbl_with_replica_query,replica_query
 
 #it.databases=H2,MySQL,Oracle,SQLServer,PostgreSQL
 it.databases=H2
+it.databases.embedded=false
 
 it.run.additional.cases=false
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/replica_query/scenario-env.properties b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/replica_query/scenario-env.properties
index f7d7fd4..942cafd 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/replica_query/scenario-env.properties
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/replica_query/scenario-env.properties
@@ -19,6 +19,10 @@ it.replica_query.mysql.host=127.0.0.1
 it.replica_query.mysql.port=33260
 it.replica_query.mysql.username=root
 it.replica_query.mysql.password=
+#it.replica_query.mysql.distribution.url=http://mirrors.ustc.edu.cn/mysql-ftp/Downloads
+it.replica_query.mysql.distribution.url=https://dev.mysql.com/get/Downloads
+# v5_5_latest | v5_6_latest | v5_7_latest | v8_0_latest
+it.replica_query.mysql.distribution.version=v5_7_latest
 
 it.replica_query.postgresql.host=127.0.0.1
 it.replica_query.postgresql.port=5432
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/tbl/scenario-env.properties b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/tbl/scenario-env.properties
index b0b6f56..14f3bc2 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/tbl/scenario-env.properties
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/env/tbl/scenario-env.properties
@@ -19,6 +19,10 @@ it.tbl.mysql.host=127.0.0.1
 it.tbl.mysql.port=33160
 it.tbl.mysql.username=root
 it.tbl.mysql.password=
+#it.tbl.mysql.distribution.url=http://mirrors.ustc.edu.cn/mysql-ftp/Downloads
+it.tbl.mysql.distribution.url=https://dev.mysql.com/get/Downloads
+# v5_5_latest | v5_6_latest | v5_7_latest | v8_0_latest
+it.tbl.mysql.distribution.version=v5_7_latest
 
 it.tbl.postgresql.host=127.0.0.1
 it.tbl.postgresql.port=5432