Search in sources :

Example 26 with HttpClient

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 {
    }
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) RestVerticle(org.folio.rest.RestVerticle) BeforeClass(org.junit.BeforeClass) AES(org.folio.rest.security.AES) Date(java.util.Date) MimeBodyPart(javax.mail.internet.MimeBodyPart) RunWith(org.junit.runner.RunWith) SimpleDateFormat(java.text.SimpleDateFormat) VertxUtils(org.folio.rest.tools.utils.VertxUtils) LoggerFactory(io.vertx.core.logging.LoggerFactory) ArrayList(java.util.ArrayList) BodyPart(javax.mail.BodyPart) BigDecimal(java.math.BigDecimal) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClientResponse(io.vertx.core.http.HttpClientResponse) Locale(java.util.Locale) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) JsonObject(io.vertx.core.json.JsonObject) Datetime(org.folio.rest.jaxrs.model.Datetime) Metadata(org.folio.rest.jaxrs.model.Metadata) Logger(io.vertx.core.logging.Logger) MimeMultipart(javax.mail.internet.MimeMultipart) AfterClass(org.junit.AfterClass) RmbtestsClient(org.folio.rest.client.RmbtestsClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) Test(org.junit.Test) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) JsonPathParser(org.folio.rest.tools.parser.JsonPathParser) Data(org.folio.rest.jaxrs.model.Data) File(java.io.File) NetworkUtils(org.folio.rest.tools.utils.NetworkUtils) Book(org.folio.rest.jaxrs.model.Book) IOUtils(org.apache.commons.io.IOUtils) Messages(org.folio.rest.tools.messages.Messages) List(java.util.List) InternetHeaders(javax.mail.internet.InternetHeaders) Buffer(io.vertx.core.buffer.Buffer) DeploymentOptions(io.vertx.core.DeploymentOptions) AdminClient(org.folio.rest.client.AdminClient) HttpMethod(io.vertx.core.http.HttpMethod) SecretKey(javax.crypto.SecretKey) PersistMethod(org.folio.rest.jaxrs.resource.AdminResource.PersistMethod) Handler(io.vertx.core.Handler) HttpClient(io.vertx.core.http.HttpClient) HttpClientRequest(io.vertx.core.http.HttpClientRequest) Async(io.vertx.ext.unit.Async) HttpClient(io.vertx.core.http.HttpClient) HttpClientResponse(io.vertx.core.http.HttpClientResponse) HttpMethod(io.vertx.core.http.HttpMethod)

Example 27 with HttpClient

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)));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) OC(io.vertx.it.openshift.utils.OC) Route(io.fabric8.openshift.api.model.Route) OpenShiftHelper(io.vertx.it.openshift.utils.OpenShiftHelper) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) Ensure(io.vertx.it.openshift.utils.Ensure) TestName(org.junit.rules.TestName) After(org.junit.After) Assertions(org.assertj.core.api.Assertions) Service(io.fabric8.kubernetes.api.model.Service) Before(org.junit.Before) Vertx(io.vertx.core.Vertx) Kube(io.vertx.it.openshift.utils.Kube) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) TreeMap(java.util.TreeMap) RestAssured(io.restassured.RestAssured) Awaitility(org.awaitility.Awaitility) SortedMap(java.util.SortedMap) HttpClient(io.vertx.core.http.HttpClient) HttpClient(io.vertx.core.http.HttpClient) CountDownLatch(java.util.concurrent.CountDownLatch) URL(java.net.URL) Test(org.junit.Test)

Example 28 with HttpClient

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());
}
Also used : BeforeClass(org.junit.BeforeClass) URL(java.net.URL) OC(io.vertx.it.openshift.utils.OC) Route(io.fabric8.openshift.api.model.Route) OpenShiftHelper(io.vertx.it.openshift.utils.OpenShiftHelper) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Ensure(io.vertx.it.openshift.utils.Ensure) TestName(org.junit.rules.TestName) After(org.junit.After) Assertions(org.assertj.core.api.Assertions) Service(io.fabric8.kubernetes.api.model.Service) Before(org.junit.Before) Vertx(io.vertx.core.Vertx) Kube(io.vertx.it.openshift.utils.Kube) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) Ignore(org.junit.Ignore) TreeMap(java.util.TreeMap) RestAssured(io.restassured.RestAssured) Assert(org.junit.Assert) Awaitility(org.awaitility.Awaitility) SortedMap(java.util.SortedMap) HttpClient(io.vertx.core.http.HttpClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpClient(io.vertx.core.http.HttpClient) CountDownLatch(java.util.concurrent.CountDownLatch) URL(java.net.URL) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 29 with HttpClient

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));
    }
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) BeforeClass(org.junit.BeforeClass) URL(java.net.URL) OC(io.vertx.it.openshift.utils.OC) Route(io.fabric8.openshift.api.model.Route) OpenShiftHelper(io.vertx.it.openshift.utils.OpenShiftHelper) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) Ensure(io.vertx.it.openshift.utils.Ensure) TestName(org.junit.rules.TestName) After(org.junit.After) Assertions(org.assertj.core.api.Assertions) JsonObject(io.vertx.core.json.JsonObject) Service(io.fabric8.kubernetes.api.model.Service) Before(org.junit.Before) Vertx(io.vertx.core.Vertx) Kube(io.vertx.it.openshift.utils.Kube) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) Rule(org.junit.Rule) TreeMap(java.util.TreeMap) RestAssured(io.restassured.RestAssured) Awaitility(org.awaitility.Awaitility) SortedMap(java.util.SortedMap) HttpClient(io.vertx.core.http.HttpClient) HttpClient(io.vertx.core.http.HttpClient) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) URL(java.net.URL) Test(org.junit.Test)

Example 30 with HttpClient

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();
}
Also used : HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient)

Aggregations

HttpClient (io.vertx.core.http.HttpClient)77 Test (org.junit.Test)47 HttpClientRequest (io.vertx.core.http.HttpClientRequest)36 HttpClientOptions (io.vertx.core.http.HttpClientOptions)25 Vertx (io.vertx.core.Vertx)22 HttpMethod (io.vertx.core.http.HttpMethod)22 JsonObject (io.vertx.core.json.JsonObject)22 Handler (io.vertx.core.Handler)18 Buffer (io.vertx.core.buffer.Buffer)18 HttpClientResponse (io.vertx.core.http.HttpClientResponse)16 TimeUnit (java.util.concurrent.TimeUnit)16 HttpServer (io.vertx.core.http.HttpServer)15 Async (io.vertx.ext.unit.Async)15 Before (org.junit.Before)15 File (java.io.File)14 CountDownLatch (java.util.concurrent.CountDownLatch)14 URL (java.net.URL)12 HttpServerOptions (io.vertx.core.http.HttpServerOptions)11 IOException (java.io.IOException)10 List (java.util.List)10