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/01 06:19:42 UTC

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #4531: Add unit test case for sharding-orchestration-center-apollo module #4451

kimmking commented on a change in pull request #4531: Add unit test case for sharding-orchestration-center-apollo module #4451
URL: https://github.com/apache/incubator-shardingsphere/pull/4531#discussion_r386080810
 
 

 ##########
 File path: sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-apollo/src/test/java/org/apache/shardingsphere/orchestration/center/instance/ApolloInstanceTest.java
 ##########
 @@ -82,4 +91,65 @@ public void onChange(final DataChangedEvent dataChangedEvent) {
         assertThat(changeEvent.getValue(), is("value3"));
         assertThat(changeEvent.getChangedType(), is(DataChangedEvent.ChangedType.UPDATED));
     }
+
+    @Test
+    @SneakyThrows
+    public void assertGetWithNonExistentKey() {
+        when(openApiWrapper.getValue(eq("test.nonExistentKey"))).thenReturn(null);
+        assertNull(configCenterRepository.get("/test/nonExistentKey"));
+    }
+
+    @Test
+    @SneakyThrows
+    public void assertUpdate() {
+        final SettableFuture<DataChangedEvent> future = SettableFuture.create();
+        configCenterRepository.watch("/test/children/1", new DataChangedEventListener() {
+
+            @Override
+            public void onChange(final DataChangedEvent dataChangedEvent) {
+                future.set(dataChangedEvent);
+            }
+        });
+        embeddedApollo.addOrModifyProperty("orchestration", "test.children.1", "newValue1");
+        DataChangedEvent changeEvent = future.get(5, TimeUnit.SECONDS);
+        assertThat(changeEvent.getKey(), is("/test/children/1"));
+        assertThat(changeEvent.getValue(), is("newValue1"));
+        assertThat(changeEvent.getChangedType(), is(DataChangedEvent.ChangedType.UPDATED));
+    }
+
+    @Test
+    @SneakyThrows
+    public void assertWatchDeletedChangedType() {
+        final SettableFuture<DataChangedEvent> future = SettableFuture.create();
+        configCenterRepository.watch("/test/children/1", new DataChangedEventListener() {
+
+            @Override
+            public void onChange(final DataChangedEvent dataChangedEvent) {
+                future.set(dataChangedEvent);
+            }
+        });
+        embeddedApollo.deleteProperty("orchestration", "test.children.1");
+        DataChangedEvent changeEvent = future.get(5, TimeUnit.SECONDS);
+        assertThat(changeEvent.getKey(), is("/test/children/1"));
+        assertNull(changeEvent.getValue());
+        assertThat(changeEvent.getChangedType(), is(DataChangedEvent.ChangedType.DELETED));
 
 Review comment:
   now we support delete?

----------------------------------------------------------------
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