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

sunnianjun 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 631868570de Completed build MySQL MGR cluster and build discovery rule 
(#22372)
631868570de is described below

commit 631868570de90c9a263500c06b21be21a7c70e12
Author: zhaojinchao <[email protected]>
AuthorDate: Wed Nov 23 23:42:05 2022 +0800

    Completed build MySQL MGR cluster and build discovery rule (#22372)
    
    * Completed build MySQL MGR cluster and build discovery rule
    
    * Remove unless code
---
 .../discovery/build/DiscoveryRuleBuilder.java      |  78 ++++++++++++++++
 .../discovery/build/MySQLMGRBuilder.java           | 100 +++++++++++++++++++++
 .../discovery/cases/base/BaseITCase.java           |  25 +-----
 .../cases/mysql/MySQLDiscoveryGeneralIT.java       |  17 ++--
 .../discovery/command/DiscoveryDistSQLCommand.java |  44 +++++++++
 .../command/MGRPrimaryReplicaCommand.java          |  40 +++++++++
 .../container/compose/BaseContainerComposer.java   |  14 +--
 .../container/compose/DockerContainerComposer.java |  21 ++---
 .../MySQLContainerConfigurationFactory.java        |   2 +-
 .../resources/env/common/discovery-command.xml     |  54 +++++++++++
 .../env/common/mgr-primary-replica-command.xml     |  34 +++++++
 .../{mysql_discovery => discovery}/mysql_1/my.cnf  |  12 ++-
 .../{mysql_discovery => discovery}/mysql_2/my.cnf  |  12 ++-
 .../{mysql_discovery => discovery}/mysql_3/my.cnf  |  11 ++-
 .../proxy/server.yaml                              |   2 +-
 .../scenario/mysql_discovery/mysql_1/01-initdb.sql |  18 ----
 .../scenario/mysql_discovery/mysql_2/01-initdb.sql |  18 ----
 .../scenario/mysql_discovery/mysql_3/01-initdb.sql |  18 ----
 18 files changed, 401 insertions(+), 119 deletions(-)

diff --git 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/build/DiscoveryRuleBuilder.java
 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/build/DiscoveryRuleBuilder.java
new file mode 100644
index 00000000000..a696398486b
--- /dev/null
+++ 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/build/DiscoveryRuleBuilder.java
@@ -0,0 +1,78 @@
+/*
+ * 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.test.integration.discovery.build;
+
+import org.apache.shardingsphere.data.pipeline.core.util.ThreadUtil;
+import 
org.apache.shardingsphere.test.integration.discovery.cases.base.BaseITCase;
+import 
org.apache.shardingsphere.test.integration.discovery.command.DiscoveryDistSQLCommand;
+
+import javax.sql.DataSource;
+import javax.xml.bind.JAXB;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Build Discovery Rule.
+ */
+public final class DiscoveryRuleBuilder {
+    
+    private final DiscoveryDistSQLCommand discoveryDistSQLCommand;
+    
+    private final DataSource proxyDataSource;
+    
+    public DiscoveryRuleBuilder(final DataSource proxyDataSource) throws 
SQLException {
+        this.proxyDataSource = proxyDataSource;
+        discoveryDistSQLCommand = 
JAXB.unmarshal(Objects.requireNonNull(BaseITCase.class.getClassLoader().getResource("env/common/discovery-command.xml")),
 DiscoveryDistSQLCommand.class);
+        buildDiscoveryEnvironment();
+    }
+    
+    private void buildDiscoveryEnvironment() throws SQLException {
+        try (
+                Connection connection = proxyDataSource.getConnection();
+                Statement statement = connection.createStatement()) {
+            createDatabase(statement);
+            registerStorageUnits(statement);
+            createDiscoveryRule(statement);
+            createReadwriteSplittingRule(statement);
+        }
+    }
+    
+    private void createDatabase(final Statement statement) throws SQLException 
{
+        statement.execute("CREATE DATABASE db_discovery");
+        ThreadUtil.sleep(1, TimeUnit.SECONDS);
+        statement.execute("USE db_discovery");
+    }
+    
+    private void registerStorageUnits(final Statement statement) throws 
SQLException {
+        statement.execute(discoveryDistSQLCommand.getRegisterStorageUnit());
+        ThreadUtil.sleep(2, TimeUnit.SECONDS);
+    }
+    
+    private void createDiscoveryRule(final Statement statement) throws 
SQLException {
+        statement.execute(discoveryDistSQLCommand.getCreateDiscoveryRule());
+        ThreadUtil.sleep(2, TimeUnit.SECONDS);
+    }
+    
+    private void createReadwriteSplittingRule(final Statement statement) 
throws SQLException {
+        
statement.execute(discoveryDistSQLCommand.getCreateReadwriteSplittingRule());
+        ThreadUtil.sleep(2, TimeUnit.SECONDS);
+    }
+}
diff --git 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/build/MySQLMGRBuilder.java
 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/build/MySQLMGRBuilder.java
new file mode 100644
index 00000000000..723e684ac4d
--- /dev/null
+++ 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/build/MySQLMGRBuilder.java
@@ -0,0 +1,100 @@
+/*
+ * 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.test.integration.discovery.build;
+
+import com.google.common.base.Splitter;
+import lombok.Getter;
+import 
org.apache.shardingsphere.test.integration.discovery.cases.base.BaseITCase;
+import 
org.apache.shardingsphere.test.integration.discovery.command.MGRPrimaryReplicaCommand;
+
+import javax.sql.DataSource;
+import javax.xml.bind.JAXB;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Build MySQL MGR.
+ */
+public final class MySQLMGRBuilder {
+    
+    private final MGRPrimaryReplicaCommand mgrPrimaryReplicaCommand;
+    
+    @Getter
+    private final DataSource primaryDataSource;
+    
+    @Getter
+    private final List<DataSource> replicaDataSources;
+    
+    public MySQLMGRBuilder(final List<DataSource> dataSources) throws 
SQLException {
+        this.primaryDataSource = dataSources.get(0);
+        this.replicaDataSources = dataSources.subList(1, dataSources.size());
+        mgrPrimaryReplicaCommand = 
JAXB.unmarshal(Objects.requireNonNull(BaseITCase.class.getClassLoader().getResource("env/common/mgr-primary-replica-command.xml")),
+                MGRPrimaryReplicaCommand.class);
+        buildMGRPrimaryDataSource(primaryDataSource);
+        buildMGRReplicaDataSources(dataSources.subList(1, dataSources.size()));
+    }
+    
+    private void buildMGRPrimaryDataSource(final DataSource dataSource) throws 
SQLException {
+        try (
+                Connection connection = dataSource.getConnection();
+                Statement statement = connection.createStatement()) {
+            buildMGRPrimaryDataSource(statement);
+        }
+    }
+    
+    private void buildMGRPrimaryDataSource(final Statement statement) throws 
SQLException {
+        for (String each : 
Splitter.on(";").trimResults().omitEmptyStrings().split(mgrPrimaryReplicaCommand.getBuildPrimaryNodeSQL()))
 {
+            statement.execute(each);
+        }
+    }
+    
+    private void buildMGRReplicaDataSources(final List<DataSource> 
dataSources) throws SQLException {
+        for (DataSource each : dataSources) {
+            buildMGRReplicaDataSource(each);
+        }
+    }
+    
+    private void buildMGRReplicaDataSource(final DataSource dataSource) throws 
SQLException {
+        try (
+                Connection connection = dataSource.getConnection();
+                Statement statement = connection.createStatement()) {
+            buildMGRReplicaDataSource(statement);
+        }
+    }
+    
+    private void buildMGRReplicaDataSource(final Statement statement) throws 
SQLException {
+        for (String each : 
Splitter.on(";").trimResults().omitEmptyStrings().split(mgrPrimaryReplicaCommand.getBuildReplicaNodeSQL()))
 {
+            statement.execute(each);
+        }
+    }
+    
+    /**
+     * Create database.
+     * @throws SQLException SQL exception
+     */
+    public void createDatabase() throws SQLException {
+        try (
+                Connection connection = primaryDataSource.getConnection();
+                Statement statement = connection.createStatement()) {
+            statement.execute("CREATE DATABASE it_discovery_test");
+        }
+    }
+}
diff --git 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/cases/base/BaseITCase.java
 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/cases/base/BaseITCase.java
index 1958ac35181..5809661b14e 100644
--- 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/cases/base/BaseITCase.java
+++ 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/cases/base/BaseITCase.java
@@ -20,7 +20,6 @@ package 
org.apache.shardingsphere.test.integration.discovery.cases.base;
 import lombok.AccessLevel;
 import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.shardingsphere.infra.database.metadata.url.JdbcUrlAppender;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import 
org.apache.shardingsphere.test.integration.discovery.env.IntegrationTestEnvironment;
 import 
org.apache.shardingsphere.test.integration.discovery.framework.container.compose.BaseContainerComposer;
@@ -39,35 +38,19 @@ public abstract class BaseITCase {
     
     protected static final IntegrationTestEnvironment ENV = 
IntegrationTestEnvironment.getInstance();
     
-    protected static final JdbcUrlAppender JDBC_URL_APPENDER = new 
JdbcUrlAppender();
-    
-    private final String databaseName;
-    
     private final BaseContainerComposer containerComposer;
     
     private final DatabaseType databaseType;
     
-    private List<DataSource> exposedDataSources;
+    private final List<DataSource> mappedDataSources;
     
-    private List<DataSource> mappedDataSources;
-    
-    private DataSource proxyDataSource;
+    private final DataSource proxyDataSource;
     
     public BaseITCase(final DiscoveryParameterized discoveryParameterized) {
         databaseType = discoveryParameterized.getDatabaseType();
         containerComposer = new 
DockerContainerComposer(discoveryParameterized.getScenario(), 
discoveryParameterized.getDatabaseType(), 
discoveryParameterized.getStorageContainerImage());
         containerComposer.start();
-        databaseName = "";
-        initStorageDataSources();
-        initProxyDataSource();
-    }
-    
-    private void initStorageDataSources() {
-        exposedDataSources = 
containerComposer.getExposedDatasource(databaseName);
-        mappedDataSources = 
containerComposer.getMappedDatasource(databaseName);
-    }
-    
-    private void initProxyDataSource() {
-        proxyDataSource = containerComposer.getProxyDatasource(databaseName);
+        mappedDataSources = containerComposer.getMappedDatasource();
+        proxyDataSource = containerComposer.getProxyDatasource();
     }
 }
diff --git 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/cases/mysql/MySQLDiscoveryGeneralIT.java
 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/cases/mysql/MySQLDiscoveryGeneralIT.java
index 7423fb530cc..adea2fa4f03 100644
--- 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/cases/mysql/MySQLDiscoveryGeneralIT.java
+++ 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/cases/mysql/MySQLDiscoveryGeneralIT.java
@@ -19,6 +19,8 @@ package 
org.apache.shardingsphere.test.integration.discovery.cases.mysql;
 
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import 
org.apache.shardingsphere.test.integration.discovery.build.DiscoveryRuleBuilder;
+import 
org.apache.shardingsphere.test.integration.discovery.build.MySQLMGRBuilder;
 import 
org.apache.shardingsphere.test.integration.discovery.cases.base.BaseITCase;
 import 
org.apache.shardingsphere.test.integration.discovery.framework.parameter.DiscoveryParameterized;
 import org.junit.Test;
@@ -26,10 +28,9 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
-import javax.sql.DataSource;
+import java.sql.SQLException;
 import java.util.Collection;
 import java.util.LinkedList;
-import java.util.List;
 
 /**
  * MySQL Discovery Integration Test.
@@ -50,17 +51,15 @@ public final class MySQLDiscoveryGeneralIT extends 
BaseITCase {
         Collection<DiscoveryParameterized> result = new LinkedList<>();
         MySQLDatabaseType databaseType = new MySQLDatabaseType();
         for (String each : ENV.listStorageContainerImages(databaseType)) {
-            result.add(new DiscoveryParameterized(databaseType, each, 
"mysql_discovery"));
+            result.add(new DiscoveryParameterized(databaseType, each, 
"discovery"));
         }
         return result;
     }
     
     @Test
-    public void assertProxyJdbcConnection() {
-        List<DataSource> mappedDataSources = getMappedDataSources();
-        List<DataSource> exposedDataSources = getExposedDataSources();
-        // TODO add the MySQL Discovery logic here.
-        mappedDataSources.forEach(each -> log.info(each.toString()));
-        exposedDataSources.forEach(each -> log.info(each.toString()));
+    public void assertMySQLMGRDiscovery() throws SQLException {
+        new MySQLMGRBuilder(getMappedDataSources()).createDatabase();
+        new DiscoveryRuleBuilder(getProxyDataSource());
+        // TODO Add some assert
     }
 }
diff --git 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/command/DiscoveryDistSQLCommand.java
 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/command/DiscoveryDistSQLCommand.java
new file mode 100644
index 00000000000..6e5d9588d57
--- /dev/null
+++ 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/command/DiscoveryDistSQLCommand.java
@@ -0,0 +1,44 @@
+/*
+ * 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.test.integration.discovery.command;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@Setter
+@XmlRootElement(name = "command")
+@XmlAccessorType(XmlAccessType.FIELD)
+public final class DiscoveryDistSQLCommand {
+    
+    @XmlElement(name = "register-storage-unit")
+    @Getter
+   private String registerStorageUnit;
+    
+    @XmlElement(name = "create-discovery-rule")
+    @Getter
+    private String createDiscoveryRule;
+    
+    @XmlElement(name = "create-readwrite-splitting-rule")
+    @Getter
+    private String createReadwriteSplittingRule;
+}
diff --git 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/command/MGRPrimaryReplicaCommand.java
 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/command/MGRPrimaryReplicaCommand.java
new file mode 100644
index 00000000000..7d8706786ed
--- /dev/null
+++ 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/command/MGRPrimaryReplicaCommand.java
@@ -0,0 +1,40 @@
+/*
+ * 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.test.integration.discovery.command;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@Setter
+@XmlRootElement(name = "command")
+@XmlAccessorType(XmlAccessType.FIELD)
+public final class MGRPrimaryReplicaCommand {
+    
+    @XmlElement(name = "build-primary-node-sql")
+    @Getter
+   private String buildPrimaryNodeSQL;
+    
+    @XmlElement(name = "build-replica-node-sql")
+    @Getter
+    private String buildReplicaNodeSQL;
+}
diff --git 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/compose/BaseContainerComposer.java
 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/compose/BaseContainerComposer.java
index 9995aa1211c..af30ed6dcce 100644
--- 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/compose/BaseContainerComposer.java
+++ 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/compose/BaseContainerComposer.java
@@ -42,26 +42,16 @@ public abstract class BaseContainerComposer implements 
Startable {
     /**
      * Get proxy data source.
      *
-     * @param databaseName database name
      * @return proxy data source
      */
-    public abstract DataSource getProxyDatasource(String databaseName);
-    
-    /**
-     * Get Datasource with storage container exposed port and network alias.
-     * 
-     * @param databaseName database name
-     * @return list of datasource
-     */
-    public abstract List<DataSource> getExposedDatasource(String databaseName);
+    public abstract DataSource getProxyDatasource();
     
     /**
      * Get Datasource with storage container mapped port and host.
      *
-     * @param databaseName database name
      * @return list of datasource
      */
-    public abstract List<DataSource> getMappedDatasource(String databaseName);
+    public abstract List<DataSource> getMappedDatasource();
     
     @Override
     public void start() {
diff --git 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/compose/DockerContainerComposer.java
 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/compose/DockerContainerComposer.java
index 2cb6c9a409e..98b0ae66057 100644
--- 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/compose/DockerContainerComposer.java
+++ 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/compose/DockerContainerComposer.java
@@ -20,12 +20,13 @@ package 
org.apache.shardingsphere.test.integration.discovery.framework.container
 import lombok.Getter;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import 
org.apache.shardingsphere.test.integration.discovery.framework.container.config.mysql.MySQLContainerConfigurationFactory;
+import 
org.apache.shardingsphere.test.integration.discovery.framework.container.config.MySQLContainerConfigurationFactory;
 import 
org.apache.shardingsphere.test.integration.env.container.atomic.adapter.AdapterContainerFactory;
 import 
org.apache.shardingsphere.test.integration.env.container.atomic.adapter.config.AdaptorContainerConfiguration;
 import 
org.apache.shardingsphere.test.integration.env.container.atomic.adapter.impl.ShardingSphereProxyClusterContainer;
 import 
org.apache.shardingsphere.test.integration.env.container.atomic.constants.AdapterContainerConstants;
 import 
org.apache.shardingsphere.test.integration.env.container.atomic.constants.EnvironmentConstants;
+import 
org.apache.shardingsphere.test.integration.env.container.atomic.constants.ProxyContainerConstants;
 import 
org.apache.shardingsphere.test.integration.env.container.atomic.constants.StorageContainerConstants;
 import 
org.apache.shardingsphere.test.integration.env.container.atomic.governance.GovernanceContainer;
 import 
org.apache.shardingsphere.test.integration.env.container.atomic.governance.impl.ZookeeperContainer;
@@ -80,23 +81,15 @@ public final class DockerContainerComposer extends 
BaseContainerComposer {
     }
     
     @Override
-    public DataSource getProxyDatasource(final String databaseName) {
-        return 
StorageContainerUtil.generateDataSource(DataSourceEnvironment.getURL(databaseType,
 proxyContainer.getHost(), proxyContainer.getFirstMappedPort(), databaseName),
-                StorageContainerConstants.USERNAME, 
StorageContainerConstants.PASSWORD);
+    public DataSource getProxyDatasource() {
+        return 
StorageContainerUtil.generateDataSource(DataSourceEnvironment.getURL(databaseType,
 proxyContainer.getHost(), proxyContainer.getFirstMappedPort(), ""),
+                ProxyContainerConstants.USERNAME, 
ProxyContainerConstants.PASSWORD);
     }
     
     @Override
-    public List<DataSource> getExposedDatasource(final String databaseName) {
+    public List<DataSource> getMappedDatasource() {
         return getStorageContainers().stream()
-                .map(each -> DataSourceEnvironment.getURL(databaseType, 
each.getNetworkAliases().get(0), each.getExposedPort(), databaseName))
-                .map(each -> StorageContainerUtil.generateDataSource(each, 
StorageContainerConstants.USERNAME, StorageContainerConstants.PASSWORD))
-                .collect(Collectors.toList());
-    }
-    
-    @Override
-    public List<DataSource> getMappedDatasource(final String databaseName) {
-        return getStorageContainers().stream()
-                .map(each -> DataSourceEnvironment.getURL(databaseType, 
each.getHost(), each.getMappedPort(), databaseName))
+                .map(each -> DataSourceEnvironment.getURL(databaseType, 
each.getHost(), each.getMappedPort(), ""))
                 .map(each -> StorageContainerUtil.generateDataSource(each, 
StorageContainerConstants.USERNAME, StorageContainerConstants.PASSWORD))
                 .collect(Collectors.toList());
     }
diff --git 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/config/mysql/MySQLContainerConfigurationFactory.java
 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/config/MySQLContainerConfigurationFactory.java
similarity index 99%
rename from 
test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/config/mysql/MySQLContainerConfigurationFactory.java
rename to 
test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/config/MySQLContainerConfigurationFactory.java
index 8e391a87d2b..d9162591c17 100644
--- 
a/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/config/mysql/MySQLContainerConfigurationFactory.java
+++ 
b/test/integration-test/discovery/src/test/java/org/apache/shardingsphere/test/integration/discovery/framework/container/config/MySQLContainerConfigurationFactory.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package 
org.apache.shardingsphere.test.integration.discovery.framework.container.config.mysql;
+package 
org.apache.shardingsphere.test.integration.discovery.framework.container.config;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
diff --git 
a/test/integration-test/discovery/src/test/resources/env/common/discovery-command.xml
 
b/test/integration-test/discovery/src/test/resources/env/common/discovery-command.xml
new file mode 100644
index 00000000000..c8a213494da
--- /dev/null
+++ 
b/test/integration-test/discovery/src/test/resources/env/common/discovery-command.xml
@@ -0,0 +1,54 @@
+<!--
+  ~ 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.
+  -->
+
+<command>
+    <register-storage-unit>
+        REGISTER STORAGE UNIT ds_0 (
+        HOST="mysql_1",
+        PORT=3306,
+        DB="it_discovery_test",
+        USER="test_user",
+        PASSWORD="Test@123"
+        ),ds_1 (
+        HOST="mysql_2",
+        PORT=3306,
+        DB="it_discovery_test",
+        USER="test_user",
+        PASSWORD="Test@123"
+        ),ds_2 (
+        HOST="mysql_3",
+        PORT=3306,
+        DB="it_discovery_test",
+        USER="test_user",
+        PASSWORD="Test@123"
+        );
+    </register-storage-unit>
+
+    <create-discovery-rule>
+        CREATE DB_DISCOVERY RULE replica_ds (
+        STORAGE_UNITS(ds_0, ds_1, ds_2),
+        
TYPE(NAME='MySQL.MGR',PROPERTIES('group-name'='558edd3c-02ec-11ea-9bb3-080027e39bd2')),
+        HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?'))
+        );
+    </create-discovery-rule>
+
+    <create-readwrite-splitting-rule>
+        CREATE READWRITE_SPLITTING RULE readwrite_ds (
+        AUTO_AWARE_RESOURCE=replica_ds
+        );
+    </create-readwrite-splitting-rule>
+</command>
diff --git 
a/test/integration-test/discovery/src/test/resources/env/common/mgr-primary-replica-command.xml
 
b/test/integration-test/discovery/src/test/resources/env/common/mgr-primary-replica-command.xml
new file mode 100644
index 00000000000..85a124ed2b7
--- /dev/null
+++ 
b/test/integration-test/discovery/src/test/resources/env/common/mgr-primary-replica-command.xml
@@ -0,0 +1,34 @@
+<!--
+  ~ 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.
+  -->
+
+<command>
+    <build-primary-node-sql>
+        reset master;
+        stop group_replication;
+        set global group_replication_single_primary_mode=on;
+        CHANGE MASTER TO MASTER_USER='test_user', MASTER_PASSWORD='Test@123' 
FOR CHANNEL 'group_replication_recovery';
+        set global group_replication_bootstrap_group=ON;
+        start group_replication;
+    </build-primary-node-sql>
+
+    <build-replica-node-sql>
+        reset master;
+        stop group_replication;
+        CHANGE MASTER TO MASTER_USER='test_user', MASTER_PASSWORD='Test@123' 
FOR CHANNEL 'group_replication_recovery';
+        start group_replication;
+    </build-replica-node-sql>
+</command>
diff --git 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_1/my.cnf
 
b/test/integration-test/discovery/src/test/resources/env/scenario/discovery/mysql_1/my.cnf
similarity index 73%
rename from 
test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_1/my.cnf
rename to 
test/integration-test/discovery/src/test/resources/env/scenario/discovery/mysql_1/my.cnf
index 39152346b6f..e808b180cf3 100644
--- 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_1/my.cnf
+++ 
b/test/integration-test/discovery/src/test/resources/env/scenario/discovery/mysql_1/my.cnf
@@ -18,18 +18,26 @@
 [mysql]
 
 [mysqld]
+log-error=/var/lib/mysql/mysql.err
+default_authentication_plugin=mysql_native_password
+max_connections=50000
 server_id = 100
 gtid_mode = ON
 enforce_gtid_consistency = ON
 master_info_repository = TABLE
 relay_log_info_repository = TABLE
+relay_log_info_repository = TABLE
 binlog_checksum = NONE
 log_slave_updates = ON
 log_bin = binlog
 binlog_format = ROW
 transaction_write_set_extraction = XXHASH64
+loose-plugin_load_add = 'group_replication.so'
 loose-group_replication_group_name = '558edd3c-02ec-11ea-9bb3-080027e39bd2'
 loose-group_replication_start_on_boot = OFF
-loose-group_replication_local_address = '127.0.0.1:10001'
-loose-group_replication_group_seeds = 
'127.0.0.1:10001,127.0.0.1:10002,127.0.0.1:10003'
+loose-group_replication_local_address = 'mysql_1:10001'
+loose-group_replication_group_seeds = 
'mysql_1:10001,mysql_2:10002,mysql_3:10003'
 loose-group_replication_bootstrap_group = OFF
+loose-group_replication_ip_whitelist = 'mysql_1, mysql_2, mysql_3'
+report_host = mysql_1
+report_port = 3306
\ No newline at end of file
diff --git 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_2/my.cnf
 
b/test/integration-test/discovery/src/test/resources/env/scenario/discovery/mysql_2/my.cnf
similarity index 75%
rename from 
test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_2/my.cnf
rename to 
test/integration-test/discovery/src/test/resources/env/scenario/discovery/mysql_2/my.cnf
index a0ce1691b8f..3db76e1c69a 100644
--- 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_2/my.cnf
+++ 
b/test/integration-test/discovery/src/test/resources/env/scenario/discovery/mysql_2/my.cnf
@@ -18,6 +18,9 @@
 [mysql]
 
 [mysqld]
+log-error=/var/lib/mysql/mysql.err
+default_authentication_plugin=mysql_native_password
+max_connections=50000
 server_id = 101
 gtid_mode = ON
 enforce_gtid_consistency = ON
@@ -28,9 +31,12 @@ log_slave_updates = ON
 log_bin = binlog
 binlog_format= ROW
 transaction_write_set_extraction = XXHASH64
+loose-plugin_load_add = 'group_replication.so'
 loose-group_replication_group_name = '558edd3c-02ec-11ea-9bb3-080027e39bd2'
 loose-group_replication_start_on_boot = OFF
-loose-group_replication_local_address = '127.0.0.1:10002'
-loose-group_replication_group_seeds  
'127.0.0.1:10001,127.0.0.1:10002,127.0.0.1:10003'
+loose-group_replication_local_address = 'mysql_2:10002'
+loose-group_replication_group_seeds = 
'mysql_1:10001,mysql_2:10002,mysql_3:10003'
 loose-group_replication_bootstrap_group = OFF
-
+loose-group_replication_ip_whitelist = 'mysql_1, mysql_2, mysql_3'
+report_host = mysql_2
+report_port = 3306
\ No newline at end of file
diff --git 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_3/my.cnf
 
b/test/integration-test/discovery/src/test/resources/env/scenario/discovery/mysql_3/my.cnf
similarity index 75%
rename from 
test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_3/my.cnf
rename to 
test/integration-test/discovery/src/test/resources/env/scenario/discovery/mysql_3/my.cnf
index 14dc12ba18f..ea577b97e5f 100644
--- 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_3/my.cnf
+++ 
b/test/integration-test/discovery/src/test/resources/env/scenario/discovery/mysql_3/my.cnf
@@ -18,6 +18,9 @@
 [mysql]
 
 [mysqld]
+log-error=/var/lib/mysql/mysql.err
+default_authentication_plugin=mysql_native_password
+max_connections=50000
 server_id = 102
 gtid_mode = ON
 enforce_gtid_consistency = ON
@@ -28,8 +31,12 @@ log_slave_updates = ON
 log_bin = binlog
 binlog_format= ROW
 transaction_write_set_extraction = XXHASH64
+loose-plugin_load_add = 'group_replication.so'
 loose-group_replication_group_name = '558edd3c-02ec-11ea-9bb3-080027e39bd2'
 loose-group_replication_start_on_boot = OFF
-loose-group_replication_local_address = '127.0.0.1:10003'
-loose-group_replication_group_seeds  
'127.0.0.1:10001,127.0.0.1:10002,127.0.0.1:10003'
+loose-group_replication_local_address = 'mysql_3:10003'
+loose-group_replication_group_seeds = 
'mysql_1:10001,mysql_2:10002,mysql_3:10003'
 loose-group_replication_bootstrap_group = OFF
+loose-group_replication_ip_whitelist = 'mysql_1, mysql_2, mysql_3'
+report_host = mysql_3
+report_port = 3306
\ No newline at end of file
diff --git 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/proxy/server.yaml
 
b/test/integration-test/discovery/src/test/resources/env/scenario/discovery/proxy/server.yaml
similarity index 97%
rename from 
test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/proxy/server.yaml
rename to 
test/integration-test/discovery/src/test/resources/env/scenario/discovery/proxy/server.yaml
index 3f6ca12fbe8..598b9c9491a 100644
--- 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/proxy/server.yaml
+++ 
b/test/integration-test/discovery/src/test/resources/env/scenario/discovery/proxy/server.yaml
@@ -20,7 +20,7 @@ mode:
   repository:
     type: ZooKeeper
     props:
-      namespace: it_db_mysql
+      namespace: it_discovery
       server-lists: zk.host:2181
       timeToLiveSeconds: 60
       operationTimeoutMilliseconds: 500
diff --git 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_1/01-initdb.sql
 
b/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_1/01-initdb.sql
deleted file mode 100644
index bd71ad0163c..00000000000
--- 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_1/01-initdb.sql
+++ /dev/null
@@ -1,18 +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.
---
-
-CREATE DATABASE discovery_test;
diff --git 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_2/01-initdb.sql
 
b/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_2/01-initdb.sql
deleted file mode 100644
index bd71ad0163c..00000000000
--- 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_2/01-initdb.sql
+++ /dev/null
@@ -1,18 +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.
---
-
-CREATE DATABASE discovery_test;
diff --git 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_3/01-initdb.sql
 
b/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_3/01-initdb.sql
deleted file mode 100644
index bd71ad0163c..00000000000
--- 
a/test/integration-test/discovery/src/test/resources/env/scenario/mysql_discovery/mysql_3/01-initdb.sql
+++ /dev/null
@@ -1,18 +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.
---
-
-CREATE DATABASE discovery_test;


Reply via email to