Search in sources :

Example 1 with HttpContext

use of io.vertx.ext.web.client.impl.HttpContext in project vertx-web by vert-x3.

the class InterceptorTest method testInterceptorsOrderFailOutsideInterceptor.

@Test
public void testInterceptorsOrderFailOutsideInterceptor() throws Exception {
    List<String> events = Collections.synchronizedList(new ArrayList<>());
    client.addInterceptor(context -> {
        events.add(context.phase().name() + "_1");
        context.next();
    });
    HttpContext[] httpCtx = { null };
    CountDownLatch failLatch = new CountDownLatch(1);
    client.addInterceptor(context -> {
        events.add(context.phase().name() + "_2");
        if (context.phase() == ClientPhase.CREATE_REQUEST) {
            httpCtx[0] = context;
            failLatch.countDown();
        } else {
            context.next();
        }
    });
    client.addInterceptor(context -> {
        events.add(context.phase().name() + "_3");
        context.next();
    });
    HttpRequest<Buffer> builder = client.get("/somepath");
    builder.send(onFailure(err -> {
        assertEquals(Arrays.asList("PREPARE_REQUEST_1", "PREPARE_REQUEST_2", "PREPARE_REQUEST_3", "CREATE_REQUEST_1", "CREATE_REQUEST_2", "FAILURE_1", "FAILURE_2", "FAILURE_3"), events);
        complete();
    }));
    awaitLatch(failLatch);
    httpCtx[0].fail(new Exception("Something happens"));
    await();
}
Also used : Buffer(io.vertx.core.buffer.Buffer) AsyncFile(io.vertx.core.file.AsyncFile) Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) MultiMap(io.vertx.core.MultiMap) BodyCodec(io.vertx.ext.web.codec.BodyCodec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AddressResolverOptions(io.vertx.core.dns.AddressResolverOptions) ClientPhase(io.vertx.ext.web.client.impl.ClientPhase) ArrayList(java.util.ArrayList) HttpTestBase(io.vertx.core.http.HttpTestBase) HttpVersion(io.vertx.core.http.HttpVersion) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpClientOptions(io.vertx.core.http.HttpClientOptions) RepeatRule(io.vertx.ext.unit.junit.RepeatRule) WebClientInternal(io.vertx.ext.web.client.impl.WebClientInternal) OpenOptions(io.vertx.core.file.OpenOptions) Files(java.nio.file.Files) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test) File(java.io.File) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Rule(org.junit.Rule) Buffer(io.vertx.core.buffer.Buffer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Handler(io.vertx.core.Handler) Collections(java.util.Collections) HttpContext(io.vertx.ext.web.client.impl.HttpContext) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HttpContext(io.vertx.ext.web.client.impl.HttpContext) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

Handler (io.vertx.core.Handler)1 MultiMap (io.vertx.core.MultiMap)1 VertxOptions (io.vertx.core.VertxOptions)1 Buffer (io.vertx.core.buffer.Buffer)1 AddressResolverOptions (io.vertx.core.dns.AddressResolverOptions)1 AsyncFile (io.vertx.core.file.AsyncFile)1 OpenOptions (io.vertx.core.file.OpenOptions)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1 HttpServerOptions (io.vertx.core.http.HttpServerOptions)1 HttpTestBase (io.vertx.core.http.HttpTestBase)1 HttpVersion (io.vertx.core.http.HttpVersion)1 JsonArray (io.vertx.core.json.JsonArray)1 RepeatRule (io.vertx.ext.unit.junit.RepeatRule)1 ClientPhase (io.vertx.ext.web.client.impl.ClientPhase)1 HttpContext (io.vertx.ext.web.client.impl.HttpContext)1 WebClientInternal (io.vertx.ext.web.client.impl.WebClientInternal)1 BodyCodec (io.vertx.ext.web.codec.BodyCodec)1 File (java.io.File)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1