You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/06/23 05:42:36 UTC
[shardingsphere] branch master updated: Add test cases for XAConnectionWrapperFactoryTest (#17920)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 9ce97590451 Add test cases for XAConnectionWrapperFactoryTest (#17920)
9ce97590451 is described below
commit 9ce97590451b5f23dcfed3ee28a895fa4023db4d
Author: windWheel <18...@qq.com>
AuthorDate: Thu Jun 23 13:42:28 2022 +0800
Add test cases for XAConnectionWrapperFactoryTest (#17920)
Add test cases for XAConnectionWrapperFactoryTest
---
.../connection/XAConnectionWrapperFactoryTest.java | 37 +++++++++++++++++++---
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/XAConnectionWrapperFactoryTest.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/XAConnecti [...]
index 8f7f02bd912..45daa54bd6f 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/XAConnectionWrapperFactoryTest.java
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/jta/connection/XAConnectionWrapperFactoryTest.java
@@ -17,17 +17,46 @@
package org.apache.shardingsphere.transaction.xa.jta.connection;
+import com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection;
+import com.zaxxer.hikari.HikariDataSource;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeFactory;
-import org.apache.shardingsphere.transaction.xa.jta.connection.dialect.H2XAConnectionWrapper;
+import org.apache.shardingsphere.transaction.xa.fixture.DataSourceUtils;
+import org.apache.shardingsphere.transaction.xa.jta.datasource.properties.XADataSourceDefinition;
+import org.apache.shardingsphere.transaction.xa.jta.datasource.properties.XADataSourceDefinitionFactory;
+import org.apache.shardingsphere.transaction.xa.jta.datasource.swapper.DataSourceSwapper;
import org.junit.Test;
+import javax.sql.DataSource;
+import javax.sql.XAConnection;
+import javax.sql.XADataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public final class XAConnectionWrapperFactoryTest {
-
+
@Test
- public void assertGetInstance() {
- assertThat(XAConnectionWrapperFactory.getInstance(DatabaseTypeFactory.getInstance("H2")), instanceOf(H2XAConnectionWrapper.class));
+ public void assertGetInstance() throws SQLException {
+ DatabaseType databaseType = DatabaseTypeFactory.getInstance("MySQL");
+ XAConnectionWrapper xaConnectionWrapper = XAConnectionWrapperFactory.getInstance(databaseType);
+ XAConnection actual = xaConnectionWrapper.wrap(createXADataSource(databaseType), mockConnection());
+ assertThat(actual.getXAResource(), instanceOf(JDBC4MysqlXAConnection.class));
+ }
+
+ private XADataSource createXADataSource(final DatabaseType databaseType) {
+ DataSource dataSource = DataSourceUtils.build(HikariDataSource.class, databaseType, "foo_ds");
+ XADataSourceDefinition xaDataSourceDefinitionFixture = XADataSourceDefinitionFactory.getInstance(databaseType);
+ return new DataSourceSwapper(xaDataSourceDefinitionFixture).swap(dataSource);
+ }
+
+ private Connection mockConnection() throws SQLException {
+ Connection result = mock(Connection.class);
+ when(result.unwrap(com.mysql.jdbc.Connection.class)).thenReturn(mock(com.mysql.jdbc.Connection.class));
+ return result;
}
}