use of io.netty.handler.codec.http.websocketx.WebSocketCloseStatus in project netty by netty.
the class WebSocketCloseStatusTest method testValidationDisabled.
@Test
public void testValidationDisabled() {
WebSocketCloseStatus status = new WebSocketCloseStatus(1006, "validation disabled", false);
assertEquals(1006, status.code());
assertEquals("validation disabled", status.reasonText());
}
use of io.netty.handler.codec.http.websocketx.WebSocketCloseStatus in project reactor-netty by reactor.
the class HttpServerTests method testCancelReceivingForWebSocketServer.
@Test
void testCancelReceivingForWebSocketServer() 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();
}).subscribe();
in.receive().take(1).subscribe();
return Mono.never();
})).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> {
in.receiveCloseStatus().doOnNext(o -> {
statusClient.set(o);
latch.countDown();
}).subscribe();
return out.sendString(Flux.interval(Duration.ofMillis(10)).map(l -> l + ""));
}).subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(statusClient.get()).isNotNull().isEqualTo(WebSocketCloseStatus.EMPTY);
assertThat(statusServer.get()).isNotNull().isEqualTo(WebSocketCloseStatus.ABNORMAL_CLOSURE);
}
use of io.netty.handler.codec.http.websocketx.WebSocketCloseStatus in project reactor-netty by reactor.
the class HttpServerTests method testNormalConnectionCloseForWebSocketServer.
@Test
void testNormalConnectionCloseForWebSocketServer() 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) -> out.sendClose(4404, "test").then(in.receiveCloseStatus().doOnNext(o -> {
statusClient.set(o);
latch.countDown();
}))).blockLast();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(statusClient.get()).isNotNull().isEqualTo(new WebSocketCloseStatus(4404, "test"));
assertThat(statusServer.get()).isNotNull().isEqualTo(new WebSocketCloseStatus(4404, "test"));
}
use of io.netty.handler.codec.http.websocketx.WebSocketCloseStatus in project reactor-netty by reactor.
the class HttpServerTests method testCancelReceivingForWebSocketClient.
@Test
void testCancelReceivingForWebSocketClient() 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();
}).subscribe();
return out.sendString(Flux.interval(Duration.ofMillis(10)).map(l -> l + ""));
})).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> {
in.receiveCloseStatus().doOnNext(o -> {
statusClient.set(o);
latch.countDown();
}).subscribe();
in.receive().take(1).subscribe();
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 HttpServerTests method testCancelConnectionCloseForWebSocketServer.
@Test
void testCancelConnectionCloseForWebSocketServer() 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();
}).subscribe();
in.withConnection(Connection::dispose);
return Mono.never();
})).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> {
in.receiveCloseStatus().doOnNext(o -> {
statusClient.set(o);
latch.countDown();
}).subscribe();
return Mono.never();
}).subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(statusClient.get()).isNotNull().isEqualTo(WebSocketCloseStatus.EMPTY);
assertThat(statusServer.get()).isNotNull().isEqualTo(WebSocketCloseStatus.ABNORMAL_CLOSURE);
}
Aggregations