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

zhangliang 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 a67df15e371 Replace H2DatabaseType with DatabaseType in 
H2MetaDataLoaderTest (#35333)
a67df15e371 is described below

commit a67df15e371d7d516d926d9e46828b3ff4e37c8a
Author: Liang Zhang <zhangli...@apache.org>
AuthorDate: Mon May 5 15:47:56 2025 +0800

    Replace H2DatabaseType with DatabaseType in H2MetaDataLoaderTest (#35333)
    
    * Replace H2DatabaseType with DatabaseType in H2MetaDataLoaderTest
    
    - Remove direct usage of H2DatabaseType class
    - Use DatabaseType interface with TypedSPILoader to get H2 database type- 
Update test cases to use the new DatabaseType instance
    
    * Replace H2DatabaseType with TypedSPILoader for DatabaseType
    
    - Use TypedSPILoader.getService(DatabaseType.class, "FIXTURE") instead of 
H2DatabaseType
    - This change improves code flexibility and decouples the sharding route 
engine from H2DatabaseType
---
 .../engine/fixture/ShardingRouteEngineFixtureBuilder.java      |  5 +++--
 .../database/h2/metadata/data/loader/H2MetaDataLoaderTest.java | 10 +++++++---
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRouteEngineFixtureBuilder.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRouteEngineFixtureBuilder.java
index f08ea964f75..0bc98622279 100644
--- 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRouteEngineFixtureBuilder.java
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/fixture/ShardingRouteEngineFixtureBuilder.java
@@ -23,10 +23,11 @@ import lombok.SneakyThrows;
 import org.apache.groovy.util.Maps;
 import 
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
 import 
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.database.h2.type.H2DatabaseType;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
 import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
 import 
org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableReferenceRuleConfiguration;
 import 
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
@@ -293,7 +294,7 @@ public final class ShardingRouteEngineFixtureBuilder {
      */
     public static SingleRule createSingleRule(final 
Collection<ShardingSphereRule> rules) {
         Map<String, DataSource> dataSourceMap = createDataSourceMap();
-        SingleRule result = new SingleRule(new SingleRuleConfiguration(), 
"foo_db", new H2DatabaseType(), dataSourceMap, rules);
+        SingleRule result = new SingleRule(new SingleRuleConfiguration(), 
"foo_db", TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), 
dataSourceMap, rules);
         
result.getAttributes().getAttribute(MutableDataNodeRuleAttribute.class).put(dataSourceMap.keySet().iterator().next(),
 "foo_db", "t_category");
         return result;
     }
diff --git 
a/infra/database/type/h2/src/test/java/org/apache/shardingsphere/infra/database/h2/metadata/data/loader/H2MetaDataLoaderTest.java
 
b/infra/database/type/h2/src/test/java/org/apache/shardingsphere/infra/database/h2/metadata/data/loader/H2MetaDataLoaderTest.java
index a445bfcc5ac..10ab86db12c 100644
--- 
a/infra/database/type/h2/src/test/java/org/apache/shardingsphere/infra/database/h2/metadata/data/loader/H2MetaDataLoaderTest.java
+++ 
b/infra/database/type/h2/src/test/java/org/apache/shardingsphere/infra/database/h2/metadata/data/loader/H2MetaDataLoaderTest.java
@@ -26,7 +26,6 @@ import 
org.apache.shardingsphere.infra.database.core.metadata.data.model.TableMe
 import 
org.apache.shardingsphere.infra.database.core.metadata.database.datatype.DataTypeRegistry;
 import 
org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.database.h2.type.H2DatabaseType;
 import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.junit.jupiter.api.Test;
 
@@ -48,6 +47,9 @@ import static org.mockito.Mockito.when;
 
 class H2MetaDataLoaderTest {
     
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "H2");
+    
+    @SuppressWarnings("JDBCResourceOpenedButNotSafelyClosed")
     @Test
     void assertLoadWithoutTables() throws SQLException {
         DataSource dataSource = mockDataSource();
@@ -69,9 +71,10 @@ class H2MetaDataLoaderTest {
                         + " INFORMATION_SCHEMA.INDEXES I ON 
C.TABLE_NAME=I.TABLE_NAME WHERE C.TABLE_CATALOG=? AND C.TABLE_SCHEMA=?")
                 .executeQuery()).thenReturn(generatedInfo);
         DataTypeRegistry.load(dataSource, "H2");
-        assertTableMetaDataMap(getDialectTableMetaDataLoader().load(new 
MetaDataLoaderMaterial(Collections.emptyList(), "foo_ds", dataSource, new 
H2DatabaseType(), "sharding_db")));
+        assertTableMetaDataMap(getDialectTableMetaDataLoader().load(new 
MetaDataLoaderMaterial(Collections.emptyList(), "foo_ds", dataSource, 
databaseType, "sharding_db")));
     }
     
+    @SuppressWarnings("JDBCResourceOpenedButNotSafelyClosed")
     @Test
     void assertLoadWithTables() throws SQLException {
         DataSource dataSource = mockDataSource();
@@ -94,9 +97,10 @@ class H2MetaDataLoaderTest {
                         + " RIGHT JOIN INFORMATION_SCHEMA.INDEXES I ON 
C.TABLE_NAME=I.TABLE_NAME WHERE C.TABLE_CATALOG=? AND C.TABLE_SCHEMA=? AND 
C.TABLE_NAME IN ('tbl')")
                 .executeQuery()).thenReturn(generatedInfo);
         DataTypeRegistry.load(dataSource, "H2");
-        assertTableMetaDataMap(getDialectTableMetaDataLoader().load(new 
MetaDataLoaderMaterial(Collections.singletonList("tbl"), "foo_ds", dataSource, 
new H2DatabaseType(), "sharding_db")));
+        assertTableMetaDataMap(getDialectTableMetaDataLoader().load(new 
MetaDataLoaderMaterial(Collections.singletonList("tbl"), "foo_ds", dataSource, 
databaseType, "sharding_db")));
     }
     
+    @SuppressWarnings("JDBCResourceOpenedButNotSafelyClosed")
     private DataSource mockDataSource() throws SQLException {
         DataSource result = mock(DataSource.class, RETURNS_DEEP_STUBS);
         ResultSet typeInfoResultSet = mockTypeInfoResultSet();

Reply via email to