Search in sources :

Example 1 with SendContext

use of io.vertx.core.eventbus.SendContext in project vert.x by eclipse.

the class EventBusInterceptorTest method testRemoveInterceptor.

@Test
public void testRemoveInterceptor() {
    AtomicInteger cnt1 = new AtomicInteger();
    AtomicInteger cnt2 = new AtomicInteger();
    Handler<SendContext> eb1 = sc -> {
        cnt1.incrementAndGet();
        sc.next();
    };
    Handler<SendContext> eb2 = sc -> {
        cnt2.incrementAndGet();
        sc.next();
    };
    eb.addInterceptor(eb1).addInterceptor(eb2);
    eb.consumer("some-address", msg -> {
        if (msg.body().equals("armadillo")) {
            assertEquals(1, cnt1.get());
            assertEquals(1, cnt2.get());
            eb.removeInterceptor(eb2);
            eb.send("some-address", "aardvark");
        } else if (msg.body().equals("aardvark")) {
            assertEquals(2, cnt1.get());
            assertEquals(1, cnt2.get());
            testComplete();
        } else {
            fail("wrong body");
        }
    });
    eb.send("some-address", "armadillo");
    await();
}
Also used : EventBus(io.vertx.core.eventbus.EventBus) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SendContext(io.vertx.core.eventbus.SendContext) Test(org.junit.Test) Handler(io.vertx.core.Handler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SendContext(io.vertx.core.eventbus.SendContext) Test(org.junit.Test)

Example 2 with SendContext

use of io.vertx.core.eventbus.SendContext in project vert.x by eclipse.

the class EventBusInterceptorTest method testExceptionInInterceptor.

@Test
public void testExceptionInInterceptor() {
    AtomicInteger cnt = new AtomicInteger();
    Handler<SendContext> eb1 = sc -> {
        cnt.incrementAndGet();
        vertx.runOnContext(v -> sc.next());
        throw new RuntimeException("foo");
    };
    Handler<SendContext> eb2 = sc -> {
        cnt.incrementAndGet();
        sc.next();
    };
    eb.addInterceptor(eb1).addInterceptor(eb2);
    eb.consumer("some-address", msg -> {
        assertEquals("armadillo", msg.body());
        assertEquals(2, cnt.get());
        testComplete();
    });
    eb.send("some-address", "armadillo");
    await();
}
Also used : EventBus(io.vertx.core.eventbus.EventBus) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SendContext(io.vertx.core.eventbus.SendContext) Test(org.junit.Test) Handler(io.vertx.core.Handler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SendContext(io.vertx.core.eventbus.SendContext) Test(org.junit.Test)

Aggregations

Handler (io.vertx.core.Handler)2 EventBus (io.vertx.core.eventbus.EventBus)2 SendContext (io.vertx.core.eventbus.SendContext)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Test (org.junit.Test)2