You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/06/23 05:50:28 UTC

[shardingsphere] branch master updated: Refactor XAConnectionWrapperFactoryTest (#18531)

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 9bf2d037825 Refactor XAConnectionWrapperFactoryTest (#18531)
9bf2d037825 is described below

commit 9bf2d0378254b42ec23eb5fc2bf1e0123967d513
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Jun 23 13:50:21 2022 +0800

    Refactor XAConnectionWrapperFactoryTest (#18531)
---
 .../connection/XAConnectionWrapperFactoryTest.java | 33 ++--------------------
 1 file changed, 3 insertions(+), 30 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 45daa54bd6f..66f89d2369e 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,46 +17,19 @@
 
 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.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.apache.shardingsphere.transaction.xa.jta.connection.dialect.H2XAConnectionWrapper;
 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() 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;
+        assertThat(XAConnectionWrapperFactory.getInstance(DatabaseTypeFactory.getInstance("H2")), instanceOf(H2XAConnectionWrapper.class));
     }
 }