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 b74cf90  Add update from event test cases for 
DataSourceStatusRegistryService (#10430)
b74cf90 is described below

commit b74cf904835a97e43ae4ffa5a557c914a525957f
Author: Ahmed Elkholy <[email protected]>
AuthorDate: Sat May 22 08:10:25 2021 +0200

    Add update from event test cases for DataSourceStatusRegistryService 
(#10430)
    
    * Add update from event test cases for DataSourceStatusRegistryService
    
    * Update DataSourceStatusRegistryServiceTest.java
---
 .../state/DataSourceStatusRegistryServiceTest.java | 34 ++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git 
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryServiceTest.java
 
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryServiceTest.java
index 4894cb4..2f32e47 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryServiceTest.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/service/state/DataSourceStatusRegistryServiceTest.java
@@ -17,7 +17,11 @@
 
 package org.apache.shardingsphere.governance.core.registry.service.state;
 
+import org.apache.shardingsphere.governance.core.registry.RegistryCenterNode;
+import 
org.apache.shardingsphere.governance.core.registry.RegistryCenterNodeStatus;
 import 
org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
+import org.apache.shardingsphere.infra.rule.event.impl.DataSourceDisabledEvent;
+import org.apache.shardingsphere.infra.rule.event.impl.PrimaryDataSourceEvent;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -56,6 +60,32 @@ public final class DataSourceStatusRegistryServiceTest {
         verify(registryCenterRepository).getChildrenKeys(anyString());
         verify(registryCenterRepository).get(anyString());
     }
-    
-    // TODO add update assertions
+
+    @Test
+    public void assertUpdateDataSourceDisabledState() {
+        assertUpdateDataSourceState(true, 
RegistryCenterNodeStatus.DISABLED.toString());
+    }
+
+    @Test
+    public void assertUpdateDataSourceEnabledState() {
+        assertUpdateDataSourceState(false, "");
+    }
+
+    private void assertUpdateDataSourceState(final boolean isDisabled, final 
String value) {
+        String schemaName = "replica_query_db";
+        String dataSourceName = "replica_ds_0";
+        DataSourceDisabledEvent dataSourceDisabledEvent = new 
DataSourceDisabledEvent(schemaName, dataSourceName, isDisabled);
+        dataSourceStatusRegistryService.update(dataSourceDisabledEvent);
+        verify(registryCenterRepository).persist(new 
RegistryCenterNode().getDataSourcePath(schemaName, dataSourceName), value);
+    }
+
+    @Test
+    public void assertUpdatePrimaryDataSourceState() {
+        String schemaName = "replica_query_db";
+        String groupName = "group1";
+        String dataSourceName = "replica_ds_0";
+        PrimaryDataSourceEvent primaryDataSourceEvent = new 
PrimaryDataSourceEvent(schemaName, groupName, dataSourceName);
+        dataSourceStatusRegistryService.update(primaryDataSourceEvent);
+        verify(registryCenterRepository).persist(new 
RegistryCenterNode().getPrimaryDataSourcePath(schemaName, groupName), 
dataSourceName);
+    }
 }

Reply via email to