You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/05/05 23:39:48 UTC

[shardingsphere] branch master updated: Refactor DataSourcePoolDestroyerTest and YamlDataSourcePropertiesSwapperTest (#25479)

This is an automated email from the ASF dual-hosted git repository.

panjuan 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 1d393a454da Refactor DataSourcePoolDestroyerTest and YamlDataSourcePropertiesSwapperTest (#25479)
1d393a454da is described below

commit 1d393a454da2420270f4762afc1ffcb60277937e
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat May 6 07:39:31 2023 +0800

    Refactor DataSourcePoolDestroyerTest and YamlDataSourcePropertiesSwapperTest (#25479)
---
 .../destroyer/DataSourcePoolDestroyerTest.java     | 22 +++++++---------------
 .../YamlDataSourcePropertiesSwapperTest.java       | 15 +++++++--------
 2 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyerTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyerTest.java
index 1a553b5f1cb..5afd0e07d26 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyerTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyerTest.java
@@ -17,42 +17,34 @@
 
 package org.apache.shardingsphere.infra.datasource.pool.destroyer;
 
-import com.zaxxer.hikari.HikariConfig;
-import com.zaxxer.hikari.HikariDataSource;
 import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
-import org.apache.shardingsphere.test.fixture.jdbc.MockedDriver;
 import org.awaitility.Awaitility;
 import org.junit.jupiter.api.Test;
 
+import javax.sql.DataSource;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.concurrent.TimeUnit;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
 
 class DataSourcePoolDestroyerTest {
     
     @Test
-    void assertAsyncDestroyWithoutAutoCloseable() {
-        new DataSourcePoolDestroyer(new MockedDataSource()).asyncDestroy();
+    void assertAsyncDestroyWithoutAutoCloseableDataSource() {
+        new DataSourcePoolDestroyer(mock(DataSource.class)).asyncDestroy();
     }
     
     @Test
-    void assertAsyncDestroyHikariDataSource() throws SQLException {
-        HikariDataSource dataSource = createHikariDataSource();
+    void assertAsyncDestroyWithAutoCloseableDataSource() throws SQLException {
+        MockedDataSource dataSource = new MockedDataSource();
         try (Connection ignored = dataSource.getConnection()) {
             new DataSourcePoolDestroyer(dataSource).asyncDestroy();
             assertFalse(dataSource.isClosed());
         }
-        Awaitility.await().atMost(2L, TimeUnit.SECONDS).pollInterval(10L, TimeUnit.MILLISECONDS).until(dataSource::isClosed);
+        Awaitility.await().atMost(1L, TimeUnit.SECONDS).pollInterval(10L, TimeUnit.MILLISECONDS).until(dataSource::isClosed);
         assertTrue(dataSource.isClosed());
     }
-    
-    private HikariDataSource createHikariDataSource() {
-        HikariConfig config = new HikariConfig();
-        config.setDriverClassName(MockedDriver.class.getName());
-        config.setJdbcUrl("mock:jdbc");
-        return new HikariDataSource(config);
-    }
 }
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/resource/YamlDataSourcePropertiesSwapperTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/resource/YamlDataSourcePropertiesSwapperTest.java
index fb0b82a7fce..ba4f3865e8c 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/resource/YamlDataSourcePropertiesSwapperTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/yaml/config/swapper/resource/YamlDataSourcePropertiesSwapperTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.infra.yaml.config.swapper.resource;
 
-import com.zaxxer.hikari.HikariDataSource;
 import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
 import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
 import org.junit.jupiter.api.Test;
@@ -38,12 +37,12 @@ class YamlDataSourcePropertiesSwapperTest {
     void assertSwapToDataSources() {
         Map<String, Map<String, Object>> yamlConfig = createYamlConfig();
         Map<String, DataSource> dataSources = swapper.swapToDataSources(yamlConfig);
-        HikariDataSource actual0 = (HikariDataSource) dataSources.get("ds_0");
-        assertThat(actual0.getJdbcUrl(), is("jdbc:mock://127.0.0.1/ds_0"));
+        MockedDataSource actual0 = (MockedDataSource) dataSources.get("ds_0");
+        assertThat(actual0.getUrl(), is("jdbc:mock://127.0.0.1/ds_0"));
         assertThat(actual0.getUsername(), is("root"));
         assertThat(actual0.getPassword(), is("root"));
-        HikariDataSource actual1 = (HikariDataSource) dataSources.get("ds_1");
-        assertThat(actual1.getJdbcUrl(), is("jdbc:mock://127.0.0.1/ds_1"));
+        MockedDataSource actual1 = (MockedDataSource) dataSources.get("ds_1");
+        assertThat(actual1.getUrl(), is("jdbc:mock://127.0.0.1/ds_1"));
         assertThat(actual1.getUsername(), is("root"));
         assertThat(actual1.getPassword(), is("root"));
     }
@@ -83,9 +82,9 @@ class YamlDataSourcePropertiesSwapperTest {
     }
     
     private Map<String, Object> createPropertyMap(final String name) {
-        Map<String, Object> result = new LinkedHashMap<>(5, 1);
-        result.put("dataSourceClassName", "com.zaxxer.hikari.HikariDataSource");
-        result.put("jdbcUrl", String.format("jdbc:mock://127.0.0.1/%s", name));
+        Map<String, Object> result = new LinkedHashMap<>(4, 1);
+        result.put("dataSourceClassName", MockedDataSource.class.getName());
+        result.put("url", String.format("jdbc:mock://127.0.0.1/%s", name));
         result.put("username", "root");
         result.put("password", "root");
         return result;