use of io.netty.handler.codec.http.websocketx.WebSocketCloseStatus in project reactor-netty by reactor.
the class HttpServerTests method testCancelConnectionCloseForWebSocketClient.
@Test
void testCancelConnectionCloseForWebSocketClient() throws Exception {
AtomicReference<WebSocketCloseStatus> statusServer = new AtomicReference<>();
AtomicReference<WebSocketCloseStatus> statusClient = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(2);
disposableServer = createServer().handle((req, resp) -> resp.sendWebsocket((in, out) -> in.receiveCloseStatus().doOnNext(o -> {
statusServer.set(o);
latch.countDown();
}).then())).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> {
in.receiveCloseStatus().doOnNext(o -> {
statusClient.set(o);
latch.countDown();
}).subscribe();
in.withConnection(Connection::dispose);
return Mono.never();
}).subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(statusClient.get()).isNotNull().isEqualTo(WebSocketCloseStatus.ABNORMAL_CLOSURE);
assertThat(statusServer.get()).isNotNull().isEqualTo(WebSocketCloseStatus.EMPTY);
}
use of io.netty.handler.codec.http.websocketx.WebSocketCloseStatus in project reactor-netty by reactor.
the class WebsocketTest method testIssue1485_CloseFrameSentByServer.
@Test
void testIssue1485_CloseFrameSentByServer() throws Exception {
AtomicReference<WebSocketCloseStatus> statusServer = new AtomicReference<>();
AtomicReference<WebSocketCloseStatus> statusClient = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(2);
disposableServer = createServer().handle((req, res) -> res.sendWebsocket((in, out) -> {
in.receiveCloseStatus().doOnNext(status -> {
statusServer.set(status);
latch.countDown();
}).subscribe();
return out.sendObject(new CloseWebSocketFrame()).then(in.receive().then());
})).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> {
in.receiveCloseStatus().doOnNext(status -> {
statusClient.set(status);
latch.countDown();
}).subscribe();
return in.receive();
}).blockLast(Duration.ofSeconds(5));
assertThat(latch.await(5, TimeUnit.SECONDS)).isTrue();
assertThat(statusClient.get()).isNotNull().isEqualTo(WebSocketCloseStatus.EMPTY);
assertThat(statusServer.get()).isNotNull().isEqualTo(WebSocketCloseStatus.EMPTY);
}
Aggregations