Search in sources :

Example 16 with AbstractVerticle

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();
}
Also used : AbstractVerticle(io.vertx.core.AbstractVerticle) Verticle(io.vertx.core.Verticle) DeploymentOptions(io.vertx.core.DeploymentOptions) Vertx(io.vertx.core.Vertx) AbstractVerticle(io.vertx.core.AbstractVerticle) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 17 with AbstractVerticle

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();
}
Also used : AbstractVerticle(io.vertx.core.AbstractVerticle) Verticle(io.vertx.core.Verticle) Vertx(io.vertx.core.Vertx) AbstractVerticle(io.vertx.core.AbstractVerticle) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 18 with AbstractVerticle

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();
}
Also used : AbstractVerticle(io.vertx.core.AbstractVerticle) Verticle(io.vertx.core.Verticle) Vertx(io.vertx.core.Vertx) AbstractVerticle(io.vertx.core.AbstractVerticle) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 19 with AbstractVerticle

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);
}
Also used : Vertx(io.vertx.core.Vertx) Set(java.util.Set) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) CompletableFuture(java.util.concurrent.CompletableFuture) Context(io.vertx.core.Context) AtomicReference(java.util.concurrent.atomic.AtomicReference) WorkerExecutor(io.vertx.core.WorkerExecutor) HashSet(java.util.HashSet) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) DeploymentOptions(io.vertx.core.DeploymentOptions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractVerticle(io.vertx.core.AbstractVerticle) Collections(java.util.Collections) DeploymentOptions(io.vertx.core.DeploymentOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) AbstractVerticle(io.vertx.core.AbstractVerticle) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Example 20 with AbstractVerticle

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractVerticle(io.vertx.core.AbstractVerticle) Test(org.junit.Test)

Aggregations

AbstractVerticle (io.vertx.core.AbstractVerticle)22 Test (org.junit.Test)21 DeploymentOptions (io.vertx.core.DeploymentOptions)16 Context (io.vertx.core.Context)12 CountDownLatch (java.util.concurrent.CountDownLatch)9 Vertx (io.vertx.core.Vertx)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 Verticle (io.vertx.core.Verticle)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Future (io.vertx.core.Future)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 WorkerExecutor (io.vertx.core.WorkerExecutor)4 Buffer (io.vertx.core.buffer.Buffer)4 Collections (java.util.Collections)4 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)4 TimeUnit (java.util.concurrent.TimeUnit)4 Consumer (java.util.function.Consumer)4 CharsetUtil (io.netty.util.CharsetUtil)3 VertxOptions (io.vertx.core.VertxOptions)3