use of io.vertx.mutiny.core.http.HttpServer in project smallrye-mutiny-vertx-bindings by smallrye.
the class MicrometerMetricsTest method test.
@Test
public void test() {
Vertx vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions().setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)).setEnabled(true)));
Router router = Router.router(vertx);
router.route("/metrics").handler(x -> PrometheusScrapingHandler.create().handle(x));
HttpServer server = vertx.createHttpServer().requestHandler(router).listenAndAwait(8080);
WebClient client = WebClient.create(vertx, new WebClientOptions().setDefaultPort(8080));
String s = client.get("/metrics").sendAndAwait().bodyAsString();
assertThat(s).contains("vertx_http_client_active_connections");
MetricsService metricsService = MetricsService.create(server);
JsonObject metrics = metricsService.getMetricsSnapshot();
System.out.println(metrics);
assertThat(metrics.getJsonArray("vertx.http.server.active.connections")).isNotNull();
}
use of io.vertx.mutiny.core.http.HttpServer in project smallrye-mutiny-vertx-bindings by smallrye.
the class OtherWebClientTest method testResponseBodyAsAsJsonMapped.
@Test
public void testResponseBodyAsAsJsonMapped() throws Exception {
JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.response().endAndForget(expected.encode()));
try {
server.listenAndAwait();
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Uni<HttpResponse<WineAndCheese>> uni = client.get(8080, "localhost", "/the_uri").as(BodyCodec.json(WineAndCheese.class)).send();
uni.subscribe().with(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.body());
testComplete();
}, this::fail);
await();
} finally {
server.closeAndAwait();
}
}
use of io.vertx.mutiny.core.http.HttpServer in project smallrye-mutiny-vertx-bindings by smallrye.
the class OtherWebClientTest method testGet.
@Test
public void testGet() {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.response().setChunked(true).endAndForget("some_content"));
try {
server.listenAndAwait();
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Uni<HttpResponse<Buffer>> uni = client.get(8080, "localhost", "/the_uri").as(BodyCodec.buffer()).send();
for (int i = 0; i < times; i++) {
uni.subscribe().with(resp -> {
Buffer body = resp.body();
assertEquals("some_content", body.toString("UTF-8"));
complete();
}, this::fail);
}
await();
} finally {
server.closeAndAwait();
}
}
use of io.vertx.mutiny.core.http.HttpServer in project smallrye-mutiny-vertx-bindings by smallrye.
the class OtherWebClientTest method testPost.
@Test
public void testPost() {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.bodyHandler(buff -> {
assertEquals("onetwothree", buff.toString());
req.response().endAndForget();
}));
try {
server.listenAndAwait();
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Multi<Buffer> stream = Multi.createFrom().items(Buffer.buffer("one"), Buffer.buffer("two"), Buffer.buffer("three"));
Uni<HttpResponse<Buffer>> uni = client.post(8080, "localhost", "/the_uri").sendStream(stream);
for (int i = 0; i < times; i++) {
uni.subscribe().with(resp -> complete(), this::fail);
}
await();
} finally {
server.closeAndAwait();
}
}
use of io.vertx.mutiny.core.http.HttpServer in project smallrye-mutiny-vertx-bindings by smallrye.
the class OtherWebClientTest method testResponseMissingBody.
@Test
public void testResponseMissingBody() throws Exception {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.response().setStatusCode(403).endAndForget());
try {
server.listenAndAwait();
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Uni<HttpResponse<Buffer>> uni = client.get(8080, "localhost", "/the_uri").send();
for (int i = 0; i < times; i++) {
uni.subscribe().with(resp -> {
System.out.println("done");
assertEquals(403, resp.statusCode());
assertNull(resp.body());
complete();
}, this::fail);
}
await();
} finally {
server.closeAndAwait();
}
}
Aggregations