This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 89fab329a9c Add exception occurred within the transaction integration
test case (#20254)
89fab329a9c is described below
commit 89fab329a9c4fc65924f301789cfc85e361d9992
Author: ZhangCheng <[email protected]>
AuthorDate: Fri Aug 19 19:20:58 2022 +0800
Add exception occurred within the transaction integration test case (#20254)
* Add exception occurred within the transaction integration test case
* Add exception occurred within the transaction integration test case
* Fix
* Fix
* Modify the connection pool size
* Log error cause
* Log error cause
* Fix
* Fix
* Fix review issues
---
.../ExceptionInTransactionTestCase.java | 79 ++++++++++++++++++++++
.../transaction/engine/base/BaseITCase.java | 4 +-
.../engine/base/BaseTransactionITCase.java | 16 ++++-
.../engine/mysql/MySQLJdbcTransactionIT.java | 1 -
.../engine/mysql/MySQLProxyTransactionIT.java | 1 -
.../opengauss/OpenGaussJdbcTransactionIT.java | 6 --
.../opengauss/OpenGaussProxyTransactionIT.java | 6 --
.../postgresql/PostgreSQLJdbcTransactionIT.java | 6 --
.../postgresql/PostgreSQLProxyTransactionIT.java | 6 --
.../resources/env/transaction-it-env.properties | 2 +-
10 files changed, 96 insertions(+), 31 deletions(-)
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/commitrollback/ExceptionInTransactionTestCase.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/commitrollback/ExceptionInTransactionTestCase.java
new file mode 100644
index 00000000000..5834e252764
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/commitrollback/ExceptionInTransactionTestCase.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.integration.transaction.cases.commitrollback;
+
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import
org.apache.shardingsphere.integration.transaction.cases.base.BaseTransactionTestCase;
+import
org.apache.shardingsphere.integration.transaction.engine.base.BaseTransactionITCase;
+import
org.apache.shardingsphere.integration.transaction.engine.base.TransactionTestCase;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/**
+ * An exception occurred within the transaction integration test.
+ */
+@Slf4j
+@TransactionTestCase
+public final class ExceptionInTransactionTestCase extends
BaseTransactionTestCase {
+
+ public ExceptionInTransactionTestCase(final BaseTransactionITCase
baseTransactionITCase, final DataSource dataSource) {
+ super(baseTransactionITCase, dataSource);
+ }
+
+ @Override
+ @SneakyThrows(SQLException.class)
+ protected void executeTest() {
+ Connection conn = null;
+ try {
+ conn = getDataSource().getConnection();
+ conn.setAutoCommit(false);
+ assertAccountRowCount(conn, 0);
+ executeWithLog(conn, "insert into account(id, balance,
transaction_id) values(1, 1, 1);");
+ int causedExceptionResult = 1 / 0;
+ executeWithLog(conn, "insert into account(id, balance,
transaction_id) values(2, 2, 2);");
+ conn.commit();
+ fail("It should fail here.");
+ } catch (final ArithmeticException ex) {
+ assertThat(ex.getMessage(), is("/ by zero"));
+ } finally {
+ if (null != conn) {
+ conn.rollback();
+ }
+ }
+ Thread queryThread = new Thread(() -> {
+ log.info("Execute query in new thread.");
+ try (Connection connection = getDataSource().getConnection()) {
+ assertAccountRowCount(connection, 0);
+ } catch (final SQLException ignored) {
+ }
+ });
+ queryThread.start();
+ try {
+ queryThread.join();
+ log.info("ExceptionInTransactionTestCase test over.");
+ } catch (final InterruptedException ignored) {
+ }
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseITCase.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseITCase.java
index 11bbdc55401..5f30be3bde5 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseITCase.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseITCase.java
@@ -142,7 +142,9 @@ public abstract class BaseITCase {
result.setJdbcUrl(DataSourceEnvironment.getURL(databaseType,
databaseContainer.getHost(),
databaseContainer.getMappedPort(databaseContainer.getPort()), dataSourceName));
result.setUsername(databaseContainer.getUsername());
result.setPassword(databaseContainer.getUnifiedPassword());
- result.setMaximumPoolSize(4);
+ result.setMaximumPoolSize(50);
+ result.setIdleTimeout(60000);
+ result.setMaxLifetime(1800000);
result.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
return result;
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseTransactionITCase.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseTransactionITCase.java
index 334b89c6e96..be0db28edbe 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseTransactionITCase.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/BaseTransactionITCase.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.integration.transaction.engine.base;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.data.pipeline.core.util.ThreadUtil;
+import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import
org.apache.shardingsphere.integration.transaction.cases.base.BaseTransactionTestCase;
import
org.apache.shardingsphere.integration.transaction.engine.constants.TransactionTestConstants;
import
org.apache.shardingsphere.integration.transaction.framework.param.TransactionParameterized;
@@ -201,13 +202,22 @@ public abstract class BaseTransactionITCase extends
BaseITCase {
return result;
}
- @SneakyThrows
protected void callTestCases(final TransactionParameterized parameterized)
{
for (Class<? extends BaseTransactionTestCase> each :
parameterized.getTransactionTestCaseClasses()) {
log.info("Transaction IT {} -> {} test begin.", parameterized,
each.getSimpleName());
- each.getConstructor(BaseTransactionITCase.class,
DataSource.class).newInstance(this, getDataSource()).execute();
+ try {
+ each.getConstructor(BaseTransactionITCase.class,
DataSource.class).newInstance(this, getDataSource()).execute();
+ // CHECKSTYLE:OFF
+ } catch (final Exception ex) {
+ // CHECKSTYLE:ON
+ log.error(String.format("Transaction IT %s -> %s test failed",
parameterized, each.getSimpleName()), ex);
+ throw new ShardingSphereException(ex);
+ }
log.info("Transaction IT {} -> {} test end.", parameterized,
each.getSimpleName());
- getDataSource().close();
+ try {
+ getDataSource().close();
+ } catch (final SQLException ignored) {
+ }
}
}
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/mysql/MySQLJdbcTransactionIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/mysql/MySQLJdbcTransactionIT.java
index a4d5cd06d8b..502dfc56a69 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/mysql/MySQLJdbcTransactionIT.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/mysql/MySQLJdbcTransactionIT.java
@@ -58,7 +58,6 @@ public final class MySQLJdbcTransactionIT extends
BaseTransactionITCase {
}
@Test
- @SneakyThrows
public void assertTransaction() {
callTestCases(parameterized);
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/mysql/MySQLProxyTransactionIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/mysql/MySQLProxyTransactionIT.java
index 9798eae7bf6..5d78a9f32b3 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/mysql/MySQLProxyTransactionIT.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/mysql/MySQLProxyTransactionIT.java
@@ -74,7 +74,6 @@ public final class MySQLProxyTransactionIT extends
BaseTransactionITCase {
}
@Test
- @SneakyThrows
public void assertTransaction() {
callTestCases(parameterized);
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussJdbcTransactionIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussJdbcTransactionIT.java
index 4bcdc0c49f0..88ca6a1cc1e 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussJdbcTransactionIT.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussJdbcTransactionIT.java
@@ -58,13 +58,7 @@ public final class OpenGaussJdbcTransactionIT extends
BaseTransactionITCase {
}
@Test
- @SneakyThrows
public void assertTransaction() {
- callTestCases();
- }
-
- @SneakyThrows
- private void callTestCases() {
callTestCases(parameterized);
}
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussProxyTransactionIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussProxyTransactionIT.java
index 9938758181a..df6f1ffb705 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussProxyTransactionIT.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussProxyTransactionIT.java
@@ -74,13 +74,7 @@ public final class OpenGaussProxyTransactionIT extends
BaseTransactionITCase {
}
@Test
- @SneakyThrows
public void assertTransaction() {
- callTestCases();
- }
-
- @SneakyThrows
- private void callTestCases() {
callTestCases(parameterized);
}
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/postgresql/PostgreSQLJdbcTransactionIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/postgresql/PostgreSQLJdbcTransactionIT.java
index d7077215932..6356ddfc720 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/postgresql/PostgreSQLJdbcTransactionIT.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/postgresql/PostgreSQLJdbcTransactionIT.java
@@ -58,13 +58,7 @@ public final class PostgreSQLJdbcTransactionIT extends
BaseTransactionITCase {
}
@Test
- @SneakyThrows
public void assertTransaction() {
- callTestCases();
- }
-
- @SneakyThrows
- private void callTestCases() {
callTestCases(parameterized);
}
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/postgresql/PostgreSQLProxyTransactionIT.java
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/postgresql/PostgreSQLProxyTransactionIT.java
index 386bf49deb1..43bb20d20af 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/postgresql/PostgreSQLProxyTransactionIT.java
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/postgresql/PostgreSQLProxyTransactionIT.java
@@ -74,13 +74,7 @@ public final class PostgreSQLProxyTransactionIT extends
BaseTransactionITCase {
}
@Test
- @SneakyThrows
public void assertTransaction() {
- callTestCases();
- }
-
- @SneakyThrows
- private void callTestCases() {
callTestCases(parameterized);
}
}
diff --git
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/transaction-it-env.properties
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/transaction-it-env.properties
index 34f137d198d..d90407c2e43 100644
---
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/transaction-it-env.properties
+++
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/transaction-it-env.properties
@@ -17,7 +17,7 @@
# transaction.it.type=DOCKER,NATIVE
transaction.it.env.type=
# transaction.it.env.cases= MySQLAutoCommitTestCase,
PostgresSQLAutoCommitTestCase, ClassicTransferTestCase,
MultiTableCommitAndRollbackTestCase, SingleTableCommitAndRollbackTestCase,
MySQLSetReadOnlyTestCase, MySQLSavePointTestCase, PostgreSQLSavePointTestCase
-transaction.it.env.cases=MultiTableCommitAndRollbackTestCase,
SingleTableCommitAndRollbackTestCase, MySQLSetReadOnlyTestCase,
MySQLSavePointTestCase, MySQLLocalTruncateTestCase, MySQLXATruncateTestCase
+transaction.it.env.cases=ExceptionInTransactionTestCase,
MultiTableCommitAndRollbackTestCase, SingleTableCommitAndRollbackTestCase,
MySQLSetReadOnlyTestCase, MySQLSavePointTestCase, MySQLLocalTruncateTestCase,
MySQLXATruncateTestCase
# transaction.it.env.transtypes=LOCAL, XA, BASE
transaction.it.env.transtypes=LOCAL, XA
# transaction.it.env.xa.providers=Atomikos, Bitronix, Narayana