shardingsphere-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhangli...@apache.org
Subject [shardingsphere] branch master updated: Add more assertions in MetaDataChangedWatcherTest (#10765)
Date Fri, 11 Jun 2021 12:44:33 GMT
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 99a093d  Add more assertions in MetaDataChangedWatcherTest (#10765)
99a093d is described below

commit 99a093d484c4ad0665befbadf49a70b427fa87fc
Author: Da Xiang Huang <localhost80@foxmail.com>
AuthorDate: Fri Jun 11 20:43:59 2021 +0800

    Add more assertions in MetaDataChangedWatcherTest (#10765)
---
 .../watcher/MetaDataChangedWatcherTest.java        | 74 +++++++++++++++++++++-
 1 file changed, 72 insertions(+), 2 deletions(-)

diff --git a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/metadata/watcher/MetaDataChangedWatcherTest.java
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/metadata/watcher/MetaDataChangedWatcherTest.java
index c9cfad4..2df9369 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/metadata/watcher/MetaDataChangedWatcherTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/metadata/watcher/MetaDataChangedWatcherTest.java
@@ -25,13 +25,83 @@ import org.junit.Test;
 import java.util.Optional;
 
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 public final class MetaDataChangedWatcherTest {
     
     @Test
     public void assertCreateEventWithInvalidPath() {
-        DataChangedEvent dataChangedEvent = new DataChangedEvent("/metadata_invalid/sharding_db",
"encrypt_db", Type.UPDATED);
-        Optional<GovernanceEvent> actual = new MetaDataChangedWatcher().createGovernanceEvent(dataChangedEvent);
+        String key = "/metadata_invalid/sharding_db";
+        String value = "encrypt_db";
+        Optional<GovernanceEvent> actual = createEvent(key, value, Type.UPDATED);
+        assertFalse(actual.isPresent());
+        actual = createEvent(key, value, Type.ADDED);
+        assertFalse(actual.isPresent());
+        actual = createEvent(key, value, Type.DELETED);
+        assertFalse(actual.isPresent());
+        actual = createEvent(key, value, Type.IGNORED);
+        assertFalse(actual.isPresent());
+    }
+    
+    @Test
+    public void assertCreateAddedEvent() {
+        String key = "/metadata/sharding_db";
+        String value = "encrypt_db";
+        Optional<GovernanceEvent> actual = createEvent(key, value, Type.UPDATED);
+        assertTrue(actual.isPresent());
+        actual = createEvent(key, value, Type.ADDED);
+        assertTrue(actual.isPresent());
+        actual = createEvent(key, value, Type.IGNORED);
         assertFalse(actual.isPresent());
     }
+    
+    @Test
+    public void assertEmptyValue() {
+        String key = "/metadata/sharding_db/dataSources";
+        Optional<GovernanceEvent> actual = createEvent(key, null, Type.UPDATED);
+        assertFalse(actual.isPresent());
+    }
+    
+    @Test
+    public void assertCreateDeletedEvent() {
+        String key = "/metadata/sharding_db";
+        String value = "encrypt_db";
+        Optional<GovernanceEvent> actual = createEvent(key, value, Type.DELETED);
+        assertTrue(actual.isPresent());
+    }
+    
+    @Test
+    public void assertCreateDataSourceChangedEvent() {
+        String key = "/metadata/sharding_db/dataSources";
+        String value = "{}";
+        Optional<GovernanceEvent> actual = createEvent(key, value, Type.UPDATED);
+        assertTrue(actual.isPresent());
+    }
+    
+    @Test
+    public void assertCreateRuleChangedEvent() {
+        String key = "/metadata/sharding_db/rules";
+        Optional<GovernanceEvent> actual = createEvent(key, "[]", Type.UPDATED);
+        assertTrue(actual.isPresent());
+    }
+    
+    @Test
+    public void assertCreateCachedEvent() {
+        String key = "/metadata/sharding_db/rules/cache";
+        Optional<GovernanceEvent> actual = createEvent(key, "[]", Type.UPDATED);
+        assertTrue(actual.isPresent());
+    }
+    
+    @Test
+    public void assertCreateSchemaChangedEvent() {
+        String key = "/metadata/sharding_db/schema";
+        Optional<GovernanceEvent> actual = createEvent(key, "{}", Type.UPDATED);
+        assertTrue(actual.isPresent());
+    }
+    
+    private Optional<GovernanceEvent> createEvent(final String key, final String value,
final Type type) {
+        DataChangedEvent dataChangedEvent = new DataChangedEvent(key, value, type);
+        Optional<GovernanceEvent> actual = new MetaDataChangedWatcher().createGovernanceEvent(dataChangedEvent);
+        return actual;
+    }
 }

Mime
View raw message