use of io.netty.handler.codec.http.websocketx.WebSocketCloseStatus in project reactor-netty by reactor.
the class WebsocketTest method testIssue900_1.
@Test
void testIssue900_1() throws Exception {
AtomicReference<WebSocketCloseStatus> statusClient = new AtomicReference<>();
disposableServer = createServer().handle((req, res) -> res.sendWebsocket((in, out) -> out.sendObject(in.receiveFrames().doOnNext(WebSocketFrame::retain)))).bindNow();
CountDownLatch latch = new CountDownLatch(1);
Flux<WebSocketFrame> response = createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> {
in.receiveCloseStatus().doOnNext(o -> {
statusClient.set(o);
latch.countDown();
}).subscribe();
return out.sendObject(Flux.just(new TextWebSocketFrame("echo"), new CloseWebSocketFrame(1008, "something"))).then().thenMany(in.receiveFrames());
});
StepVerifier.create(response).expectNextMatches(webSocketFrame -> webSocketFrame instanceof TextWebSocketFrame && "echo".equals(((TextWebSocketFrame) webSocketFrame).text())).expectComplete().verify(Duration.ofSeconds(30));
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(statusClient.get()).isNotNull().isEqualTo(new WebSocketCloseStatus(1008, "something"));
}
use of io.netty.handler.codec.http.websocketx.WebSocketCloseStatus in project reactor-netty by reactor.
the class WebsocketTest method testIssue1485_CloseFrameSentByClient.
@Test
void testIssue1485_CloseFrameSentByClient() 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 in.receive().then();
})).bindNow();
createClient(disposableServer.port()).websocket().uri("/").handle((in, out) -> {
in.receiveCloseStatus().doOnNext(status -> {
statusClient.set(status);
latch.countDown();
}).subscribe();
return out.sendObject(new CloseWebSocketFrame()).then(in.receive().then());
}).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.WebSocketCloseStatus in project netty by netty.
the class WebSocketCloseStatusTest method testUserDefinedStatuses.
@Test
public void testUserDefinedStatuses() {
// Given, when
WebSocketCloseStatus feedTimeot = new WebSocketCloseStatus(6033, "Feed timed out");
WebSocketCloseStatus untradablePrice = new WebSocketCloseStatus(6034, "Untradable price");
// Then
assertNotSame(feedTimeot, valueOf(6033));
assertEquals(feedTimeot.code(), 6033);
assertEquals(feedTimeot.reasonText(), "Feed timed out");
assertNotSame(untradablePrice, valueOf(6034));
assertEquals(untradablePrice.code(), 6034);
assertEquals(untradablePrice.reasonText(), "Untradable price");
}
use of io.netty.handler.codec.http.websocketx.WebSocketCloseStatus in project reactor-netty by reactor.
the class HttpServerTests method testNormalConnectionCloseForWebSocketClient.
@Test
void testNormalConnectionCloseForWebSocketClient() throws Exception {
Flux<String> flux = Flux.range(0, 100).map(n -> String.format("%010d", n));
AtomicReference<List<String>> receiver = new AtomicReference<>(new ArrayList<>());
AtomicReference<WebSocketCloseStatus> statusServer = new AtomicReference<>();
AtomicReference<WebSocketCloseStatus> statusClient = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(3);
List<String> test = flux.collectList().block();
assertThat(test).isNotNull();
disposableServer = createServer().handle((req, resp) -> resp.sendWebsocket((in, out) -> out.sendString(flux).then(out.sendClose(4404, "test")).then(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();
return in.receive().asString().doOnNext(s -> receiver.get().add(s)).doFinally(sig -> latch.countDown()).then(Mono.delay(Duration.ofMillis(500)));
}).blockLast();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(receiver.get()).containsAll(test);
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 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"));
}
Aggregations