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 1c5251cfe2e Refactor ComputeNodePersistService.loadInstanceLabels() as 
private (#34304)
1c5251cfe2e is described below

commit 1c5251cfe2ed42b1977143a79b49dd3ec849d8be
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Jan 11 00:23:25 2025 +0800

    Refactor ComputeNodePersistService.loadInstanceLabels() as private (#34304)
---
 .../service/unified/ComputeNodePersistService.java    | 19 +++++++------------
 .../unified/ComputeNodePersistServiceTest.java        | 15 ---------------
 2 files changed, 7 insertions(+), 27 deletions(-)

diff --git 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/unified/ComputeNodePersistService.java
 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/unified/ComputeNodePersistService.java
index bdc19463920..b72f0f03167 100644
--- 
a/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/unified/ComputeNodePersistService.java
+++ 
b/mode/core/src/main/java/org/apache/shardingsphere/mode/persist/service/unified/ComputeNodePersistService.java
@@ -34,6 +34,7 @@ import org.apache.shardingsphere.mode.spi.PersistRepository;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.LinkedList;
 import java.util.Objects;
 import java.util.Optional;
@@ -83,18 +84,6 @@ public final class ComputeNodePersistService {
         
repository.persistEphemeral(ComputeNodePath.getWorkerIdPath(instanceId), 
String.valueOf(workerId));
     }
     
-    /**
-     * Load instance labels.
-     *
-     * @param instanceId instance ID
-     * @return labels
-     */
-    @SuppressWarnings("unchecked")
-    public Collection<String> loadInstanceLabels(final String instanceId) {
-        String yamlContent = 
repository.query(ComputeNodePath.getLabelsPath(instanceId));
-        return Strings.isNullOrEmpty(yamlContent) ? new LinkedList<>() : 
YamlEngine.unmarshal(yamlContent, Collection.class);
-    }
-    
     /**
      * Load compute node state.
      *
@@ -157,6 +146,12 @@ public final class ComputeNodePersistService {
         return result;
     }
     
+    @SuppressWarnings("unchecked")
+    private Collection<String> loadInstanceLabels(final String instanceId) {
+        String yamlContent = 
repository.query(ComputeNodePath.getLabelsPath(instanceId));
+        return Strings.isNullOrEmpty(yamlContent) ? Collections.emptyList() : 
YamlEngine.unmarshal(yamlContent, Collection.class);
+    }
+    
     /**
      * Get assigned worker IDs.
      *
diff --git 
a/mode/core/src/test/java/org/apache/shardingsphere/mode/persist/service/unified/ComputeNodePersistServiceTest.java
 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/persist/service/unified/ComputeNodePersistServiceTest.java
index 0dc2a8d964d..50c73be6236 100644
--- 
a/mode/core/src/test/java/org/apache/shardingsphere/mode/persist/service/unified/ComputeNodePersistServiceTest.java
+++ 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/persist/service/unified/ComputeNodePersistServiceTest.java
@@ -39,7 +39,6 @@ import java.util.Optional;
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.verify;
@@ -82,20 +81,6 @@ class ComputeNodePersistServiceTest {
         
verify(repository).persistEphemeral("/nodes/compute_nodes/worker_id/foo_instance_id",
 String.valueOf(100));
     }
     
-    @Test
-    void assertLoadEmptyInstanceLabels() {
-        String instanceId = new ProxyInstanceMetaData("foo_instance_id", 
3307).getId();
-        
when(repository.query("/nodes/compute_nodes/labels/foo_instance_id")).thenReturn("");
-        
assertTrue(computeNodePersistService.loadInstanceLabels(instanceId).isEmpty());
-    }
-    
-    @Test
-    void assertLoadInstanceLabels() {
-        String instanceId = new ProxyInstanceMetaData("foo_instance_id", 
3307).getId();
-        
when(repository.query("/nodes/compute_nodes/labels/foo_instance_id")).thenReturn("{xxx:xxx}");
-        
assertFalse(computeNodePersistService.loadInstanceLabels(instanceId).isEmpty());
-    }
-    
     @Test
     void assertLoadComputeNodeState() {
         String instanceId = new ProxyInstanceMetaData("foo_instance_id", 
3307).getId();

Reply via email to