diff --git a/sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-nacos/src/test/java/org/apache/shardingsphere/orchestration/center/instance/NacosCenterRepositoryTest.java b/sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-nacos/src/test/java/org/apache/shardingsphere/orchestration/center/instance/NacosCenterRepositoryTest.java index 8cdab8dd66b5d2cb39069c598dedfb41462bde9b..44089895fa5895a65bed427e11c1bf651b4fa6b2 100644 --- a/sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-nacos/src/test/java/org/apache/shardingsphere/orchestration/center/instance/NacosCenterRepositoryTest.java +++ b/sharding-orchestration/sharding-orchestration-center/sharding-orchestration-center-nacos/src/test/java/org/apache/shardingsphere/orchestration/center/instance/NacosCenterRepositoryTest.java @@ -36,6 +36,7 @@ import java.util.Properties; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertNotNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; @@ -144,6 +145,48 @@ public final class NacosCenterRepositoryTest { verify(configService).removeConfig("sharding.test", group); } + @SneakyThrows + @Test + public void assertDeleteWhenThrowException() { + when(configService.getConfig(eq("sharding.test"), eq(group), anyLong())).thenReturn("value"); + doThrow(NacosException.class).when(configService).removeConfig(eq("sharding.test"), eq(group)); + REPOSITORY.delete("/sharding/test"); + assertNotNull(REPOSITORY.get("/sharding/test")); + } + + @SneakyThrows + @Test + public void assertWatchWhenThrowException() { + final ChangedType[] actualType = {null}; + doThrow(NacosException.class) + .when(configService) + .addListener(anyString(), anyString(), any(Listener.class)); + DataChangedEventListener listener = dataChangedEvent -> actualType[0] = dataChangedEvent.getChangedType(); + REPOSITORY.watch("/sharding/test", listener); + assertNull(actualType[0]); + } + + @Test + @SneakyThrows + public void assertPersistWhenThrowException() { + String value = "value"; + doThrow(NacosException.class).when(configService).publishConfig(eq("sharding.test"), eq(group), eq(value)); + REPOSITORY.persist("/sharding/test", value); + assertNull(REPOSITORY.get("/sharding/test")); + } + + @Test + public void assertProperties() { + Properties properties = new Properties(); + REPOSITORY.setProperties(properties); + assertThat(REPOSITORY.getProperties(), is(properties)); + } + + @Test + public void assertGetChildrenKeys() { + assertNull(REPOSITORY.getChildrenKeys("/sharding/test")); + } + private VoidAnswer3 getListenerAnswer(final String expectValue) { return (VoidAnswer3) (dataId, group, listener) -> listener.receiveConfigInfo(expectValue); }