use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class BlockedThreadCheckerTest method testBlockCheckWorker.
@Test
public void testBlockCheckWorker() throws Exception {
Verticle verticle = new AbstractVerticle() {
@Override
public void start() throws InterruptedException {
Thread.sleep(2000);
testComplete();
}
};
// set warning threshold to 1s and the exception threshold as well
VertxOptions vertxOptions = new VertxOptions();
vertxOptions.setMaxWorkerExecuteTime(1000000000);
vertxOptions.setWarningExceptionTime(1000000000);
Vertx newVertx = vertx(vertxOptions);
DeploymentOptions deploymentOptions = new DeploymentOptions();
deploymentOptions.setWorker(true);
newVertx.deployVerticle(verticle, deploymentOptions);
await();
}
use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class BlockedThreadCheckerTest method testBlockCheckExecuteBlocking.
@Test
public void testBlockCheckExecuteBlocking() throws Exception {
Verticle verticle = new AbstractVerticle() {
@Override
public void start() throws InterruptedException {
vertx.executeBlocking(fut -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
fail();
}
testComplete();
}, ar -> {
});
}
};
// set warning threshold to 1s and the exception threshold as well
VertxOptions vertxOptions = new VertxOptions();
vertxOptions.setMaxWorkerExecuteTime(1000000000);
vertxOptions.setWarningExceptionTime(1000000000);
Vertx newVertx = vertx(vertxOptions);
newVertx.deployVerticle(verticle);
await();
}
use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class BlockedThreadCheckerTest method testBlockCheckExceptionTimeLimit.
@Test
public void testBlockCheckExceptionTimeLimit() throws Exception {
Verticle verticle = new AbstractVerticle() {
@Override
public void start() throws InterruptedException {
Thread.sleep(2000);
testComplete();
}
};
// set warning threshold to 1s and the exception threshold as well
VertxOptions vertxOptions = new VertxOptions();
vertxOptions.setMaxEventLoopExecuteTime(1000000000);
vertxOptions.setWarningExceptionTime(1000000000);
Vertx newVertx = vertx(vertxOptions);
newVertx.deployVerticle(verticle);
await();
}
use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class NamedWorkerPoolTest method testDeployWorkerUsingNamedPool.
@Test
public void testDeployWorkerUsingNamedPool() throws Exception {
AtomicReference<Thread> thread = new AtomicReference<>();
AtomicReference<String> deployment = new AtomicReference<>();
String poolName = "vert.x-" + TestUtils.randomAlphaString(10);
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() throws Exception {
thread.set(Thread.currentThread());
assertTrue(Context.isOnVertxThread());
assertTrue(Context.isOnWorkerThread());
assertFalse(Context.isOnEventLoopThread());
assertTrue(Thread.currentThread().getName().startsWith(poolName + "-"));
context.runOnContext(v -> {
vertx.undeploy(context.deploymentID());
});
}
}, new DeploymentOptions().setWorker(true).setWorkerPoolName(poolName), onSuccess(deployment::set));
waitUntil(() -> thread.get() != null && thread.get().getState() == Thread.State.TERMINATED);
}
use of io.vertx.core.AbstractVerticle in project vert.x by eclipse.
the class TimerTest method testInVerticle.
@Test
public void testInVerticle() throws Exception {
class MyVerticle extends AbstractVerticle {
AtomicInteger cnt = new AtomicInteger();
@Override
public void start() {
Thread thr = Thread.currentThread();
vertx.setTimer(1, id -> {
assertSame(thr, Thread.currentThread());
if (cnt.incrementAndGet() == 5) {
testComplete();
}
});
vertx.setPeriodic(2, id -> {
assertSame(thr, Thread.currentThread());
if (cnt.incrementAndGet() == 5) {
testComplete();
}
});
}
}
MyVerticle verticle = new MyVerticle();
vertx.deployVerticle(verticle);
await();
}
Aggregations