@Test public void echo() throws Exception { int count = 100; Flux<String> input = Flux.range(1, count).map(index -> "msg-" + index); ReplayProcessor<Object> output = ReplayProcessor.create(count); this.client.execute(getUrl("/echo"), session -> session .send(input.map(session::textMessage)) .thenMany(session.receive().take(count).map(WebSocketMessage::getPayloadAsText)) .subscribeWith(output) .then()) .block(TIMEOUT); assertEquals(input.collectList().block(TIMEOUT), output.collectList().block(TIMEOUT)); }
.take(count) .subscribeWith(output) .then())) .blockLast(Duration.ofSeconds(30));
private void doTestConnectionAliveWhenTransformationErrors(BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> handler, Flux<String> expectation, int count) { httpServer = HttpServer.create() .port(0) .handle((req, res) -> res.sendWebsocket(handler)) .wiretap(true) .bindNow(); ReplayProcessor<String> output = ReplayProcessor.create(); HttpClient.create() .port(httpServer.address().getPort()) .websocket() .uri("/") .handle((in, out) -> out.sendString(Flux.just("1", "text", "2")) .then(in.aggregateFrames() .receiveFrames() .map(WebSocketFrame::content) .map(byteBuf -> byteBuf.readCharSequence(byteBuf.readableBytes(), Charset.defaultCharset()).toString()) .take(count) .subscribeWith(output) .then())) .blockLast(Duration.ofSeconds(30)); assertThat(output.collectList().block(Duration.ofSeconds(30))) .isEqualTo(expectation.collectList().block(Duration.ofSeconds(30))); }