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 34892c93942 Optimize integration test of DDL in cluster mode (#20678)
34892c93942 is described below
commit 34892c9394286fa0a1017382bbe903726906296e
Author: gin <[email protected]>
AuthorDate: Wed Aug 31 20:59:19 2022 +0800
Optimize integration test of DDL in cluster mode (#20678)
---
.../test/integration/engine/ddl/BaseDDLIT.java | 34 +++++++++-------------
1 file changed, 13 insertions(+), 21 deletions(-)
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
index e2d412249e1..6b754e8d69b 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ddl/BaseDDLIT.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.test.integration.engine.ddl;
import com.google.common.base.Splitter;
-import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.dialect.exception.syntax.table.NoSuchTableException;
import org.apache.shardingsphere.infra.util.expr.InlineExpressionParser;
@@ -40,7 +39,6 @@ import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
@@ -59,38 +57,32 @@ public abstract class BaseDDLIT extends SingleITCase {
assertNotNull("Expected affected table is required",
getAssertion().getInitialSQL());
assertNotNull("Init SQL is required",
getAssertion().getInitialSQL().getAffectedTable());
try (Connection connection = getTargetDataSource().getConnection()) {
- executeInitSQLs(connection);
+ synchronizedExecuteInitSQLs(connection);
}
- sleepIntervalTime();
}
- @SneakyThrows(InterruptedException.class)
- private void sleepIntervalTime() {
- if ("Cluster".equalsIgnoreCase(getMode())) {
- TimeUnit.MILLISECONDS.sleep(200L);
+ private synchronized void synchronizedExecuteInitSQLs(final Connection
connection) throws SQLException {
+ if (null == getAssertion().getInitialSQL().getSql()) {
+ return;
+ }
+ for (String each :
Splitter.on(";").trimResults().splitToList(getAssertion().getInitialSQL().getSql()))
{
+ try (PreparedStatement preparedStatement =
connection.prepareStatement(each)) {
+ preparedStatement.executeUpdate();
+ }
}
}
@After
public final void tearDown() {
try (Connection connection = getTargetDataSource().getConnection()) {
- String dropSql = String.format("DROP TABLE %s",
getAssertion().getInitialSQL().getAffectedTable());
- try (PreparedStatement preparedStatement =
connection.prepareStatement(dropSql)) {
- preparedStatement.executeUpdate();
- }
+ synchronizedExecuteDropSQLs(connection, String.format("DROP TABLE
%s", getAssertion().getInitialSQL().getAffectedTable()));
} catch (final SQLException | NoSuchTableException ignored) {
}
- sleepIntervalTime();
}
- private void executeInitSQLs(final Connection connection) throws
SQLException {
- if (null == getAssertion().getInitialSQL().getSql()) {
- return;
- }
- for (String each :
Splitter.on(";").trimResults().splitToList(getAssertion().getInitialSQL().getSql()))
{
- try (PreparedStatement preparedStatement =
connection.prepareStatement(each)) {
- preparedStatement.executeUpdate();
- }
+ private synchronized void synchronizedExecuteDropSQLs(final Connection
connection, final String sql) throws SQLException {
+ try (PreparedStatement preparedStatement =
connection.prepareStatement(sql)) {
+ preparedStatement.executeUpdate();
}
}