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/28 03:31:38 UTC

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

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

 ##########
 File path: sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-nacos/src/test/java/org/apache/shardingsphere/orchestration/center/instance/NacosConfigInstanceTest.java
 ##########
 @@ -99,7 +101,69 @@ public void onChange(final DataChangedEvent dataChangedEvent) {
             }
         };
         nacosConfigCenterRepository.watch("/sharding/test", listener);
-        Assert.assertEquals(expectValue, actualValue[0]);
+        assertEquals(expectValue, actualValue[0]);
+    }
+    
+    @Test
+    @SneakyThrows
+    public void assertGetWithNonExistentKey() {
+        when(configService.getConfig(eq("sharding.nonExistentKey"), eq(group), anyLong())).thenReturn(null);
+        assertEquals(null, nacosConfigCenterRepository.get("/sharding/nonExistentKey"));
+    }
+    
+    @Test
+    @SneakyThrows
+    public void assertGetWhenThrowException() {
+        doThrow(NacosException.class).when(configService).getConfig(eq("sharding.test"), eq(group), anyLong());
+        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);
+        assertEquals(expectValue, actualValue[0]);
+        assertEquals(DataChangedEvent.ChangedType.UPDATED, actualType[0]);
 
 Review comment:
   Please use assertThat instead of assertEquals

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