use of reactor.ipc.netty.http.client.HttpClientResponse in project spring-cloud-sleuth by spring-cloud.
the class WebClientTests method shouldAttachTraceIdWhenCallingAnotherServiceForNettyHttpClient.
@Test
@SuppressWarnings("unchecked")
public void shouldAttachTraceIdWhenCallingAnotherServiceForNettyHttpClient() throws Exception {
Span span = this.tracer.nextSpan().name("foo").start();
try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
HttpClientResponse response = this.nettyHttpClient.get("http://localhost:" + port).block();
then(response).isNotNull();
}
then(this.tracer.currentSpan()).isNull();
then(this.reporter.getSpans()).isNotEmpty().extracting("traceId", String.class).containsOnly(span.context().traceIdString());
then(this.reporter.getSpans()).extracting("kind.name").contains("CLIENT");
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class HttpServerTests method testRestart.
// from https://github.com/reactor/reactor-netty/issues/90
@Test
public void testRestart() {
// start a first server with a handler that answers HTTP 200 OK
NettyContext context = HttpServer.create(8080).newHandler((req, resp) -> resp.status(200).send().log()).block();
HttpClientResponse response = HttpClient.create(8080).get("/").block();
// checking the response status, OK
assertThat(response.status().code()).isEqualTo(200);
// dispose the Netty context and wait for the channel close
response.dispose();
context.dispose();
context.onClose().block();
// REQUIRED - bug pool does not detect/translate properly lifecycle
HttpResources.reset();
// create a totally new server instance, with a different handler that answers HTTP 201
context = HttpServer.create(8080).newHandler((req, resp) -> resp.status(201).send()).block();
response = HttpClient.create(8080).get("/").block();
// fails, response status is 200 and debugging shows the the previous handler is called
assertThat(response.status().code()).isEqualTo(201);
response.dispose();
context.dispose();
context.onClose().block();
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class HttpServerTests method errorResponseAndReturn.
@Test
public void errorResponseAndReturn() throws Exception {
NettyContext c = HttpServer.create(0).newHandler((req, resp) -> Mono.error(new Exception("returnError"))).block();
HttpClientResponse res = HttpClient.create(c.address().getPort()).get("/return", r -> r.failOnServerError(false)).block();
assertThat(res.status().code()).isEqualTo(500);
res.dispose();
c.dispose();
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class HttpServerTests method startRouter.
@Test
public void startRouter() {
BlockingNettyContext facade = HttpServer.create(0).startRouter(routes -> routes.get("/hello", (req, resp) -> resp.sendString(Mono.just("hello!"))));
try {
HttpClientResponse res = HttpClient.create(facade.getPort()).get("/hello").block();
assertThat(res.status().code()).isEqualTo(200);
res.dispose();
res = HttpClient.create(facade.getPort()).get("/helloMan", req -> req.failOnClientError(false)).block();
assertThat(res.status().code()).isEqualTo(404);
res.dispose();
} finally {
facade.shutdown();
}
}
use of reactor.ipc.netty.http.client.HttpClientResponse in project reactor-netty by reactor.
the class HttpServerTests method assertSendFile.
private void assertSendFile(Function<HttpServerResponse, NettyOutbound> fn) {
NettyContext context = HttpServer.create(opt -> opt.host("localhost")).newHandler((req, resp) -> fn.apply(resp)).block();
HttpClientResponse response = HttpClient.create(opt -> opt.connectAddress(() -> context.address())).get("/foo").block(Duration.ofSeconds(120));
context.dispose();
context.onClose().block();
String body = response.receive().aggregate().asString(StandardCharsets.UTF_8).block();
assertThat(body).startsWith("This is an UTF-8 file that is larger than 1024 bytes. " + "It contains accents like é.").contains("1024 mark here -><- 1024 mark here").endsWith("End of File");
}
Aggregations