This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng 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 e64242b8acd Refactor Scaling Native mode (#17371)
e64242b8acd is described below

commit e64242b8acd8b1d17deb952166defd13b208b2d8
Author: azexcy <101622833+aze...@users.noreply.github.com>
AuthorDate: Fri May 6 14:34:57 2022 +0800

    Refactor Scaling Native mode (#17371)
---
 .../data/pipeline/cases/BaseITCase.java            |   4 +-
 .../container/cluster/ZookeeperContainer.java      |   5 -
 .../container/compose/BaseComposedContainer.java   |   5 -
 .../container/compose/DockerComposedContainer.java |   8 +-
 ...Container.java => NativeComposedContainer.java} |  12 +--
 .../proxy/ShardingSphereProxyDockerContainer.java  |   3 +-
 .../proxy/ShardingSphereProxyLocalContainer.java   | 102 ---------------------
 .../src/test/resources/env/it-env.properties       |   2 +-
 8 files changed, 14 insertions(+), 127 deletions(-)

diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/BaseITCase.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/BaseITCase.java
index 6cfca94fe8a..b7bc5492305 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/BaseITCase.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/BaseITCase.java
@@ -34,7 +34,7 @@ import 
org.apache.shardingsphere.integration.data.pipeline.env.enums.ITEnvTypeEn
 import org.apache.shardingsphere.integration.data.pipeline.framework.ITWatcher;
 import 
org.apache.shardingsphere.integration.data.pipeline.framework.container.compose.BaseComposedContainer;
 import 
org.apache.shardingsphere.integration.data.pipeline.framework.container.compose.DockerComposedContainer;
-import 
org.apache.shardingsphere.integration.data.pipeline.framework.container.compose.LocalComposedContainer;
+import 
org.apache.shardingsphere.integration.data.pipeline.framework.container.compose.NativeComposedContainer;
 import 
org.apache.shardingsphere.integration.data.pipeline.framework.container.database.DockerDatabaseContainer;
 import 
org.apache.shardingsphere.integration.data.pipeline.framework.param.ScalingParameterized;
 import 
org.apache.shardingsphere.integration.data.pipeline.util.DatabaseTypeUtil;
@@ -88,7 +88,7 @@ public abstract class BaseITCase {
         if (ENV.getItEnvType() == ITEnvTypeEnum.DOCKER) {
             composedContainer = new 
DockerComposedContainer(parameterized.getDatabaseType(), 
parameterized.getDockerImageName());
         } else {
-            composedContainer = new 
LocalComposedContainer(parameterized.getDatabaseType(), 
parameterized.getDockerImageName());
+            composedContainer = new 
NativeComposedContainer(parameterized.getDatabaseType(), 
parameterized.getDockerImageName());
         }
         composedContainer.start();
         commonSQLCommand = 
JAXB.unmarshal(BaseITCase.class.getClassLoader().getResource("env/common/command.xml"),
 CommonSQLCommand.class);
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/cluster/ZookeeperContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/cluster/ZookeeperContainer.java
index 157e1feb06e..4887afaab10 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/cluster/ZookeeperContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/cluster/ZookeeperContainer.java
@@ -17,8 +17,6 @@
 
 package 
org.apache.shardingsphere.integration.data.pipeline.framework.container.cluster;
 
-import 
org.apache.shardingsphere.integration.data.pipeline.env.IntegrationTestEnvironment;
-import 
org.apache.shardingsphere.integration.data.pipeline.env.enums.ITEnvTypeEnum;
 import 
org.apache.shardingsphere.test.integration.framework.container.atomic.governance.GovernanceContainer;
 import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
 
@@ -31,9 +29,6 @@ public final class ZookeeperContainer extends 
GovernanceContainer {
         super("zookeeper", "zookeeper:3.6.2");
         setWaitStrategy(new 
LogMessageWaitStrategy().withRegEx(".*PrepRequestProcessor \\(sid:[0-9]+\\) 
started.*"));
         withExposedPorts(2181);
-        if (ITEnvTypeEnum.NATIVE == 
IntegrationTestEnvironment.getInstance().getItEnvType()) {
-            addFixedExposedPort(2181, 2181);
-        }
     }
     
     @Override
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/BaseComposedContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/BaseComposedContainer.java
index 645e6ef9bb7..46c4be8c1cf 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/BaseComposedContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/BaseComposedContainer.java
@@ -20,10 +20,8 @@ package 
org.apache.shardingsphere.integration.data.pipeline.framework.container.
 import lombok.Getter;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import 
org.apache.shardingsphere.integration.data.pipeline.factory.DatabaseContainerFactory;
-import 
org.apache.shardingsphere.integration.data.pipeline.framework.container.cluster.ZookeeperContainer;
 import 
org.apache.shardingsphere.integration.data.pipeline.framework.container.database.DockerDatabaseContainer;
 import 
org.apache.shardingsphere.test.integration.framework.container.atomic.ITContainers;
-import 
org.apache.shardingsphere.test.integration.framework.container.atomic.governance.GovernanceContainer;
 import org.apache.shardingsphere.test.integration.util.NetworkAliasUtil;
 import org.testcontainers.lifecycle.Startable;
 
@@ -32,13 +30,10 @@ public abstract class BaseComposedContainer implements 
Startable {
     
     private final ITContainers containers;
     
-    private final GovernanceContainer governanceContainer;
-    
     private final DockerDatabaseContainer databaseContainer;
     
     public BaseComposedContainer(final DatabaseType databaseType, final String 
dockerImageName) {
         this.containers = new ITContainers("");
-        this.governanceContainer = containers.registerContainer(new 
ZookeeperContainer(), NetworkAliasUtil.getNetworkAlias("zk"));
         this.databaseContainer = 
containers.registerContainer(DatabaseContainerFactory.newInstance(databaseType, 
dockerImageName), NetworkAliasUtil.getNetworkAlias("db"));
     }
     
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/DockerComposedContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/DockerComposedContainer.java
index c85036500ae..0c8439fba06 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/DockerComposedContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/DockerComposedContainer.java
@@ -19,7 +19,9 @@ package 
org.apache.shardingsphere.integration.data.pipeline.framework.container.
 
 import lombok.Getter;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import 
org.apache.shardingsphere.integration.data.pipeline.framework.container.cluster.ZookeeperContainer;
 import 
org.apache.shardingsphere.integration.data.pipeline.framework.container.proxy.ShardingSphereProxyDockerContainer;
+import 
org.apache.shardingsphere.test.integration.framework.container.atomic.governance.GovernanceContainer;
 import org.apache.shardingsphere.test.integration.util.NetworkAliasUtil;
 
 /**
@@ -28,13 +30,15 @@ import 
org.apache.shardingsphere.test.integration.util.NetworkAliasUtil;
 @Getter
 public final class DockerComposedContainer extends BaseComposedContainer {
     
+    private final GovernanceContainer governanceContainer;
+    
     private final ShardingSphereProxyDockerContainer proxyContainer;
     
     public DockerComposedContainer(final DatabaseType databaseType, final 
String dockerImageName) {
         super(databaseType, dockerImageName);
         ShardingSphereProxyDockerContainer proxyContainer = new 
ShardingSphereProxyDockerContainer(databaseType);
-        proxyContainer.addExposedPort(3307);
-        proxyContainer.dependsOn(getGovernanceContainer(), 
getDatabaseContainer());
+        governanceContainer = getContainers().registerContainer(new 
ZookeeperContainer(), NetworkAliasUtil.getNetworkAlias("zk"));
+        proxyContainer.dependsOn(governanceContainer, getDatabaseContainer());
         this.proxyContainer = 
getContainers().registerContainer(proxyContainer, 
NetworkAliasUtil.getNetworkAlias("sharding-proxy"));
     }
     
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/LocalComposedContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/NativeComposedContainer.java
similarity index 67%
rename from 
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/LocalComposedContainer.java
rename to 
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/NativeComposedContainer.java
index c2ce14b33a7..4246f00dfc4 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/LocalComposedContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/compose/NativeComposedContainer.java
@@ -17,26 +17,20 @@
 
 package 
org.apache.shardingsphere.integration.data.pipeline.framework.container.compose;
 
-import lombok.SneakyThrows;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.integration.data.pipeline.framework.container.proxy.ShardingSphereProxyLocalContainer;
 
 /**
- * Local composed container.
+ * Native composed container, you need start ShardingSphere-Proxy at firstly.
  */
-public final class LocalComposedContainer extends BaseComposedContainer {
-    private ShardingSphereProxyLocalContainer shardingSphereProxyContainer;
+public final class NativeComposedContainer extends BaseComposedContainer {
     
-    public LocalComposedContainer(final DatabaseType databaseType, final 
String dockerImageName) {
+    public NativeComposedContainer(final DatabaseType databaseType, final 
String dockerImageName) {
         super(databaseType, dockerImageName);
     }
     
-    @SneakyThrows
     @Override
     public void start() {
         super.start();
-        shardingSphereProxyContainer = new 
ShardingSphereProxyLocalContainer(getDatabaseContainer().getDatabaseType());
-        shardingSphereProxyContainer.start();
     }
     
     @Override
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/proxy/ShardingSphereProxyDockerContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/proxy/ShardingSphereProxyDockerContainer.java
index f2b24ca1e85..eacb7b98a9f 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/proxy/ShardingSphereProxyDockerContainer.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/proxy/ShardingSphereProxyDockerContainer.java
@@ -43,6 +43,7 @@ public final class ShardingSphereProxyDockerContainer extends 
DockerITContainer
     
     @Override
     protected void configure() {
+        withExposedPorts(3307);
         mapConfigurationFiles();
         if (DatabaseTypeUtil.isPostgreSQL(databaseType)) {
             setWaitStrategy(new JDBCConnectionWaitStrategy(() -> 
DriverManager.getConnection(DataSourceEnvironment.getURL(databaseType, 
getHost(), getMappedPort(3307), "postgres"), "root", "root")));
@@ -53,7 +54,7 @@ public final class ShardingSphereProxyDockerContainer extends 
DockerITContainer
     
     private void mapConfigurationFiles() {
         withClasspathResourceMapping(String.format("/env/%s/server.yaml", 
databaseType.getName().toLowerCase()), 
"/opt/shardingsphere-proxy/conf/server.yaml", BindMode.READ_ONLY);
-        withClasspathResourceMapping(String.format("/env/logback.xml", 
databaseType.getName().toLowerCase()), 
"/opt/shardingsphere-proxy/conf/logback.xml", BindMode.READ_ONLY);
+        withClasspathResourceMapping("/env/logback.xml", 
"/opt/shardingsphere-proxy/conf/logback.xml", BindMode.READ_ONLY);
         if (ITEnvTypeEnum.NATIVE == 
IntegrationTestEnvironment.getInstance().getItEnvType()) {
             addFixedExposedPort(3307, 3307);
             addFixedExposedPort(3308, 5005);
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/proxy/ShardingSphereProxyLocalContainer.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/proxy/ShardingSphereProxyLocalContainer.java
deleted file mode 100644
index 9190e1ecae1..00000000000
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/framework/container/proxy/ShardingSphereProxyLocalContainer.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package 
org.apache.shardingsphere.integration.data.pipeline.framework.container.proxy;
-
-import lombok.Getter;
-import lombok.SneakyThrows;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.integration.data.pipeline.util.DatabaseTypeUtil;
-import org.apache.shardingsphere.proxy.backend.config.ProxyConfigurationLoader;
-import org.apache.shardingsphere.proxy.backend.config.YamlProxyConfiguration;
-import org.apache.shardingsphere.proxy.frontend.ShardingSphereProxy;
-import org.apache.shardingsphere.proxy.initializer.BootstrapInitializer;
-import org.apache.shardingsphere.test.integration.env.DataSourceEnvironment;
-
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.concurrent.TimeUnit;
-
-@Slf4j
-@Getter
-public final class ShardingSphereProxyLocalContainer {
-    
-    private final DatabaseType databaseType;
-    
-    private final String defaultDatabaseName;
-    
-    private volatile boolean started;
-    
-    @SneakyThrows
-    public ShardingSphereProxyLocalContainer(final DatabaseType databaseType) {
-        this.databaseType = databaseType;
-        if (DatabaseTypeUtil.isPostgreSQL(databaseType)) {
-            defaultDatabaseName = "postgres";
-        } else {
-            defaultDatabaseName = "";
-        }
-    }
-    
-    /**
-     * Wait proxy started.
-     *
-     * @param databaseType database type
-     */
-    @SneakyThrows
-    public void waitProxyStarted(final DatabaseType databaseType) {
-        for (int retry = 0; retry < 60; retry++) {
-            try (Connection connection = 
DriverManager.getConnection(DataSourceEnvironment.getURL(databaseType, 
"localhost", 3307, defaultDatabaseName), "root", "root")) {
-                log.info("Container ready");
-                started = true;
-                return;
-                // CHECKSTYLE:OFF
-            } catch (final Exception ignored) {
-                // CHECKSTYLE:ON
-            }
-            TimeUnit.SECONDS.sleep(1);
-        }
-        throw new RuntimeException("Proxy not started");
-    }
-    
-    /**
-     * Start proxy.
-     */
-    public void start() {
-        if (started) {
-            return;
-        }
-        synchronized (this) {
-            if (started) {
-                return;
-            }
-            new Thread(() -> {
-                try {
-                    YamlProxyConfiguration yamlConfig = 
ProxyConfigurationLoader.load(String.format("/env/%s", 
databaseType.getName().toLowerCase()));
-                    
yamlConfig.getServerConfiguration().getMode().getRepository().getProps().setProperty("server-lists",
 "localhost:2181");
-                    new BootstrapInitializer().init(yamlConfig, 3307);
-                    new ShardingSphereProxy().start(3307);
-                } catch (final IOException | SQLException ex) {
-                    throw new RuntimeException(ex);
-                }
-            }).start();
-            waitProxyStarted(databaseType);
-        }
-    }
-}
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/it-env.properties
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/it-env.properties
index 5f784c66d11..427f58dc0f3 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/it-env.properties
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/resources/env/it-env.properties
@@ -18,5 +18,5 @@
 it.cluster.env.type=DOCKER
 # it.env.mysql.version=mysql:5.7,mysql:8.0
 it.env.mysql.version=
-# it.env.postgresql.version=postgres:12,postgres:13
+# 
it.env.postgresql.version=postgres:10-alpine,postgres:11-alpine,postgres:12-alpine,postgres:13-alpine,postgres:14-alpine
 it.env.postgresql.version=

Reply via email to