You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/03/04 16:07:36 UTC

[GitHub] [incubator-shardingsphere] terrymanu commented on a change in pull request #4599: add unit tests for zookeeper orchestration center

terrymanu commented on a change in pull request #4599: add unit tests for zookeeper orchestration center
URL: https://github.com/apache/incubator-shardingsphere/pull/4599#discussion_r387768015
 
 

 ##########
 File path: sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-zookeeper-curator/src/test/java/org/apache/shardingsphere/orchestration/center/instance/CuratorZookeeperInstanceTest.java
 ##########
 @@ -67,4 +83,114 @@ public void assertGetChildrenKeys() {
         List<String> childrenKeys = curatorZookeeperInstance.getChildrenKeys("/test/children");
         assertThat(childrenKeys.size(), is(3));
     }
+    
+    @Test
+    @SneakyThrows
+    public void assertWatchUpdatedChangedType() {
+        curatorZookeeperInstance.persist("/test/children/1", "value1");
+        final SettableFuture<DataChangedEvent> future = SettableFuture.create();
+        curatorZookeeperInstance.watch("/test/children", dataChangedEvent -> future.set(dataChangedEvent));
+        curatorZookeeperInstance.persist("/test/children/1", "value2");
+        DataChangedEvent dataChangedEvent = future.get(5, TimeUnit.SECONDS);
+        assertNotNull(dataChangedEvent);
+        assertThat(dataChangedEvent.getChangedType(), is(DataChangedEvent.ChangedType.UPDATED));
+        assertThat(dataChangedEvent.getKey(), is("/test/children/1"));
+        assertThat(dataChangedEvent.getValue(), is("value2"));
+        assertThat(curatorZookeeperInstance.get("/test/children/1"), is("value2"));
+    }
+    
+    @Test
+    @SneakyThrows
+    public void assertWatchDeletedChangedType() {
+        curatorZookeeperInstance.persist("/test/children/5", "value5");
+        final SettableFuture<DataChangedEvent> future = SettableFuture.create();
+        curatorZookeeperInstance.watch("/test/children/5", dataChangedEvent -> future.set(dataChangedEvent));
+        client.delete().forPath("/test/children/5");
+        DataChangedEvent dataChangedEvent = future.get(5, TimeUnit.SECONDS);
+        assertNotNull(dataChangedEvent);
+        assertThat(dataChangedEvent.getChangedType(), is(DataChangedEvent.ChangedType.DELETED));
+        assertThat(dataChangedEvent.getKey(), is("/test/children/5"));
+        assertThat(dataChangedEvent.getValue(), is("value5"));
+    }
+    
+    @Test
+    @SneakyThrows
 
 Review comment:
   Just throw exception from method signature, @SneakyThrows should use only in the situation for exception never occur
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services