use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class NamedWorkerPoolTest method testDestroyWorkerPoolWhenVerticleUndeploys.
@Test
public void testDestroyWorkerPoolWhenVerticleUndeploys() throws Exception {
String poolName = "vert.x-" + TestUtils.randomAlphaString(10);
AtomicReference<Thread> thread = new AtomicReference<>();
CompletableFuture<String> deploymentIdRef = new CompletableFuture<>();
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
WorkerExecutor pool = vertx.createSharedWorkerExecutor(poolName);
pool.executeBlocking(fut -> {
thread.set(Thread.currentThread());
}, ar -> {
});
}
}, onSuccess(deploymentIdRef::complete));
waitUntil(() -> thread.get() != null);
String deploymentId = deploymentIdRef.get(20, TimeUnit.SECONDS);
vertx.undeploy(deploymentId, onSuccess(v -> {
}));
waitUntil(() -> thread.get().getState() == Thread.State.TERMINATED);
}
use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class ContextTest method testExceptionHandlerOnAsyncDeploymentAsyncResultHandlerFailure.
@Test
public void testExceptionHandlerOnAsyncDeploymentAsyncResultHandlerFailure() {
RuntimeException failure = new RuntimeException();
Context ctx = vertx.getOrCreateContext();
ctx.exceptionHandler(err -> {
assertSame(failure, err);
testComplete();
});
ctx.runOnContext(v -> {
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start(Future<Void> startFuture) throws Exception {
context.runOnContext(startFuture::complete);
}
}, ar -> {
throw failure;
});
});
await();
}
use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class ContextTest method testVerticleUseDifferentOrderedExecutor.
private void testVerticleUseDifferentOrderedExecutor(boolean worker) throws Exception {
waitFor(2);
CountDownLatch latch1 = new CountDownLatch(1);
CountDownLatch latch2 = new CountDownLatch(1);
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
vertx.executeBlocking(fut -> {
latch1.countDown();
try {
awaitLatch(latch2);
fut.complete();
} catch (InterruptedException e) {
fut.fail(e);
}
}, ar -> {
assertTrue(ar.succeeded());
complete();
});
}
}, new DeploymentOptions().setWorker(worker));
awaitLatch(latch1);
CountDownLatch latch3 = new CountDownLatch(1);
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
vertx.executeBlocking(fut -> {
latch3.countDown();
fut.complete();
}, ar -> {
assertTrue(ar.succeeded());
complete();
});
}
}, new DeploymentOptions().setWorker(worker));
awaitLatch(latch3);
latch2.countDown();
await();
}
use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class DNSTest method testUseInMultithreadedWorker.
@Test
public void testUseInMultithreadedWorker() throws Exception {
class MyVerticle extends AbstractVerticle {
@Override
public void start() {
assertIllegalStateException(() -> vertx.createDnsClient(1234, "localhost"));
testComplete();
}
}
MyVerticle verticle = new MyVerticle();
vertx.deployVerticle(verticle, new DeploymentOptions().setWorker(true).setMultiThreaded(true));
await();
}
use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class BlockedThreadCheckerTest method testBlockCheckDefault.
@Test
public void testBlockCheckDefault() throws Exception {
Verticle verticle = new AbstractVerticle() {
@Override
public void start() throws InterruptedException {
Thread.sleep(6000);
testComplete();
}
};
vertx.deployVerticle(verticle);
await();
}
Aggregations