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/08/18 17:00:47 UTC

[shardingsphere] branch master updated: Remove dependencies of ShardingSphereDataSource.getDataSourceMap() and test cases (#11890)

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 dcc1d36  Remove dependencies of ShardingSphereDataSource.getDataSourceMap() and test cases (#11890)
dcc1d36 is described below

commit dcc1d366c8fe7fd4762c92784125bfa8e602fcc8
Author: Liang Zhang <te...@163.com>
AuthorDate: Thu Aug 19 00:59:59 2021 +0800

    Remove dependencies of ShardingSphereDataSource.getDataSourceMap() and test cases (#11890)
---
 .../datasource/ShardingSphereDataSourceTest.java    |  2 +-
 .../spring/boot/SpringBootJNDIDataSourceTest.java   | 11 ++++++-----
 .../spring/boot/SpringBootStarterTest.java          | 10 ++++++----
 .../shardingsphere/spring/SpringNamespaceTest.java  | 21 ++++++++++++---------
 4 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
index 1066b70..1364b5e 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
@@ -157,7 +157,7 @@ public final class ShardingSphereDataSourceTest {
         dataSourceMap.put("ds", dataSource);
         TransactionTypeHolder.set(TransactionType.XA);
         ShardingSphereDataSource shardingSphereDataSource = createShardingSphereDataSource(dataSourceMap);
-        assertThat(shardingSphereDataSource.getDataSourceMap().size(), is(1));
+        assertThat(shardingSphereDataSource.getContextManager().getMetaDataContexts().getMetaData(DefaultSchema.LOGIC_NAME).getResource().getDataSources().size(), is(1));
         ShardingSphereConnection connection = shardingSphereDataSource.getConnection();
         assertThat(connection.getDataSourceMap().size(), is(1));
     }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootJNDIDataSourceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootJNDIDataSourceTest.java
index 0288e12..8c47001 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootJNDIDataSourceTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootJNDIDataSourceTest.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.spring.boot;
 
 import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
+import org.apache.shardingsphere.infra.database.DefaultSchema;
 import org.apache.shardingsphere.spring.boot.fixture.TestJndiInitialContextFactory;
 import org.apache.shardingsphere.test.mock.MockedDataSource;
 import org.junit.BeforeClass;
@@ -54,10 +55,10 @@ public class SpringBootJNDIDataSourceTest {
     }
     
     @Test
-    public void assertDatasourceMap() {
-        Map<String, DataSource> dataSourceMap = dataSource.getDataSourceMap();
-        assertThat(dataSourceMap.size(), is(2));
-        assertTrue(dataSourceMap.containsKey("jndi0"));
-        assertTrue(dataSourceMap.containsKey("jndi1"));
+    public void assertDataSources() {
+        Map<String, DataSource> dataSources = dataSource.getContextManager().getMetaDataContexts().getMetaData(DefaultSchema.LOGIC_NAME).getResource().getDataSources();
+        assertThat(dataSources.size(), is(2));
+        assertTrue(dataSources.containsKey("jndi0"));
+        assertTrue(dataSources.containsKey("jndi1"));
     }
 }
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
index a703150..30154b4 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/test/java/org/apache/shardingsphere/spring/boot/SpringBootStarterTest.java
@@ -43,6 +43,7 @@ import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
 import javax.annotation.Resource;
+import javax.sql.DataSource;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -65,10 +66,11 @@ public class SpringBootStarterTest {
     private ShardingSphereDataSource dataSource;
     
     @Test
-    public void assertDataSourceMap() {
-        assertThat(dataSource.getDataSourceMap().size(), is(2));
-        assertTrue(dataSource.getDataSourceMap().containsKey("ds_0"));
-        assertTrue(dataSource.getDataSourceMap().containsKey("ds_1"));
+    public void assertDataSources() {
+        Map<String, DataSource> dataSources = dataSource.getContextManager().getMetaDataContexts().getMetaData(DefaultSchema.LOGIC_NAME).getResource().getDataSources();
+        assertThat(dataSources.size(), is(2));
+        assertTrue(dataSources.containsKey("ds_0"));
+        assertTrue(dataSources.containsKey("ds_1"));
     }
     
     @Test
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/SpringNamespaceTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/SpringNamespaceTest.java
index c0de402..368582d 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/SpringNamespaceTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-namespace/src/test/java/org/apache/shardingsphere/spring/SpringNamespaceTest.java
@@ -30,8 +30,10 @@ import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
 
 import javax.annotation.Resource;
+import javax.sql.DataSource;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Map;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertNotNull;
@@ -46,7 +48,7 @@ public final class SpringNamespaceTest extends AbstractJUnit4SpringContextTests
     
     @Test
     public void assertShardingSphereDataSource() {
-        assertDataSourceMap();
+        assertDataSources();
         Collection<ShardingSphereRule> rules = dataSource.getContextManager().getMetaDataContexts().getMetaData(DefaultSchema.LOGIC_NAME).getRuleMetaData().getRules();
         assertThat(rules.size(), is(4));
         for (ShardingSphereRule each : rules) {
@@ -60,14 +62,15 @@ public final class SpringNamespaceTest extends AbstractJUnit4SpringContextTests
         }
     }
     
-    private void assertDataSourceMap() {
-        assertThat(dataSource.getDataSourceMap().size(), is(6));
-        assertTrue(dataSource.getDataSourceMap().containsKey("ds_0_write"));
-        assertTrue(dataSource.getDataSourceMap().containsKey("ds_0_read_0"));
-        assertTrue(dataSource.getDataSourceMap().containsKey("ds_0_read_1"));
-        assertTrue(dataSource.getDataSourceMap().containsKey("ds_1_write"));
-        assertTrue(dataSource.getDataSourceMap().containsKey("ds_1_read_0"));
-        assertTrue(dataSource.getDataSourceMap().containsKey("ds_1_read_1"));
+    private void assertDataSources() {
+        Map<String, DataSource> dataSources = dataSource.getContextManager().getMetaDataContexts().getMetaData(DefaultSchema.LOGIC_NAME).getResource().getDataSources();
+        assertThat(dataSources.size(), is(6));
+        assertTrue(dataSources.containsKey("ds_0_write"));
+        assertTrue(dataSources.containsKey("ds_0_read_0"));
+        assertTrue(dataSources.containsKey("ds_0_read_1"));
+        assertTrue(dataSources.containsKey("ds_1_write"));
+        assertTrue(dataSources.containsKey("ds_1_read_0"));
+        assertTrue(dataSources.containsKey("ds_1_read_1"));
     }
     
     private void assertShardingRule(final ShardingRule rule) {