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 f0d3762b1b5 Add more test cases on MetaDataLoaderTest (#38222)
f0d3762b1b5 is described below

commit f0d3762b1b59002954a7360fb72d78a0ef94504a
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Feb 26 21:55:19 2026 +0800

    Add more test cases on MetaDataLoaderTest (#38222)
    
    * Add more test cases on MetaDataLoaderTest
    
    * Add more test cases on BroadcastRuleChangedProcessorTest
---
 .../metadata/data/loader/MetaDataLoaderTest.java   | 28 +++++--
 .../changed/BroadcastRuleChangedProcessorTest.java | 87 ++++++++++++++++++++++
 2 files changed, 107 insertions(+), 8 deletions(-)

diff --git 
a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/data/loader/MetaDataLoaderTest.java
 
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/data/loader/MetaDataLoaderTest.java
index ef202760b64..f0e60a19844 100644
--- 
a/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/data/loader/MetaDataLoaderTest.java
+++ 
b/database/connector/core/src/test/java/org/apache/shardingsphere/database/connector/core/metadata/data/loader/MetaDataLoaderTest.java
@@ -35,6 +35,8 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Map;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
@@ -95,15 +97,25 @@ class MetaDataLoaderTest {
     }
     
     @Test
-    void assertLoadWhenInterrupted() throws SQLException {
+    void assertLoadWhenInterrupted() throws Exception {
         MetaDataLoaderMaterial material = new 
MetaDataLoaderMaterial(Collections.emptyList(), "foo_ds", 
mock(DataSource.class, RETURNS_DEEP_STUBS), databaseType, "foo_db");
-        Thread.currentThread().interrupt();
-        try {
-            Map<String, SchemaMetaData> actual = 
MetaDataLoader.load(Collections.singleton(material));
-            assertTrue(actual.isEmpty());
-            assertTrue(Thread.currentThread().isInterrupted());
-        } finally {
-            Thread.interrupted();
+        CountDownLatch latch = new CountDownLatch(1);
+        DialectMetaDataLoader dialectMetaDataLoader = 
mock(DialectMetaDataLoader.class);
+        when(dialectMetaDataLoader.getType()).thenReturn(databaseType);
+        
when(dialectMetaDataLoader.load(any(MetaDataLoaderMaterial.class))).thenAnswer(invocation
 -> {
+            latch.await(5L, TimeUnit.SECONDS);
+            return Collections.singleton(new SchemaMetaData("foo_db", 
Collections.emptyList()));
+        });
+        try (AutoCloseable ignored = 
registerDialectMetaDataLoader(dialectMetaDataLoader)) {
+            Thread.currentThread().interrupt();
+            try {
+                Map<String, SchemaMetaData> actual = 
MetaDataLoader.load(Collections.singleton(material));
+                assertTrue(actual.isEmpty());
+                assertTrue(Thread.currentThread().isInterrupted());
+            } finally {
+                Thread.interrupted();
+                latch.countDown();
+            }
         }
     }
     
diff --git 
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastRuleChangedProcessorTest.java
 
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastRuleChangedProcessorTest.java
new file mode 100644
index 00000000000..4c29bad837e
--- /dev/null
+++ 
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/changed/BroadcastRuleChangedProcessorTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.broadcast.rule.changed;
+
+import org.apache.shardingsphere.broadcast.config.BroadcastRuleConfiguration;
+import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
+import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.mode.spi.rule.RuleChangedItemType;
+import 
org.apache.shardingsphere.mode.spi.rule.RuleItemConfigurationChangedProcessor;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.LinkedList;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+class BroadcastRuleChangedProcessorTest {
+    
+    private final BroadcastRuleChangedProcessor processor = 
(BroadcastRuleChangedProcessor) TypedSPILoader.getService(
+            RuleItemConfigurationChangedProcessor.class, new 
RuleChangedItemType("broadcast", null));
+    
+    @Test
+    void assertSwapRuleItemConfiguration() {
+        assertThat(processor.swapRuleItemConfiguration("unused", "- 
foo_tbl").getTables(), is(Collections.singleton("foo_tbl")));
+    }
+    
+    @Test
+    void assertFindRuleConfigurationWhenRuleExists() {
+        BroadcastRuleConfiguration ruleConfig = 
mock(BroadcastRuleConfiguration.class);
+        
assertThat(processor.findRuleConfiguration(mockDatabaseWithRule(ruleConfig)), 
is(ruleConfig));
+    }
+    
+    private ShardingSphereDatabase mockDatabaseWithRule(final 
BroadcastRuleConfiguration ruleConfig) {
+        BroadcastRule rule = mock(BroadcastRule.class);
+        when(rule.getConfiguration()).thenReturn(ruleConfig);
+        ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
+        when(result.getRuleMetaData()).thenReturn(new 
RuleMetaData(Collections.singleton(rule)));
+        return result;
+    }
+    
+    @Test
+    void assertFindRuleConfigurationWhenRuleAbsent() {
+        
assertTrue(processor.findRuleConfiguration(mockDatabaseWithoutRule()).getTables().isEmpty());
+    }
+    
+    private ShardingSphereDatabase mockDatabaseWithoutRule() {
+        ShardingSphereDatabase result = mock(ShardingSphereDatabase.class);
+        when(result.getRuleMetaData()).thenReturn(new 
RuleMetaData(Collections.emptyList()));
+        return result;
+    }
+    
+    @Test
+    void assertChangeRuleItemConfiguration() {
+        BroadcastRuleConfiguration currentRuleConfig = new 
BroadcastRuleConfiguration(new LinkedList<>(Collections.singleton("foo_tbl")));
+        BroadcastRuleConfiguration toBeChangedItemConfig = new 
BroadcastRuleConfiguration(new LinkedList<>(Collections.singleton("bar_tbl")));
+        processor.changeRuleItemConfiguration("unused", currentRuleConfig, 
toBeChangedItemConfig);
+        assertThat(currentRuleConfig.getTables(), 
is(Collections.singletonList("bar_tbl")));
+    }
+    
+    @Test
+    void assertDropRuleItemConfiguration() {
+        BroadcastRuleConfiguration currentRuleConfig = new 
BroadcastRuleConfiguration(new LinkedList<>(Collections.singleton("foo_tbl")));
+        processor.dropRuleItemConfiguration("unused", currentRuleConfig);
+        assertTrue(currentRuleConfig.getTables().isEmpty());
+    }
+}

Reply via email to