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/11 05:11:10 UTC

[shardingsphere] branch master updated: Remove useless code on ShardingSphereJDBCContainer (#15350)

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 83a52b3  Remove useless code on ShardingSphereJDBCContainer (#15350)
83a52b3 is described below

commit 83a52b311cf2b4b1831539790de531dbe8f814db
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri Feb 11 13:10:12 2022 +0800

    Remove useless code on ShardingSphereJDBCContainer (#15350)
    
    * Refactor BaseITCase
    
    * Remove useless code on ShardingSphereJDBCContainer
---
 .../test/integration/engine/BaseITCase.java        |  4 +--
 .../adapter/impl/ShardingSphereJDBCContainer.java  | 30 ++++++++++------------
 2 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java
index abd50e3..efed83a 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/BaseITCase.java
@@ -60,8 +60,6 @@ public abstract class BaseITCase {
     
     private final StorageContainer storageContainer;
     
-    private Map<String, DataSource> dataSourceMap;
-    
     private DataSource targetDataSource;
     
     private DataSource dataSourceForReader;
@@ -78,7 +76,7 @@ public abstract class BaseITCase {
     
     @Before
     public void init() throws Exception {
-        dataSourceMap = composedContainer.getDataSourceMap();
+        Map<String, DataSource> dataSourceMap = composedContainer.getDataSourceMap();
         targetDataSource = dataSourceMap.get("adapterForWriter");
         if (composedContainer instanceof ClusterComposedContainer) {
             dataSourceForReader = dataSourceMap.get("adapterForReader");
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java
index 43892a1..ca7ac8c 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/adapter/impl/ShardingSphereJDBCContainer.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.test.integration.framework.container.atomic.adapter.impl;
 
+import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
 import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
@@ -28,24 +29,21 @@ import org.apache.shardingsphere.infra.yaml.config.swapper.YamlRuleConfiguration
 import org.apache.shardingsphere.infra.yaml.config.swapper.mode.ModeConfigurationYamlSwapper;
 import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
 import org.apache.shardingsphere.test.integration.env.EnvironmentPath;
-import org.apache.shardingsphere.test.integration.framework.container.atomic.ShardingSphereContainer;
 import org.apache.shardingsphere.test.integration.framework.container.atomic.adapter.AdapterContainer;
 import org.apache.shardingsphere.test.integration.framework.container.atomic.storage.StorageContainer;
 import org.apache.shardingsphere.test.integration.framework.param.model.ParameterizedArray;
-import org.testcontainers.containers.wait.strategy.WaitStrategy;
 import org.testcontainers.lifecycle.Startable;
 
 import javax.sql.DataSource;
 import java.io.File;
 import java.io.IOException;
 import java.sql.SQLException;
-import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Properties;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicReference;
-import java.util.stream.Collectors;
 
 /**
  * ShardingSphere JDBC container.
@@ -67,13 +65,16 @@ public final class ShardingSphereJDBCContainer extends AdapterContainer {
     @Override
     public void start() {
         super.start();
-        List<Startable> startables = getDependencies().stream()
-                .filter(e -> e instanceof StorageContainer)
-                .collect(Collectors.toList());
-        dataSourceMap = ((StorageContainer) startables.get(0)).getDataSourceMap();
+        dataSourceMap = findStorageContainer().getDataSourceMap();
         isHealthy.set(true);
     }
-
+    
+    private StorageContainer findStorageContainer() {
+        Optional<Startable> result = getDependencies().stream().filter(each -> each instanceof StorageContainer).findFirst();
+        Preconditions.checkState(result.isPresent());
+        return (StorageContainer) result.get();
+    }
+    
     /**
      * Get data source.
      *
@@ -87,9 +88,9 @@ public final class ShardingSphereJDBCContainer extends AdapterContainer {
                 dataSourceProvider.lazySet(createGovernanceDataSource(serverLists));
             } else {
                 try {
-                    dataSourceProvider.lazySet(YamlShardingSphereDataSourceFactory.createDataSource(dataSourceMap,
-                            new File(EnvironmentPath.getRulesConfigurationFile(getParameterizedArray().getScenario()))));
-                } catch (SQLException | IOException ex) {
+                    dataSourceProvider.lazySet(
+                            YamlShardingSphereDataSourceFactory.createDataSource(dataSourceMap, new File(EnvironmentPath.getRulesConfigurationFile(getParameterizedArray().getScenario()))));
+                } catch (final SQLException | IOException ex) {
                     throw new RuntimeException(ex);
                 }
             }
@@ -140,9 +141,4 @@ public final class ShardingSphereJDBCContainer extends AdapterContainer {
     public boolean isHealthy() {
         return isHealthy.get();
     }
-    
-    @Override
-    public ShardingSphereContainer waitingFor(final WaitStrategy waitStrategy) {
-        return super.waitingFor(waitStrategy);
-    }
 }