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 309c34fb646 Add HA integration test basic framework (#20628)
309c34fb646 is described below
commit 309c34fb64647c584bddfdc3cac9b0ec25853b85
Author: 孙念君 Nianjun Sun <[email protected]>
AuthorDate: Mon Aug 29 14:39:39 2022 +0800
Add HA integration test basic framework (#20628)
* Add : add ha module for testing HA related function
* Add : add code for ha scenario
* Add : add new method to extract the database type name
* Add : add base IT for test case
* Refactor : add abstract descriptor for abstract class
* Add : add base IT for ha test
* Refactor : add annotation to make the IT runnable
* Add : add MySQL Configuration factor for the further container management
* Refactor : refactor the container composed class for ha test
* Refactor : add proxy container config for HA test
* Fix : fix all checkstyle issues
* Refactor : refactor the config files
* Refactor : rename a base class
* Add : add basic HA structure
* Refacotr : refactor the alias network settings to avoid the suite test
* Refactor : refacor the descriptor off HAContainerUtil
---
.../shardingsphere-integration-test/pom.xml | 1 +
.../atomic/storage/DockerStorageContainer.java | 6 +-
.../atomic/util/StorageContainerUtil.java | 41 +++++++++
.../shardingsphere-integration-test-ha/pom.xml | 89 ++++++++++++++++++++
.../test/integration/ha/cases/base/BaseITCase.java | 95 +++++++++++++++++++++
.../ha/cases/mysql/MySQLHAGeneralIT.java | 64 ++++++++++++++
.../ha/env/IntegrationTestEnvironment.java | 97 ++++++++++++++++++++++
.../integration/ha/env/enums/ITEnvTypeEnum.java | 23 +++++
.../container/compose/BaseComposedContainer.java | 56 +++++++++++++
.../container/compose/DockerComposedContainer.java | 96 +++++++++++++++++++++
.../ProxyClusterContainerConfigurationFactory.java | 49 +++++++++++
.../StorageContainerConfigurationFactory.java | 50 +++++++++++
.../mysql/MySQLContainerConfigurationFactory.java | 83 ++++++++++++++++++
.../OpenGaussContainerConfigurationFactory.java | 58 +++++++++++++
.../PostgreSQLContainerConfigurationFactory.java | 54 ++++++++++++
.../ha/framework/parameter/HAParameterized.java | 35 ++++++++
.../test/integration/ha/util/HAContainerUtil.java | 59 +++++++++++++
.../src/test/resources/env/it-env.properties | 38 +++++++++
.../src/test/resources/env/mysql/01-initdb.sql | 21 +++++
.../env/scenario/mysql_ha/mysql_1/01-initdb.sql | 18 ++++
.../resources/env/scenario/mysql_ha/mysql_1/my.cnf | 27 ++++++
.../env/scenario/mysql_ha/mysql_2/01-initdb.sql | 18 ++++
.../resources/env/scenario/mysql_ha/mysql_2/my.cnf | 27 ++++++
.../env/scenario/mysql_ha/mysql_3/01-initdb.sql | 18 ++++
.../resources/env/scenario/mysql_ha/mysql_3/my.cnf | 27 ++++++
.../env/scenario/mysql_ha/proxy/server.yaml | 44 ++++++++++
.../src/test/resources/logback-test.xml | 33 ++++++++
27 files changed, 1224 insertions(+), 3 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/pom.xml
b/shardingsphere-test/shardingsphere-integration-test/pom.xml
index 1c428965bf1..dbb3792255d 100644
--- a/shardingsphere-test/shardingsphere-integration-test/pom.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/pom.xml
@@ -34,6 +34,7 @@
<module>shardingsphere-integration-test-suite</module>
<module>shardingsphere-integration-test-scaling</module>
<module>shardingsphere-integration-test-transaction</module>
+ <module>shardingsphere-integration-test-ha</module>
</modules>
<properties>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/DockerStorageContainer.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/DockerStorageContainer.java
index 09203cb8cb9..ded554f7450 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/DockerStorageContainer.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/storage/DockerStorageContainer.java
@@ -110,7 +110,7 @@ public abstract class DockerStorageContainer extends
DockerITContainer implement
/**
* Create access data source.
- *
+ *
* @param dataSourceName data source name
* @return access data source
*/
@@ -127,7 +127,7 @@ public abstract class DockerStorageContainer extends
DockerITContainer implement
/**
* Get JDBC URL.
- *
+ *
* @param dataSourceName datasource name
* @return JDBC URL
*/
@@ -137,7 +137,7 @@ public abstract class DockerStorageContainer extends
DockerITContainer implement
/**
* Get username.
- *
+ *
* @return username
*/
public final String getUsername() {
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/StorageContainerUtil.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/StorageContainerUtil.java
new file mode 100644
index 00000000000..11c28a6c7a9
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-env/src/test/java/org/apache/shardingsphere/test/integration/env/container/atomic/util/StorageContainerUtil.java
@@ -0,0 +1,41 @@
+/*
+ * 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.env.container.atomic.util;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Storage container util.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class StorageContainerUtil {
+
+ private static final AtomicInteger ATOMIC_STORAGE_CONTAINER_ID = new
AtomicInteger(1);
+
+ /**
+ * Generate a unique storage container id.
+ *
+ * @return unique storage container id
+ */
+ public static int generateContainerId() {
+ return ATOMIC_STORAGE_CONTAINER_ID.getAndIncrement();
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/pom.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/pom.xml
new file mode 100644
index 00000000000..0cd515f4816
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/pom.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-integration-test</artifactId>
+ <version>5.1.3-SNAPSHOT</version>
+ </parent>
+ <artifactId>shardingsphere-integration-test-ha</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-integration-test-env</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-integration-test-fixture</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>postgresql</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>com.zaxxer</groupId>
+ <artifactId>HikariCP</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.testcontainers</groupId>
+ <artifactId>testcontainers</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-resources</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <phase>validate</phase>
+ <configuration>
+
<outputDirectory>target/test-classes</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/cases/base/BaseITCase.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/cases/base/BaseITCase.java
new file mode 100644
index 00000000000..6f2a5c60926
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/cases/base/BaseITCase.java
@@ -0,0 +1,95 @@
+/*
+ * 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.ha.cases.base;
+
+import com.zaxxer.hikari.HikariDataSource;
+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.env.container.atomic.adapter.impl.ShardingSphereProxyClusterContainer;
+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.storage.DockerStorageContainer;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.util.DatabaseTypeUtil;
+import
org.apache.shardingsphere.test.integration.env.runtime.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.integration.ha.env.IntegrationTestEnvironment;
+import
org.apache.shardingsphere.test.integration.ha.framework.container.compose.BaseComposedContainer;
+import
org.apache.shardingsphere.test.integration.ha.framework.container.compose.DockerComposedContainer;
+import
org.apache.shardingsphere.test.integration.ha.framework.parameter.HAParameterized;
+
+import javax.sql.DataSource;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Base integration test.
+ */
+@Slf4j
+@Getter(AccessLevel.PROTECTED)
+public abstract class BaseITCase {
+
+ protected static final IntegrationTestEnvironment ENV =
IntegrationTestEnvironment.getInstance();
+
+ protected static final JdbcUrlAppender JDBC_URL_APPENDER = new
JdbcUrlAppender();
+
+ protected static final String DEFAULT_SCHEMA = "ha_test";
+
+ private final BaseComposedContainer composedContainer;
+
+ private final DatabaseType databaseType;
+
+ private List<DataSource> storageDataSources;
+
+ private DataSource proxyDataSource;
+
+ public BaseITCase(final HAParameterized haParameterized) {
+ databaseType = haParameterized.getDatabaseType();
+ composedContainer = new
DockerComposedContainer(haParameterized.getScenario(),
haParameterized.getDatabaseType(), haParameterized.getDockerImageName());
+ composedContainer.start();
+ initStorageDataSources();
+ initProxyDataSource();
+ }
+
+ private void initProxyDataSource() {
+ String databaseName = (DatabaseTypeUtil.isPostgreSQL(databaseType) ||
DatabaseTypeUtil.isOpenGauss(databaseType)) ? "postgres" : "";
+ ShardingSphereProxyClusterContainer proxyContainer =
((DockerComposedContainer) composedContainer).getProxyContainer();
+ this.proxyDataSource =
getDataSource(DataSourceEnvironment.getURL(databaseType,
proxyContainer.getHost(), proxyContainer.getFirstMappedPort(),
+ composedContainer.getProxyJdbcUrl(databaseName)),
ProxyContainerConstants.USERNAME, ProxyContainerConstants.PASSWORD);
+ }
+
+ private void initStorageDataSources() {
+ List<DockerStorageContainer> storageContainers =
((DockerComposedContainer) composedContainer).getStorageContainers();
+ this.storageDataSources = storageContainers.stream()
+ .map(storageContainer ->
DataSourceEnvironment.getURL(getDatabaseType(),
storageContainer.getNetworkAliases().get(0), storageContainer.getPort(),
DEFAULT_SCHEMA))
+ .map(jdbcUrl -> getDataSource(jdbcUrl,
StorageContainerConstants.USERNAME, StorageContainerConstants.PASSWORD))
+ .collect(Collectors.toList());
+ }
+
+ private DataSource getDataSource(final String jdbcUrl, final String
username, final String password) {
+ HikariDataSource result = new HikariDataSource();
+
result.setDriverClassName(DataSourceEnvironment.getDriverClassName(getDatabaseType()));
+ result.setJdbcUrl(jdbcUrl);
+ result.setUsername(username);
+ result.setPassword(password);
+ result.setMaximumPoolSize(2);
+ result.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
+ return result;
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/cases/mysql/MySQLHAGeneralIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/cases/mysql/MySQLHAGeneralIT.java
new file mode 100644
index 00000000000..b65a23c0ee0
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/cases/mysql/MySQLHAGeneralIT.java
@@ -0,0 +1,64 @@
+/*
+ * 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.ha.cases.mysql;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import org.apache.shardingsphere.test.integration.ha.cases.base.BaseITCase;
+import
org.apache.shardingsphere.test.integration.ha.framework.parameter.HAParameterized;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import javax.sql.DataSource;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * MySQL High Availability Integration Test.
+ */
+@Slf4j
+@RunWith(Parameterized.class)
+public final class MySQLHAGeneralIT extends BaseITCase {
+
+ private final HAParameterized haParameterized;
+
+ public MySQLHAGeneralIT(final HAParameterized haParameterized) {
+ super(haParameterized);
+ this.haParameterized = haParameterized;
+ }
+
+ @Parameters(name = "{0}")
+ public static Collection<HAParameterized> getParameters() {
+ Collection<HAParameterized> result = new LinkedList<>();
+ MySQLDatabaseType databaseType = new MySQLDatabaseType();
+ for (String version : ENV.listDatabaseDockerImageNames(databaseType)) {
+ result.add(new HAParameterized(databaseType, version, "mysql_ha"));
+ }
+ return result;
+ }
+
+ @Test
+ public void assertProxyJdbcConnection() {
+ List<DataSource> dataSourceList = getStorageDataSources();
+ // TODO add the MySQL HA logic here.
+ dataSourceList.forEach(each -> log.info(each.toString()));
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/env/IntegrationTestEnvironment.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/env/IntegrationTestEnvironment.java
new file mode 100644
index 00000000000..30a143d7ce1
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/env/IntegrationTestEnvironment.java
@@ -0,0 +1,97 @@
+/*
+ * 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.ha.env;
+
+import lombok.Getter;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.test.integration.ha.env.enums.ITEnvTypeEnum;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+@Getter
+@Slf4j
+public final class IntegrationTestEnvironment {
+
+ private static final IntegrationTestEnvironment INSTANCE = new
IntegrationTestEnvironment();
+
+ private final Properties props;
+
+ private final ITEnvTypeEnum itEnvType;
+
+ private final List<String> mysqlVersions;
+
+ private final List<String> postgresVersions;
+
+ private final List<String> openGaussVersions;
+
+ private IntegrationTestEnvironment() {
+ props = loadProperties();
+ itEnvType =
ITEnvTypeEnum.valueOf(StringUtils.defaultIfBlank(props.getProperty("it.env.type").toUpperCase(),
ITEnvTypeEnum.NONE.name()));
+ mysqlVersions =
Arrays.stream(props.getOrDefault("it.docker.mysql.version",
"").toString().split(",")).filter(StringUtils::isNotBlank).collect(Collectors.toList());
+ postgresVersions =
Arrays.stream(props.getOrDefault("it.docker.postgresql.version",
"").toString().split(",")).filter(StringUtils::isNotBlank).collect(Collectors.toList());
+ openGaussVersions =
Arrays.stream(props.getOrDefault("it.docker.opengauss.version",
"").toString().split(",")).filter(StringUtils::isNotBlank).collect(Collectors.toList());
+ }
+
+ @SneakyThrows(IOException.class)
+ private Properties loadProperties() {
+ Properties result = new Properties();
+ try (InputStream inputStream =
IntegrationTestEnvironment.class.getClassLoader().getResourceAsStream("env/it-env.properties"))
{
+ result.load(inputStream);
+ }
+ for (String each : System.getProperties().stringPropertyNames()) {
+ result.setProperty(each, System.getProperty(each));
+ }
+ return result;
+ }
+
+ /**
+ * Get instance.
+ *
+ * @return singleton instance
+ */
+ public static IntegrationTestEnvironment getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * List database docker image names.
+ *
+ * @param databaseType database type.
+ * @return database docker image names
+ */
+ public List<String> listDatabaseDockerImageNames(final DatabaseType
databaseType) {
+ switch (databaseType.getType()) {
+ case "MySQL":
+ return mysqlVersions;
+ case "PostgreSQL":
+ return postgresVersions;
+ case "openGauss":
+ return openGaussVersions;
+ default:
+ throw new UnsupportedOperationException("Unsupported database
type: " + databaseType.getType());
+ }
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/env/enums/ITEnvTypeEnum.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/env/enums/ITEnvTypeEnum.java
new file mode 100644
index 00000000000..9f4e96d2016
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/env/enums/ITEnvTypeEnum.java
@@ -0,0 +1,23 @@
+/*
+ * 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.ha.env.enums;
+
+public enum ITEnvTypeEnum {
+
+ NONE, DOCKER, NATIVE
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/compose/BaseComposedContainer.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/compose/BaseComposedContainer.java
new file mode 100644
index 00000000000..f3e19d6ecfb
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/compose/BaseComposedContainer.java
@@ -0,0 +1,56 @@
+/*
+ * 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.ha.framework.container.compose;
+
+import lombok.Getter;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.ITContainers;
+import org.testcontainers.lifecycle.Startable;
+
+/**
+ * Abstract composed container.
+ */
+public abstract class BaseComposedContainer implements Startable {
+
+ @Getter
+ private final ITContainers containers;
+
+ private final String scenario;
+
+ public BaseComposedContainer(final String scenario) {
+ this.scenario = scenario;
+ this.containers = new ITContainers(scenario);
+ }
+
+ /**
+ * Get proxy JDBC URL.
+ *
+ * @param databaseName database name
+ * @return proxy JDBC URL
+ */
+ public abstract String getProxyJdbcUrl(String databaseName);
+
+ @Override
+ public void start() {
+ getContainers().start();
+ }
+
+ @Override
+ public void stop() {
+ getContainers().stop();
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/compose/DockerComposedContainer.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/compose/DockerComposedContainer.java
new file mode 100644
index 00000000000..1ffb7fc1146
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/compose/DockerComposedContainer.java
@@ -0,0 +1,96 @@
+/*
+ * 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.ha.framework.container.compose;
+
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+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.governance.GovernanceContainer;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.governance.impl.ZookeeperContainer;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.storage.DockerStorageContainer;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.storage.StorageContainerFactory;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.storage.config.StorageContainerConfiguration;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.util.StorageContainerUtil;
+import
org.apache.shardingsphere.test.integration.env.runtime.DataSourceEnvironment;
+import
org.apache.shardingsphere.test.integration.ha.framework.container.config.ProxyClusterContainerConfigurationFactory;
+import
org.apache.shardingsphere.test.integration.ha.framework.container.config.StorageContainerConfigurationFactory;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Composed container, include governance container and storage container.
+ */
+@Slf4j
+@Getter
+public final class DockerComposedContainer extends BaseComposedContainer {
+
+ private final DatabaseType databaseType;
+
+ private final ShardingSphereProxyClusterContainer proxyContainer;
+
+ @Getter
+ private final List<DockerStorageContainer> storageContainers;
+
+ @Getter
+ private final GovernanceContainer governanceContainer;
+
+ public DockerComposedContainer(final String scenario, final DatabaseType
databaseType, final String dockerImageName) {
+ super("");
+ this.databaseType = databaseType;
+ this.storageContainers = new LinkedList<>();
+ governanceContainer = getContainers().registerContainer(new
ZookeeperContainer());
+ List<StorageContainerConfiguration> containerConfigs =
StorageContainerConfigurationFactory.newInstance(scenario, databaseType);
+ containerConfigs.forEach(each -> {
+ DockerStorageContainer storageContainer =
getContainers().registerContainer((DockerStorageContainer)
StorageContainerFactory.newInstance(databaseType, dockerImageName, null, each));
+
storageContainer.setNetworkAliases(Collections.singletonList(databaseType.getType().toLowerCase()
+ "_" + StorageContainerUtil.generateContainerId()));
+ storageContainers.add(storageContainer);
+ });
+
+ AdaptorContainerConfiguration containerConfig =
ProxyClusterContainerConfigurationFactory.newInstance(scenario);
+ ShardingSphereProxyClusterContainer proxyClusterContainer =
(ShardingSphereProxyClusterContainer) AdapterContainerFactory
+ .newInstance("Cluster", "proxy", databaseType, null, "",
containerConfig);
+ storageContainers.forEach(each ->
proxyClusterContainer.dependsOn(governanceContainer, each));
+ proxyContainer =
getContainers().registerContainer(proxyClusterContainer);
+ }
+
+ /**
+ * Get proxy JDBC URL.
+ *
+ * @param databaseName database name
+ * @return proxy JDBC URL
+ */
+ public String getProxyJdbcUrl(final String databaseName) {
+ return DataSourceEnvironment.getURL(databaseType,
proxyContainer.getHost(), proxyContainer.getFirstMappedPort(), databaseName);
+ }
+
+ /**
+ * Get storage containers JDBC URL.
+ *
+ * @param databaseName database name
+ * @return storage containers JDBC URL
+ */
+ public List<String> getJdbcUrls(final String databaseName) {
+ return storageContainers.stream().map(each ->
each.getJdbcUrl(databaseName)).collect(Collectors.toList());
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/ProxyClusterContainerConfigurationFactory.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/ProxyClusterContainerConfigurationFactory.java
new file mode 100644
index 00000000000..dc7d33afdb5
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/ProxyClusterContainerConfigurationFactory.java
@@ -0,0 +1,49 @@
+/*
+ * 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.ha.framework.container.config;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.adapter.config.AdaptorContainerConfiguration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Proxy cluster container configuration factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ProxyClusterContainerConfigurationFactory {
+
+ /**
+ * Create new instance of adaptor container configuration.
+ *
+ * @param scenario scenario
+ * @return created instance
+ */
+ public static AdaptorContainerConfiguration newInstance(final String
scenario) {
+ return new AdaptorContainerConfiguration("",
getMountedResources(scenario));
+ }
+
+ private static Map<String, String> getMountedResources(final String
scenario) {
+ Map<String, String> result = new HashMap<>(2, 1);
+ result.put("logback-test.xml",
"/opt/shardingsphere-proxy/conf/logback.xml");
+ result.put(String.format("env/scenario/%s/proxy/server.yaml",
scenario), "/opt/shardingsphere-proxy/conf/server.yaml");
+ return result;
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/StorageContainerConfigurationFactory.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/StorageContainerConfigurationFactory.java
new file mode 100644
index 00000000000..5acf7f276b2
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/StorageContainerConfigurationFactory.java
@@ -0,0 +1,50 @@
+/*
+ * 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.ha.framework.container.config;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.storage.config.StorageContainerConfiguration;
+import
org.apache.shardingsphere.test.integration.ha.framework.container.config.mysql.MySQLContainerConfigurationFactory;
+
+import java.util.List;
+
+/**
+ * Storage container configuration factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class StorageContainerConfigurationFactory {
+
+ /**
+ * Create new instance of storage container configuration.
+ *
+ * @param scenario scenario
+ * @param databaseType database type
+ * @return created instance
+ */
+ public static List<StorageContainerConfiguration> newInstance(final String
scenario, final DatabaseType databaseType) {
+ switch (databaseType.getType()) {
+ case "MySQL":
+ return
MySQLContainerConfigurationFactory.newInstance(scenario, databaseType);
+ // TODO please add other configuration factory for PG or OG if
there is HA solution for these database types.
+ default:
+ throw new RuntimeException(String.format("Database `%s` is
unknown.", databaseType.getType()));
+ }
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/mysql/MySQLContainerConfigurationFactory.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/mysql/MySQLContainerConfigurationFactory.java
new file mode 100644
index 00000000000..cdbf0b64eb7
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/mysql/MySQLContainerConfigurationFactory.java
@@ -0,0 +1,83 @@
+/*
+ * 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.ha.framework.container.config.mysql;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.constants.StorageContainerConstants;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.storage.config.StorageContainerConfiguration;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.util.MySQLContainerUtil;
+import org.apache.shardingsphere.test.integration.ha.util.HAContainerUtil;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * MySQL container configuration factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class MySQLContainerConfigurationFactory {
+
+ /**
+ * Create new instance of MySQL container configuration.
+ *
+ * @param scenario scenario
+ * @param databaseType database type
+ * @return created instance
+ */
+ public static List<StorageContainerConfiguration> newInstance(final String
scenario, final DatabaseType databaseType) {
+ Integer containerQuantity =
HAContainerUtil.loadContainerRawNamesAndQuantity(scenario).get(databaseType.getType().toLowerCase());
+ if (containerQuantity == null) {
+ return getDefaultConfiguration(databaseType);
+ }
+ if (1 == containerQuantity) {
+ return Collections.singletonList(new
StorageContainerConfiguration(getCommand(), getContainerEnvironments(),
getMountedResources(scenario, databaseType, 0)));
+ }
+ List<StorageContainerConfiguration> result = new LinkedList<>();
+ for (int i = 1; i <= containerQuantity; i++) {
+ result.add(new StorageContainerConfiguration(getCommand(),
getContainerEnvironments(), getMountedResources(scenario, databaseType, i)));
+ }
+ return result;
+ }
+
+ private static String getCommand() {
+ return "--server-id=" + MySQLContainerUtil.generateServerId();
+ }
+
+ private static Map<String, String> getContainerEnvironments() {
+ Map<String, String> result = new HashMap<>(2, 1);
+ result.put("LANG", "C.UTF-8");
+ result.put("MYSQL_RANDOM_ROOT_PASSWORD", "yes");
+ return result;
+ }
+
+ private static Map<String, String> getMountedResources(final String
scenario, final DatabaseType databaseType, final int order) {
+ return 0 == order ?
Collections.singletonMap(String.format("/env/scenario/%s/my.cnf", scenario),
StorageContainerConstants.MYSQL_CONF_IN_CONTAINER)
+ :
Collections.singletonMap(String.format("/env/scenario/%s/%s/my.cnf", scenario,
databaseType.getType().toLowerCase() + "_" + order),
+ StorageContainerConstants.MYSQL_CONF_IN_CONTAINER);
+ }
+
+ private static List<StorageContainerConfiguration>
getDefaultConfiguration(final DatabaseType databaseType) {
+ return Collections.singletonList(new
StorageContainerConfiguration(getCommand(), getContainerEnvironments(),
+ Collections.singletonMap(String.format("/env/%s/my.cnf",
databaseType.getType().toLowerCase()),
StorageContainerConstants.MYSQL_CONF_IN_CONTAINER)));
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/opengauss/OpenGaussContainerConfigurationFactory.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/opengauss/OpenGaussContainerConfigurationFactory.java
new file mode 100644
index 00000000000..685278d193e
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/opengauss/OpenGaussContainerConfigurationFactory.java
@@ -0,0 +1,58 @@
+/*
+ * 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.ha.framework.container.config.opengauss;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.constants.StorageContainerConstants;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.storage.config.StorageContainerConfiguration;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * OpenGauss container configuration factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class OpenGaussContainerConfigurationFactory {
+
+ /**
+ * Create new instance of openGauss container configuration.
+ *
+ * @return created instance
+ */
+ public static StorageContainerConfiguration newInstance() {
+ return new StorageContainerConfiguration(getCommand(),
getContainerEnvironments(), getMountedResources());
+ }
+
+ private static String getCommand() {
+ return "";
+ }
+
+ private static Map<String, String> getContainerEnvironments() {
+ return Collections.singletonMap("GS_PASSWORD",
StorageContainerConstants.PASSWORD);
+ }
+
+ private static Map<String, String> getMountedResources() {
+ Map<String, String> result = new HashMap<>(2, 1);
+ result.put("/env/postgresql/postgresql.conf",
StorageContainerConstants.OPENGAUSS_CONF_IN_CONTAINER);
+ result.put("/env/opengauss/pg_hba.conf",
StorageContainerConstants.OPENGAUSS_HBA_IN_CONF_CONTAINER);
+ return result;
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/postgresql/PostgreSQLContainerConfigurationFactory.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/postgresql/PostgreSQLContainerConfigurationFactory.java
new file mode 100644
index 00000000000..fec8f42378d
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/container/config/postgresql/PostgreSQLContainerConfigurationFactory.java
@@ -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.
+ */
+
+package
org.apache.shardingsphere.test.integration.ha.framework.container.config.postgresql;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.constants.StorageContainerConstants;
+import
org.apache.shardingsphere.test.integration.env.container.atomic.storage.config.StorageContainerConfiguration;
+
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * PostgreSQL container configuration factory.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class PostgreSQLContainerConfigurationFactory {
+
+ /**
+ * Create new instance of PostgreSQL container configuration.
+ *
+ * @return created instance
+ */
+ public static StorageContainerConfiguration newInstance() {
+ return new StorageContainerConfiguration(getCommand(),
getContainerEnvironments(), getMountedResources());
+ }
+
+ private static String getCommand() {
+ return "-c config_file=" +
StorageContainerConstants.POSTGRESQL_CONF_IN_CONTAINER;
+ }
+
+ private static Map<String, String> getContainerEnvironments() {
+ return Collections.singletonMap("POSTGRES_PASSWORD",
StorageContainerConstants.PASSWORD);
+ }
+
+ private static Map<String, String> getMountedResources() {
+ return Collections.singletonMap("/env/postgresql/postgresql.conf",
StorageContainerConstants.POSTGRESQL_CONF_IN_CONTAINER);
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/parameter/HAParameterized.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/parameter/HAParameterized.java
new file mode 100644
index 00000000000..ba062913fd8
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/framework/parameter/HAParameterized.java
@@ -0,0 +1,35 @@
+/*
+ * 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.ha.framework.parameter;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.ToString;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+
+@Getter
+@RequiredArgsConstructor
+@ToString
+public final class HAParameterized {
+
+ private final DatabaseType databaseType;
+
+ private final String dockerImageName;
+
+ private final String scenario;
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/util/HAContainerUtil.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/util/HAContainerUtil.java
new file mode 100644
index 00000000000..e22f6240762
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/java/org/apache/shardingsphere/test/integration/ha/util/HAContainerUtil.java
@@ -0,0 +1,59 @@
+/*
+ * 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.ha.util;
+
+import lombok.NoArgsConstructor;
+
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * HA container utility.
+ */
+@NoArgsConstructor
+public final class HAContainerUtil {
+
+ /**
+ * Get container names and quantity.
+ * @param scenario scenario
+ * @return container names and quantity
+ */
+ public static Map<String, Integer> loadContainerRawNamesAndQuantity(final
String scenario) {
+ Map<String, Integer> result = new HashMap<>(3, 1);
+ ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
+ URL resource = classLoader.getResource("env/scenario/" + scenario);
+ if (resource != null) {
+ String[] containerNames = new File(resource.getPath()).list((dir,
name) -> new File(dir, name).isDirectory());
+ if (containerNames != null) {
+ result = extractContainerNamesWithQuantity(containerNames);
+ }
+ }
+ return result;
+ }
+
+ private static Map<String, Integer>
extractContainerNamesWithQuantity(final String[] rawContainerNames) {
+ Map<String, Integer> result = new HashMap<>(3, 1);
+ for (String each : rawContainerNames) {
+ String databaseTypeName = each.contains("_") ? each.substring(0,
each.indexOf("_")) : each;
+ result.merge(databaseTypeName, 1, Integer::sum);
+ }
+ return result;
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/it-env.properties
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/it-env.properties
new file mode 100644
index 00000000000..8ea8583a6ec
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/it-env.properties
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+# it.type=DOCKER,NATIVE
+it.env.type=
+# it.env.cases=mysql_ha
+it.env.cases=
+# it.docker.mysql.version=mysql:5.7,mysql:8.0
+it.docker.mysql.version=
+#
it.docker.postgresql.version=postgres:10-alpine,postgres:11-alpine,postgres:12-alpine,postgres:13-alpine,postgres:14-alpine
+it.docker.postgresql.version=
+# it.docker.opengauss.version=enmotech/opengauss:3.0.0,enmotech/opengauss:2.1.0
+it.docker.opengauss.version=
+# it.native.database=mysql or postgresql or opengauss
+#it.native.database=
+#it.native.mysql.username=root
+#it.native.mysql.password=root
+#it.native.mysql.port=3306
+#it.native.postgresql.username=postgres
+#it.native.postgresql.password=root
+#it.native.postgresql.port=5432
+#it.native.opengauss.username=gaussdb
+#it.native.opengauss.password=Root@123
+#it.native.opengauss.port=5432
+
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/mysql/01-initdb.sql
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/mysql/01-initdb.sql
new file mode 100644
index 00000000000..b46490db647
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/mysql/01-initdb.sql
@@ -0,0 +1,21 @@
+--
+-- 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 ha_test;
+
+GRANT REPLICATION CLIENT, REPLICATION SLAVE, SELECT, INSERT, UPDATE, DELETE,
INDEX ON *.* TO `test_user`@`%`;
+GRANT CREATE, DROP ON TABLE *.* TO test_user;
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_1/01-initdb.sql
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_1/01-initdb.sql
new file mode 100644
index 00000000000..b57a1c65e14
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_1/01-initdb.sql
@@ -0,0 +1,18 @@
+--
+-- 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 ha_test;
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_1/my.cnf
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_1/my.cnf
new file mode 100644
index 00000000000..1a0e57d805e
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_1/my.cnf
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+[mysql]
+
+[mysqld]
+server-id=1
+log-bin=mysql-bin
+binlog-format=row
+binlog-row-image=full
+max_connections=600
+# for mysql 8.0
+secure_file_priv=/var/lib/mysql
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_2/01-initdb.sql
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_2/01-initdb.sql
new file mode 100644
index 00000000000..b57a1c65e14
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_2/01-initdb.sql
@@ -0,0 +1,18 @@
+--
+-- 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 ha_test;
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_2/my.cnf
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_2/my.cnf
new file mode 100644
index 00000000000..1a0e57d805e
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_2/my.cnf
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+[mysql]
+
+[mysqld]
+server-id=1
+log-bin=mysql-bin
+binlog-format=row
+binlog-row-image=full
+max_connections=600
+# for mysql 8.0
+secure_file_priv=/var/lib/mysql
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_3/01-initdb.sql
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_3/01-initdb.sql
new file mode 100644
index 00000000000..b57a1c65e14
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_3/01-initdb.sql
@@ -0,0 +1,18 @@
+--
+-- 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 ha_test;
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_3/my.cnf
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_3/my.cnf
new file mode 100644
index 00000000000..1a0e57d805e
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/mysql_3/my.cnf
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+[mysql]
+
+[mysqld]
+server-id=1
+log-bin=mysql-bin
+binlog-format=row
+binlog-row-image=full
+max_connections=600
+# for mysql 8.0
+secure_file_priv=/var/lib/mysql
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/proxy/server.yaml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/proxy/server.yaml
new file mode 100644
index 00000000000..4904389dcd7
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/env/scenario/mysql_ha/proxy/server.yaml
@@ -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.
+#
+
+mode:
+ type: Cluster
+ repository:
+ type: ZooKeeper
+ props:
+ namespace: it_db_mysql
+ server-lists: zk.host:2181
+ timeToLiveSeconds: 60
+ operationTimeoutMilliseconds: 500
+ retryIntervalMilliseconds: 500
+ maxRetries: 3
+ overwrite: false
+
+rules:
+ - !AUTHORITY
+ users:
+ - proxy@:Proxy@123
+ provider:
+ type: ALL_PERMITTED
+
+props:
+ max-connections-size-per-query: 1
+ kernel-executor-size: 16 # Infinite by default.
+ proxy-frontend-flush-threshold: 128 # The default value is 128.
+ proxy-hint-enabled: true
+ sql-show: true
+ sql-federation-enabled: true
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/logback-test.xml
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/logback-test.xml
new file mode 100644
index 00000000000..c7fbb061cd7
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-ha/src/test/resources/logback-test.xml
@@ -0,0 +1,33 @@
+<?xml version="1.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.
+ -->
+
+<configuration>
+ <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread]
%logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+ <logger name="org.apache.shardingsphere" level="warn" additivity="true">
+ <appender-ref ref="console" />
+ </logger>
+ <logger name="com.zaxxer.hikari" level="warn" />
+ <root>
+ <level value="info" />
+ <appender-ref ref="console" />
+ </root>
+</configuration>