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/09/16 16:17:07 UTC

[shardingsphere] branch master updated: Add more test cases for StatusNode (#12506)

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 c7bf424  Add more test cases for StatusNode (#12506)
c7bf424 is described below

commit c7bf424ce87e0b9cd914636047089deee6f79ad6
Author: Liang Zhang <te...@163.com>
AuthorDate: Fri Sep 17 00:16:35 2021 +0800

    Add more test cases for StatusNode (#12506)
    
    * Remove StatusNode.PRIMARY_NODE
    
    * Add more test case for StatusNode
---
 .../registry/status/node/StatusNode.java            |  8 +++-----
 .../watcher/StorageNodeStateChangedWatcher.java     |  4 ++--
 .../registry/status/node/StatusNodeTest.java        | 21 ++++++++++++++++++---
 3 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java
index f0be277..e46f5f6 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNode.java
@@ -37,8 +37,6 @@ public final class StatusNode {
     
     private static final String STORAGE_NODE = "storage_nodes";
     
-    private static final String PRIMARY_NODE = "primarynodes";
-    
     private static final String PRIVILEGE_NODE = "privilegenode";
     
     /**
@@ -84,13 +82,13 @@ public final class StatusNode {
     }
     
     /**
-     * Get cluster schema.
+     * Find cluster schema.
      *
      * @param status storage node status
      * @param storageNodeFullPath storage node full path
-     * @return cluster schema
+     * @return found cluster schema
      */
-    public static Optional<ClusterSchema> getClusterSchema(final StorageNodeStatus status, final String storageNodeFullPath) {
+    public static Optional<ClusterSchema> findClusterSchema(final StorageNodeStatus status, final String storageNodeFullPath) {
         String prefix = String.join("/", "", ROOT_NODE, STORAGE_NODE, status.name().toLowerCase());
         return storageNodeFullPath.startsWith(prefix) ? Optional.of(new ClusterSchema(storageNodeFullPath.substring(storageNodeFullPath.lastIndexOf("/") + 1))) : Optional.empty();
     }
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java
index 3baa790..4745be0 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/watcher/StorageNodeStateChangedWatcher.java
@@ -47,11 +47,11 @@ public final class StorageNodeStateChangedWatcher implements GovernanceWatcher<G
     
     @Override
     public Optional<GovernanceEvent> createGovernanceEvent(final DataChangedEvent event) {
-        Optional<GovernanceEvent> primaryStateChangedEvent = StatusNode.getClusterSchema(
+        Optional<GovernanceEvent> primaryStateChangedEvent = StatusNode.findClusterSchema(
                 StorageNodeStatus.PRIMARY, event.getKey()).map(schema -> new PrimaryStateChangedEvent(schema, event.getValue()));
         if (primaryStateChangedEvent.isPresent()) {
             return primaryStateChangedEvent;
         }
-        return StatusNode.getClusterSchema(StorageNodeStatus.DISABLE, event.getKey()).map(schema -> new DisabledStateChangedEvent(schema, Type.ADDED == event.getType()));
+        return StatusNode.findClusterSchema(StorageNodeStatus.DISABLE, event.getKey()).map(schema -> new DisabledStateChangedEvent(schema, Type.ADDED == event.getType()));
     }
 }
diff --git a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java
index 85bd4bc..b95d241 100644
--- a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/status/node/StatusNodeTest.java
@@ -32,12 +32,27 @@ public final class StatusNodeTest {
     
     @Test
     public void assertGetComputeNodePath() {
-        assertThat(StatusNode.getComputeNodePath(ComputeNodeStatus.ONLINE, "testId"), is("/status/compute_nodes/online/testId"));
+        assertThat(StatusNode.getComputeNodePath(ComputeNodeStatus.CIRCUIT_BREAKER), is("/status/compute_nodes/circuit_breaker"));
     }
     
     @Test
-    public void assertGetClusterSchema() {
-        Optional<ClusterSchema> actual = StatusNode.getClusterSchema(StorageNodeStatus.DISABLE, "/status/storage_nodes/disable/replica_query_db.replica_ds_0");
+    public void assertGetComputeNodePathWithInstanceId() {
+        assertThat(StatusNode.getComputeNodePath(ComputeNodeStatus.ONLINE, "127.0.0.0@3307"), is("/status/compute_nodes/online/127.0.0.0@3307"));
+    }
+    
+    @Test
+    public void assertGetStorageNodePath() {
+        assertThat(StatusNode.getStorageNodePath(StorageNodeStatus.DISABLE), is("/status/storage_nodes/disable"));
+    }
+    
+    @Test
+    public void assertGetStorageNodePathWithSchema() {
+        assertThat(StatusNode.getStorageNodePath(StorageNodeStatus.PRIMARY, new ClusterSchema("replica_query_db.replica_ds_0")), is("/status/storage_nodes/primary/replica_query_db.replica_ds_0"));
+    }
+    
+    @Test
+    public void assertFindClusterSchema() {
+        Optional<ClusterSchema> actual = StatusNode.findClusterSchema(StorageNodeStatus.DISABLE, "/status/storage_nodes/disable/replica_query_db.replica_ds_0");
         assertTrue(actual.isPresent());
         assertThat(actual.get().getSchemaName(), is("replica_query_db"));
         assertThat(actual.get().getDataSourceName(), is("replica_ds_0"));