You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/10/07 16:25:00 UTC
[shardingsphere] branch master updated: Fix test cases for
ShardingSphereConnection (#12921)
This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 27dcc37 Fix test cases for ShardingSphereConnection (#12921)
27dcc37 is described below
commit 27dcc3789591b8d7c851f319e0f31b6ee78fdf90
Author: Liang Zhang <te...@163.com>
AuthorDate: Fri Oct 8 00:21:48 2021 +0800
Fix test cases for ShardingSphereConnection (#12921)
* Refactor ShardingSphereConnectionTest
* Add test case for getRandomPhysicalDataSourceName
* Refactor ShardingSphereConnectionTest
* Add more test cases
* Add more test case of transaction operation
* Add more test case of transaction operation
* Add more test case of transaction operation
* Add more test case of transaction operation
* Fix test case for setTransactionIsolation
---
.../core/connection/ShardingSphereConnection.java | 10 +-
.../connection/ShardingSphereConnectionTest.java | 265 ++++++++++++---------
...actShardingSphereTransactionManagerFixture.java | 84 -------
...ASEShardingSphereTransactionManagerFixture.java | 28 ---
.../XAShardingSphereTransactionManagerFixture.java | 28 ---
...ransaction.spi.ShardingSphereTransactionManager | 19 --
6 files changed, 161 insertions(+), 273 deletions(-)
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
index 5f884d8..b9e2984 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
@@ -255,15 +255,15 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter im
@Override
public void setAutoCommit(final boolean autoCommit) throws SQLException {
+ this.autoCommit = autoCommit;
if (connectionTransaction.isLocalTransaction()) {
- processLocalTransaction(autoCommit);
+ processLocalTransaction();
} else {
- processDistributeTransaction(autoCommit);
+ processDistributeTransaction();
}
}
- private void processLocalTransaction(final boolean autoCommit) throws SQLException {
- this.autoCommit = autoCommit;
+ private void processLocalTransaction() throws SQLException {
recordMethodInvocation(Connection.class, "setAutoCommit", new Class[]{boolean.class}, new Object[]{autoCommit});
forceExecuteTemplate.execute(cachedConnections.values(), connection -> connection.setAutoCommit(autoCommit));
if (!autoCommit) {
@@ -271,7 +271,7 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter im
}
}
- private void processDistributeTransaction(final boolean autoCommit) throws SQLException {
+ private void processDistributeTransaction() throws SQLException {
switch (connectionTransaction.getDistributedTransactionOperationType(autoCommit)) {
case BEGIN:
closeCachedConnections();
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
index 7ea676c..0abe99e 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
@@ -19,34 +19,25 @@ package org.apache.shardingsphere.driver.jdbc.core.connection;
import com.google.common.collect.Multimap;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.driver.jdbc.core.fixture.BASEShardingSphereTransactionManagerFixture;
-import org.apache.shardingsphere.driver.jdbc.core.fixture.XAShardingSphereTransactionManagerFixture;
import org.apache.shardingsphere.infra.database.DefaultSchema;
-import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
-import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
-import org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.ConnectionTransaction;
+import org.apache.shardingsphere.transaction.ConnectionTransaction.DistributedTransactionOperationType;
import org.apache.shardingsphere.transaction.TransactionHolder;
-import org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
-import org.apache.shardingsphere.transaction.context.TransactionContexts;
-import org.apache.shardingsphere.transaction.core.TransactionOperationType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
import org.junit.After;
import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.Test;
import javax.sql.DataSource;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Collections;
+import java.util.List;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
@@ -60,109 +51,175 @@ import static org.mockito.Mockito.when;
public final class ShardingSphereConnectionTest {
- private static Map<String, DataSource> dataSourceMap;
-
private ShardingSphereConnection connection;
- private MetaDataContexts metaDataContexts;
-
- private TransactionContexts transactionContexts;
-
- @BeforeClass
- public static void init() throws SQLException {
- DataSource primaryDataSource = mockDataSource();
- DataSource replicaDataSource = mockDataSource();
- dataSourceMap = new HashMap<>(2, 1);
- dataSourceMap.put("test_primary_ds", primaryDataSource);
- dataSourceMap.put("test_replica_ds", replicaDataSource);
+ @Before
+ public void setUp() throws SQLException {
+ connection = new ShardingSphereConnection(DefaultSchema.LOGIC_NAME, mockContextManager());
}
- private static DataSource mockDataSource() throws SQLException {
- DataSource result = mock(DataSource.class);
- when(result.getConnection()).thenReturn(mock(Connection.class));
+ private ContextManager mockContextManager() {
+ ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
+ when(result.getDataSourceMap(DefaultSchema.LOGIC_NAME)).thenReturn(Collections.singletonMap("ds", mock(DataSource.class, RETURNS_DEEP_STUBS)));
+ when(result.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TransactionRule.class)).thenReturn(Optional.empty());
return result;
}
- @Before
- public void setUp() {
- metaDataContexts = mock(MetaDataContexts.class, RETURNS_DEEP_STUBS);
- ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
- when(metaDataContexts.getMetaData(DefaultSchema.LOGIC_NAME).getResource().getDatabaseType()).thenReturn(DatabaseTypeRegistry.getActualDatabaseType("H2"));
- when(metaDataContexts.getMetaData(DefaultSchema.LOGIC_NAME)).thenReturn(metaData);
- transactionContexts = mock(TransactionContexts.class);
- when(transactionContexts.getEngines()).thenReturn(mock(Map.class));
- when(transactionContexts.getEngines().get(DefaultSchema.LOGIC_NAME)).thenReturn(new ShardingSphereTransactionManagerEngine());
- ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
- shardingRuleConfig.getTables().add(new ShardingTableRuleConfiguration("test"));
- ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
- when(contextManager.getTransactionContexts()).thenReturn(transactionContexts);
- when(contextManager.getDataSourceMap(DefaultSchema.LOGIC_NAME)).thenReturn(dataSourceMap);
- when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TransactionRule.class)).thenReturn(Optional.empty());
- connection = new ShardingSphereConnection(DefaultSchema.LOGIC_NAME, contextManager);
- }
-
@After
public void clear() {
try {
connection.close();
TransactionTypeHolder.clear();
- XAShardingSphereTransactionManagerFixture.getInvocations().clear();
- BASEShardingSphereTransactionManagerFixture.getInvocations().clear();
} catch (final SQLException ignored) {
}
}
@Test
- public void assertGetConnectionFromCache() throws SQLException {
- assertThat(connection.getConnection("test_primary_ds"), is(connection.getConnection("test_primary_ds")));
+ public void assertGetRandomPhysicalDataSourceNameFromContextManager() {
+ String actual = connection.getRandomPhysicalDataSourceName();
+ assertThat(actual, is("ds"));
+ }
+
+ @Test
+ public void assertGetRandomPhysicalDataSourceNameFromCache() throws SQLException {
+ connection.getConnection("ds");
+ String actual = connection.getRandomPhysicalDataSourceName();
+ assertThat(actual, is("ds"));
+ }
+
+ @Test
+ public void assertGetConnection() throws SQLException {
+ assertThat(connection.getConnection("ds"), is(connection.getConnection("ds")));
}
- @Test(expected = IllegalStateException.class)
- public void assertGetConnectionFailure() throws SQLException {
- connection.getConnection("not_exist");
+ @Test
+ public void assertGetConnectionsWhenAllInCache() throws SQLException {
+ Connection expected = connection.getConnection("ds");
+ List<Connection> actual = connection.getConnections("ds", 1, ConnectionMode.CONNECTION_STRICTLY);
+ assertThat(actual.size(), is(1));
+ assertThat(actual.get(0), is(expected));
}
@Test
- public void assertLOCALTransactionOperation() throws SQLException {
+ public void assertGetConnectionsWhenEmptyCache() throws SQLException {
+ List<Connection> actual = connection.getConnections("ds", 1, ConnectionMode.MEMORY_STRICTLY);
+ assertThat(actual.size(), is(1));
+ }
+
+ @Test
+ public void assertGetConnectionsWhenPartInCacheWithMemoryStrictlyMode() throws SQLException {
+ connection.getConnection("ds");
+ List<Connection> actual = connection.getConnections("ds", 3, ConnectionMode.MEMORY_STRICTLY);
+ assertThat(actual.size(), is(3));
+ }
+
+ @Test
+ public void assertGetConnectionsWhenPartInCacheWithConnectionStrictlyMode() throws SQLException {
+ connection.getConnection("ds");
+ List<Connection> actual = connection.getConnections("ds", 3, ConnectionMode.CONNECTION_STRICTLY);
+ assertThat(actual.size(), is(3));
+ }
+
+ @Test
+ public void assertGetConnectionsWhenConnectionCreateFailed() throws SQLException {
+ when(connection.getContextManager().getDataSourceMap(DefaultSchema.LOGIC_NAME).get("ds").getConnection()).thenThrow(new SQLException());
+ try {
+ connection.getConnections("ds", 3, ConnectionMode.CONNECTION_STRICTLY);
+ } catch (final SQLException ex) {
+ assertThat(ex.getMessage(), is("Can not get 3 connections one time, partition succeed connection(0) have released!"));
+ }
+ }
+
+ @Test
+ public void assertIsHoldTransaction() throws SQLException {
+ connection.setAutoCommit(false);
+ assertTrue(connection.isHoldTransaction());
+ }
+
+ @Test
+ public void assertIsNotHoldTransaction() throws SQLException {
connection.setAutoCommit(true);
- assertFalse(TransactionHolder.isTransaction());
+ assertFalse(connection.isHoldTransaction());
+ }
+
+ @Test
+ public void assertSetAutoCommitWithLocalTransaction() throws SQLException {
+ Connection physicalConnection = mock(Connection.class);
+ when(connection.getContextManager().getDataSourceMap(DefaultSchema.LOGIC_NAME).get("ds").getConnection()).thenReturn(physicalConnection);
+ connection.getConnection("ds");
+ connection.setAutoCommit(true);
+ assertTrue(connection.getAutoCommit());
+ verify(physicalConnection).setAutoCommit(true);
+ }
+
+ @Test
+ public void assertSetAutoCommitWithDistributedTransaction() throws SQLException {
+ ConnectionTransaction connectionTransaction = mock(ConnectionTransaction.class);
+ when(connectionTransaction.getDistributedTransactionOperationType(true)).thenReturn(DistributedTransactionOperationType.COMMIT);
+ setConnectionTransaction(connectionTransaction);
+ connection.setAutoCommit(true);
+ assertTrue(connection.getAutoCommit());
+ verify(connectionTransaction).commit();
+ }
+
+ @Test
+ public void assertCommitWithLocalTransaction() throws SQLException {
+ Connection physicalConnection = mock(Connection.class);
+ when(connection.getContextManager().getDataSourceMap(DefaultSchema.LOGIC_NAME).get("ds").getConnection()).thenReturn(physicalConnection);
+ connection.getConnection("ds");
connection.setAutoCommit(false);
+ assertFalse(connection.getAutoCommit());
assertTrue(TransactionHolder.isTransaction());
+ verify(physicalConnection).setAutoCommit(false);
+ connection.commit();
+ assertFalse(TransactionHolder.isTransaction());
+ verify(physicalConnection).commit();
}
@Test
- public void assertXATransactionOperation() throws SQLException {
- ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
- when(contextManager.getTransactionContexts()).thenReturn(transactionContexts);
- when(contextManager.getDataSourceMap(DefaultSchema.LOGIC_NAME)).thenReturn(dataSourceMap);
- TransactionRule transactionRule = new TransactionRule(new TransactionRuleConfiguration("XA", null));
- when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TransactionRule.class)).thenReturn(Optional.of(transactionRule));
- connection = new ShardingSphereConnection(connection.getSchema(), contextManager);
+ public void assertCommitWithDistributedTransaction() throws SQLException {
+ ConnectionTransaction connectionTransaction = mock(ConnectionTransaction.class);
+ when(connectionTransaction.getDistributedTransactionOperationType(false)).thenReturn(DistributedTransactionOperationType.BEGIN);
+ setConnectionTransaction(connectionTransaction);
connection.setAutoCommit(false);
- assertTrue(XAShardingSphereTransactionManagerFixture.getInvocations().contains(TransactionOperationType.BEGIN));
+ assertFalse(connection.getAutoCommit());
+ assertTrue(TransactionHolder.isTransaction());
+ verify(connectionTransaction).begin();
connection.commit();
- assertTrue(XAShardingSphereTransactionManagerFixture.getInvocations().contains(TransactionOperationType.COMMIT));
+ assertFalse(TransactionHolder.isTransaction());
+ verify(connectionTransaction).commit();
+ }
+
+ @Test
+ public void assertRollbackWithLocalTransaction() throws SQLException {
+ Connection physicalConnection = mock(Connection.class);
+ when(connection.getContextManager().getDataSourceMap(DefaultSchema.LOGIC_NAME).get("ds").getConnection()).thenReturn(physicalConnection);
+ connection.getConnection("ds");
+ connection.setAutoCommit(false);
+ assertFalse(connection.getAutoCommit());
connection.rollback();
- assertTrue(XAShardingSphereTransactionManagerFixture.getInvocations().contains(TransactionOperationType.ROLLBACK));
+ verify(physicalConnection).rollback();
}
@Test
- public void assertBASETransactionOperation() throws SQLException {
- ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
- when(contextManager.getTransactionContexts()).thenReturn(transactionContexts);
- when(contextManager.getDataSourceMap(DefaultSchema.LOGIC_NAME)).thenReturn(dataSourceMap);
- TransactionRule transactionRule = new TransactionRule(new TransactionRuleConfiguration("BASE", null));
- when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TransactionRule.class)).thenReturn(Optional.of(transactionRule));
- connection = new ShardingSphereConnection(connection.getSchema(), contextManager);
+ public void assertRollbackWithDistributedTransaction() throws SQLException {
+ ConnectionTransaction connectionTransaction = mock(ConnectionTransaction.class);
+ when(connectionTransaction.getDistributedTransactionOperationType(false)).thenReturn(DistributedTransactionOperationType.BEGIN);
+ setConnectionTransaction(connectionTransaction);
connection.setAutoCommit(false);
- assertTrue(BASEShardingSphereTransactionManagerFixture.getInvocations().contains(TransactionOperationType.BEGIN));
- connection.commit();
- assertTrue(BASEShardingSphereTransactionManagerFixture.getInvocations().contains(TransactionOperationType.COMMIT));
+ assertFalse(connection.getAutoCommit());
+ assertTrue(TransactionHolder.isTransaction());
+ verify(connectionTransaction).begin();
connection.rollback();
- assertTrue(BASEShardingSphereTransactionManagerFixture.getInvocations().contains(TransactionOperationType.ROLLBACK));
+ assertFalse(TransactionHolder.isTransaction());
+ verify(connectionTransaction).rollback();
+ }
+
+ @SneakyThrows(ReflectiveOperationException.class)
+ private void setConnectionTransaction(final ConnectionTransaction connectionTransaction) {
+ Field field = connection.getClass().getDeclaredField("connectionTransaction");
+ field.setAccessible(true);
+ field.set(connection, connectionTransaction);
}
@Test
@@ -172,62 +229,52 @@ public final class ShardingSphereConnectionTest {
@Test
public void assertIsInvalid() throws SQLException {
- connection.getConnection("test_replica_ds");
+ connection.getConnection("ds");
assertFalse(connection.isValid(0));
}
@Test
public void assertSetReadOnly() throws SQLException {
- ShardingSphereConnection actual = createShardingSphereConnection();
- assertFalse(actual.isReadOnly());
- Connection connection = actual.getConnection("test_replica_ds");
- actual.setReadOnly(true);
- assertTrue(actual.isReadOnly());
- verify(connection).setReadOnly(true);
+ assertFalse(connection.isReadOnly());
+ Connection physicalConnection = connection.getConnection("ds");
+ connection.setReadOnly(true);
+ assertTrue(connection.isReadOnly());
+ verify(physicalConnection).setReadOnly(true);
}
@Test
public void assertGetTransactionIsolationWithoutCachedConnections() throws SQLException {
- assertThat(createShardingSphereConnection().getTransactionIsolation(), is(Connection.TRANSACTION_READ_UNCOMMITTED));
+ assertThat(connection.getTransactionIsolation(), is(Connection.TRANSACTION_READ_UNCOMMITTED));
}
@Test
public void assertSetTransactionIsolation() throws SQLException {
- ShardingSphereConnection actual = createShardingSphereConnection();
- Connection connection = actual.getConnection("test_replica_ds");
- actual.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
- verify(connection).setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+ Connection physicalConnection = connection.getConnection("ds");
+ connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+ verify(physicalConnection).setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
}
@SuppressWarnings("unchecked")
@SneakyThrows(ReflectiveOperationException.class)
- private Multimap<String, Connection> getCachedConnections(final ShardingSphereConnection connectionAdapter) {
+ private Multimap<String, Connection> getCachedConnections(final ShardingSphereConnection shardingSphereConnection) {
Field field = ShardingSphereConnection.class.getDeclaredField("cachedConnections");
field.setAccessible(true);
- return (Multimap<String, Connection>) field.get(connectionAdapter);
+ return (Multimap<String, Connection>) field.get(shardingSphereConnection);
}
@Test
public void assertClose() throws SQLException {
- ShardingSphereConnection actual = createShardingSphereConnection();
- actual.close();
- assertTrue(actual.isClosed());
- assertTrue(getCachedConnections(actual).isEmpty());
+ connection.close();
+ assertTrue(connection.isClosed());
+ assertTrue(getCachedConnections(connection).isEmpty());
}
@Test
public void assertCloseShouldNotClearTransactionType() throws SQLException {
- ShardingSphereConnection actual = createShardingSphereConnection();
TransactionTypeHolder.set(TransactionType.XA);
- actual.close();
- assertTrue(actual.isClosed());
- assertTrue(getCachedConnections(actual).isEmpty());
+ connection.close();
+ assertTrue(connection.isClosed());
+ assertTrue(getCachedConnections(connection).isEmpty());
assertThat(TransactionTypeHolder.get(), is(TransactionType.XA));
}
-
- private ShardingSphereConnection createShardingSphereConnection() {
- ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- when(contextManager.getMetaDataContexts().getGlobalRuleMetaData().findSingleRule(TransactionRule.class)).thenReturn(Optional.empty());
- return new ShardingSphereConnection(DefaultSchema.LOGIC_NAME, contextManager);
- }
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/fixture/AbstractShardingSphereTransactionManagerFixture.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/fixture/AbstractShardingSphereTransactionManagerFixture.java
deleted file mode 100644
index 1592149..0000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/fixture/AbstractShardingSphereTransactionManagerFixture.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.driver.jdbc.core.fixture;
-
-import org.apache.shardingsphere.infra.database.type.DatabaseType;
-import org.apache.shardingsphere.transaction.core.ResourceDataSource;
-import org.apache.shardingsphere.transaction.core.TransactionOperationType;
-import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import org.apache.shardingsphere.transaction.spi.ShardingSphereTransactionManager;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Map;
-
-public abstract class AbstractShardingSphereTransactionManagerFixture implements ShardingSphereTransactionManager {
-
- private static final Collection<TransactionOperationType> INVOCATIONS = new LinkedList<>();
-
- private final Map<String, DataSource> dataSourceMap = new HashMap<>();
-
- /**
- * Get invocations.
- *
- * @return invocations
- */
- public static Collection<TransactionOperationType> getInvocations() {
- return INVOCATIONS;
- }
-
- @Override
- public final void init(final DatabaseType databaseType, final Collection<ResourceDataSource> resourceDataSources, final TransactionRule transactionRule) {
- for (ResourceDataSource each : resourceDataSources) {
- dataSourceMap.put(each.getOriginalName(), each.getDataSource());
- }
- }
-
- @Override
- public final boolean isInTransaction() {
- return INVOCATIONS.contains(TransactionOperationType.BEGIN);
- }
-
- @Override
- public final Connection getConnection(final String dataSourceName) throws SQLException {
- return dataSourceMap.get(dataSourceName).getConnection();
- }
-
- @Override
- public final void begin() {
- INVOCATIONS.add(TransactionOperationType.BEGIN);
- }
-
- @Override
- public final void commit() {
- INVOCATIONS.add(TransactionOperationType.COMMIT);
- }
-
- @Override
- public final void rollback() {
- INVOCATIONS.add(TransactionOperationType.ROLLBACK);
- }
-
- @Override
- public final void close() {
- }
-}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/fixture/BASEShardingSphereTransactionManagerFixture.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/fixture/BASEShardingSphereTransactionManagerFixture.java
deleted file mode 100644
index c31e05d..0000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/fixture/BASEShardingSphereTransactionManagerFixture.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.driver.jdbc.core.fixture;
-
-import org.apache.shardingsphere.transaction.core.TransactionType;
-
-public final class BASEShardingSphereTransactionManagerFixture extends AbstractShardingSphereTransactionManagerFixture {
-
- @Override
- public TransactionType getTransactionType() {
- return TransactionType.BASE;
- }
-}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/fixture/XAShardingSphereTransactionManagerFixture.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/fixture/XAShardingSphereTransactionManagerFixture.java
deleted file mode 100644
index 88952ad..0000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/fixture/XAShardingSphereTransactionManagerFixture.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.driver.jdbc.core.fixture;
-
-import org.apache.shardingsphere.transaction.core.TransactionType;
-
-public final class XAShardingSphereTransactionManagerFixture extends AbstractShardingSphereTransactionManagerFixture {
-
- @Override
- public TransactionType getTransactionType() {
- return TransactionType.XA;
- }
-}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/META-INF/services/org.apache.shardingsphere.transaction.spi.ShardingSphereTransactionManager b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/META-INF/services/org.apache.shardingsphere.transaction.spi.ShardingSphereTransactionManager
deleted file mode 100644
index eceedc9..0000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/resources/META-INF/services/org.apache.shardingsphere.transaction.spi.ShardingSphereTransactionManager
+++ /dev/null
@@ -1,19 +0,0 @@
-#
-# 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.
-#
-
-org.apache.shardingsphere.driver.jdbc.core.fixture.XAShardingSphereTransactionManagerFixture
-org.apache.shardingsphere.driver.jdbc.core.fixture.BASEShardingSphereTransactionManagerFixture