Search in sources :

Example 26 with Vertx

use of io.vertx.core.Vertx 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 27 with Vertx

use of io.vertx.core.Vertx 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 28 with Vertx

use of io.vertx.core.Vertx 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 29 with Vertx

use of io.vertx.core.Vertx in project vert.x by eclipse.

the class VertxTest method testCloseHooksCalled.

@Test
public void testCloseHooksCalled() throws Exception {
    AtomicInteger closedCount = new AtomicInteger();
    Closeable myCloseable1 = completionHandler -> {
        closedCount.incrementAndGet();
        completionHandler.handle(Future.succeededFuture());
    };
    Closeable myCloseable2 = completionHandler -> {
        closedCount.incrementAndGet();
        completionHandler.handle(Future.succeededFuture());
    };
    VertxInternal vertx = (VertxInternal) Vertx.vertx();
    vertx.addCloseHook(myCloseable1);
    vertx.addCloseHook(myCloseable2);
    // Now undeploy
    vertx.close(ar -> {
        assertTrue(ar.succeeded());
        assertEquals(2, closedCount.get());
        testComplete();
    });
    await();
}
Also used : Closeable(io.vertx.core.Closeable) VertxInternal(io.vertx.core.impl.VertxInternal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) Future(io.vertx.core.Future) VertxInternal(io.vertx.core.impl.VertxInternal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Closeable(io.vertx.core.Closeable) Test(org.junit.Test)

Example 30 with Vertx

use of io.vertx.core.Vertx in project vert.x by eclipse.

the class VertxTestBase method vertx.

/**
   * @return create a blank new Vert.x instance with @{@code options} closed when tear down executes.
   */
protected Vertx vertx(VertxOptions options) {
    if (created == null) {
        created = new ArrayList<>();
    }
    Vertx vertx = Vertx.vertx(options);
    created.add(vertx);
    return vertx;
}
Also used : Vertx(io.vertx.core.Vertx)

Aggregations

Vertx (io.vertx.core.Vertx)43 Test (org.junit.Test)17 VertxOptions (io.vertx.core.VertxOptions)11 Buffer (io.vertx.core.buffer.Buffer)10 Handler (io.vertx.core.Handler)8 NetSocket (io.vertx.core.net.NetSocket)7 Pump (io.vertx.core.streams.Pump)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 DeploymentOptions (io.vertx.core.DeploymentOptions)6 VertxInternal (io.vertx.core.impl.VertxInternal)6 NetServer (io.vertx.core.net.NetServer)6 NetServerOptions (io.vertx.core.net.NetServerOptions)6 JsonObject (io.vertx.core.json.JsonObject)5 Launcher (io.vertx.core.Launcher)4 RunCommandTest (io.vertx.core.impl.launcher.commands.RunCommandTest)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 AbstractVerticle (io.vertx.core.AbstractVerticle)3 AsyncResult (io.vertx.core.AsyncResult)3