You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/09/08 14:54:24 UTC
(shardingsphere) branch master updated: Add more test cases on ZookeeperExceptionHandler (#32811)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 6322c1090db Add more test cases on ZookeeperExceptionHandler (#32811)
6322c1090db is described below
commit 6322c1090db7b40d1150ae699ece563ab0bbf5d3
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Sep 8 22:54:18 2024 +0800
Add more test cases on ZookeeperExceptionHandler (#32811)
---
.../handler/ZookeeperExceptionHandlerTest.java | 66 +++++++++++++++++-----
1 file changed, 51 insertions(+), 15 deletions(-)
diff --git a/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/handler/ZookeeperExceptionHandlerTest.java b/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/handler/ZookeeperExceptionHandlerTest.java
index 9fd418e7616..f3eab960a04 100644
--- a/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/handler/ZookeeperExceptionHandlerTest.java
+++ b/mode/type/cluster/repository/provider/zookeeper/src/test/java/org/apache/shardingsphere/mode/repository/cluster/zookeeper/handler/ZookeeperExceptionHandlerTest.java
@@ -18,27 +18,63 @@
package org.apache.shardingsphere.mode.repository.cluster.zookeeper.handler;
import org.apache.shardingsphere.mode.repository.cluster.exception.ClusterRepositoryPersistException;
+import org.apache.zookeeper.KeeperException.ConnectionLossException;
import org.apache.zookeeper.KeeperException.NoNodeException;
+import org.apache.zookeeper.KeeperException.NodeExistsException;
import org.junit.jupiter.api.Test;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.fail;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
class ZookeeperExceptionHandlerTest {
@Test
- void assertHandleException() {
- ZookeeperExceptionHandler.handleException(null);
- ZookeeperExceptionHandler.handleException(new NoNodeException(""));
- ZookeeperExceptionHandler.handleException(new Exception(new NoNodeException("")));
- try {
- ZookeeperExceptionHandler.handleException(new Exception(""));
- fail("must be failed handle new Exception().");
- // CHECKSTYLE:OFF
- } catch (final Exception ex) {
- // CHECKSTYLE:ON
- assertThat(ex, instanceOf(ClusterRepositoryPersistException.class));
- }
+ void assertHandleNullException() {
+ assertDoesNotThrow(() -> ZookeeperExceptionHandler.handleException(null));
+ }
+
+ @Test
+ void assertHandleConnectionLossException() {
+ assertDoesNotThrow(() -> ZookeeperExceptionHandler.handleException(new ConnectionLossException()));
+ }
+
+ @Test
+ void assertHandleConnectionLossExceptionWithCause() {
+ assertDoesNotThrow(() -> ZookeeperExceptionHandler.handleException(new Exception(new ConnectionLossException())));
+ }
+
+ @Test
+ void assertHandleNoNodeException() {
+ assertDoesNotThrow(() -> ZookeeperExceptionHandler.handleException(new NoNodeException()));
+ }
+
+ @Test
+ void assertHandleNoNodeExceptionWithCause() {
+ assertDoesNotThrow(() -> ZookeeperExceptionHandler.handleException(new Exception(new NoNodeException())));
+ }
+
+ @Test
+ void assertHandleNodeExistsException() {
+ assertDoesNotThrow(() -> ZookeeperExceptionHandler.handleException(new NodeExistsException()));
+ }
+
+ @Test
+ void assertHandleNodeExistsExceptionWithCause() {
+ assertDoesNotThrow(() -> ZookeeperExceptionHandler.handleException(new Exception(new NodeExistsException())));
+ }
+
+ @Test
+ void assertHandleInterruptedException() {
+ assertDoesNotThrow(() -> ZookeeperExceptionHandler.handleException(new InterruptedException()));
+ }
+
+ @Test
+ void assertHandleUnIgnoredException() {
+ assertThrows(ClusterRepositoryPersistException.class, () -> ZookeeperExceptionHandler.handleException(new Exception("")));
+ }
+
+ @Test
+ void assertHandleUnIgnoredExceptionWithCause() {
+ assertThrows(ClusterRepositoryPersistException.class, () -> ZookeeperExceptionHandler.handleException(new Exception(new RuntimeException(""))));
}
}