You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by lu...@apache.org on 2022/07/25 08:26:05 UTC
[shardingsphere] branch master updated: Support transaction integration tests to run in the JDBC container (#19468)
This is an automated email from the ASF dual-hosted git repository.
lujingshang 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 002b10b8dd9 Support transaction integration tests to run in the JDBC container (#19468)
002b10b8dd9 is described below
commit 002b10b8dd9e8982778aec7b205b518100617d0d
Author: ZhangCheng <fl...@outlook.com>
AuthorDate: Mon Jul 25 16:25:53 2022 +0800
Support transaction integration tests to run in the JDBC container (#19468)
* Support transaction integration tests to run in the JDBC container
* Fix transaction test run error
* Remove unsupported transaction test case
* Revert "Remove unsupported transaction test case"
This reverts commit efc64a119c10a437e75fa1b38a22c9af4a604c3a.
* Remove unsupported transaction test cases
---
.../PostgreSQLSetReadOnlyTestCase.java} | 46 +++++-----
.../savepoint/PostgreSQLSavePointTestCase.java | 4 +-
.../transaction/engine/base/BaseITCase.java | 60 +++++++++++--
.../engine/base/BaseTransactionITCase.java | 16 +++-
.../transaction/engine/base/JDBCDataSource.java | 60 +++++++++++++
...nsactionIT.java => MySQLJdbcTransactionIT.java} | 19 ++---
.../engine/mysql/MySQLProxyTransactionIT.java | 26 ++++--
...tionIT.java => OpenGaussJdbcTransactionIT.java} | 19 ++---
.../opengauss/OpenGaussProxyTransactionIT.java | 27 ++++--
.../PostgreSQLJdbcTransactionIT.java} | 21 ++---
.../postgresql/PostgreSQLProxyTransactionIT.java | 27 ++++--
.../env/IntegrationTestEnvironment.java | 3 +
.../env/enums/TransactionTestCaseRegistry.java | 9 ++
.../container/compose/DockerComposedContainer.java | 44 ++++++++--
.../container/database/DatabaseContainer.java | 7 ++
.../container/database/MySQLContainer.java | 9 +-
.../container/database/OpenGaussContainer.java | 7 +-
.../container/database/PostgreSQLContainer.java | 5 --
.../jdbc/ShardingSphereJDBCContainer.java | 73 ++++++++++++++++
.../framework/param/TransactionParameterized.java | 10 ++-
.../src/test/resources/env/common/command.xml | 2 +-
.../env/jdbc/mysql/config-sharding-local.yaml | 97 +++++++++++++++++++++
.../env/jdbc/mysql/config-sharding-xa.yaml | 98 ++++++++++++++++++++++
.../env/jdbc/opengauss/config-sharding-local.yaml | 97 +++++++++++++++++++++
.../env/jdbc/opengauss/config-sharding-xa.yaml | 98 ++++++++++++++++++++++
.../env/jdbc/postgresql/config-sharding-local.yaml | 97 +++++++++++++++++++++
.../env/jdbc/postgresql/config-sharding-xa.yaml | 98 ++++++++++++++++++++++
.../resources/env/transaction-it-env.properties | 4 +-
28 files changed, 950 insertions(+), 133 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java
similarity index 54%
copy from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java
copy to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java
index fc3a7857e22..b276760ab91 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/readonly/PostgreSQLSetReadOnlyTestCase.java
@@ -15,58 +15,52 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.integration.transaction.cases.savepoint;
+package org.apache.shardingsphere.integration.transaction.cases.readonly;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.integration.transaction.engine.base.TransactionTestCase;
import org.apache.shardingsphere.integration.transaction.engine.constants.TransactionTestConstants;
import org.junit.Assert;
-import org.postgresql.jdbc.PSQLSavepoint;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
+import java.sql.Statement;
/**
- * PostgreSQL savepoint transaction integration test.
+ * PostgreSQL set read only transaction integration test.
*/
@Slf4j
@TransactionTestCase(dbTypes = {TransactionTestConstants.POSTGRESQL})
-public final class PostgreSQLSavePointTestCase extends BaseSavePointTestCase {
+public final class PostgreSQLSetReadOnlyTestCase extends SetReadOnlyTestCase {
- public PostgreSQLSavePointTestCase(final DataSource dataSource) {
+ public PostgreSQLSetReadOnlyTestCase(final DataSource dataSource) {
super(dataSource);
}
@Override
@SneakyThrows
public void executeTest() {
- assertRollback2Savepoint();
- assertReleaseSavepoint();
- assertErrors();
+ assertSetReadOnly();
+ assertNotSetReadOnly();
}
- @SneakyThrows(SQLException.class)
- private void assertErrors() {
+ private void assertSetReadOnly() throws SQLException {
+ Connection connection = getDataSource().getConnection();
+ executeUpdateWithLog(connection, "insert into account(id,balance) values (1,0),(2,100);");
Connection conn = getDataSource().getConnection();
+ conn.setReadOnly(true);
+ assertQueryBalance(conn);
+ Statement updateStatement = conn.createStatement();
try {
- conn.setSavepoint("point");
- Assert.fail("Expect exception, but no exception report.");
- } catch (SQLException ex) {
- Assert.assertEquals("25P01", ex.getSQLState());
- }
- try {
- conn.rollback(new PSQLSavepoint("point1"));
- Assert.fail("Expect exception, but no exception report.");
- } catch (SQLException ex) {
- Assert.assertTrue(ex.getMessage().endsWith("ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks"));
- }
- try {
- conn.releaseSavepoint(new PSQLSavepoint("point1"));
- Assert.fail("Expect exception, but no exception report.");
- } catch (SQLException ex) {
- Assert.assertTrue(ex.getMessage().endsWith("ERROR: RELEASE SAVEPOINT can only be used in transaction blocks"));
+ String updateSql = "update account set balance=100 where id=2;";
+ log.info("Connection execute update: {}.", updateSql);
+ updateStatement.execute(updateSql);
+ log.info("Using the driver of postgresql:42.3.3 expect to update successfully");
+ } catch (SQLException e) {
+ Assert.fail("Update failed, should be successfully.");
}
}
+
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java
index fc3a7857e22..48bc91016f3 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/cases/savepoint/PostgreSQLSavePointTestCase.java
@@ -54,18 +54,20 @@ public final class PostgreSQLSavePointTestCase extends BaseSavePointTestCase {
conn.setSavepoint("point");
Assert.fail("Expect exception, but no exception report.");
} catch (SQLException ex) {
- Assert.assertEquals("25P01", ex.getSQLState());
+ Assert.assertEquals("Savepoint can only be used in transaction blocks.", ex.getMessage());
}
try {
conn.rollback(new PSQLSavepoint("point1"));
Assert.fail("Expect exception, but no exception report.");
} catch (SQLException ex) {
+ // TODO can not run to get the correct result in JDBC mode.
Assert.assertTrue(ex.getMessage().endsWith("ERROR: ROLLBACK TO SAVEPOINT can only be used in transaction blocks"));
}
try {
conn.releaseSavepoint(new PSQLSavepoint("point1"));
Assert.fail("Expect exception, but no exception report.");
} catch (SQLException ex) {
+ // TODO can not run to get the correct result in JDBC mode.
Assert.assertTrue(ex.getMessage().endsWith("ERROR: RELEASE SAVEPOINT can only be used in transaction blocks"));
}
}
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 ab9d12f2380..456ec52f84b 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
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.integration.transaction.engine.base;
+import com.zaxxer.hikari.HikariDataSource;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.SneakyThrows;
@@ -43,7 +44,9 @@ import org.apache.shardingsphere.integration.transaction.framework.param.Transac
import org.apache.shardingsphere.integration.transaction.util.DatabaseTypeUtil;
import org.apache.shardingsphere.integration.transaction.util.TransactionTestCaseClassScanner;
import org.apache.shardingsphere.test.integration.env.runtime.DataSourceEnvironment;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import javax.sql.DataSource;
import javax.xml.bind.JAXB;
import java.sql.Connection;
import java.sql.DriverManager;
@@ -54,6 +57,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
@@ -88,6 +92,8 @@ public abstract class BaseITCase {
private final DatabaseType databaseType;
+ private final String adapter;
+
@Getter
private AutoDataSource dataSource;
@@ -99,10 +105,41 @@ public abstract class BaseITCase {
public BaseITCase(final TransactionParameterized parameterized) {
databaseType = parameterized.getDatabaseType();
+ adapter = parameterized.getAdapter();
composedContainer = createAndStartComposedContainer(parameterized);
commonSQLCommand = getSqlCommand();
initActualDataSources();
- createProxyDatabase(parameterized.getDatabaseType());
+ if (isProxyAdapter(parameterized)) {
+ createProxyDatabase();
+ } else {
+ createJdbcDataSource();
+ }
+ }
+
+ private void createJdbcDataSource() {
+ if (composedContainer instanceof DockerComposedContainer) {
+ DockerComposedContainer dockerComposedContainer = (DockerComposedContainer) composedContainer;
+ DatabaseContainer databaseContainer = dockerComposedContainer.getDatabaseContainer();
+ Map<String, DataSource> actualDataSourceMap = databaseContainer.getActualDataSourceMap();
+ actualDataSourceMap.put("ds_0", createDataSource(databaseContainer, DS_0));
+ actualDataSourceMap.put("ds_1", createDataSource(databaseContainer, DS_1));
+ dataSource = new JDBCDataSource(dockerComposedContainer);
+ }
+ }
+
+ private DataSource createDataSource(final DatabaseContainer databaseContainer, final String dataSourceName) {
+ HikariDataSource result = new HikariDataSource();
+ result.setDriverClassName(DataSourceEnvironment.getDriverClassName(databaseType));
+ result.setJdbcUrl(DataSourceEnvironment.getURL(databaseType, databaseContainer.getHost(), databaseContainer.getMappedPort(databaseContainer.getPort()), dataSourceName));
+ result.setUsername(databaseContainer.getUsername());
+ result.setPassword(databaseContainer.getPassword());
+ result.setMaximumPoolSize(4);
+ result.setTransactionIsolation("TRANSACTION_READ_COMMITTED");
+ return result;
+ }
+
+ protected boolean isProxyAdapter(final TransactionParameterized parameterized) {
+ return parameterized.getAdapter().equalsIgnoreCase(TransactionTestConstants.PROXY);
}
protected static Collection<TransactionParameterized> getTransactionParameterizedList(final Class<? extends BaseTransactionITCase> testCaseClass) {
@@ -157,7 +194,19 @@ public abstract class BaseITCase {
log.info("Collect transaction test case, runMode is not matched, skip: {}.", caseClass.getName());
continue;
}
- result.add(new TransactionParameterized(getSqlDatabaseType(currentTestCaseInfo.getDbType()), getDockerImageName(currentTestCaseInfo.getDbType(), version), caseClass));
+ addParametersByTransactionTypes(result, version, currentTestCaseInfo, caseClass, annotation);
+ }
+ }
+
+ private static void addParametersByTransactionTypes(final Collection<TransactionParameterized> result, final String version, final TransactionTestCaseRegistry currentTestCaseInfo,
+ final Class<? extends BaseTransactionTestCase> caseClass, final TransactionTestCase annotation) {
+ for (TransactionType each : annotation.transactionTypes()) {
+ if (!ENV.getAllowTransactionTypes().isEmpty() && !ENV.getAllowTransactionTypes().contains(each.toString())) {
+ log.info("Collect transaction test case, need to run transaction types don't contain this, skip: {}-{}.", caseClass.getName(), each);
+ continue;
+ }
+ result.add(new TransactionParameterized(getSqlDatabaseType(currentTestCaseInfo.getDbType()), currentTestCaseInfo.getRunningAdaptor(), each,
+ getDockerImageName(currentTestCaseInfo.getDbType(), version), caseClass));
}
}
@@ -193,7 +242,7 @@ public abstract class BaseITCase {
private BaseComposedContainer createAndStartComposedContainer(final TransactionParameterized parameterized) {
final BaseComposedContainer composedContainer;
if (ENV.getItEnvType() == TransactionITEnvTypeEnum.DOCKER) {
- composedContainer = new DockerComposedContainer(parameterized.getDatabaseType(), parameterized.getDockerImageName());
+ composedContainer = new DockerComposedContainer(parameterized);
} else {
composedContainer = new NativeComposedContainer(parameterized.getDatabaseType());
}
@@ -255,11 +304,10 @@ public abstract class BaseITCase {
@SneakyThrows(SQLException.class)
protected Connection getProxyConnection() {
- String jdbcUrl = composedContainer.getProxyJdbcUrl(SHARDING_DB);
- return DriverManager.getConnection(jdbcUrl, ENV.getProxyUserName(), ENV.getProxyPassword());
+ return dataSource.getConnection();
}
- protected void createProxyDatabase(final DatabaseType databaseType) {
+ protected void createProxyDatabase() {
String jdbcUrl = getProxyJdbcUrl(databaseType);
try (Connection connection = DriverManager.getConnection(jdbcUrl, ENV.getProxyUserName(), ENV.getProxyPassword())) {
if (ENV.getItEnvType() == TransactionITEnvTypeEnum.NATIVE) {
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 8364a95fc0f..03b0d265ffa 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
@@ -41,7 +41,11 @@ public abstract class BaseTransactionITCase extends BaseITCase {
public BaseTransactionITCase(final TransactionParameterized parameterized) throws SQLException {
super(parameterized);
- initProxyConfig();
+ if (isProxyAdapter(parameterized)) {
+ initProxyConfig();
+ } else {
+ initJDBCConfig();
+ }
}
private void initProxyConfig() throws SQLException {
@@ -52,6 +56,10 @@ public abstract class BaseTransactionITCase extends BaseITCase {
createTables();
}
+ private void initJDBCConfig() throws SQLException {
+ createTables();
+ }
+
private void createTables() throws SQLException {
Connection conn = getProxyConnection();
createOrderTable(conn);
@@ -88,7 +96,7 @@ public abstract class BaseTransactionITCase extends BaseITCase {
}
protected void dropAccountTable(final Connection connection) throws SQLException {
- executeWithLog(connection, "DROP TABLE IF EXISTS ACCOUNT;");
+ executeWithLog(connection, "DROP TABLE IF EXISTS account;");
}
protected void createOrderItemTable(final Connection connection) throws SQLException {
@@ -96,7 +104,7 @@ public abstract class BaseTransactionITCase extends BaseITCase {
}
protected void dropOrderItemTable(final Connection connection) throws SQLException {
- executeWithLog(connection, "DROP TABLE IF EXISTS T_ORDER_ITEM;");
+ executeWithLog(connection, "DROP TABLE IF EXISTS t_order_item;");
}
protected void createOrderTable(final Connection connection) throws SQLException {
@@ -104,7 +112,7 @@ public abstract class BaseTransactionITCase extends BaseITCase {
}
protected void dropOrderTable(final Connection connection) throws SQLException {
- executeWithLog(connection, "DROP TABLE IF EXISTS T_ORDER;");
+ executeWithLog(connection, "DROP TABLE IF EXISTS t_order;");
}
protected void assertAccountRowCount(final Connection conn, final int rowNum) {
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/JDBCDataSource.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/JDBCDataSource.java
new file mode 100644
index 00000000000..08dfd7dda27
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/base/JDBCDataSource.java
@@ -0,0 +1,60 @@
+/*
+ * 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.engine.base;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.integration.transaction.framework.container.compose.DockerComposedContainer;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * JDBC data source.
+ */
+@Slf4j
+public final class JDBCDataSource extends AutoDataSource {
+
+ private final DockerComposedContainer composedContainer;
+
+ public JDBCDataSource(final DockerComposedContainer composedContainer) {
+ this.composedContainer = composedContainer;
+ }
+
+ @Override
+ public Connection getConnection() throws SQLException {
+ Connection result = createConnection();
+ synchronized (this) {
+ getConnectionCache().add(result);
+ }
+ return result;
+ }
+
+ @Override
+ public Connection getConnection(final String username, final String password) throws SQLException {
+ Connection result = composedContainer.getJdbcContainer().getTargetDataSource().getConnection();
+ synchronized (this) {
+ getConnectionCache().add(result);
+ }
+ return result;
+ }
+
+ private Connection createConnection() throws SQLException {
+ return composedContainer.getJdbcContainer().getTargetDataSource().getConnection();
+ }
+
+}
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/MySQLJdbcTransactionIT.java
similarity index 78%
copy from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/mysql/MySQLProxyTransactionIT.java
copy to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/mysql/MySQLJdbcTransactionIT.java
index 9c931e84276..a5598a8e5ab 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/MySQLJdbcTransactionIT.java
@@ -32,15 +32,15 @@ import java.sql.SQLException;
import java.util.Collection;
/**
- * MySQL general transaction test case with proxy container, includes multiple cases.
+ * MySQL general transaction test case with JDBC container, includes multiple cases.
*/
@Slf4j
@RunWith(Parameterized.class)
-public final class MySQLProxyTransactionIT extends BaseTransactionITCase {
+public final class MySQLJdbcTransactionIT extends BaseTransactionITCase {
private final TransactionParameterized parameterized;
- public MySQLProxyTransactionIT(final TransactionParameterized parameterized) throws SQLException {
+ public MySQLJdbcTransactionIT(final TransactionParameterized parameterized) throws SQLException {
super(parameterized);
this.parameterized = parameterized;
log.info("Parameterized:{}", parameterized);
@@ -48,7 +48,7 @@ public final class MySQLProxyTransactionIT extends BaseTransactionITCase {
@Parameters(name = "{0}")
public static Collection<TransactionParameterized> getParameters() {
- return getTransactionParameterizedList(MySQLProxyTransactionIT.class);
+ return getTransactionParameterizedList(MySQLJdbcTransactionIT.class);
}
@After
@@ -60,15 +60,7 @@ public final class MySQLProxyTransactionIT extends BaseTransactionITCase {
@Test
@SneakyThrows
- public void assertLocalTransaction() {
- alterLocalTransactionRule();
- callTestCases();
- }
-
- @Test
- @SneakyThrows
- public void assertDistributedTransaction() {
- alterXaAtomikosTransactionRule();
+ public void assertTransaction() {
callTestCases();
}
@@ -76,5 +68,4 @@ public final class MySQLProxyTransactionIT extends BaseTransactionITCase {
private void callTestCases() {
parameterized.getTransactionTestCaseClass().getConstructor(DataSource.class).newInstance(getDataSource()).executeTest();
}
-
}
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 9c931e84276..1369ec73653 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
@@ -20,8 +20,11 @@ package org.apache.shardingsphere.integration.transaction.engine.mysql;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.integration.transaction.engine.base.BaseTransactionITCase;
+import org.apache.shardingsphere.integration.transaction.engine.constants.TransactionTestConstants;
import org.apache.shardingsphere.integration.transaction.framework.param.TransactionParameterized;
+import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -30,6 +33,7 @@ import org.junit.runners.Parameterized.Parameters;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.Objects;
/**
* MySQL general transaction test case with proxy container, includes multiple cases.
@@ -51,6 +55,18 @@ public final class MySQLProxyTransactionIT extends BaseTransactionITCase {
return getTransactionParameterizedList(MySQLProxyTransactionIT.class);
}
+ @Before
+ @SneakyThrows(SQLException.class)
+ public void before() {
+ if (TransactionTestConstants.PROXY.equalsIgnoreCase(parameterized.getAdapter())) {
+ if (Objects.equals(parameterized.getTransactionType(), TransactionType.LOCAL)) {
+ alterLocalTransactionRule();
+ } else if (Objects.equals(parameterized.getTransactionType(), TransactionType.XA)) {
+ alterXaAtomikosTransactionRule();
+ }
+ }
+ }
+
@After
@SneakyThrows(SQLException.class)
public void after() {
@@ -60,15 +76,7 @@ public final class MySQLProxyTransactionIT extends BaseTransactionITCase {
@Test
@SneakyThrows
- public void assertLocalTransaction() {
- alterLocalTransactionRule();
- callTestCases();
- }
-
- @Test
- @SneakyThrows
- public void assertDistributedTransaction() {
- alterXaAtomikosTransactionRule();
+ public void assertTransaction() {
callTestCases();
}
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/OpenGaussJdbcTransactionIT.java
similarity index 78%
copy from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussProxyTransactionIT.java
copy to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussJdbcTransactionIT.java
index 04924cba7bf..87311837c4f 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/OpenGaussJdbcTransactionIT.java
@@ -32,15 +32,15 @@ import java.sql.SQLException;
import java.util.Collection;
/**
- * OpenGauss general transaction test case with proxy container, includes multiple cases.
+ * OpenGauss general transaction test case with JDBC container, includes multiple cases.
*/
@Slf4j
@RunWith(Parameterized.class)
-public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
+public final class OpenGaussJdbcTransactionIT extends BaseTransactionITCase {
private final TransactionParameterized parameterized;
- public OpenGaussProxyTransactionIT(final TransactionParameterized parameterized) throws SQLException {
+ public OpenGaussJdbcTransactionIT(final TransactionParameterized parameterized) throws SQLException {
super(parameterized);
this.parameterized = parameterized;
log.info("Parameterized:{}", parameterized);
@@ -48,7 +48,7 @@ public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
@Parameters(name = "{0}")
public static Collection<TransactionParameterized> getParameters() {
- return getTransactionParameterizedList(OpenGaussProxyTransactionIT.class);
+ return getTransactionParameterizedList(OpenGaussJdbcTransactionIT.class);
}
@After
@@ -60,15 +60,7 @@ public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
@Test
@SneakyThrows
- public void assertLocalTransaction() {
- alterLocalTransactionRule();
- callTestCases();
- }
-
- @Test
- @SneakyThrows
- public void assertDistributedTransaction() {
- alterXaAtomikosTransactionRule();
+ public void assertTransaction() {
callTestCases();
}
@@ -76,4 +68,5 @@ public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
private void callTestCases() {
parameterized.getTransactionTestCaseClass().getConstructor(DataSource.class).newInstance(getDataSource()).executeTest();
}
+
}
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 04924cba7bf..495ad59bcf2 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
@@ -20,8 +20,11 @@ package org.apache.shardingsphere.integration.transaction.engine.opengauss;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.integration.transaction.engine.base.BaseTransactionITCase;
+import org.apache.shardingsphere.integration.transaction.engine.constants.TransactionTestConstants;
import org.apache.shardingsphere.integration.transaction.framework.param.TransactionParameterized;
+import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -30,6 +33,7 @@ import org.junit.runners.Parameterized.Parameters;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.Objects;
/**
* OpenGauss general transaction test case with proxy container, includes multiple cases.
@@ -51,6 +55,18 @@ public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
return getTransactionParameterizedList(OpenGaussProxyTransactionIT.class);
}
+ @Before
+ @SneakyThrows(SQLException.class)
+ public void before() {
+ if (TransactionTestConstants.PROXY.equalsIgnoreCase(parameterized.getAdapter())) {
+ if (Objects.equals(parameterized.getTransactionType(), TransactionType.LOCAL)) {
+ alterLocalTransactionRule();
+ } else if (Objects.equals(parameterized.getTransactionType(), TransactionType.XA)) {
+ alterXaAtomikosTransactionRule();
+ }
+ }
+ }
+
@After
@SneakyThrows(SQLException.class)
public void after() {
@@ -60,15 +76,7 @@ public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
@Test
@SneakyThrows
- public void assertLocalTransaction() {
- alterLocalTransactionRule();
- callTestCases();
- }
-
- @Test
- @SneakyThrows
- public void assertDistributedTransaction() {
- alterXaAtomikosTransactionRule();
+ public void assertTransaction() {
callTestCases();
}
@@ -76,4 +84,5 @@ public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
private void callTestCases() {
parameterized.getTransactionTestCaseClass().getConstructor(DataSource.class).newInstance(getDataSource()).executeTest();
}
+
}
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/postgresql/PostgreSQLJdbcTransactionIT.java
similarity index 81%
copy from shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/opengauss/OpenGaussProxyTransactionIT.java
copy to shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/engine/postgresql/PostgreSQLJdbcTransactionIT.java
index 04924cba7bf..4e0b74a7530 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/postgresql/PostgreSQLJdbcTransactionIT.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.integration.transaction.engine.opengauss;
+package org.apache.shardingsphere.integration.transaction.engine.postgresql;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
@@ -32,15 +32,15 @@ import java.sql.SQLException;
import java.util.Collection;
/**
- * OpenGauss general transaction test case with proxy container, includes multiple cases.
+ * PostgreSQL general transaction test case with JDBC container, includes multiple cases.
*/
@Slf4j
@RunWith(Parameterized.class)
-public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
+public final class PostgreSQLJdbcTransactionIT extends BaseTransactionITCase {
private final TransactionParameterized parameterized;
- public OpenGaussProxyTransactionIT(final TransactionParameterized parameterized) throws SQLException {
+ public PostgreSQLJdbcTransactionIT(final TransactionParameterized parameterized) throws SQLException {
super(parameterized);
this.parameterized = parameterized;
log.info("Parameterized:{}", parameterized);
@@ -48,7 +48,7 @@ public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
@Parameters(name = "{0}")
public static Collection<TransactionParameterized> getParameters() {
- return getTransactionParameterizedList(OpenGaussProxyTransactionIT.class);
+ return getTransactionParameterizedList(PostgreSQLJdbcTransactionIT.class);
}
@After
@@ -60,15 +60,7 @@ public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
@Test
@SneakyThrows
- public void assertLocalTransaction() {
- alterLocalTransactionRule();
- callTestCases();
- }
-
- @Test
- @SneakyThrows
- public void assertDistributedTransaction() {
- alterXaAtomikosTransactionRule();
+ public void assertTransaction() {
callTestCases();
}
@@ -76,4 +68,5 @@ public final class OpenGaussProxyTransactionIT extends BaseTransactionITCase {
private void callTestCases() {
parameterized.getTransactionTestCaseClass().getConstructor(DataSource.class).newInstance(getDataSource()).executeTest();
}
+
}
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 04332799fe6..981fd716e3d 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
@@ -20,8 +20,11 @@ package org.apache.shardingsphere.integration.transaction.engine.postgresql;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.integration.transaction.engine.base.BaseTransactionITCase;
+import org.apache.shardingsphere.integration.transaction.engine.constants.TransactionTestConstants;
import org.apache.shardingsphere.integration.transaction.framework.param.TransactionParameterized;
+import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -30,6 +33,7 @@ import org.junit.runners.Parameterized.Parameters;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.Objects;
/**
* PostgreSQL general transaction test case with proxy container, includes multiple cases.
@@ -51,6 +55,18 @@ public final class PostgreSQLProxyTransactionIT extends BaseTransactionITCase {
return getTransactionParameterizedList(PostgreSQLProxyTransactionIT.class);
}
+ @Before
+ @SneakyThrows(SQLException.class)
+ public void before() {
+ if (TransactionTestConstants.PROXY.equalsIgnoreCase(parameterized.getAdapter())) {
+ if (Objects.equals(parameterized.getTransactionType(), TransactionType.LOCAL)) {
+ alterLocalTransactionRule();
+ } else if (Objects.equals(parameterized.getTransactionType(), TransactionType.XA)) {
+ alterXaAtomikosTransactionRule();
+ }
+ }
+ }
+
@After
@SneakyThrows(SQLException.class)
public void after() {
@@ -60,15 +76,7 @@ public final class PostgreSQLProxyTransactionIT extends BaseTransactionITCase {
@Test
@SneakyThrows
- public void assertLocalTransaction() {
- alterLocalTransactionRule();
- callTestCases();
- }
-
- @Test
- @SneakyThrows
- public void assertDistributedTransaction() {
- alterXaAtomikosTransactionRule();
+ public void assertTransaction() {
callTestCases();
}
@@ -76,4 +84,5 @@ public final class PostgreSQLProxyTransactionIT extends BaseTransactionITCase {
private void callTestCases() {
parameterized.getTransactionTestCaseClass().getConstructor(DataSource.class).newInstance(getDataSource()).executeTest();
}
+
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/IntegrationTestEnvironment.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/IntegrationTestEnvironment.java
index 49548260047..c35852fe2be 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/IntegrationTestEnvironment.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/IntegrationTestEnvironment.java
@@ -53,6 +53,8 @@ public final class IntegrationTestEnvironment {
private final List<String> needToRunTestCases;
+ private final List<String> allowTransactionTypes;
+
private final Map<String, TransactionTestCaseRegistry> transactionTestCaseRegistryMap;
private IntegrationTestEnvironment() {
@@ -62,6 +64,7 @@ public final class IntegrationTestEnvironment {
postgresVersions = splitProperty("transaction.it.docker.postgresql.version");
openGaussVersions = splitProperty("transaction.it.docker.opengauss.version");
needToRunTestCases = splitProperty("transaction.it.env.cases");
+ allowTransactionTypes = splitProperty("transaction.it.env.transtypes");
transactionTestCaseRegistryMap = initTransactionTestCaseRegistryMap();
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/enums/TransactionTestCaseRegistry.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/enums/TransactionTestCaseRegistry.java
index b1f65bf4200..0f735cc5e08 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/enums/TransactionTestCaseRegistry.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/env/enums/TransactionTestCaseRegistry.java
@@ -21,8 +21,11 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.integration.transaction.engine.base.BaseTransactionITCase;
import org.apache.shardingsphere.integration.transaction.engine.constants.TransactionTestConstants;
+import org.apache.shardingsphere.integration.transaction.engine.mysql.MySQLJdbcTransactionIT;
import org.apache.shardingsphere.integration.transaction.engine.mysql.MySQLProxyTransactionIT;
+import org.apache.shardingsphere.integration.transaction.engine.opengauss.OpenGaussJdbcTransactionIT;
import org.apache.shardingsphere.integration.transaction.engine.opengauss.OpenGaussProxyTransactionIT;
+import org.apache.shardingsphere.integration.transaction.engine.postgresql.PostgreSQLJdbcTransactionIT;
import org.apache.shardingsphere.integration.transaction.engine.postgresql.PostgreSQLProxyTransactionIT;
/**
@@ -32,10 +35,16 @@ import org.apache.shardingsphere.integration.transaction.engine.postgresql.Postg
@Getter
public enum TransactionTestCaseRegistry {
+ MySQL_JDBC_IT(MySQLJdbcTransactionIT.class, TransactionTestConstants.MYSQL, TransactionTestConstants.JDBC),
+
MySQL_PROXY_IT(MySQLProxyTransactionIT.class, TransactionTestConstants.MYSQL, TransactionTestConstants.PROXY),
+ OPENGAUSS_JDBC_IT(OpenGaussJdbcTransactionIT.class, TransactionTestConstants.OPENGAUSS, TransactionTestConstants.JDBC),
+
OPENGAUSS_PROXY_IT(OpenGaussProxyTransactionIT.class, TransactionTestConstants.OPENGAUSS, TransactionTestConstants.PROXY),
+ POSTGRESQL_JDBC_IT(PostgreSQLJdbcTransactionIT.class, TransactionTestConstants.POSTGRESQL, TransactionTestConstants.JDBC),
+
POSTGRESQL_PROXY_IT(PostgreSQLProxyTransactionIT.class, TransactionTestConstants.POSTGRESQL, TransactionTestConstants.PROXY);
private final Class<? extends BaseTransactionITCase> testCaseClass;
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/compose/DockerComposedContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/compose/DockerComposedContainer.java
index 91ced611937..90a025e5c43 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/compose/DockerComposedContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/compose/DockerComposedContainer.java
@@ -18,17 +18,24 @@
package org.apache.shardingsphere.integration.transaction.framework.container.compose;
import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
+import org.apache.shardingsphere.integration.transaction.engine.constants.TransactionTestConstants;
import org.apache.shardingsphere.integration.transaction.factory.DatabaseContainerFactory;
import org.apache.shardingsphere.integration.transaction.framework.container.database.DatabaseContainer;
+import org.apache.shardingsphere.integration.transaction.framework.container.jdbc.ShardingSphereJDBCContainer;
import org.apache.shardingsphere.integration.transaction.framework.container.proxy.ShardingSphereProxyDockerContainer;
+import org.apache.shardingsphere.integration.transaction.framework.param.TransactionParameterized;
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.runtime.DataSourceEnvironment;
+import java.util.Objects;
+
/**
* Composed container, include governance container and database container.
*/
+@Slf4j
@Getter
public final class DockerComposedContainer extends BaseComposedContainer {
@@ -38,25 +45,48 @@ public final class DockerComposedContainer extends BaseComposedContainer {
private final ShardingSphereProxyDockerContainer proxyContainer;
+ private final ShardingSphereJDBCContainer jdbcContainer;
+
private final DatabaseContainer databaseContainer;
- public DockerComposedContainer(final DatabaseType databaseType, final String dockerImageName) {
- this.databaseType = databaseType;
- ShardingSphereProxyDockerContainer proxyContainer = new ShardingSphereProxyDockerContainer(databaseType);
+ public DockerComposedContainer(final TransactionParameterized parameterized) {
+ this.databaseType = parameterized.getDatabaseType();
governanceContainer = getContainers().registerContainer(new ZookeeperContainer());
- databaseContainer = getContainers().registerContainer(DatabaseContainerFactory.newInstance(databaseType, dockerImageName));
- proxyContainer.dependsOn(governanceContainer, databaseContainer);
- this.proxyContainer = getContainers().registerContainer(proxyContainer);
+ databaseContainer = getContainers().registerContainer(DatabaseContainerFactory.newInstance(this.databaseType, parameterized.getDockerImageName()));
+ if (TransactionTestConstants.PROXY.equalsIgnoreCase(parameterized.getAdapter())) {
+ this.jdbcContainer = null;
+ ShardingSphereProxyDockerContainer proxyContainer = new ShardingSphereProxyDockerContainer(this.databaseType);
+ proxyContainer.dependsOn(governanceContainer, databaseContainer);
+ this.proxyContainer = getContainers().registerContainer(proxyContainer);
+ } else {
+ this.proxyContainer = null;
+ ShardingSphereJDBCContainer jdbcContainer = new ShardingSphereJDBCContainer(databaseContainer,
+ Objects.requireNonNull(ShardingSphereJDBCContainer.class.getClassLoader().getResource(getShardingSphereConfigResource(parameterized))).getFile());
+ this.jdbcContainer = getContainers().registerContainer(jdbcContainer);
+ }
+ }
+
+ private String getShardingSphereConfigResource(final TransactionParameterized parameterized) {
+ String result = String.format("env/%s/%s/config-sharding-%s.yaml", parameterized.getAdapter().toLowerCase(),
+ parameterized.getDatabaseType().getType().toLowerCase(), parameterized.getTransactionType().toString().toLowerCase());
+ log.info("Transaction IT tests use the configuration file: {}", result);
+ return result;
}
@Override
public void stop() {
super.stop();
- proxyContainer.stop();
+ if (null != proxyContainer) {
+ proxyContainer.stop();
+ }
+ if (null != jdbcContainer) {
+ jdbcContainer.stop();
+ }
}
@Override
public String getProxyJdbcUrl(final String databaseName) {
return DataSourceEnvironment.getURL(databaseType, proxyContainer.getHost(), proxyContainer.getFirstMappedPort(), databaseName);
}
+
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/DatabaseContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/DatabaseContainer.java
index f82ea65a06d..d01b8a84e8f 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/DatabaseContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/DatabaseContainer.java
@@ -21,6 +21,10 @@ import lombok.Getter;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.test.integration.env.container.atomic.DockerITContainer;
+import javax.sql.DataSource;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
/**
* Docker storage container.
*/
@@ -29,9 +33,12 @@ public abstract class DatabaseContainer extends DockerITContainer {
private final DatabaseType databaseType;
+ private final Map<String, DataSource> actualDataSourceMap;
+
public DatabaseContainer(final DatabaseType databaseType, final String dockerImageName) {
super(databaseType.getType().toLowerCase(), dockerImageName);
this.databaseType = databaseType;
+ actualDataSourceMap = new LinkedHashMap<>();
}
/**
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/MySQLContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/MySQLContainer.java
index 45d8447f3d7..67afcafec25 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/MySQLContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/MySQLContainer.java
@@ -19,8 +19,6 @@ package org.apache.shardingsphere.integration.transaction.framework.container.da
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.integration.transaction.env.IntegrationTestEnvironment;
-import org.apache.shardingsphere.integration.transaction.env.enums.TransactionITEnvTypeEnum;
import org.apache.shardingsphere.test.integration.env.container.wait.JDBCConnectionWaitStrategy;
import org.apache.shardingsphere.test.integration.env.runtime.DataSourceEnvironment;
import org.testcontainers.containers.BindMode;
@@ -48,14 +46,11 @@ public final class MySQLContainer extends DatabaseContainer {
protected void configure() {
withCommand("--sql_mode=", "--default-authentication-plugin=mysql_native_password");
addEnv("LANG", "C.UTF-8");
- addEnv("MYSQL_ROOT_PASSWORD", username);
+ addEnv("MYSQL_ROOT_PASSWORD", password);
addEnv("MYSQL_ROOT_HOST", "%");
withClasspathResourceMapping("/env/mysql/my.cnf", "/etc/mysql/my.cnf", BindMode.READ_ONLY);
withExposedPorts(getPort());
- if (TransactionITEnvTypeEnum.NATIVE == IntegrationTestEnvironment.getInstance().getItEnvType()) {
- addFixedExposedPort(port, port);
- }
- setWaitStrategy(new JDBCConnectionWaitStrategy(() -> DriverManager.getConnection(DataSourceEnvironment.getURL(DATABASE_TYPE, "localhost", getFirstMappedPort()), "root", "root")));
+ setWaitStrategy(new JDBCConnectionWaitStrategy(() -> DriverManager.getConnection(DataSourceEnvironment.getURL(DATABASE_TYPE, "localhost", getFirstMappedPort()), username, password)));
}
@Override
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/OpenGaussContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/OpenGaussContainer.java
index c7095979d47..9c7d82a6b79 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/OpenGaussContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/OpenGaussContainer.java
@@ -20,8 +20,6 @@ package org.apache.shardingsphere.integration.transaction.framework.container.da
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.OpenGaussDatabaseType;
-import org.apache.shardingsphere.integration.transaction.env.IntegrationTestEnvironment;
-import org.apache.shardingsphere.integration.transaction.env.enums.TransactionITEnvTypeEnum;
import org.apache.shardingsphere.test.integration.env.container.wait.JDBCConnectionWaitStrategy;
import org.apache.shardingsphere.test.integration.env.runtime.DataSourceEnvironment;
import org.testcontainers.containers.BindMode;
@@ -52,9 +50,6 @@ public final class OpenGaussContainer extends DatabaseContainer {
withClasspathResourceMapping("/env/postgresql/postgresql.conf", "/usr/local/opengauss/share/postgresql/postgresql.conf.sample", BindMode.READ_ONLY);
withPrivilegedMode(true);
withExposedPorts(port);
- if (TransactionITEnvTypeEnum.NATIVE == IntegrationTestEnvironment.getInstance().getItEnvType()) {
- addFixedExposedPort(port, port);
- }
setWaitStrategy(new JDBCConnectionWaitStrategy(() -> DriverManager.getConnection(DataSourceEnvironment.getURL(DATABASE_TYPE, "localhost", getFirstMappedPort(), "postgres"),
username, password)));
}
@@ -81,6 +76,6 @@ public final class OpenGaussContainer extends DatabaseContainer {
@Override
public String getAbbreviation() {
- return "openguass";
+ return "opengauss";
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/PostgreSQLContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/PostgreSQLContainer.java
index 611e10a6181..ed822b676aa 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/PostgreSQLContainer.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/database/PostgreSQLContainer.java
@@ -19,8 +19,6 @@ package org.apache.shardingsphere.integration.transaction.framework.container.da
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.dialect.PostgreSQLDatabaseType;
-import org.apache.shardingsphere.integration.transaction.env.IntegrationTestEnvironment;
-import org.apache.shardingsphere.integration.transaction.env.enums.TransactionITEnvTypeEnum;
import org.apache.shardingsphere.test.integration.env.container.wait.JDBCConnectionWaitStrategy;
import org.apache.shardingsphere.test.integration.env.runtime.DataSourceEnvironment;
import org.testcontainers.containers.BindMode;
@@ -51,9 +49,6 @@ public final class PostgreSQLContainer extends DatabaseContainer {
addEnv("POSTGRES_PASSWORD", password);
withClasspathResourceMapping("/env/postgresql/postgresql.conf", "/etc/postgresql/postgresql.conf", BindMode.READ_ONLY);
withExposedPorts(port);
- if (TransactionITEnvTypeEnum.NATIVE == IntegrationTestEnvironment.getInstance().getItEnvType()) {
- addFixedExposedPort(port, port);
- }
setWaitStrategy(new JDBCConnectionWaitStrategy(() -> DriverManager.getConnection(DataSourceEnvironment.getURL(DATABASE_TYPE, "localhost", getFirstMappedPort(), "postgres"),
username, password)));
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/jdbc/ShardingSphereJDBCContainer.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/jdbc/ShardingSphereJDBCContainer.java
new file mode 100644
index 00000000000..d02281b8814
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/container/jdbc/ShardingSphereJDBCContainer.java
@@ -0,0 +1,73 @@
+/*
+ * 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.framework.container.jdbc;
+
+import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.integration.transaction.framework.container.database.DatabaseContainer;
+import org.apache.shardingsphere.test.integration.env.container.atomic.EmbeddedITContainer;
+
+import javax.sql.DataSource;
+import java.io.File;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * ShardingSphere JDBC container.
+ */
+public final class ShardingSphereJDBCContainer implements EmbeddedITContainer {
+
+ private final DatabaseContainer databaseContainer;
+
+ private final String ruleConfigPath;
+
+ private final AtomicReference<DataSource> targetDataSourceProvider = new AtomicReference<>();
+
+ public ShardingSphereJDBCContainer(final DatabaseContainer databaseContainer, final String ruleConfigPath) {
+ this.databaseContainer = databaseContainer;
+ this.ruleConfigPath = ruleConfigPath;
+ }
+
+ @Override
+ public void start() {
+ }
+
+ /**
+ * Get target data source.
+ *
+ * @return target data source
+ */
+ public DataSource getTargetDataSource() {
+ DataSource dataSource = targetDataSourceProvider.get();
+ if (Objects.isNull(dataSource)) {
+ try {
+ targetDataSourceProvider.set(
+ YamlShardingSphereDataSourceFactory.createDataSource(databaseContainer.getActualDataSourceMap(), new File(ruleConfigPath)));
+ } catch (final SQLException | IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ return targetDataSourceProvider.get();
+ }
+
+ @Override
+ public String getAbbreviation() {
+ return "jdbc";
+ }
+}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/param/TransactionParameterized.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/param/TransactionParameterized.java
index 7fffaa07720..b7cabb9d7fc 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/param/TransactionParameterized.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/java/org/apache/shardingsphere/integration/transaction/framework/param/TransactionParameterized.java
@@ -21,19 +21,27 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.integration.transaction.cases.base.BaseTransactionTestCase;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+/**
+ * Transaction test parameters.
+ */
@Getter
@RequiredArgsConstructor
public final class TransactionParameterized {
private final DatabaseType databaseType;
+ private final String adapter;
+
+ private final TransactionType transactionType;
+
private final String dockerImageName;
private final Class<? extends BaseTransactionTestCase> transactionTestCaseClass;
@Override
public String toString() {
- return String.format("%s -> %s -> %s", databaseType.getType(), dockerImageName, transactionTestCaseClass.getSimpleName());
+ return String.format("%s -> %s -> %s -> %s -> %s", databaseType.getType(), adapter, transactionType, dockerImageName, transactionTestCaseClass.getSimpleName());
}
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/common/command.xml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/common/command.xml
index 9313da5fc83..d67cafac5ad 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/common/command.xml
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/common/command.xml
@@ -98,7 +98,7 @@
</source-add-resource-template>
<create-account-table>
- CREATE TABLE ACCOUNT
+ CREATE TABLE account
(
ID BIGINT, BALANCE FLOAT,
TRANSACTION_ID INT
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/mysql/config-sharding-local.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/mysql/config-sharding-local.yaml
new file mode 100644
index 00000000000..51c01e70f9f
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/mysql/config-sharding-local.yaml
@@ -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.
+#
+
+######################################################################################################
+#
+# If you want to configure governance, authorization and proxy properties, please refer to this file.
+#
+######################################################################################################
+
+databaseName: sharding_db
+rules:
+ - !TRANSACTION
+ defaultType: LOCAL
+ - !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_${0..1}.t_order_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_inline
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+ t_order_item:
+ actualDataNodes: ds_${0..1}.t_order_item_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_item_inline
+ keyGenerateStrategy:
+ column: order_item_id
+ keyGeneratorName: snowflake
+ account:
+ actualDataNodes: ds_${0..1}.account_${0..1}
+ databaseStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: database_id_inline
+ tableStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: account_inline
+ keyGenerateStrategy:
+ column: id
+ keyGeneratorName: snowflake
+ bindingTables:
+ - t_order,t_order_item
+ defaultDatabaseStrategy:
+ standard:
+ shardingColumn: user_id
+ shardingAlgorithmName: database_inline
+ defaultTableStrategy:
+ none:
+
+ shardingAlgorithms:
+ database_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${user_id % 2}
+ database_id_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${id % 2}
+ t_order_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_${order_id % 2}
+ t_order_item_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_item_${order_id % 2}
+ account_inline:
+ type: INLINE
+ props:
+ algorithm-expression: account_${id % 2}
+
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
+
+props:
+ sql-show: false
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/mysql/config-sharding-xa.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/mysql/config-sharding-xa.yaml
new file mode 100644
index 00000000000..d76760f284d
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/mysql/config-sharding-xa.yaml
@@ -0,0 +1,98 @@
+#
+# 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.
+#
+
+######################################################################################################
+#
+# If you want to configure governance, authorization and proxy properties, please refer to this file.
+#
+######################################################################################################
+
+databaseName: sharding_db
+rules:
+ - !TRANSACTION
+ defaultType: XA
+ providerType: Atomikos
+ - !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_${0..1}.t_order_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_inline
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+ t_order_item:
+ actualDataNodes: ds_${0..1}.t_order_item_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_item_inline
+ keyGenerateStrategy:
+ column: order_item_id
+ keyGeneratorName: snowflake
+ account:
+ actualDataNodes: ds_${0..1}.account_${0..1}
+ databaseStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: database_id_inline
+ tableStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: account_inline
+ keyGenerateStrategy:
+ column: id
+ keyGeneratorName: snowflake
+ bindingTables:
+ - t_order,t_order_item
+ defaultDatabaseStrategy:
+ standard:
+ shardingColumn: user_id
+ shardingAlgorithmName: database_inline
+ defaultTableStrategy:
+ none:
+
+ shardingAlgorithms:
+ database_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${user_id % 2}
+ database_id_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${id % 2}
+ t_order_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_${order_id % 2}
+ t_order_item_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_item_${order_id % 2}
+ account_inline:
+ type: INLINE
+ props:
+ algorithm-expression: account_${id % 2}
+
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
+
+props:
+ sql-show: false
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/opengauss/config-sharding-local.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/opengauss/config-sharding-local.yaml
new file mode 100644
index 00000000000..51c01e70f9f
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/opengauss/config-sharding-local.yaml
@@ -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.
+#
+
+######################################################################################################
+#
+# If you want to configure governance, authorization and proxy properties, please refer to this file.
+#
+######################################################################################################
+
+databaseName: sharding_db
+rules:
+ - !TRANSACTION
+ defaultType: LOCAL
+ - !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_${0..1}.t_order_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_inline
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+ t_order_item:
+ actualDataNodes: ds_${0..1}.t_order_item_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_item_inline
+ keyGenerateStrategy:
+ column: order_item_id
+ keyGeneratorName: snowflake
+ account:
+ actualDataNodes: ds_${0..1}.account_${0..1}
+ databaseStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: database_id_inline
+ tableStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: account_inline
+ keyGenerateStrategy:
+ column: id
+ keyGeneratorName: snowflake
+ bindingTables:
+ - t_order,t_order_item
+ defaultDatabaseStrategy:
+ standard:
+ shardingColumn: user_id
+ shardingAlgorithmName: database_inline
+ defaultTableStrategy:
+ none:
+
+ shardingAlgorithms:
+ database_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${user_id % 2}
+ database_id_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${id % 2}
+ t_order_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_${order_id % 2}
+ t_order_item_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_item_${order_id % 2}
+ account_inline:
+ type: INLINE
+ props:
+ algorithm-expression: account_${id % 2}
+
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
+
+props:
+ sql-show: false
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/opengauss/config-sharding-xa.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/opengauss/config-sharding-xa.yaml
new file mode 100644
index 00000000000..d76760f284d
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/opengauss/config-sharding-xa.yaml
@@ -0,0 +1,98 @@
+#
+# 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.
+#
+
+######################################################################################################
+#
+# If you want to configure governance, authorization and proxy properties, please refer to this file.
+#
+######################################################################################################
+
+databaseName: sharding_db
+rules:
+ - !TRANSACTION
+ defaultType: XA
+ providerType: Atomikos
+ - !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_${0..1}.t_order_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_inline
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+ t_order_item:
+ actualDataNodes: ds_${0..1}.t_order_item_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_item_inline
+ keyGenerateStrategy:
+ column: order_item_id
+ keyGeneratorName: snowflake
+ account:
+ actualDataNodes: ds_${0..1}.account_${0..1}
+ databaseStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: database_id_inline
+ tableStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: account_inline
+ keyGenerateStrategy:
+ column: id
+ keyGeneratorName: snowflake
+ bindingTables:
+ - t_order,t_order_item
+ defaultDatabaseStrategy:
+ standard:
+ shardingColumn: user_id
+ shardingAlgorithmName: database_inline
+ defaultTableStrategy:
+ none:
+
+ shardingAlgorithms:
+ database_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${user_id % 2}
+ database_id_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${id % 2}
+ t_order_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_${order_id % 2}
+ t_order_item_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_item_${order_id % 2}
+ account_inline:
+ type: INLINE
+ props:
+ algorithm-expression: account_${id % 2}
+
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
+
+props:
+ sql-show: false
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/postgresql/config-sharding-local.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/postgresql/config-sharding-local.yaml
new file mode 100644
index 00000000000..51c01e70f9f
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/postgresql/config-sharding-local.yaml
@@ -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.
+#
+
+######################################################################################################
+#
+# If you want to configure governance, authorization and proxy properties, please refer to this file.
+#
+######################################################################################################
+
+databaseName: sharding_db
+rules:
+ - !TRANSACTION
+ defaultType: LOCAL
+ - !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_${0..1}.t_order_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_inline
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+ t_order_item:
+ actualDataNodes: ds_${0..1}.t_order_item_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_item_inline
+ keyGenerateStrategy:
+ column: order_item_id
+ keyGeneratorName: snowflake
+ account:
+ actualDataNodes: ds_${0..1}.account_${0..1}
+ databaseStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: database_id_inline
+ tableStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: account_inline
+ keyGenerateStrategy:
+ column: id
+ keyGeneratorName: snowflake
+ bindingTables:
+ - t_order,t_order_item
+ defaultDatabaseStrategy:
+ standard:
+ shardingColumn: user_id
+ shardingAlgorithmName: database_inline
+ defaultTableStrategy:
+ none:
+
+ shardingAlgorithms:
+ database_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${user_id % 2}
+ database_id_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${id % 2}
+ t_order_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_${order_id % 2}
+ t_order_item_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_item_${order_id % 2}
+ account_inline:
+ type: INLINE
+ props:
+ algorithm-expression: account_${id % 2}
+
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
+
+props:
+ sql-show: false
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/postgresql/config-sharding-xa.yaml b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/postgresql/config-sharding-xa.yaml
new file mode 100644
index 00000000000..d76760f284d
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-transaction/src/test/resources/env/jdbc/postgresql/config-sharding-xa.yaml
@@ -0,0 +1,98 @@
+#
+# 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.
+#
+
+######################################################################################################
+#
+# If you want to configure governance, authorization and proxy properties, please refer to this file.
+#
+######################################################################################################
+
+databaseName: sharding_db
+rules:
+ - !TRANSACTION
+ defaultType: XA
+ providerType: Atomikos
+ - !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_${0..1}.t_order_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_inline
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+ t_order_item:
+ actualDataNodes: ds_${0..1}.t_order_item_${0..1}
+ tableStrategy:
+ standard:
+ shardingColumn: order_id
+ shardingAlgorithmName: t_order_item_inline
+ keyGenerateStrategy:
+ column: order_item_id
+ keyGeneratorName: snowflake
+ account:
+ actualDataNodes: ds_${0..1}.account_${0..1}
+ databaseStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: database_id_inline
+ tableStrategy:
+ standard:
+ shardingColumn: id
+ shardingAlgorithmName: account_inline
+ keyGenerateStrategy:
+ column: id
+ keyGeneratorName: snowflake
+ bindingTables:
+ - t_order,t_order_item
+ defaultDatabaseStrategy:
+ standard:
+ shardingColumn: user_id
+ shardingAlgorithmName: database_inline
+ defaultTableStrategy:
+ none:
+
+ shardingAlgorithms:
+ database_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${user_id % 2}
+ database_id_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${id % 2}
+ t_order_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_${order_id % 2}
+ t_order_item_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_item_${order_id % 2}
+ account_inline:
+ type: INLINE
+ props:
+ algorithm-expression: account_${id % 2}
+
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
+
+props:
+ sql-show: false
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 95fd5c72945..3f41f2c24aa 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,9 @@
# 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=PostgresSQLAutoCommitTestCase, MultiTableCommitAndRollbackTestCase, SingleTableCommitAndRollbackTestCase, MySQLSetReadOnlyTestCase, MySQLSavePointTestCase, PostgreSQLSavePointTestCase
+transaction.it.env.cases=PostgresSQLAutoCommitTestCase, MultiTableCommitAndRollbackTestCase, SingleTableCommitAndRollbackTestCase, MySQLSetReadOnlyTestCase, MySQLSavePointTestCase
+# transaction.it.env.transtypes=LOCAL, XA, BASE
+transaction.it.env.transtypes=LOCAL, XA
# transaction.it.docker.mysql.version=5.7,8.0
transaction.it.docker.mysql.version=
# transaction.it.docker.postgresql.version=postgres:10-alpine,postgres:11-alpine,postgres:12-alpine,postgres:13-alpine,postgres:14-alpine