use of io.netty.handler.codec.http.websocketx.CloseWebSocketFrame in project reactor-netty by reactor.
the class WebsocketTest method testCloseWebSocketFrameSentByClient.
@Test
void testCloseWebSocketFrameSentByClient() {
disposableServer = createServer().handle((req, res) -> res.sendWebsocket((in, out) -> out.sendString(Mono.just("echo")).sendObject(new CloseWebSocketFrame()))).bindNow();
Mono<Void> response = createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> out.sendObject(in.receiveFrames().doOnNext(WebSocketFrame::retain).then())).next();
StepVerifier.create(response).expectComplete().verify(Duration.ofSeconds(30));
}
use of io.netty.handler.codec.http.websocketx.CloseWebSocketFrame in project reactor-netty by reactor.
the class WebsocketTest method testIssue900_2.
@Test
void testIssue900_2() throws Exception {
AtomicReference<WebSocketCloseStatus> statusServer = new AtomicReference<>();
AtomicReference<String> incomingData = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
disposableServer = createServer().handle((req, res) -> res.sendWebsocket((in, out) -> {
in.receiveCloseStatus().doOnNext(o -> {
statusServer.set(o);
latch.countDown();
}).subscribe();
return out.sendObject(Flux.just(new TextWebSocketFrame("echo"), new CloseWebSocketFrame(1008, "something")).delayElements(Duration.ofMillis(100))).then(in.receiveFrames().doOnNext(o -> {
if (o instanceof TextWebSocketFrame) {
incomingData.set(((TextWebSocketFrame) o).text());
}
}).then());
})).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> out.sendObject(in.receiveFrames().doOnNext(WebSocketFrame::retain))).subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(incomingData.get()).isNotNull().isEqualTo("echo");
assertThat(statusServer.get()).isNotNull().isEqualTo(new WebSocketCloseStatus(1008, "something"));
}
use of io.netty.handler.codec.http.websocketx.CloseWebSocketFrame in project reactor-netty by reactor.
the class WebsocketTest method testIssue663_3.
@Test
void testIssue663_3() throws Exception {
AtomicBoolean incomingData = new AtomicBoolean();
CountDownLatch latch = new CountDownLatch(1);
disposableServer = createServer().handle((req, resp) -> resp.sendWebsocket((i, o) -> i.receiveFrames().then())).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> out.sendObject(Flux.just(new PingWebSocketFrame(), new CloseWebSocketFrame()).delayElements(Duration.ofMillis(100))).then(in.receiveFrames().doOnNext(f -> {
if (f instanceof PongWebSocketFrame) {
incomingData.set(true);
}
}).doOnComplete(latch::countDown).then())).subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(incomingData.get()).isTrue();
}
use of io.netty.handler.codec.http.websocketx.CloseWebSocketFrame 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);
}
use of io.netty.handler.codec.http.websocketx.CloseWebSocketFrame in project reactor-netty by reactor.
the class WebsocketTest method testIssue663_4.
@Test
void testIssue663_4() throws Exception {
AtomicBoolean incomingData = new AtomicBoolean();
CountDownLatch latch = new CountDownLatch(1);
disposableServer = createServer().handle((req, resp) -> resp.sendWebsocket((i, o) -> i.receiveFrames().then(), WebsocketServerSpec.builder().handlePing(true).build())).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> out.sendObject(Flux.just(new PingWebSocketFrame(), new CloseWebSocketFrame()).delayElements(Duration.ofMillis(100))).then(in.receiveFrames().doOnNext(f -> incomingData.set(true)).doOnComplete(latch::countDown).then())).subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(incomingData.get()).isFalse();
}
Aggregations