Skip to content

Commit 382788a

Browse files
committed
test: enhance assertions in EtcdClientTest for better clarity and reliability
1 parent 8f70ae3 commit 382788a

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

  • shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd

shenyu-registry/shenyu-registry-etcd/src/test/java/org/apache/shenyu/registry/etcd/EtcdClientTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,33 @@ public void etcdClientTest() {
6767

6868
when(client.getLeaseClient().grant(anyLong())).thenReturn(completableFuture);
6969
when(completableFuture.get()).thenReturn(leaseGrantResponse);
70-
Assertions.assertDoesNotThrow(() -> EtcdClient.builder().client(Client.builder().endpoints("url").build()).ttl(60L).timeout(3000L).build());
71-
7270
List<StreamObserver<LeaseKeepAliveResponse>> observerList = new ArrayList<>();
7371
doAnswer(invocation -> {
7472
observerList.add(invocation.getArgument(1));
7573
return lease;
7674
}).when(lease).keepAlive(anyLong(), any());
77-
Assertions.assertDoesNotThrow(() -> EtcdClient.builder().client(Client.builder().endpoints("url").build()).ttl(60L).timeout(3000L).build());
75+
76+
final EtcdClient etcdClient = Assertions.assertDoesNotThrow(() -> EtcdClient.builder()
77+
.client(Client.builder().endpoints("url").build())
78+
.ttl(60L)
79+
.timeout(3000L)
80+
.build());
81+
Assertions.assertNotNull(etcdClient);
82+
7883
final LeaseKeepAliveResponse leaseKeepAliveResponse = mock(LeaseKeepAliveResponse.class);
7984
observerList.forEach(streamObserver -> {
8085
streamObserver.onCompleted();
8186
streamObserver.onError(new ShenyuException("test"));
8287
streamObserver.onNext(leaseKeepAliveResponse);
8388
});
89+
etcdClient.close();
8490

8591
doThrow(new InterruptedException("error")).when(completableFuture).get();
86-
Assertions.assertThrows(ShenyuException.class, () -> EtcdClient.builder().client(Client.builder().endpoints("url").build()).ttl(60L).timeout(3000L).build());
92+
Assertions.assertThrows(ShenyuException.class, () -> EtcdClient.builder()
93+
.client(Client.builder().endpoints("url").build())
94+
.ttl(60L)
95+
.timeout(3000L)
96+
.build());
8797
} catch (Exception e) {
8898
throw new ShenyuException(e.getCause());
8999
}

0 commit comments

Comments
 (0)