Search in sources :

Example 11 with AbstractVerticle

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);
}
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) CompletableFuture(java.util.concurrent.CompletableFuture) WorkerExecutor(io.vertx.core.WorkerExecutor) AtomicReference(java.util.concurrent.atomic.AtomicReference) AbstractVerticle(io.vertx.core.AbstractVerticle) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Example 12 with AbstractVerticle

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

Example 13 with AbstractVerticle

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();
}
Also used : CyclicBarrier(java.util.concurrent.CyclicBarrier) Vertx(io.vertx.core.Vertx) ContextInternal(io.vertx.core.impl.ContextInternal) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Context(io.vertx.core.Context) Future(io.vertx.core.Future) AtomicReference(java.util.concurrent.atomic.AtomicReference) WorkerExecutor(io.vertx.core.WorkerExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) DeploymentOptions(io.vertx.core.DeploymentOptions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AbstractVerticle(io.vertx.core.AbstractVerticle) TaskQueue(io.vertx.core.impl.TaskQueue) DeploymentOptions(io.vertx.core.DeploymentOptions) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractVerticle(io.vertx.core.AbstractVerticle) BrokenBarrierException(java.util.concurrent.BrokenBarrierException)

Example 14 with AbstractVerticle

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

Example 15 with AbstractVerticle

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