use of io.vertx.core.http.HttpClient in project vertx-micrometer-metrics by vert-x3.
the class MetricsServiceImplTest method runClientRequests.
private void runClientRequests(TestContext ctx, HttpClient httpClient, int count, String path) {
Async async = ctx.async(count);
for (int i = 0; i < count; i++) {
httpClient.post(9195, "127.0.0.1", path, response -> {
async.countDown();
if (response.statusCode() != 200) {
ctx.fail(response.statusMessage());
}
}).exceptionHandler(t -> {
async.countDown();
ctx.fail(t);
}).putHeader("Content-Length", String.valueOf(CLIENT_REQUEST.getBytes().length)).write(CLIENT_REQUEST).end();
}
async.await();
}
use of io.vertx.core.http.HttpClient in project vertx-micrometer-metrics by vert-x3.
the class MetricsServiceImplTest method shouldGetCompleteSnapshot.
@Test
public void shouldGetCompleteSnapshot(TestContext ctx) throws InterruptedException {
HttpClient httpClient = vertx.createHttpClient();
runClientRequests(ctx, httpClient, 10, "/r1");
runClientRequests(ctx, httpClient, 5, "/r2");
httpClient.close();
JsonObject snapshot = MetricsService.create(vertx).getMetricsSnapshot();
assertThat(snapshot).extracting(Map.Entry::getKey).containsExactly("vertx.http.client.bytesReceived", "vertx.http.client.bytesSent", "vertx.http.client.connections", "vertx.http.client.requestCount", "vertx.http.client.requests", "vertx.http.client.responseCount", "vertx.http.client.responseTime", "vertx.http.server.bytesReceived", "vertx.http.server.bytesSent", "vertx.http.server.connections", "vertx.http.server.requestCount", "vertx.http.server.requests", "vertx.http.server.responseTime");
assertThat(snapshot).flatExtracting(e -> (List<JsonObject>) ((JsonArray) (e.getValue())).getList()).filteredOn(obj -> obj.getString("type").equals("counter")).hasSize(6).flatExtracting(JsonObject::fieldNames).contains("count");
assertThat(snapshot).flatExtracting(e -> (List<JsonObject>) ((JsonArray) (e.getValue())).getList()).filteredOn(obj -> obj.getString("type").equals("summary")).hasSize(4).flatExtracting(JsonObject::fieldNames).contains("mean", "max", "total");
assertThat(snapshot).flatExtracting(e -> (List<JsonObject>) ((JsonArray) (e.getValue())).getList()).filteredOn(obj -> obj.getString("type").equals("timer")).hasSize(4).flatExtracting(JsonObject::fieldNames).contains("totalTimeMs", "meanMs", "maxMs");
}
use of io.vertx.core.http.HttpClient in project strimzi by strimzi.
the class Main method isOnOpenShift.
static Future<Boolean> isOnOpenShift(Vertx vertx, KubernetesClient client) {
URL kubernetesApi = client.getMasterUrl();
Future<Boolean> fut = Future.future();
HttpClientOptions httpClientOptions = new HttpClientOptions();
httpClientOptions.setDefaultHost(kubernetesApi.getHost());
if (kubernetesApi.getPort() == -1) {
httpClientOptions.setDefaultPort(kubernetesApi.getDefaultPort());
} else {
httpClientOptions.setDefaultPort(kubernetesApi.getPort());
}
if (kubernetesApi.getProtocol().equals("https")) {
httpClientOptions.setSsl(true);
httpClientOptions.setTrustAll(true);
}
HttpClient httpClient = vertx.createHttpClient(httpClientOptions);
httpClient.getNow("/oapi", res -> {
if (res.statusCode() == HttpResponseStatus.OK.code()) {
log.debug("{} returned {}. We are on OpenShift.", res.request().absoluteURI(), res.statusCode());
// We should be on OpenShift based on the /oapi result. We can now safely try isAdaptable() to be 100% sure.
Boolean isOpenShift = Boolean.TRUE.equals(client.isAdaptable(OpenShiftClient.class));
fut.complete(isOpenShift);
} else {
log.debug("{} returned {}. We are not on OpenShift.", res.request().absoluteURI(), res.statusCode());
fut.complete(Boolean.FALSE);
}
});
return fut;
}
use of io.vertx.core.http.HttpClient in project vertx-sync by vert-x3.
the class TestVerticle method testFiberHandler.
@Suspendable
protected void testFiberHandler() {
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestHandler(fiberHandler(req -> {
String res = awaitResult(h -> ai.methodWithParamsAndHandlerNoReturn("oranges", 23, h));
assertEquals("oranges23", res);
req.response().end();
}));
server.listen(res -> {
assertTrue(res.succeeded());
HttpClient client = vertx.createHttpClient(new HttpClientOptions().setDefaultPort(8080));
client.getNow("/somepath", resp -> {
assertTrue(resp.statusCode() == 200);
client.close();
server.close(res2 -> {
complete();
});
});
});
}
use of io.vertx.core.http.HttpClient in project engine by Lumeer.
the class RestImportTest method startServer.
private void startServer(final List<RequestDto> messages) {
final Vertx vertx = Vertx.vertx();
final HttpServer server = vertx.createHttpServer();
final Router router = Router.router(vertx);
final HttpClient client = vertx.createHttpClient();
router.route("/*").handler(BodyHandler.create());
router.route("/*").handler((context) -> {
messages.add(new RequestDto(context.request().method().toString(), context.getBodyAsString(), context.request().headers()));
context.response().setStatusCode(200).end();
});
this.server = server;
this.serverThread = new Thread(() -> server.requestHandler(router::accept).listen(8091));
this.serverThread.start();
}
Aggregations