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/02/27 13:48:30 UTC

[GitHub] [incubator-shardingsphere] haetao commented on a change in pull request #4498: Add Unit test case to NacosConfigInstanceTest

haetao commented on a change in pull request #4498: Add Unit test case to NacosConfigInstanceTest
URL: https://github.com/apache/incubator-shardingsphere/pull/4498#discussion_r385135842
 
 

 ##########
 File path: sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-nacos/src/test/java/org/apache/shardingsphere/orchestration/center/instance/NacosConfigInstanceTest.java
 ##########
 @@ -101,6 +103,68 @@ public void onChange(final DataChangedEvent dataChangedEvent) {
         nacosConfigCenterRepository.watch("/sharding/test", listener);
         Assert.assertEquals(expectValue, actualValue[0]);
     }
+
+    @Test
+    @SneakyThrows
+    public void assertGetWithNonExistentKey() {
+        when(configService.getConfig(eq("sharding.nonExistentKey"), eq(group), anyLong())).thenReturn(null);
+        Assert.assertEquals(null, nacosConfigCenterRepository.get("/sharding/nonExistentKey"));
+    }
+
+    @Test
+    @SneakyThrows
+    public void assertGetWhenThrowException() {
+        doThrow(NacosException.class).when(configService).getConfig(eq("sharding.test"), eq(group), anyLong());
+        Assert.assertEquals(null, nacosConfigCenterRepository.get("/sharding/test"));
+    }
+
+    @Test
+    @SneakyThrows
+    public void assertUpdate() {
+        String updatedValue = "newValue";
+        nacosConfigCenterRepository.persist("/sharding/test", updatedValue);
+        verify(configService).publishConfig("sharding.test", group, updatedValue);
+    }
+
+    @Test
+    @SneakyThrows
+    public void assertWatchUpdatedChangedType() {
+        final String expectValue = "expectValue";
+        final String[] actualValue = {null};
+        final DataChangedEvent.ChangedType[] actualType = {null};
+        doAnswer(AdditionalAnswers.answerVoid(getListenerAnswer(expectValue)))
+                .when(configService)
+                .addListener(anyString(), anyString(), any(Listener.class));
+        DataChangedEventListener listener = new DataChangedEventListener() {
+
+            @Override
+            public void onChange(final DataChangedEvent dataChangedEvent) {
+                actualValue[0] = dataChangedEvent.getValue();
+                actualType[0] = dataChangedEvent.getChangedType();
+            }
+        };
+        nacosConfigCenterRepository.watch("/sharding/test", listener);
+        Assert.assertEquals(expectValue, actualValue[0]);
+        Assert.assertEquals(DataChangedEvent.ChangedType.UPDATED, actualType[0]);
+    }
+
+    @Test
+    @SneakyThrows
+    public void assertWatchDeletedChangedType() {
+        final DataChangedEvent.ChangedType[] actualType = {null};
+        doAnswer(AdditionalAnswers.answerVoid(getListenerAnswer(null)))
 
 Review comment:
   ![image](https://user-images.githubusercontent.com/46469719/75450959-aec9e200-59aa-11ea-982d-20e2dc5e414a.png)
   'AdditionalAnswers' can not be used  'static import' to import.

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