This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 ab31b31 Remove dbcp2 dependency on transaction modules (#16010)
ab31b31 is described below
commit ab31b31ded275a7e82cc617182348a48ec2445b0
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Mar 11 23:10:47 2022 +0800
Remove dbcp2 dependency on transaction modules (#16010)
* Remove dbcp2 dependency on transaction modules
* Remove dbcp2 dependency on transaction modules
---
.../shardingsphere-transaction-core/pom.xml | 6 ++--
.../transaction/core/ResourceDataSourceTest.java | 12 +++----
.../pom.xml | 16 ++++------
...eataATShardingSphereTransactionManagerTest.java | 37 ++++------------------
.../src/test/resources/sql/undo_log.sql | 29 -----------------
.../shardingsphere-transaction-xa-core/pom.xml | 11 ++++---
.../DataSourcePropertyProviderLoaderTest.java | 4 +--
.../datasource/swapper/DataSourceSwapperTest.java | 36 +++------------------
8 files changed, 38 insertions(+), 113 deletions(-)
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/pom.xml
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/pom.xml
index 5404a2d..287abed 100644
---
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/pom.xml
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/pom.xml
@@ -40,8 +40,10 @@
</dependency>
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-dbcp2</artifactId>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-common</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
</dependency>
</dependencies>
</project>
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
index 7a5a9d8..f2375c6 100644
---
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/test/java/org/apache/shardingsphere/transaction/core/ResourceDataSourceTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.transaction.core;
-import org.apache.commons.dbcp2.BasicDataSource;
+import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
@@ -28,10 +28,10 @@ public final class ResourceDataSourceTest {
@Test
public void assertNewInstance() {
- ResourceDataSource testResourceDataSource = new
ResourceDataSource("sampleDataSource", new BasicDataSource());
- assertThat(testResourceDataSource.getOriginalName(),
is("sampleDataSource"));
- assertTrue(testResourceDataSource.getDataSource() instanceof
BasicDataSource);
-
assertTrue(testResourceDataSource.getUniqueResourceName().contains("resource"));
-
assertTrue(testResourceDataSource.getUniqueResourceName().contains("sampleDataSource"));
+ ResourceDataSource actual = new ResourceDataSource("fooDataSource",
new MockedDataSource());
+ assertThat(actual.getOriginalName(), is("fooDataSource"));
+ assertTrue(actual.getDataSource() instanceof MockedDataSource);
+ assertTrue(actual.getUniqueResourceName().startsWith("resource"));
+ assertTrue(actual.getUniqueResourceName().endsWith("fooDataSource"));
}
}
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/pom.xml
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/pom.xml
index b5aebed..8f0c014 100644
---
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/pom.xml
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/pom.xml
@@ -34,17 +34,15 @@
</dependency>
<dependency>
- <groupId>io.seata</groupId>
- <artifactId>seata-all</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-dbcp2</artifactId>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-common</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
+ <groupId>io.seata</groupId>
+ <artifactId>seata-all</artifactId>
</dependency>
</dependencies>
</project>
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/src/test/java/org/apache/shardingsphere/transaction/bas
[...]
index ea20865..0919df4 100644
---
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/src/test/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManagerTest.java
@@ -30,9 +30,9 @@ import io.seata.rm.datasource.ConnectionProxy;
import io.seata.rm.datasource.DataSourceProxy;
import io.seata.tm.api.GlobalTransactionContext;
import lombok.SneakyThrows;
-import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.shardingsphere.infra.database.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutorDataMap;
+import org.apache.shardingsphere.test.mock.MockedDataSource;
import
org.apache.shardingsphere.transaction.base.seata.at.fixture.MockSeataServer;
import
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
import org.apache.shardingsphere.transaction.core.ResourceDataSource;
@@ -43,14 +43,11 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
import javax.sql.DataSource;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
@@ -63,13 +60,10 @@ import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-@RunWith(MockitoJUnitRunner.class)
public final class SeataATShardingSphereTransactionManagerTest {
private static final MockSeataServer MOCK_SEATA_SERVER = new
MockSeataServer();
- private final DataSource dataSource = getDataSource();
-
private final SeataATShardingSphereTransactionManager
seataTransactionManager = new SeataATShardingSphereTransactionManager();
private final Queue<Object> requestQueue =
MOCK_SEATA_SERVER.getMessageHandler().getRequestQueue();
@@ -94,7 +88,8 @@ public final class
SeataATShardingSphereTransactionManagerTest {
@Before
public void setUp() {
TransactionRuleConfiguration transactionRuleConfiguration = new
TransactionRuleConfiguration("BASE", "Seata", new Properties());
-
seataTransactionManager.init(DatabaseTypeRegistry.getActualDatabaseType("MySQL"),
getResourceDataSources(), new TransactionRule(transactionRuleConfiguration));
+
seataTransactionManager.init(DatabaseTypeRegistry.getActualDatabaseType("MySQL"),
+ Collections.singletonList(new ResourceDataSource("foo_ds", new
MockedDataSource())), new TransactionRule(transactionRuleConfiguration));
}
@After
@@ -108,29 +103,17 @@ public final class
SeataATShardingSphereTransactionManagerTest {
responseQueue.clear();
}
- private DataSource getDataSource() {
- BasicDataSource result = new BasicDataSource();
-
result.setUrl("jdbc:h2:mem:demo_ds;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL");
- result.setUsername("sa");
- result.setPassword("");
- return result;
- }
-
- private Collection<ResourceDataSource> getResourceDataSources() {
- return Collections.singletonList(new ResourceDataSource("demo_ds",
dataSource));
- }
-
@Test
public void assertInit() {
Map<String, DataSource> actual = getDataSourceMap();
assertThat(actual.size(), is(1));
- assertThat(actual.get("demo_ds"), instanceOf(DataSourceProxy.class));
+ assertThat(actual.get("foo_ds"), instanceOf(DataSourceProxy.class));
assertThat(seataTransactionManager.getTransactionType(),
is(TransactionType.BASE));
}
@Test
public void assertGetConnection() throws SQLException {
- Connection actual = seataTransactionManager.getConnection("demo_ds");
+ Connection actual = seataTransactionManager.getConnection("foo_ds");
assertThat(actual, instanceOf(ConnectionProxy.class));
}
@@ -178,20 +161,14 @@ public final class
SeataATShardingSphereTransactionManagerTest {
private void assertResult() {
int requestQueueSize = requestQueue.size();
- if (requestQueueSize == 3) {
+ if (3 == requestQueueSize) {
assertThat(requestQueue.poll(),
instanceOf(RegisterRMRequest.class));
- if (requestQueueSize == 4) {
- assertThat(requestQueue.poll(),
instanceOf(RegisterRMRequest.class));
- }
assertThat(requestQueue.poll(),
instanceOf(RegisterTMRequest.class));
assertThat(requestQueue.poll(),
instanceOf(MergedWarpMessage.class));
}
int responseQueueSize = responseQueue.size();
- if (responseQueueSize == 3) {
+ if (3 == responseQueueSize) {
assertThat(responseQueue.poll(),
instanceOf(RegisterRMResponse.class));
- if (responseQueueSize == 4) {
- assertThat(responseQueue.poll(),
instanceOf(RegisterRMResponse.class));
- }
assertThat(responseQueue.poll(),
instanceOf(RegisterTMResponse.class));
assertThat(responseQueue.poll(),
instanceOf(MergeResultMessage.class));
}
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/src/test/resources/sql/undo_log.sql
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/src/test/resources/sql/undo_log.sql
deleted file mode 100644
index 967b8e5..0000000
---
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-base/shardingsphere-transaction-base-seata-at/src/test/resources/sql/undo_log.sql
+++ /dev/null
@@ -1,29 +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.
- */
-
-CREATE TABLE `undo_log` (
- `id` bigint(20) NOT NULL AUTO_INCREMENT,
- `branch_id` bigint(20) NOT NULL,
- `xid` varchar(100) NOT NULL,
- `rollback_info` longblob NOT NULL,
- `log_status` int(11) NOT NULL,
- `log_created` datetime NOT NULL,
- `log_modified` datetime NOT NULL,
- `ext` varchar(100) DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
-) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/pom.xml
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/pom.xml
index 57c0484..1528d08 100644
---
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/pom.xml
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/pom.xml
@@ -39,12 +39,15 @@
</dependency>
<dependency>
- <groupId>com.zaxxer</groupId>
- <artifactId>HikariCP</artifactId>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-test-common</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
</dependency>
+
<dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-dbcp2</artifactId>
+ <groupId>com.zaxxer</groupId>
+ <artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
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/datasource/swapper/DataSourcePropertyProviderLoaderTest.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/datasou
[...]
index ea98387..cac4d83 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/datasource/swapper/DataSourcePropertyProviderLoaderTest.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/datasource/swapper/DataSourcePropertyProviderLoaderTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.transaction.xa.jta.datasource.swapper;
import com.zaxxer.hikari.HikariDataSource;
-import org.apache.commons.dbcp2.BasicDataSource;
+import org.apache.shardingsphere.test.mock.MockedDataSource;
import
org.apache.shardingsphere.transaction.xa.jta.datasource.swapper.impl.DefaultDataSourcePropertyProvider;
import
org.apache.shardingsphere.transaction.xa.jta.datasource.swapper.impl.HikariCPPropertyProvider;
import org.junit.Test;
@@ -30,7 +30,7 @@ public final class DataSourcePropertyProviderLoaderTest {
@Test
public void assertGetProviderByDefault() {
- assertThat(DataSourcePropertyProviderLoader.getProvider(new
BasicDataSource()), instanceOf(DefaultDataSourcePropertyProvider.class));
+ assertThat(DataSourcePropertyProviderLoader.getProvider(new
MockedDataSource()), instanceOf(DefaultDataSourcePropertyProvider.class));
}
@Test
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/datasource/swapper/DataSourceSwapperTest.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/datasource/swapper/Dat
[...]
index 7f18b5c..4f91e4e 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/datasource/swapper/DataSourceSwapperTest.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/datasource/swapper/DataSourceSwapperTest.java
@@ -18,8 +18,7 @@
package org.apache.shardingsphere.transaction.xa.jta.datasource.swapper;
import com.google.common.collect.ImmutableList;
-import com.zaxxer.hikari.HikariDataSource;
-import org.apache.commons.dbcp2.BasicDataSource;
+import org.apache.shardingsphere.test.mock.MockedDataSource;
import
org.apache.shardingsphere.transaction.xa.jta.datasource.properties.XADataSourceDefinition;
import org.h2.jdbcx.JdbcDataSource;
import org.junit.Before;
@@ -28,7 +27,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import javax.sql.DataSource;
import javax.sql.XADataSource;
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -42,45 +40,21 @@ public final class DataSourceSwapperTest {
@Mock
private XADataSourceDefinition xaDataSourceDefinition;
- private DataSourceSwapper swapper;
-
@Before
public void before() {
when(xaDataSourceDefinition.getXADriverClassName()).thenReturn(ImmutableList.of("org.h2.jdbcx.JdbcDataSource"));
}
@Test
- public void assertSwapByDefaultProvider() {
- swapper = new DataSourceSwapper(xaDataSourceDefinition);
- assertResult(swapper.swap(createDBCPDataSource()));
- }
-
- private DataSource createDBCPDataSource() {
- BasicDataSource result = new BasicDataSource();
- result.setUrl("jdbc:mysql://localhost:3306/demo_ds");
- result.setUsername("root");
- result.setPassword("root");
- return result;
- }
-
- @Test
- public void assertSwapBySPIProvider() {
- swapper = new DataSourceSwapper(xaDataSourceDefinition);
- assertResult(swapper.swap(createHikariCPDataSource()));
- }
-
- private DataSource createHikariCPDataSource() {
- HikariDataSource result = new HikariDataSource();
- result.setJdbcUrl("jdbc:mysql://localhost:3306/demo_ds");
- result.setUsername("root");
- result.setPassword("root");
- return result;
+ public void assertSwap() {
+ DataSourceSwapper swapper = new
DataSourceSwapper(xaDataSourceDefinition);
+ assertResult(swapper.swap(new MockedDataSource()));
}
private void assertResult(final XADataSource xaDataSource) {
assertThat(xaDataSource, instanceOf(JdbcDataSource.class));
JdbcDataSource h2XADataSource = (JdbcDataSource) xaDataSource;
- assertThat(h2XADataSource.getUrl(),
is("jdbc:mysql://localhost:3306/demo_ds"));
+ assertThat(h2XADataSource.getUrl(),
is("jdbc:mock://127.0.0.1/foo_ds"));
assertThat(h2XADataSource.getUser(), is("root"));
assertThat(h2XADataSource.getPassword(), is("root"));
}