use of io.vertx.core.http.HttpClient in project raml-module-builder by folio-org.
the class DemoRamlRestTest method checkURLs.
public void checkURLs(TestContext context, String url, int codeExpected, String accept) {
try {
Async async = context.async();
HttpMethod method = HttpMethod.GET;
HttpClient client = vertx.createHttpClient();
HttpClientRequest request = client.requestAbs(method, url, new Handler<HttpClientResponse>() {
@Override
public void handle(HttpClientResponse httpClientResponse) {
log.info(httpClientResponse.statusCode() + ", " + codeExpected + " status expected: " + url);
context.assertEquals(codeExpected, httpClientResponse.statusCode(), url);
httpClientResponse.bodyHandler(body -> {
log.info(body.toString());
});
async.complete();
}
});
request.exceptionHandler(error -> {
context.fail(url + " - " + error.getMessage());
async.complete();
});
request.headers().add("x-okapi-tenant", TENANT);
request.headers().add("Accept", accept);
request.setChunked(true);
request.end();
} catch (Throwable e) {
log.error(e.getMessage(), e);
} finally {
}
}
use of io.vertx.core.http.HttpClient in project vertx-openshift-it by cescoffier.
the class CountersIT method testClusterWideUpdate.
@Test
public void testClusterWideUpdate() throws Exception {
HttpClient httpClient = vertx.createHttpClient();
URL url = Kube.urlForRoute(client.routes().withName(APPLICATION_NAME).get(), "/counters/" + testName.getMethodName());
int loops = 30;
CountDownLatch latch = new CountDownLatch(loops);
for (int i = 0; i < loops; i++) {
httpClient.postAbs(url.toString()).handler(resp -> latch.countDown()).exceptionHandler(t -> latch.countDown()).end(String.valueOf(i));
}
latch.await(1, TimeUnit.MINUTES);
get(url).then().assertThat().statusCode(200).body(equalTo(String.valueOf((loops * (loops - 1)) / 2)));
}
use of io.vertx.core.http.HttpClient in project vertx-openshift-it by cescoffier.
the class LocksIT method testAcquireLock.
@Test
@Ignore("Currently, IPSN locks can be re-acquired on the same VM")
public void testAcquireLock() throws Exception {
HttpClient httpClient = vertx.createHttpClient();
URL url = Kube.urlForRoute(client.routes().withName(APPLICATION_NAME).get(), "/locks/" + testName.getMethodName());
int loops = 30;
AtomicInteger acquired = new AtomicInteger();
CountDownLatch latch = new CountDownLatch(loops);
for (int i = 0; i < loops; i++) {
httpClient.getAbs(url.toString()).handler(resp -> {
if (resp.statusCode() == 200) {
acquired.incrementAndGet();
}
latch.countDown();
}).exceptionHandler(t -> latch.countDown()).end();
}
latch.await(1, TimeUnit.MINUTES);
assertEquals(1, acquired.get());
}
use of io.vertx.core.http.HttpClient in project vertx-openshift-it by cescoffier.
the class AsyncMapRollingUpdateIT method testAsyncMapDataNotLost.
@Test
public void testAsyncMapDataNotLost() throws Exception {
int loops = 30;
HttpClient httpClient = vertx.createHttpClient();
CountDownLatch putLatch = new CountDownLatch(loops);
for (int i = 0; i < loops; i++) {
String mapName = "map-" + i % 2;
String mapKey = testName.getMethodName() + "-" + i;
URL url = Kube.urlForRoute(client.routes().withName(APPLICATION_NAME).get(), "/stuff/" + mapName + "/" + mapKey);
httpClient.putAbs(url.toString()).handler(resp -> putLatch.countDown()).putHeader("Content-Type", "application/json").exceptionHandler(t -> putLatch.countDown()).end(new JsonObject().put("index", i).toBuffer());
}
putLatch.await(1, TimeUnit.MINUTES);
OC.execute("rollout", "latest", APPLICATION_NAME);
// blocks until done
OC.execute("rollout", "status", "dc/" + APPLICATION_NAME);
for (int i = 0; i < loops; i++) {
String mapName = "map-" + i % 2;
String mapKey = testName.getMethodName() + "-" + i;
URL url = Kube.urlForRoute(client.routes().withName(APPLICATION_NAME).get(), "/stuff/" + mapName + "/" + mapKey);
get(url).then().assertThat().statusCode(200).body("index", equalTo(i));
}
}
use of io.vertx.core.http.HttpClient in project georocket by georocket.
the class StoreEndpointTest method doScrolledStorepointRequest.
/**
* Performs request against the server and checks for the scroll headers.
* Fails when the headers are not present or an error occured during the request.
*
* @param context Test context
* @param url url
* @param checkHeaders should the test check the headers
* @param checkScrollIdHeaderPresent should the test check the scroll id
* @param handler response handler
*/
private void doScrolledStorepointRequest(TestContext context, String url, Boolean checkHeaders, Boolean checkScrollIdHeaderPresent, Handler<HttpClientResponse> handler) {
HttpClient client = createHttpClient();
HttpClientRequest request = client.get(url, response -> {
if (checkHeaders) {
checkScrollingResponsePresent(response, context, checkScrollIdHeaderPresent);
}
handler.handle(response);
});
request.exceptionHandler(x -> {
context.fail("Exception during query.");
});
request.end();
}
Aggregations