use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class EventBusTestBase method testSendWhileUnsubscribing.
@Test
public void testSendWhileUnsubscribing() throws Exception {
startNodes(2);
AtomicBoolean unregistered = new AtomicBoolean();
Verticle sender = new AbstractVerticle() {
@Override
public void start() throws Exception {
getVertx().runOnContext(v -> sendMsg());
}
private void sendMsg() {
if (!unregistered.get()) {
getVertx().eventBus().send("whatever", "marseille");
burnCpu();
getVertx().runOnContext(v -> sendMsg());
} else {
getVertx().eventBus().send("whatever", "marseille", ar -> {
Throwable cause = ar.cause();
assertThat(cause, instanceOf(ReplyException.class));
ReplyException replyException = (ReplyException) cause;
assertEquals(ReplyFailure.NO_HANDLERS, replyException.failureType());
testComplete();
});
}
}
};
Verticle receiver = new AbstractVerticle() {
boolean unregisterCalled;
@Override
public void start(Future<Void> startFuture) throws Exception {
EventBus eventBus = getVertx().eventBus();
MessageConsumer<String> consumer = eventBus.consumer("whatever");
consumer.handler(m -> {
if (!unregisterCalled) {
consumer.unregister(v -> unregistered.set(true));
unregisterCalled = true;
}
m.reply("ok");
}).completionHandler(startFuture);
}
};
CountDownLatch deployLatch = new CountDownLatch(1);
vertices[0].exceptionHandler(this::fail).deployVerticle(receiver, onSuccess(receiverId -> {
vertices[1].exceptionHandler(this::fail).deployVerticle(sender, onSuccess(senderId -> {
deployLatch.countDown();
}));
}));
awaitLatch(deployLatch);
await();
CountDownLatch closeLatch = new CountDownLatch(2);
vertices[0].close(v -> closeLatch.countDown());
vertices[1].close(v -> closeLatch.countDown());
awaitLatch(closeLatch);
}
use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class HttpTest method testUseInMultithreadedWorker.
@Test
public void testUseInMultithreadedWorker() throws Exception {
class MyVerticle extends AbstractVerticle {
@Override
public void start() {
assertIllegalStateException(() -> server = vertx.createHttpServer(new HttpServerOptions()));
assertIllegalStateException(() -> client = vertx.createHttpClient(new HttpClientOptions()));
testComplete();
}
}
MyVerticle verticle = new MyVerticle();
vertx.deployVerticle(verticle, new DeploymentOptions().setWorker(true).setMultiThreaded(true));
await();
}
Aggregations