You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by to...@apache.org on 2022/07/23 02:43:45 UTC
[shardingsphere] branch master updated: Add username and password in DockerStorageContainer (#19481)
This is an automated email from the ASF dual-hosted git repository.
totalo 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 8e97e304d0c Add username and password in DockerStorageContainer (#19481)
8e97e304d0c is described below
commit 8e97e304d0c724880d6348e1a39818b7b068dcf0
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Jul 23 10:43:32 2022 +0800
Add username and password in DockerStorageContainer (#19481)
---
.../atomic/storage/DockerStorageContainer.java | 29 +++++++++++++++++++++-
.../atomic/storage/impl/MySQLContainer.java | 22 +++++++++++++---
.../atomic/storage/impl/PostgreSQLContainer.java | 25 +++++++++++++++----
3 files changed, 67 insertions(+), 9 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/DockerStorageContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/DockerStorageContainer.java
index ef2b06abfae..875e2bcebe4 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/DockerStorageContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/DockerStorageContainer.java
@@ -86,7 +86,34 @@ public abstract class DockerStorageContainer extends DockerITContainer implement
return result;
}
- protected abstract int getPort();
+ /**
+ * Get jdbc url.
+ *
+ * @param databaseName database name
+ * @return jdbc url
+ */
+ public abstract String getJdbcUrl(String databaseName);
+
+ /**
+ * Get database username.
+ *
+ * @return database username
+ */
+ public abstract String getUsername();
+
+ /**
+ * Get database password.
+ *
+ * @return database username
+ */
+ public abstract String getPassword();
+
+ /**
+ * Get database port.
+ *
+ * @return database port
+ */
+ public abstract int getPort();
@Override
public final String getAbbreviation() {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/impl/MySQLContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/impl/MySQLContainer.java
index 2abaca037c0..ee58b43db7e 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/impl/MySQLContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/impl/MySQLContainer.java
@@ -38,16 +38,32 @@ public final class MySQLContainer extends DockerStorageContainer {
protected void configure() {
withCommand("--sql_mode=", "--default-authentication-plugin=mysql_native_password", "--lower_case_table_names=1");
addEnv("LANG", "C.UTF-8");
- addEnv("MYSQL_ROOT_PASSWORD", "root");
+ addEnv("MYSQL_ROOT_PASSWORD", getPassword());
addEnv("MYSQL_ROOT_HOST", "%");
withClasspathResourceMapping("/env/mysql/my.cnf", "/etc/mysql/my.cnf", BindMode.READ_ONLY);
withExposedPorts(getPort());
- setWaitStrategy(new JDBCConnectionWaitStrategy(() -> DriverManager.getConnection(DataSourceEnvironment.getURL(getDatabaseType(), "localhost", getFirstMappedPort()), "root", "root")));
super.configure();
+ setWaitStrategy(new JDBCConnectionWaitStrategy(
+ () -> DriverManager.getConnection(DataSourceEnvironment.getURL(getDatabaseType(), "localhost", getFirstMappedPort()), getUsername(), getPassword())));
}
@Override
- protected int getPort() {
+ public String getJdbcUrl(final String databaseName) {
+ return DataSourceEnvironment.getURL(getDatabaseType(), getHost(), getFirstMappedPort(), databaseName);
+ }
+
+ @Override
+ public String getUsername() {
+ return "root";
+ }
+
+ @Override
+ public String getPassword() {
+ return "root";
+ }
+
+ @Override
+ public int getPort() {
return 3306;
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/impl/PostgreSQLContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/impl/PostgreSQLContainer.java
index 9a101773500..54a58d37918 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/impl/PostgreSQLContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/container/atomic/storage/impl/PostgreSQLContainer.java
@@ -36,16 +36,31 @@ public final class PostgreSQLContainer extends DockerStorageContainer {
@Override
protected void configure() {
withCommand("--max_connections=600", "--wal_level=logical");
- addEnv("POSTGRES_USER", "root");
- addEnv("POSTGRES_PASSWORD", "root");
+ addEnv("POSTGRES_USER", getUsername());
+ addEnv("POSTGRES_PASSWORD", getPassword());
withExposedPorts(getPort());
- setWaitStrategy(
- new JDBCConnectionWaitStrategy(() -> DriverManager.getConnection(DataSourceEnvironment.getURL(getDatabaseType(), "localhost", getFirstMappedPort(), "postgres"), "root", "root")));
super.configure();
+ setWaitStrategy(new JDBCConnectionWaitStrategy(
+ () -> DriverManager.getConnection(DataSourceEnvironment.getURL(getDatabaseType(), "localhost", getFirstMappedPort(), "postgres"), getUsername(), getPassword())));
}
@Override
- protected int getPort() {
+ public String getJdbcUrl(final String databaseName) {
+ return DataSourceEnvironment.getURL(getDatabaseType(), getHost(), getFirstMappedPort(), databaseName);
+ }
+
+ @Override
+ public String getUsername() {
+ return "root";
+ }
+
+ @Override
+ public String getPassword() {
+ return "root";
+ }
+
+ @Override
+ public int getPort() {
return 5432;
}
}