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/02/10 08:58:03 UTC

[shardingsphere] branch master updated: Move ComposedContainer.executeOnStarted() to BaseDQLIT (#15336)

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 a0d06c8  Move ComposedContainer.executeOnStarted() to BaseDQLIT (#15336)
a0d06c8 is described below

commit a0d06c81937b8d9153fc56cfab606995ac23e654
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Feb 10 16:57:04 2022 +0800

    Move ComposedContainer.executeOnStarted() to BaseDQLIT (#15336)
---
 .../test/integration/engine/dql/BaseDQLIT.java     | 22 +++++++++++++---------
 .../framework/compose/ComposedContainer.java       | 19 -------------------
 2 files changed, 13 insertions(+), 28 deletions(-)

diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
index 5944902..7c189ed 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/dql/BaseDQLIT.java
@@ -43,6 +43,8 @@ import static org.junit.Assert.assertTrue;
 
 public abstract class BaseDQLIT extends SingleITCase {
     
+    private static volatile boolean filled;
+    
     public BaseDQLIT(final AssertionParameterizedArray parameter) {
         super(parameter);
     }
@@ -50,16 +52,18 @@ public abstract class BaseDQLIT extends SingleITCase {
     @Override
     public void init() throws Exception {
         super.init();
-        getComposedContainer().executeOnStarted(compose -> {
-            try {
-                new DataSetEnvironmentManager(
-                        EnvironmentPath.getDataSetFile(getScenario()),
-                        getStorageContainer().getDataSourceMap()
-                ).fillData();
-            } catch (IOException | JAXBException | SQLException | ParseException e) {
-                throw new RuntimeException(e);
+        fillDataOnlyOnce();
+    }
+    
+    private void fillDataOnlyOnce() throws SQLException, ParseException, IOException, JAXBException {
+        if (!filled) {
+            synchronized (this) {
+                if (!filled) {
+                    new DataSetEnvironmentManager(EnvironmentPath.getDataSetFile(getScenario()), getStorageContainer().getDataSourceMap()).fillData();
+                    filled = true;
+                }
             }
-        });
+        }
     }
     
     protected final void assertResultSet(final ResultSet resultSet) throws SQLException {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/compose/ComposedContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/compose/ComposedContainer.java
index 2faa227..a79d6e8 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/compose/ComposedContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/compose/ComposedContainer.java
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.test.integration.framework.container.storage.St
 
 import javax.sql.DataSource;
 import java.util.Map;
-import java.util.function.Consumer;
 
 /**
  * Composed container.
@@ -35,8 +34,6 @@ public abstract class ComposedContainer {
     @Getter(AccessLevel.PROTECTED)
     private final ShardingSphereContainers containers;
     
-    private volatile boolean executed;
-    
     public ComposedContainer(final String testSuiteName) {
         containers = new ShardingSphereContainers(testSuiteName);
     }
@@ -61,20 +58,4 @@ public abstract class ComposedContainer {
      * @return datasource map
      */
     public abstract Map<String, DataSource> getDataSourceMap();
-    
-    /**
-     * Execution initializer one time after container started.
-     *
-     * @param consumer initializer consumer
-     */
-    public final void executeOnStarted(final Consumer<ComposedContainer> consumer) {
-        if (!executed) {
-            synchronized (this) {
-                if (!executed) {
-                    consumer.accept(this);
-                    executed = true;
-                }
-            }
-        }
-    }
 }