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 fe3e3c5dd5d Replace MockedDatabaseType with TypedSPILoader in tests 
(#35322)
fe3e3c5dd5d is described below

commit fe3e3c5dd5d1e563fb2bab10df56887aa9b09732
Author: Liang Zhang <zhangli...@apache.org>
AuthorDate: Mon May 5 00:27:56 2025 +0800

    Replace MockedDatabaseType with TypedSPILoader in tests (#35322)
    
    - Remove usage of MockedDatabaseType from multiple test files
    - Use TypedSPILoader.getService(DatabaseType.class, "FIXTURE") to get 
DatabaseType instance
    - Update import statements and test logic to use the new DatabaseType 
instance
    - Improve test readability and reduce reliance on mock classes
---
 .../broadcast/rule/builder/BroadcastRuleBuilderTest.java       |  8 +++++---
 .../encrypt/rule/builder/EncryptRuleBuilderTest.java           | 10 +++++-----
 .../rule/builder/ReadwriteSplittingRuleBuilderTest.java        | 10 +++++-----
 .../service/ClusterMetaDataManagerPersistServiceTest.java      |  9 ++++++---
 .../ral/updatable/variable/SetDistVariableExecutorTest.java    |  5 ++---
 5 files changed, 23 insertions(+), 19 deletions(-)

diff --git 
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/builder/BroadcastRuleBuilderTest.java
 
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/builder/BroadcastRuleBuilderTest.java
index c579d97a638..ecb1400e5f8 100644
--- 
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/builder/BroadcastRuleBuilderTest.java
+++ 
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/builder/BroadcastRuleBuilderTest.java
@@ -19,11 +19,12 @@ package org.apache.shardingsphere.broadcast.rule.builder;
 
 import org.apache.shardingsphere.broadcast.config.BroadcastRuleConfiguration;
 import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
 import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
 import 
org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
 import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
-import org.apache.shardingsphere.test.fixture.database.MockedDatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.junit.jupiter.api.Test;
 
 import java.util.Collections;
@@ -34,12 +35,13 @@ import static org.mockito.Mockito.mock;
 
 class BroadcastRuleBuilderTest {
     
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+    
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test
     void assertBuild() {
         BroadcastRuleConfiguration ruleConfig = 
mock(BroadcastRuleConfiguration.class);
         DatabaseRuleBuilder builder = 
OrderedSPILoader.getServices(DatabaseRuleBuilder.class, 
Collections.singleton(ruleConfig)).get(ruleConfig);
-        assertThat(builder.build(ruleConfig, "", new MockedDatabaseType(), 
mock(ResourceMetaData.class), Collections.emptyList(), 
mock(ComputeNodeInstanceContext.class)),
-                instanceOf(BroadcastRule.class));
+        assertThat(builder.build(ruleConfig, "", databaseType, 
mock(ResourceMetaData.class), Collections.emptyList(), 
mock(ComputeNodeInstanceContext.class)), instanceOf(BroadcastRule.class));
     }
 }
diff --git 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
index 14aef75e89a..fb5b0a5e0f8 100644
--- 
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
+++ 
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rule/builder/EncryptRuleBuilderTest.java
@@ -19,11 +19,10 @@ package org.apache.shardingsphere.encrypt.rule.builder;
 
 import org.apache.shardingsphere.encrypt.config.EncryptRuleConfiguration;
 import org.apache.shardingsphere.encrypt.rule.EncryptRule;
-import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
-import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
 import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
-import org.apache.shardingsphere.test.fixture.database.MockedDatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import org.junit.jupiter.api.Test;
 
 import java.util.Collections;
@@ -34,12 +33,13 @@ import static org.mockito.Mockito.mock;
 
 class EncryptRuleBuilderTest {
     
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+    
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test
     void assertBuild() {
         EncryptRuleConfiguration ruleConfig = 
mock(EncryptRuleConfiguration.class);
         DatabaseRuleBuilder builder = 
OrderedSPILoader.getServices(DatabaseRuleBuilder.class, 
Collections.singleton(ruleConfig)).get(ruleConfig);
-        assertThat(builder.build(ruleConfig, "", new MockedDatabaseType(), 
mock(ResourceMetaData.class), Collections.emptyList(), 
mock(ComputeNodeInstanceContext.class)),
-                instanceOf(EncryptRule.class));
+        assertThat(builder.build(ruleConfig, "", databaseType, mock(), 
Collections.emptyList(), mock()), instanceOf(EncryptRule.class));
     }
 }
diff --git 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
index 394312a9387..28ca3b8e6ff 100644
--- 
a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
+++ 
b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/builder/ReadwriteSplittingRuleBuilderTest.java
@@ -17,14 +17,13 @@
 
 package org.apache.shardingsphere.readwritesplitting.rule.builder;
 
-import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
-import 
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.rule.builder.database.DatabaseRuleBuilder;
 import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.readwritesplitting.config.ReadwriteSplittingRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.config.rule.ReadwriteSplittingDataSourceGroupRuleConfiguration;
 import 
org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingRule;
-import org.apache.shardingsphere.test.fixture.database.MockedDatabaseType;
 import org.junit.jupiter.api.Test;
 
 import java.util.Collections;
@@ -35,13 +34,14 @@ import static org.mockito.Mockito.mock;
 
 class ReadwriteSplittingRuleBuilderTest {
     
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+    
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Test
     void assertBuild() {
         ReadwriteSplittingRuleConfiguration ruleConfig = new 
ReadwriteSplittingRuleConfiguration(Collections.singleton(
                 new ReadwriteSplittingDataSourceGroupRuleConfiguration("name", 
"writeDataSourceName", Collections.singletonList("readDataSourceName"), 
"loadBalancerName")), Collections.emptyMap());
         DatabaseRuleBuilder builder = 
OrderedSPILoader.getServices(DatabaseRuleBuilder.class, 
Collections.singleton(ruleConfig)).get(ruleConfig);
-        assertThat(builder.build(ruleConfig, "",
-                new MockedDatabaseType(), mock(ResourceMetaData.class), 
Collections.emptyList(), mock(ComputeNodeInstanceContext.class)), 
instanceOf(ReadwriteSplittingRule.class));
+        assertThat(builder.build(ruleConfig, "", databaseType, mock(), 
Collections.emptyList(), mock()), instanceOf(ReadwriteSplittingRule.class));
     }
 }
diff --git 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistServiceTest.java
 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistServiceTest.java
index 6eb754e232c..52863d49ee1 100644
--- 
a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistServiceTest.java
+++ 
b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistServiceTest.java
@@ -19,10 +19,12 @@ package 
org.apache.shardingsphere.mode.manager.cluster.persist.service;
 
 import lombok.SneakyThrows;
 import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 import 
org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.database.ClusterDatabaseListenerCoordinatorType;
 import 
org.apache.shardingsphere.mode.manager.cluster.persist.coordinator.database.ClusterDatabaseListenerPersistCoordinator;
 import org.apache.shardingsphere.mode.metadata.manager.MetaDataContextManager;
@@ -30,7 +32,6 @@ import 
org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade;
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
 import org.apache.shardingsphere.single.config.SingleRuleConfiguration;
 import org.apache.shardingsphere.single.rule.SingleRule;
-import org.apache.shardingsphere.test.fixture.database.MockedDatabaseType;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
@@ -54,6 +55,8 @@ import static org.mockito.Mockito.when;
 @ExtendWith(MockitoExtension.class)
 class ClusterMetaDataManagerPersistServiceTest {
     
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+    
     private ClusterMetaDataManagerPersistService metaDataManagerPersistService;
     
     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -129,8 +132,8 @@ class ClusterMetaDataManagerPersistServiceTest {
     @Disabled
     void assertAlterRuleConfiguration() {
         RuleConfiguration ruleConfig = new SingleRuleConfiguration();
-        
when(metaDataContextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getProtocolType()).thenReturn(new
 MockedDatabaseType());
-        metaDataManagerPersistService.alterRuleConfiguration(new 
ShardingSphereDatabase("foo_db", new MockedDatabaseType(), mock(), mock(), 
Collections.emptyList()), ruleConfig);
+        
when(metaDataContextManager.getMetaDataContexts().getMetaData().getDatabase("foo_db").getProtocolType()).thenReturn(databaseType);
+        metaDataManagerPersistService.alterRuleConfiguration(new 
ShardingSphereDatabase("foo_db", databaseType, mock(), mock(), 
Collections.emptyList()), ruleConfig);
         
verify(metaDataPersistFacade.getDatabaseRuleService()).persist("foo_db", 
Collections.singleton(ruleConfig));
     }
     
diff --git 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/variable/SetDistVariableExecutorTest.java
 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/variable/SetDistVariableExecutorTest.java
index 4b5310d765e..095026e7bfe 100644
--- 
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/variable/SetDistVariableExecutorTest.java
+++ 
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/variable/SetDistVariableExecutorTest.java
@@ -21,6 +21,7 @@ import 
org.apache.shardingsphere.distsql.statement.ral.updatable.SetDistVariable
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
 import 
org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey;
+import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.exception.kernel.syntax.InvalidVariableValueException;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstance;
 import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
@@ -34,7 +35,6 @@ import 
org.apache.shardingsphere.mode.metadata.MetaDataContexts;
 import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistFacade;
 import 
org.apache.shardingsphere.mode.metadata.persist.config.global.PropertiesPersistService;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.test.fixture.database.MockedDatabaseType;
 import org.apache.shardingsphere.test.mock.AutoMockExtension;
 import org.apache.shardingsphere.test.mock.StaticMockSettings;
 import org.junit.jupiter.api.Test;
@@ -43,7 +43,6 @@ import org.slf4j.event.Level;
 
 import java.sql.SQLException;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -84,7 +83,7 @@ class SetDistVariableExecutorTest {
         executor.executeUpdate(statement, contextManager);
         Object actualValue = 
contextManager.getMetaDataContexts().getMetaData().getProps().getProps().get("proxy-frontend-database-protocol-type");
         assertThat(actualValue.toString(), is("FIXTURE"));
-        
assertThat(contextManager.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE),
 instanceOf(MockedDatabaseType.class));
+        assertThat(((DatabaseType) 
contextManager.getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.PROXY_FRONTEND_DATABASE_PROTOCOL_TYPE)).getType(),
 is("FIXTURE"));
     }
     
     @Test

Reply via email to