Skip to content

Commit 025d616

Browse files
committed
Add close state
1 parent 0d39aae commit 025d616

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

cim-client-sdk/src/main/java/com/crossoverjie/cim/client/sdk/impl/ClientImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ public void close() {
219219
channel.close();
220220
channel = null;
221221
}
222+
super.setState(ClientState.State.Closed);
222223
this.routeManager.offLine(this.getAuth().getUserId());
223224
}
224225

cim-client-sdk/src/test/java/com/crossoverjie/cim/client/sdk/ClientTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,33 @@ public void offLineAndOnline() throws Exception {
365365
super.stopSingle();
366366
}
367367

368+
@Test
369+
public void testClose() throws Exception {
370+
super.starSingleServer();
371+
super.startRoute();
372+
String routeUrl = "http://localhost:8083";
373+
String cj = "crossoverJie";
374+
Long id = super.registerAccount(cj);
375+
var auth1 = ClientConfigurationData.Auth.builder()
376+
.userId(id)
377+
.userName(cj)
378+
.build();
379+
380+
Client client1 = Client.builder()
381+
.auth(auth1)
382+
.routeUrl(routeUrl)
383+
.build();
384+
TimeUnit.SECONDS.sleep(3);
385+
ClientState.State state = client1.getState();
386+
Awaitility.await().atMost(10, TimeUnit.SECONDS)
387+
.untilAsserted(() -> Assertions.assertEquals(ClientState.State.Ready, state));
388+
Optional<CIMServerResVO> serverInfo = client1.getServerInfo();
389+
Assertions.assertTrue(serverInfo.isPresent());
390+
System.out.println("client1 serverInfo = " + serverInfo.get());
391+
392+
client1.close();
393+
ClientState.State state1 = client1.getState();
394+
Assertions.assertEquals(ClientState.State.Closed, state1);
395+
}
396+
368397
}

0 commit comments

Comments
 (0)