use of reactor.netty.Connection in project reactor-netty by reactor.
the class HttpClientTest method testIssue975.
@Test
void testIssue975() throws Exception {
disposableServer = createServer().route(routes -> routes.get("/dispose", (req, res) -> res.sendString(Flux.range(0, 10_000).map(i -> {
if (i == 1_000) {
res.withConnection(Connection::disposeNow);
}
return "a";
})))).bindNow();
AtomicBoolean doAfterResponseSuccess = new AtomicBoolean();
AtomicBoolean doOnResponseError = new AtomicBoolean();
CountDownLatch latch = new CountDownLatch(1);
HttpClient.create().doAfterResponseSuccess((resp, conn) -> doAfterResponseSuccess.set(true)).doOnResponseError((resp, exc) -> doOnResponseError.set(true)).get().uri("http://localhost:" + disposableServer.port() + "/dispose").responseSingle((resp, bytes) -> bytes.asString()).subscribe(null, t -> latch.countDown());
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(doAfterResponseSuccess.get()).isFalse();
assertThat(doOnResponseError.get()).isTrue();
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class HttpServerTests method testIssue1001.
@Test
void testIssue1001() throws Exception {
disposableServer = createServer().host("localhost").handle((req, res) -> res.sendString(Mono.just("testIssue1001"))).bindNow();
int port = disposableServer.port();
Connection connection = TcpClient.create().remoteAddress(disposableServer::address).wiretap(true).connectNow();
CountDownLatch latch = new CountDownLatch(1);
connection.channel().closeFuture().addListener(f -> latch.countDown());
AtomicReference<String> result = new AtomicReference<>();
connection.inbound().receive().asString().doOnNext(result::set).subscribe();
String address = HttpUtil.formatHostnameForHttp((InetSocketAddress) disposableServer.address()) + ":" + port;
connection.outbound().sendString(Mono.just("GET http://" + address + "/< HTTP/1.1\r\nHost: " + address + "\r\n\r\n")).then().subscribe();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
assertThat(result.get()).contains("400", "connection: close");
assertThat(connection.channel().isActive()).isFalse();
StepVerifier.create(createClient(disposableServer::address).get().uri("/<").response()).expectError(IllegalArgumentException.class).verify(Duration.ofSeconds(30));
}
use of reactor.netty.Connection in project reactor-netty by reactor.
the class HttpServerTests method testIssue825.
@Test
void testIssue825() throws Exception {
disposableServer = createServer().handle((req, resp) -> resp.sendString(Mono.just("test"))).bindNow();
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
CountDownLatch latch = new CountDownLatch(1);
Connection client = TcpClient.create().port(disposableServer.port()).handle((in, out) -> {
in.withConnection(x -> x.addHandlerFirst(new HttpClientCodec())).receiveObject().ofType(DefaultHttpContent.class).as(ByteBufFlux::fromInbound).subscribe(ReferenceCounted::release, t -> latch.countDown(), null);
return out.sendObject(Flux.just(request)).neverComplete();
}).wiretap(true).connectNow();
assertThat(latch.await(30, TimeUnit.SECONDS)).isTrue();
client.disposeNow();
}
use of reactor.netty.Connection 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 reactor.netty.Connection in project reactor-netty by reactor.
the class HttpServerTests method doTestConnectionClosePropagatedAsError.
private void doTestConnectionClosePropagatedAsError(String request) throws Exception {
AtomicReference<Throwable> error = new AtomicReference<>();
CountDownLatch msgLatch = new CountDownLatch(1);
CountDownLatch errLatch = new CountDownLatch(1);
disposableServer = createServer().handle((req, res) -> req.receive().doOnNext(b -> msgLatch.countDown()).doOnError(t -> {
errLatch.countDown();
error.set(t);
}).then(res.send())).bindNow();
int port = disposableServer.port();
Connection connection = TcpClient.create().remoteAddress(disposableServer::address).wiretap(true).connectNow();
String address = HttpUtil.formatHostnameForHttp((InetSocketAddress) disposableServer.address()) + ":" + port;
connection.outbound().sendString(Mono.just(String.format(request, address, address))).then().subscribe();
assertThat(msgLatch.await(5, TimeUnit.SECONDS)).as("Wait for the first message").isTrue();
connection.dispose();
assertThat(errLatch.await(5, TimeUnit.SECONDS)).as("Wait for the close connection error").isTrue();
assertThat(error.get()).isNotNull().isInstanceOf(AbortedException.class).hasMessage("Connection has been closed");
}
Aggregations