This is an automated email from the ASF dual-hosted git repository.
panjuan 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 ea795d6aee4 Upgrade junit 5 on DiscoveryE2EIT (#24559)
ea795d6aee4 is described below
commit ea795d6aee469e492a231b866a0b6299e2da65fe
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Mar 12 15:08:17 2023 +0800
Upgrade junit 5 on DiscoveryE2EIT (#24559)
---
.../e2e/discovery/build/DiscoveryRuleBuilder.java | 28 +--
.../cases/DiscoveryContainerComposer.java | 51 +++++
.../e2e/discovery/cases/DiscoveryTestAction.java | 196 ++++++++++++++++++
.../discovery/cases/base/BaseDiscoveryE2EIT.java | 230 ---------------------
.../cases/mysql/MGRGeneralDiscoveryE2EIT.java | 61 ------
.../cases/mysql/MySQLMGRDiscoveryE2EIT.java | 63 ++++++
.../cases/mysql/env/MySQLMGREnvironment.java | 5 +-
7 files changed, 326 insertions(+), 308 deletions(-)
diff --git
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/build/DiscoveryRuleBuilder.java
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/build/DiscoveryRuleBuilder.java
index 0a264e07992..1b7c330c8d3 100644
---
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/build/DiscoveryRuleBuilder.java
+++
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/build/DiscoveryRuleBuilder.java
@@ -34,12 +34,12 @@ import java.sql.Statement;
@RequiredArgsConstructor
public final class DiscoveryRuleBuilder {
- private final DiscoveryDistSQLCommand discoveryDistSQLCommand;
-
private final DataSource proxyDataSource;
+ private final DiscoveryDistSQLCommand discoveryDistSQL;
+
/**
- * build Discovery Environment.
+ * Build Discovery Environment.
*
* @throws SQLException SQL exception
*/
@@ -55,12 +55,12 @@ public final class DiscoveryRuleBuilder {
}
private void createDatabase(final Statement statement) throws SQLException
{
-
statement.execute(discoveryDistSQLCommand.getCreateDatabase().getExecuteSQL());
- Awaitility.await().atMost(Durations.ONE_SECOND).until(() ->
assertResult(statement,
discoveryDistSQLCommand.getCreateDatabase().getAssertionSQL()));
+
statement.execute(discoveryDistSQL.getCreateDatabase().getExecuteSQL());
+ Awaitility.await().atMost(Durations.ONE_SECOND).until(() ->
getCreateDatabaseResult(statement,
discoveryDistSQL.getCreateDatabase().getAssertionSQL()));
}
- private boolean assertResult(final Statement statement, final String
assertionSQL) {
- try (ResultSet resultSet = statement.executeQuery(assertionSQL)) {
+ private boolean getCreateDatabaseResult(final Statement statement, final
String assertionSQL) {
+ try (ResultSet ignored = statement.executeQuery(assertionSQL)) {
return true;
} catch (final SQLException ignored) {
return false;
@@ -68,21 +68,21 @@ public final class DiscoveryRuleBuilder {
}
private void registerStorageUnits(final Statement statement) throws
SQLException {
-
statement.execute(discoveryDistSQLCommand.getRegisterStorageUnits().getExecuteSQL());
- Awaitility.await().atMost(Durations.TWO_SECONDS).until(() ->
assertResult0(statement,
discoveryDistSQLCommand.getRegisterStorageUnits().getAssertionSQL()));
+
statement.execute(discoveryDistSQL.getRegisterStorageUnits().getExecuteSQL());
+ Awaitility.await().atMost(Durations.TWO_SECONDS).until(() ->
getExecuteResult(statement,
discoveryDistSQL.getRegisterStorageUnits().getAssertionSQL()));
}
private void createDiscoveryRule(final Statement statement) throws
SQLException {
-
statement.execute(discoveryDistSQLCommand.getCreateDiscoveryRule().getExecuteSQL());
- Awaitility.await().atMost(Durations.TWO_SECONDS).until(() ->
assertResult0(statement,
discoveryDistSQLCommand.getCreateDiscoveryRule().getAssertionSQL()));
+
statement.execute(discoveryDistSQL.getCreateDiscoveryRule().getExecuteSQL());
+ Awaitility.await().atMost(Durations.TWO_SECONDS).until(() ->
getExecuteResult(statement,
discoveryDistSQL.getCreateDiscoveryRule().getAssertionSQL()));
}
private void createReadwriteSplittingRule(final Statement statement)
throws SQLException {
-
statement.execute(discoveryDistSQLCommand.getCreateReadwriteSplittingRule().getExecuteSQL());
- Awaitility.await().atMost(Durations.FIVE_SECONDS).until(() ->
assertResult0(statement,
discoveryDistSQLCommand.getCreateReadwriteSplittingRule().getAssertionSQL()));
+
statement.execute(discoveryDistSQL.getCreateReadwriteSplittingRule().getExecuteSQL());
+ Awaitility.await().atMost(Durations.FIVE_SECONDS).until(() ->
getExecuteResult(statement,
discoveryDistSQL.getCreateReadwriteSplittingRule().getAssertionSQL()));
}
- private boolean assertResult0(final Statement statement, final String
assertionSQL) {
+ private boolean getExecuteResult(final Statement statement, final String
assertionSQL) {
try (ResultSet resultSet = statement.executeQuery(assertionSQL)) {
return resultSet.next();
} catch (final SQLException ignored) {
diff --git
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/DiscoveryContainerComposer.java
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/DiscoveryContainerComposer.java
new file mode 100644
index 00000000000..661d490bd98
--- /dev/null
+++
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/DiscoveryContainerComposer.java
@@ -0,0 +1,51 @@
+/*
+ * 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.e2e.discovery.cases;
+
+import lombok.Getter;
+import
org.apache.shardingsphere.test.e2e.discovery.framework.container.compose.BaseContainerComposer;
+import
org.apache.shardingsphere.test.e2e.discovery.framework.container.compose.DockerContainerComposer;
+import
org.apache.shardingsphere.test.e2e.discovery.framework.parameter.DiscoveryTestParameter;
+
+import javax.sql.DataSource;
+import java.util.List;
+
+/**
+ * Discovery container composer.
+ */
+@Getter
+public final class DiscoveryContainerComposer implements AutoCloseable {
+
+ private final BaseContainerComposer containerComposer;
+
+ private final List<DataSource> mappedDataSources;
+
+ private final DataSource proxyDataSource;
+
+ public DiscoveryContainerComposer(final DiscoveryTestParameter testParam) {
+ containerComposer = new
DockerContainerComposer(testParam.getScenario(), testParam.getDatabaseType(),
testParam.getStorageContainerImage());
+ containerComposer.start();
+ mappedDataSources = containerComposer.getMappedDatasource();
+ proxyDataSource = containerComposer.getProxyDatasource();
+ }
+
+ @Override
+ public void close() {
+ containerComposer.close();
+ }
+}
diff --git
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/DiscoveryTestAction.java
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/DiscoveryTestAction.java
new file mode 100644
index 00000000000..88689fce4f5
--- /dev/null
+++
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/DiscoveryTestAction.java
@@ -0,0 +1,196 @@
+/*
+ * 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.e2e.discovery.cases;
+
+import com.google.common.base.Preconditions;
+import org.apache.commons.lang.StringUtils;
+import org.apache.shardingsphere.test.e2e.discovery.build.DiscoveryRuleBuilder;
+import
org.apache.shardingsphere.test.e2e.discovery.command.DiscoveryDistSQLCommand;
+import org.awaitility.Awaitility;
+import org.awaitility.Durations;
+
+import javax.sql.DataSource;
+import javax.xml.bind.JAXB;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Map;
+import java.util.Objects;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+/**
+ * Discovery test action.
+ */
+public final class DiscoveryTestAction {
+
+ private final DiscoveryContainerComposer composer;
+
+ private final DatabaseClusterEnvironment databaseClusterEnv;
+
+ private final DiscoveryDistSQLCommand discoveryDistSQL;
+
+ public DiscoveryTestAction(final DiscoveryContainerComposer composer,
final DatabaseClusterEnvironment databaseClusterEnv) {
+ this.composer = composer;
+ this.databaseClusterEnv = databaseClusterEnv;
+ discoveryDistSQL =
JAXB.unmarshal(Objects.requireNonNull(DiscoveryTestAction.class.getClassLoader().getResource("env/common/discovery-command.xml")),
DiscoveryDistSQLCommand.class);
+ }
+
+ /**
+ * Execute test action.
+ *
+ * @throws SQLException SQL exception
+ */
+ public void execute() throws SQLException {
+ initDiscoveryEnvironment();
+ assertClosePrimaryDataSource();
+ assertCloseReplicationDataSource();
+ dropDatabaseDiscoveryDatabase();
+ createReadWriteSplittingDatabase();
+ registerSingleStorageUnit();
+ }
+
+ private void initDiscoveryEnvironment() throws SQLException {
+ new DiscoveryRuleBuilder(composer.getProxyDataSource(),
discoveryDistSQL).buildDiscoveryEnvironment();
+ }
+
+ private void assertClosePrimaryDataSource() throws SQLException {
+ String oldPrimaryDataSourceName = getPrimaryDataSourceName();
+
closeDataSource(databaseClusterEnv.getDataSources().get(oldPrimaryDataSourceName));
+ Awaitility.await().atMost(Durations.ONE_MINUTE).until(() ->
!oldPrimaryDataSourceName.equals(getPrimaryDataSourceName()));
+ databaseClusterEnv.getDataSources().remove(oldPrimaryDataSourceName);
+ }
+
+ private String getPrimaryDataSourceName() throws SQLException {
+ try (
+ Connection connection =
composer.getProxyDataSource().getConnection();
+ Statement statement = connection.createStatement()) {
+ String result =
getReadwriteSplittingRulePrimaryDataSourceName(statement);
+ assertPrimaryDataSource(result,
getDiscoveryRulePrimaryDataSourceName(statement));
+ return result;
+ }
+ }
+
+ private String getReadwriteSplittingRulePrimaryDataSourceName(final
Statement statement) throws SQLException {
+ try (ResultSet resultSet = statement.executeQuery("SHOW
READWRITE_SPLITTING RULES")) {
+ return resultSet.next() ?
resultSet.getString("write_storage_unit_name") : "";
+ }
+ }
+
+ private String getDiscoveryRulePrimaryDataSourceName(final Statement
statement) throws SQLException {
+ try (ResultSet resultSet = statement.executeQuery("SHOW DB_DISCOVERY
RULES")) {
+ return resultSet.next() ?
resultSet.getString("primary_data_source_name") : "";
+ }
+ }
+
+ private void assertPrimaryDataSource(final String
actualPrimaryDataSourceName, final String expectedPrimaryDataSourceName) {
+
Preconditions.checkState(StringUtils.isNotBlank(actualPrimaryDataSourceName) &&
StringUtils.isNotBlank(expectedPrimaryDataSourceName));
+ assertThat(actualPrimaryDataSourceName,
is(expectedPrimaryDataSourceName));
+ }
+
+ private void closeDataSource(final DataSource dataSource) throws
SQLException {
+ try (
+ Connection connection = dataSource.getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.execute("SHUTDOWN");
+ }
+ }
+
+ private void assertCloseReplicationDataSource() throws SQLException {
+ databaseClusterEnv.getDataSources().remove(getPrimaryDataSourceName());
+ String closedRoutingDataSourceName =
getCloseReplicationDataSourceName(databaseClusterEnv);
+
databaseClusterEnv.getDataSources().remove(closedRoutingDataSourceName);
+ Awaitility.await().atMost(Durations.TWO_MINUTES)
+ .until(() ->
getRouteDataSourceName().equals(Objects.requireNonNull(databaseClusterEnv.getDataSources().entrySet().stream().findFirst().orElse(null)).getKey()));
+ }
+
+ private String getCloseReplicationDataSourceName(final
DatabaseClusterEnvironment databaseClusterEnv) throws SQLException {
+ for (Map.Entry<String, DataSource> entry :
databaseClusterEnv.getDataSources().entrySet()) {
+
closeDataSource(databaseClusterEnv.getDataSources().get(entry.getKey()));
+ return entry.getKey();
+ }
+ return null;
+ }
+
+ private String getRouteDataSourceName() throws SQLException {
+ try (
+ Connection connection =
composer.getProxyDataSource().getConnection();
+ Statement statement = connection.createStatement()) {
+ return getRouteDataSourceName(statement);
+ }
+ }
+
+ private String getRouteDataSourceName(final Statement statement) throws
SQLException {
+ try (ResultSet resultSet = statement.executeQuery("PREVIEW SELECT 1"))
{
+ return resultSet.next() ? resultSet.getString("data_source_name")
: "";
+ }
+ }
+
+ private void dropDatabaseDiscoveryDatabase() throws SQLException {
+ try (
+ Connection connection =
composer.getProxyDataSource().getConnection();
+ Statement statement = connection.createStatement()) {
+
statement.execute(discoveryDistSQL.getDropDatabase().getExecuteSQL());
+ Awaitility.await().atMost(Durations.FIVE_SECONDS).until(() ->
assertDropSQL(statement, discoveryDistSQL.getDropDatabase().getAssertionSQL()));
+ }
+ }
+
+ private boolean assertDropSQL(final Statement statement, final String
assertionSQL) {
+ try (ResultSet ignored = statement.executeQuery(assertionSQL)) {
+ return false;
+ } catch (final SQLException ignored) {
+ return true;
+ }
+ }
+
+ private void createReadWriteSplittingDatabase() throws SQLException {
+ try (
+ Connection connection =
composer.getProxyDataSource().getConnection();
+ Statement statement = connection.createStatement()) {
+
statement.execute(discoveryDistSQL.getCreateReadwriteSplittingDatabase().getExecuteSQL());
+ Awaitility.await().atMost(Durations.FIVE_SECONDS).until(() ->
assertCreateSQL(statement,
discoveryDistSQL.getCreateReadwriteSplittingDatabase().getAssertionSQL()));
+ }
+ }
+
+ private boolean assertCreateSQL(final Statement statement, final String
assertionSQL) {
+ try (ResultSet ignored = statement.executeQuery(assertionSQL)) {
+ return true;
+ } catch (final SQLException ignored) {
+ return false;
+ }
+ }
+
+ private void registerSingleStorageUnit() throws SQLException {
+ try (
+ Connection connection =
composer.getProxyDataSource().getConnection();
+ Statement statement = connection.createStatement()) {
+
statement.execute(discoveryDistSQL.getRegisterSingleStorageUnit().getExecuteSQL());
+ Awaitility.await().atMost(Durations.FIVE_SECONDS).until(() ->
assertRDL(statement,
discoveryDistSQL.getRegisterSingleStorageUnit().getAssertionSQL()));
+ }
+ }
+
+ private boolean assertRDL(final Statement statement, final String
assertionSQL) {
+ try (ResultSet resultSet = statement.executeQuery(assertionSQL)) {
+ return resultSet.next();
+ } catch (final SQLException ignored) {
+ return false;
+ }
+ }
+}
diff --git
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/base/BaseDiscoveryE2EIT.java
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/base/BaseDiscoveryE2EIT.java
deleted file mode 100644
index 4e5d5c62a71..00000000000
---
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/base/BaseDiscoveryE2EIT.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.test.e2e.discovery.cases.base;
-
-import com.google.common.base.Preconditions;
-import lombok.AccessLevel;
-import lombok.Getter;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang.StringUtils;
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.test.e2e.discovery.build.DiscoveryRuleBuilder;
-import
org.apache.shardingsphere.test.e2e.discovery.cases.DatabaseClusterEnvironment;
-import
org.apache.shardingsphere.test.e2e.discovery.command.DiscoveryDistSQLCommand;
-import
org.apache.shardingsphere.test.e2e.discovery.env.DiscoveryE2ETestEnvironment;
-import
org.apache.shardingsphere.test.e2e.discovery.framework.container.compose.BaseContainerComposer;
-import
org.apache.shardingsphere.test.e2e.discovery.framework.container.compose.DockerContainerComposer;
-import
org.apache.shardingsphere.test.e2e.discovery.framework.parameter.DiscoveryTestParameter;
-import org.awaitility.Awaitility;
-import org.awaitility.Durations;
-
-import javax.sql.DataSource;
-import javax.xml.bind.JAXB;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-@Getter(AccessLevel.PROTECTED)
-@Slf4j
-public abstract class BaseDiscoveryE2EIT {
-
- protected static final DiscoveryE2ETestEnvironment ENV =
DiscoveryE2ETestEnvironment.getInstance();
-
- private final BaseContainerComposer containerComposer;
-
- private final DatabaseType databaseType;
-
- private final List<DataSource> mappedDataSources;
-
- private final DataSource proxyDataSource;
-
- private final DiscoveryDistSQLCommand discoveryDistSQLCommand;
-
- public BaseDiscoveryE2EIT(final DiscoveryTestParameter testParam) {
- databaseType = testParam.getDatabaseType();
- containerComposer = new
DockerContainerComposer(testParam.getScenario(), testParam.getDatabaseType(),
testParam.getStorageContainerImage());
- containerComposer.start();
- mappedDataSources = containerComposer.getMappedDatasource();
- proxyDataSource = containerComposer.getProxyDatasource();
- discoveryDistSQLCommand =
JAXB.unmarshal(Objects.requireNonNull(BaseDiscoveryE2EIT.class.getClassLoader().getResource("env/common/discovery-command.xml")),
DiscoveryDistSQLCommand.class);
- }
-
- /**
- * Initialization discovery environment.
- *
- * @throws SQLException SQL exception
- */
- public void initDiscoveryEnvironment() throws SQLException {
- new DiscoveryRuleBuilder(discoveryDistSQLCommand,
proxyDataSource).buildDiscoveryEnvironment();
- }
-
- /**
- * Assert close primary data source.
- * @param mgrEnvironment mgr environment
- * @throws SQLException SQL Exception
- */
- public void assertClosePrimaryDataSource(final DatabaseClusterEnvironment
mgrEnvironment) throws SQLException {
- String oldPrimaryDataSourceName = getPrimaryDataSourceName();
-
closeDataSource(mgrEnvironment.getDataSources().get(oldPrimaryDataSourceName));
- Awaitility.await().atMost(Durations.ONE_MINUTE).until(() ->
!oldPrimaryDataSourceName.equals(getPrimaryDataSourceName()));
- mgrEnvironment.getDataSources().remove(oldPrimaryDataSourceName);
- }
-
- private String getPrimaryDataSourceName() throws SQLException {
- try (
- Connection connection = proxyDataSource.getConnection();
- Statement statement = connection.createStatement()) {
- String actualPrimaryDataSourceName =
getReadwriteSplittingRulePrimaryDataSourceName(statement);
- assertPrimaryDataSource(actualPrimaryDataSourceName,
getDiscoveryRulePrimaryDataSourceName(statement));
- return actualPrimaryDataSourceName;
- }
- }
-
- private String getReadwriteSplittingRulePrimaryDataSourceName(final
Statement statement) throws SQLException {
- try (ResultSet resultSet = statement.executeQuery("SHOW
READWRITE_SPLITTING RULES")) {
- return resultSet.next() ?
resultSet.getString("write_storage_unit_name") : "";
- }
- }
-
- private String getDiscoveryRulePrimaryDataSourceName(final Statement
statement) throws SQLException {
- try (ResultSet resultSet = statement.executeQuery("SHOW DB_DISCOVERY
RULES")) {
- return resultSet.next() ?
resultSet.getString("primary_data_source_name") : "";
- }
- }
-
- private void assertPrimaryDataSource(final String
actualPrimaryDataSourceName, final String expectedPrimaryDataSourceName) {
-
Preconditions.checkState(StringUtils.isNotBlank(actualPrimaryDataSourceName) &&
StringUtils.isNotBlank(expectedPrimaryDataSourceName));
- assertThat(actualPrimaryDataSourceName,
is(expectedPrimaryDataSourceName));
- }
-
- private void closeDataSource(final DataSource dataSource) throws
SQLException {
- try (
- Connection connection = dataSource.getConnection();
- Statement statement = connection.createStatement()) {
- statement.execute("SHUTDOWN");
- }
- }
-
- /**
- * Assert close replication data source.
- * @param mgrEnvironment mgr environment
- * @throws SQLException SQL Exception
- */
- public void assertCloseReplicationDataSource(final
DatabaseClusterEnvironment mgrEnvironment) throws SQLException {
- mgrEnvironment.getDataSources().remove(getPrimaryDataSourceName());
- String closedRoutingDataSourceName =
getCloseReplicationDataSourceName(mgrEnvironment);
- mgrEnvironment.getDataSources().remove(closedRoutingDataSourceName);
- Awaitility.await().atMost(Durations.TWO_MINUTES)
- .until(() ->
getRouteDataSourceName().equals(Objects.requireNonNull(mgrEnvironment.getDataSources().entrySet().stream().findFirst().orElse(null)).getKey()));
- }
-
- private String getCloseReplicationDataSourceName(final
DatabaseClusterEnvironment mgrEnvironment) throws SQLException {
- for (Map.Entry<String, DataSource> entry :
mgrEnvironment.getDataSources().entrySet()) {
-
closeDataSource(mgrEnvironment.getDataSources().get(entry.getKey()));
- return entry.getKey();
- }
- return null;
- }
-
- private String getRouteDataSourceName() throws SQLException {
- try (
- Connection connection = proxyDataSource.getConnection();
- Statement statement = connection.createStatement()) {
- return getRouteDataSourceName(statement);
- }
- }
-
- private String getRouteDataSourceName(final Statement statement) throws
SQLException {
- try (ResultSet resultSet = statement.executeQuery("PREVIEW SELECT 1"))
{
- return resultSet.next() ? resultSet.getString("data_source_name")
: "";
- }
- }
-
- /**
- * Drop database discovery database.
- *
- * @throws SQLException sql exception
- */
- public void dropDatabaseDiscoveryDatabase() throws SQLException {
- try (
- Connection connection = getProxyDataSource().getConnection();
- Statement statement = connection.createStatement()) {
-
statement.execute(discoveryDistSQLCommand.getDropDatabase().getExecuteSQL());
- Awaitility.await().atMost(Durations.FIVE_SECONDS).until(() ->
assertDropSQL(statement,
discoveryDistSQLCommand.getDropDatabase().getAssertionSQL()));
- }
- }
-
- private boolean assertDropSQL(final Statement statement, final String
assertionSQL) {
- try (ResultSet resultSet = statement.executeQuery(assertionSQL)) {
- return false;
- } catch (final SQLException ignored) {
- return true;
- }
- }
-
- /**
- * Create readwrite-splitting database.
- *
- * @throws SQLException sql exception
- */
- public void createReadWriteSplittingDatabase() throws SQLException {
- try (
- Connection connection = getProxyDataSource().getConnection();
- Statement statement = connection.createStatement()) {
-
statement.execute(discoveryDistSQLCommand.getCreateReadwriteSplittingDatabase().getExecuteSQL());
- Awaitility.await().atMost(Durations.FIVE_SECONDS).until(() ->
assertCreateSQL(statement,
discoveryDistSQLCommand.getCreateReadwriteSplittingDatabase().getAssertionSQL()));
- }
- }
-
- private boolean assertCreateSQL(final Statement statement, final String
assertionSQL) {
- try (ResultSet resultSet = statement.executeQuery(assertionSQL)) {
- return true;
- } catch (final SQLException ignored) {
- return false;
- }
- }
-
- /**
- * Register single storage units.
- *
- * @throws SQLException sql exception
- */
- public void registerSingleStorageUnit() throws SQLException {
- try (
- Connection connection = getProxyDataSource().getConnection();
- Statement statement = connection.createStatement()) {
-
statement.execute(discoveryDistSQLCommand.getRegisterSingleStorageUnit().getExecuteSQL());
- Awaitility.await().atMost(Durations.FIVE_SECONDS).until(() ->
assertRDLDistSQL(statement,
discoveryDistSQLCommand.getRegisterSingleStorageUnit().getAssertionSQL()));
- }
- }
-
- private boolean assertRDLDistSQL(final Statement statement, final String
assertionSQL) {
- try (ResultSet resultSet = statement.executeQuery(assertionSQL)) {
- return resultSet.next();
- } catch (final SQLException ignored) {
- return false;
- }
- }
-}
diff --git
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/mysql/MGRGeneralDiscoveryE2EIT.java
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/mysql/MGRGeneralDiscoveryE2EIT.java
deleted file mode 100644
index 92c93e5bdad..00000000000
---
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/mysql/MGRGeneralDiscoveryE2EIT.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.test.e2e.discovery.cases.mysql;
-
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import
org.apache.shardingsphere.test.e2e.discovery.cases.DatabaseClusterEnvironment;
-import
org.apache.shardingsphere.test.e2e.discovery.cases.DatabaseClusterEnvironmentFactory;
-import
org.apache.shardingsphere.test.e2e.discovery.cases.base.BaseDiscoveryE2EIT;
-import
org.apache.shardingsphere.test.e2e.discovery.framework.parameter.DiscoveryTestParameter;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.LinkedList;
-
-@RunWith(Parameterized.class)
-public final class MGRGeneralDiscoveryE2EIT extends BaseDiscoveryE2EIT {
-
- public MGRGeneralDiscoveryE2EIT(final DiscoveryTestParameter testParam) {
- super(testParam);
- }
-
- @Parameters(name = "{0}")
- public static Collection<DiscoveryTestParameter> getTestParameters() {
- Collection<DiscoveryTestParameter> result = new LinkedList<>();
- MySQLDatabaseType databaseType = new MySQLDatabaseType();
- for (String each : ENV.listStorageContainerImages(databaseType)) {
- result.add(new DiscoveryTestParameter(databaseType, each,
"mgr_discovery"));
- }
- return result;
- }
-
- @Test
- public void assertDiscoveryMySQLMGR() throws SQLException {
- DatabaseClusterEnvironment mgrEnvironment =
DatabaseClusterEnvironmentFactory.newInstance("MySQL.MGR",
getMappedDataSources());
- initDiscoveryEnvironment();
- assertClosePrimaryDataSource(mgrEnvironment);
- assertCloseReplicationDataSource(mgrEnvironment);
- dropDatabaseDiscoveryDatabase();
- createReadWriteSplittingDatabase();
- registerSingleStorageUnit();
- }
-}
diff --git
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/mysql/MySQLMGRDiscoveryE2EIT.java
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/mysql/MySQLMGRDiscoveryE2EIT.java
new file mode 100644
index 00000000000..39da9e9ac19
--- /dev/null
+++
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/mysql/MySQLMGRDiscoveryE2EIT.java
@@ -0,0 +1,63 @@
+/*
+ * 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.e2e.discovery.cases.mysql;
+
+import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
+import
org.apache.shardingsphere.test.e2e.discovery.cases.DatabaseClusterEnvironment;
+import
org.apache.shardingsphere.test.e2e.discovery.cases.DatabaseClusterEnvironmentFactory;
+import
org.apache.shardingsphere.test.e2e.discovery.cases.DiscoveryContainerComposer;
+import org.apache.shardingsphere.test.e2e.discovery.cases.DiscoveryTestAction;
+import
org.apache.shardingsphere.test.e2e.discovery.env.DiscoveryE2ETestEnvironment;
+import
org.apache.shardingsphere.test.e2e.discovery.framework.parameter.DiscoveryTestParameter;
+import org.junit.jupiter.api.condition.EnabledIf;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
+
+import java.sql.SQLException;
+import java.util.stream.Stream;
+
+public final class MySQLMGRDiscoveryE2EIT {
+
+ private static final MySQLDatabaseType DATABASE_TYPE = new
MySQLDatabaseType();
+
+ @ParameterizedTest(name = "{0}")
+ @EnabledIf("isEnabled")
+ @ArgumentsSource(TestCaseArgumentsProvider.class)
+ public void assertDiscoveryMySQLMGR(final DiscoveryTestParameter
testParam) throws SQLException {
+ try (DiscoveryContainerComposer composer = new
DiscoveryContainerComposer(testParam)) {
+ DatabaseClusterEnvironment databaseClusterEnv =
DatabaseClusterEnvironmentFactory.newInstance("MySQL.MGR",
composer.getMappedDataSources());
+ new DiscoveryTestAction(composer, databaseClusterEnv).execute();
+ }
+ }
+
+ private static boolean isEnabled() {
+ return
!DiscoveryE2ETestEnvironment.getInstance().listStorageContainerImages(DATABASE_TYPE).isEmpty();
+ }
+
+ private static class TestCaseArgumentsProvider implements
ArgumentsProvider {
+
+ @Override
+ public Stream<? extends Arguments> provideArguments(final
ExtensionContext extensionContext) {
+ return
DiscoveryE2ETestEnvironment.getInstance().listStorageContainerImages(DATABASE_TYPE)
+ .stream().map(each -> Arguments.of(new
DiscoveryTestParameter(DATABASE_TYPE, each, "mgr_discovery")));
+ }
+ }
+}
diff --git
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/mysql/env/MySQLMGREnvironment.java
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/mysql/env/MySQLMGREnvironment.java
index 182aed9ea95..096f84aacb2 100644
---
a/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/mysql/env/MySQLMGREnvironment.java
+++
b/test/e2e/discovery/src/test/java/org/apache/shardingsphere/test/e2e/discovery/cases/mysql/env/MySQLMGREnvironment.java
@@ -19,9 +19,8 @@ package
org.apache.shardingsphere.test.e2e.discovery.cases.mysql.env;
import com.google.common.base.Splitter;
import lombok.Getter;
-import
org.apache.shardingsphere.test.e2e.discovery.cases.base.BaseDiscoveryE2EIT;
-import
org.apache.shardingsphere.test.e2e.discovery.command.MGRPrimaryReplicaCommand;
import
org.apache.shardingsphere.test.e2e.discovery.cases.DatabaseClusterEnvironment;
+import
org.apache.shardingsphere.test.e2e.discovery.command.MGRPrimaryReplicaCommand;
import javax.sql.DataSource;
import javax.xml.bind.JAXB;
@@ -51,7 +50,7 @@ public final class MySQLMGREnvironment implements
DatabaseClusterEnvironment {
primaryDataSource = dataSources.get(0);
replicationDataSources = dataSources.subList(1, dataSources.size());
this.dataSources = getAllDataSources();
- mgrPrimaryReplicaCommand =
JAXB.unmarshal(Objects.requireNonNull(BaseDiscoveryE2EIT.class.getClassLoader().getResource("env/common/mgr-primary-replica-command.xml")),
+ mgrPrimaryReplicaCommand =
JAXB.unmarshal(Objects.requireNonNull(MySQLMGREnvironment.class.getClassLoader().getResource("env/common/mgr-primary-replica-command.xml")),
MGRPrimaryReplicaCommand.class);
buildMGRPrimaryDataSource();
buildMGRReplicaDataSources();