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/04/03 12:45:36 UTC

[shardingsphere] branch master updated: bugfix: repeatedly initialize issue in DQL testcase (#9913)

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 8081ad4  bugfix: repeatedly initialize issue in DQL testcase (#9913)
8081ad4 is described below

commit 8081ad44af1792eaf870fa98eeafd22772c8c2f5
Author: Daming <zt...@foxmail.com>
AuthorDate: Sat Apr 3 20:45:19 2021 +0800

    bugfix: repeatedly initialize issue in DQL testcase (#9913)
    
    * bugfix
    
    * fix javadoc
    
    * fix checkstyle
---
 .../junit/compose/ContainerCompose.java            | 19 ++++++++++
 .../test/integration/engine/it/ddl/BaseDDLIT.java  |  1 +
 .../test/integration/engine/it/dql/BaseDQLIT.java  | 44 +++++-----------------
 3 files changed, 30 insertions(+), 34 deletions(-)

diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/compose/ContainerCompose.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/compose/ContainerCompose.java
index fbc937a..991a079 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/compose/ContainerCompose.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-fixture/src/test/java/org/apache/shardingsphere/test/integration/junit/compose/ContainerCompose.java
@@ -40,6 +40,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
 import java.util.function.Supplier;
 
 /**
@@ -58,6 +59,8 @@ public abstract class ContainerCompose extends ExternalResource implements Close
     
     private volatile boolean started;
     
+    private volatile boolean executed;
+    
     public ContainerCompose(final String clusterName, final ParameterizedArray parameterizedArray) {
         this.clusterName = clusterName;
         this.parameterizedArray = parameterizedArray;
@@ -186,6 +189,22 @@ public abstract class ContainerCompose extends ExternalResource implements Close
         }
     }
     
+    /**
+     * Execution initializer one time after container started.
+     *
+     * @param consumer initializer
+     */
+    public final void executeOnStarted(final Consumer<ContainerCompose> consumer) {
+        if (!executed) {
+            synchronized (this) {
+                if (!executed) {
+                    consumer.accept(this);
+                    executed = true;
+                }
+            }
+        }
+    }
+    
     @Override
     public void close() {
         containers.forEach(Startable::close);
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/ddl/BaseDDLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/ddl/BaseDDLIT.java
index 3aa9491..9a04abe 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/ddl/BaseDDLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/ddl/BaseDDLIT.java
@@ -74,6 +74,7 @@ public abstract class BaseDDLIT extends SingleITCase {
     
     @After
     public final void destroyTables() throws SQLException {
+        dataSetEnvironmentManager.clearData();
         try (Connection connection = getTargetDataSource().getConnection()) {
             dropInitializedTable(connection);
         }
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/BaseDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/BaseDQLIT.java
index 87f2516..246face 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/BaseDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/it/dql/BaseDQLIT.java
@@ -22,10 +22,7 @@ import org.apache.shardingsphere.test.integration.cases.dataset.metadata.DataSet
 import org.apache.shardingsphere.test.integration.cases.dataset.row.DataSetRow;
 import org.apache.shardingsphere.test.integration.engine.it.SingleITCase;
 import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
-import org.apache.shardingsphere.test.integration.env.EnvironmentType;
-import org.apache.shardingsphere.test.integration.env.IntegrationTestEnvironment;
 import org.apache.shardingsphere.test.integration.env.dataset.DataSetEnvironmentManager;
-import org.apache.shardingsphere.test.integration.env.datasource.builder.ActualDataSourceBuilder;
 import org.apache.shardingsphere.test.integration.junit.param.model.AssertionParameterizedArray;
 import org.junit.Before;
 
@@ -47,43 +44,22 @@ import static org.junit.Assert.assertTrue;
 
 public abstract class BaseDQLIT extends SingleITCase {
     
-    private volatile boolean initialed;
-    
     public BaseDQLIT(final AssertionParameterizedArray parameter) {
         super(parameter);
     }
     
     @Before
-    public void setup() throws IOException, JAXBException, SQLException, ParseException {
-        if (!initialed) {
-            synchronized (BaseDQLIT.class) {
-                if (!initialed) {
-                    fillData();
-                    initialed = true;
-                }
+    public void setup() {
+        compose.executeOnStarted(compose -> {
+            try {
+                new DataSetEnvironmentManager(
+                        EnvironmentPath.getDataSetFile(getScenario()),
+                        getStorageContainer().getDataSourceMap()
+                ).fillData();
+            } catch (IOException | JAXBException | SQLException | ParseException e) {
+                throw new RuntimeException(e);
             }
-        }
-    }
-    
-    private void fillData() throws SQLException, ParseException, IOException, JAXBException {
-        if (EnvironmentType.DOCKER == IntegrationTestEnvironment.getInstance().getEnvType()) {
-            new DataSetEnvironmentManager(
-                    EnvironmentPath.getDataSetFile(getScenario()),
-                    getStorageContainer().getDataSourceMap()
-            ).fillData();
-        } else {
-            IntegrationTestEnvironment.getInstance().getDataSourceEnvironments().keySet()
-                    .forEach(e -> IntegrationTestEnvironment.getInstance().getScenarios().forEach(each -> {
-                        try {
-                            new DataSetEnvironmentManager(
-                                    EnvironmentPath.getDataSetFile(each),
-                                    ActualDataSourceBuilder.createActualDataSources(each, e)
-                            ).fillData();
-                        } catch (SQLException | ParseException | IOException | JAXBException jaxbException) {
-                            jaxbException.printStackTrace();
-                        }
-                    }));
-        }
+        });
     }
     
     protected final void assertResultSet(final ResultSet resultSet) throws SQLException {