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

duanzhengqiang 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 e447cd9  Unify test username and password for diff database types 
(#15428)
e447cd9 is described below

commit e447cd9955015cc35ce2aed3af37b2621d4a68d6
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Feb 16 06:50:38 2022 +0800

    Unify test username and password for diff database types (#15428)
    
    * Unify test username and password for diff database types
    
    * Refactor mapper port
    
    * Refactor mapper port
    
    * Remove useless getConnectionInitSQL
---
 .../integration/env/DataSourceEnvironment.java     |  4 +--
 .../atomic/storage/DockerStorageContainer.java     |  9 ++++---
 .../atomic/storage/EmbeddedStorageContainer.java   |  7 +++--
 .../container/atomic/storage/StorageContainer.java | 31 ----------------------
 .../container/atomic/storage/impl/H2Container.java | 15 -----------
 .../atomic/storage/impl/MySQLContainer.java        | 20 ++------------
 .../atomic/storage/impl/PostgreSQLContainer.java   | 18 +++----------
 7 files changed, 16 insertions(+), 88 deletions(-)

diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/DataSourceEnvironment.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/DataSourceEnvironment.java
index 390478a..80ccdd5 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/DataSourceEnvironment.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/env/DataSourceEnvironment.java
@@ -58,7 +58,7 @@ public final class DataSourceEnvironment {
     public static String getURL(final DatabaseType databaseType, final String 
host, final int port) {
         switch (databaseType.getName()) {
             case "H2":
-                return 
"jdbc:h2:mem:test_db;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL";
+                return 
"jdbc:h2:mem:test_db;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL;USER=root;PASSWORD=root";
             case "MySQL":
                 return 
String.format("jdbc:mysql://%s:%s?useServerPrepStmts=true&serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8",
 host, port);
             case "PostgreSQL":
@@ -84,7 +84,7 @@ public final class DataSourceEnvironment {
     public static String getURL(final DatabaseType databaseType, final String 
host, final int port, final String dataSourceName) {
         switch (databaseType.getName()) {
             case "H2":
-                return 
String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL",
 dataSourceName);
+                return 
String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL;USER=root;PASSWORD=root",
 dataSourceName);
             case "MySQL":
                 return 
String.format("jdbc:mysql://%s:%s/%s?useServerPrepStmts=true&serverTimezone=UTC&useSSL=false&useLocalSessionState=true&characterEncoding=utf-8",
 host, port, dataSourceName);
             case "PostgreSQL":
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/DockerStorageContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/DockerStorageContainer.java
index e1b96fe..91be718 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/DockerStorageContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/DockerStorageContainer.java
@@ -72,12 +72,13 @@ public abstract class DockerStorageContainer extends 
DockerITContainer implement
     private DataSource createDataSource(final String dataSourceName) {
         HikariDataSource result = new HikariDataSource();
         
result.setDriverClassName(DataSourceEnvironment.getDriverClassName(databaseType));
-        result.setJdbcUrl(DataSourceEnvironment.getURL(databaseType, 
getHost(), getPort(), dataSourceName));
-        result.setUsername(getUsername());
-        result.setPassword(getPassword());
+        result.setJdbcUrl(DataSourceEnvironment.getURL(databaseType, 
getHost(), getMappedPort(getPort()), dataSourceName));
+        result.setUsername("root");
+        result.setPassword("root");
         result.setMaximumPoolSize(4);
         result.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
-        getConnectionInitSQL().ifPresent(result::setConnectionInitSql);
         return result;
     }
+    
+    protected abstract int getPort();
 }
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/EmbeddedStorageContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/EmbeddedStorageContainer.java
index 8b78883..cfb2081 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/EmbeddedStorageContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/EmbeddedStorageContainer.java
@@ -61,12 +61,11 @@ public abstract class EmbeddedStorageContainer implements 
EmbeddedITContainer, S
     private DataSource createDataSource(final String dataSourceName) {
         HikariDataSource result = new HikariDataSource();
         
result.setDriverClassName(DataSourceEnvironment.getDriverClassName(databaseType));
-        result.setJdbcUrl(DataSourceEnvironment.getURL(databaseType, null, 
getPort(), dataSourceName));
-        result.setUsername(getUsername());
-        result.setPassword(getPassword());
+        result.setJdbcUrl(DataSourceEnvironment.getURL(databaseType, null, 0, 
dataSourceName));
+        result.setUsername("root");
+        result.setPassword("root");
         result.setMaximumPoolSize(4);
         result.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
-        getConnectionInitSQL().ifPresent(result::setConnectionInitSql);
         return result;
     }
 }
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/StorageContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/StorageContainer.java
index 55d4999..42c6d21 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/StorageContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/StorageContainer.java
@@ -21,7 +21,6 @@ import 
org.apache.shardingsphere.test.integration.framework.container.atomic.ITC
 
 import javax.sql.DataSource;
 import java.util.Map;
-import java.util.Optional;
 
 /**
  * Storage container.
@@ -29,36 +28,6 @@ import java.util.Optional;
 public interface StorageContainer extends ITContainer {
     
     /**
-     * Get username.
-     * 
-     * @return username
-     */
-    String getUsername();
-    
-    /**
-     * Get password.
-     * 
-     * @return password
-     */
-    String getPassword();
-    
-    /**
-     * Get connection init SQL.
-     * 
-     * @return connection init SQL
-     */
-    default Optional<String> getConnectionInitSQL() {
-        return Optional.empty();
-    }
-    
-    /**
-     * Get port.
-     * 
-     * @return port
-     */
-    int getPort();
-    
-    /**
      * Get actual data source map.
      *
      * @return actual data source map
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java
index d628bb0..3610c97 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/H2Container.java
@@ -63,19 +63,4 @@ public final class H2Container extends 
EmbeddedStorageContainer {
             RunScript.execute(connection, reader);
         }
     }
-    
-    @Override
-    public String getUsername() {
-        return "sa";
-    }
-    
-    @Override
-    public String getPassword() {
-        return "";
-    }
-    
-    @Override
-    public int getPort() {
-        return 0;
-    }
 }
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/MySQLContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/MySQLContainer.java
index f862565..bc4077d 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/MySQLContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/MySQLContainer.java
@@ -21,7 +21,6 @@ import 
org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
 import 
org.apache.shardingsphere.test.integration.framework.container.atomic.storage.DockerStorageContainer;
 
 import java.util.Collections;
-import java.util.Optional;
 
 /**
  * MySQL container.
@@ -40,22 +39,7 @@ public final class MySQLContainer extends 
DockerStorageContainer {
     }
     
     @Override
-    public String getUsername() {
-        return "root";
-    }
-    
-    @Override
-    public String getPassword() {
-        return "root";
-    }
-    
-    @Override
-    public Optional<String> getConnectionInitSQL() {
-        return Optional.of("SET sql_mode=(SELECT 
REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))");
-    }
-    
-    @Override
-    public int getPort() {
-        return getMappedPort(3306);
+    protected int getPort() {
+        return 3306;
     }
 }
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/PostgreSQLContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/PostgreSQLContainer.java
index 370d5a9..6b52407 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/PostgreSQLContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/storage/impl/PostgreSQLContainer.java
@@ -48,10 +48,10 @@ public final class PostgreSQLContainer extends 
DockerStorageContainer {
     @SneakyThrows({ClassNotFoundException.class, SQLException.class, 
InterruptedException.class})
     protected void execute() {
         
Class.forName(DataSourceEnvironment.getDriverClassName(getDatabaseType()));
-        String url = DataSourceEnvironment.getURL(getDatabaseType(), 
getHost(), getPort());
+        String url = DataSourceEnvironment.getURL(getDatabaseType(), 
getHost(), getMappedPort(getPort()));
         boolean connected = false;
         while (!connected) {
-            try (Connection ignored = DriverManager.getConnection(url, 
getUsername(), getPassword())) {
+            try (Connection ignored = DriverManager.getConnection(url, "root", 
"root")) {
                 connected = true;
                 break;
             } catch (final PSQLException ex) {
@@ -61,17 +61,7 @@ public final class PostgreSQLContainer extends 
DockerStorageContainer {
     }
     
     @Override
-    public String getUsername() {
-        return "root";
-    }
-    
-    @Override
-    public String getPassword() {
-        return "root";
-    }
-    
-    @Override
-    public int getPort() {
-        return getMappedPort(5432);
+    protected int getPort() {
+        return 5432;
     }
 }

Reply via email to