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();
}
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();
}
Aggregations