You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/07/22 08:31:43 UTC

[shardingsphere] branch master updated: Refactor test-env PostgreSQLContainer (#19448)

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 2e5c96050ed Refactor test-env PostgreSQLContainer (#19448)
2e5c96050ed is described below

commit 2e5c96050ed02c7c553e93a69fcc7a3d799c10a5
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Jul 22 16:31:37 2022 +0800

    Refactor test-env PostgreSQLContainer (#19448)
    
    * Refactor test-env PostgreSQLContainer
    
    * Disable --wal_level=logical
    
    * Disable --wal_level=logical
---
 .../atomic/storage/impl/PostgreSQLContainer.java   | 34 +++++-----------------
 1 file changed, 8 insertions(+), 26 deletions(-)

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 6a86f930898..e8275055f2b 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
@@ -17,16 +17,12 @@
 
 package org.apache.shardingsphere.test.integration.container.atomic.storage.impl;
 
-import lombok.SneakyThrows;
 import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
-import org.apache.shardingsphere.test.integration.env.runtime.DataSourceEnvironment;
 import org.apache.shardingsphere.test.integration.container.atomic.storage.DockerStorageContainer;
-import org.postgresql.util.PSQLException;
-import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
+import org.apache.shardingsphere.test.integration.env.container.wait.JDBCConnectionWaitStrategy;
+import org.apache.shardingsphere.test.integration.env.runtime.DataSourceEnvironment;
 
-import java.sql.Connection;
 import java.sql.DriverManager;
-import java.sql.SQLException;
 
 /**
  * PostgreSQL container.
@@ -35,35 +31,21 @@ public final class PostgreSQLContainer extends DockerStorageContainer {
     
     public PostgreSQLContainer(final String scenario) {
         super(DatabaseTypeFactory.getInstance("PostgreSQL"), "postgres:12-alpine", scenario);
-        setWaitStrategy(new LogMessageWaitStrategy().withRegEx(".*database system is ready to accept connections.*"));
     }
     
     @Override
     protected void configure() {
-        withCommand("--max_connections=200");
+        withCommand("--max_connections=600");
+        // TODO check error reason if open wal
+//        withCommand("--wal_level=logical");
         addEnv("POSTGRES_USER", "root");
         addEnv("POSTGRES_PASSWORD", "root");
+        withExposedPorts(getPort());
+        setWaitStrategy(
+                new JDBCConnectionWaitStrategy(() -> DriverManager.getConnection(DataSourceEnvironment.getURL(getDatabaseType(), "localhost", getFirstMappedPort(), "postgres"), "root", "root")));
         super.configure();
     }
     
-    @Override
-    @SneakyThrows({ClassNotFoundException.class, SQLException.class, InterruptedException.class})
-    protected void postStart() {
-        super.postStart();
-        // TODO if remove the method, DML and BatchDML run together may throw exception. Need to investigate the reason, it is better to use LogMessageWaitStrategy only
-        Class.forName(DataSourceEnvironment.getDriverClassName(getDatabaseType()));
-        String url = DataSourceEnvironment.getURL(getDatabaseType(), getHost(), getMappedPort(getPort()));
-        boolean connected = false;
-        while (!connected) {
-            try (Connection ignored = DriverManager.getConnection(url, "root", "root")) {
-                connected = true;
-                break;
-            } catch (final PSQLException ex) {
-                Thread.sleep(500L);
-            }
-        }
-    }
-    
     @Override
     protected int getPort() {
         return 5432;