Search in sources :

Example 26 with DeploymentOptions

use of io.vertx.core.DeploymentOptions 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 DeploymentOptions

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

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

the class RunCommand method run.

/**
   * Starts vert.x and deploy the verticle.
   */
@Override
public void run() {
    if (redeploy == null || redeploy.isEmpty()) {
        JsonObject conf = getConfiguration();
        if (conf == null) {
            conf = new JsonObject();
        }
        afterConfigParsed(conf);
        super.run();
        if (vertx == null) {
            // Already logged.
            ExecUtils.exitBecauseOfVertxInitializationIssue();
        }
        deploymentOptions = new DeploymentOptions();
        configureFromSystemProperties(deploymentOptions, DEPLOYMENT_OPTIONS_PROP_PREFIX);
        deploymentOptions.setConfig(conf).setWorker(worker).setHa(ha).setInstances(instances);
        beforeDeployingVerticle(deploymentOptions);
        deploy();
    } else {
        // redeploy is set, start the redeployment infrastructure (watcher).
        initializeRedeployment();
    }
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) JsonObject(io.vertx.core.json.JsonObject)

Example 29 with DeploymentOptions

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

the class HATest method testCleanCloseNoFailover.

@Test
public void testCleanCloseNoFailover() throws Exception {
    vertx1 = startVertx();
    vertx2 = startVertx();
    DeploymentOptions options = new DeploymentOptions().setHa(true);
    JsonObject config = new JsonObject().put("foo", "bar");
    options.setConfig(config);
    CountDownLatch deployLatch = new CountDownLatch(1);
    vertx2.deployVerticle("java:" + HAVerticle1.class.getName(), options, ar -> {
        assertTrue(ar.succeeded());
        deployLatch.countDown();
    });
    awaitLatch(deployLatch);
    ((VertxInternal) vertx1).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        fail("Should not be called");
    });
    vertx2.close(ar -> {
        vertx.setTimer(500, tid -> {
            testComplete();
        });
    });
    await();
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) VertxInternal(io.vertx.core.impl.VertxInternal) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 30 with DeploymentOptions

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

the class HATest method testHaGroups.

@Test
public void testHaGroups() throws Exception {
    vertx1 = startVertx("group1", 1);
    vertx2 = startVertx("group1", 1);
    vertx3 = startVertx("group2", 1);
    vertx4 = startVertx("group2", 1);
    CountDownLatch latch1 = new CountDownLatch(2);
    vertx1.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx1.deploymentIDs().contains(ar.result()));
        latch1.countDown();
    });
    vertx3.deployVerticle("java:" + HAVerticle2.class.getName(), new DeploymentOptions().setHa(true), ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx3.deploymentIDs().contains(ar.result()));
        latch1.countDown();
    });
    awaitLatch(latch1);
    CountDownLatch latch2 = new CountDownLatch(1);
    ((VertxInternal) vertx1).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        fail("Should not failover here 1");
    });
    ((VertxInternal) vertx2).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        fail("Should not failover here 2");
    });
    ((VertxInternal) vertx4).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        assertTrue(succeeded);
        latch2.countDown();
    });
    ((VertxInternal) vertx3).simulateKill();
    awaitLatch(latch2);
    assertTrue(vertx4.deploymentIDs().size() == 1);
    CountDownLatch latch3 = new CountDownLatch(1);
    ((VertxInternal) vertx2).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        assertTrue(succeeded);
        latch3.countDown();
    });
    ((VertxInternal) vertx4).failoverCompleteHandler((nodeID, haInfo, succeeded) -> {
        fail("Should not failover here 4");
    });
    ((VertxInternal) vertx1).simulateKill();
    awaitLatch(latch3);
    assertTrue(vertx2.deploymentIDs().size() == 1);
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) VertxInternal(io.vertx.core.impl.VertxInternal) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

DeploymentOptions (io.vertx.core.DeploymentOptions)38 Test (org.junit.Test)25 CountDownLatch (java.util.concurrent.CountDownLatch)17 AbstractVerticle (io.vertx.core.AbstractVerticle)15 JsonObject (io.vertx.core.json.JsonObject)10 Context (io.vertx.core.Context)8 Vertx (io.vertx.core.Vertx)7 VertxInternal (io.vertx.core.impl.VertxInternal)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Future (io.vertx.core.Future)4 HttpClientOptions (io.vertx.core.http.HttpClientOptions)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Verticle (io.vertx.core.Verticle)3 VertxException (io.vertx.core.VertxException)3 Buffer (io.vertx.core.buffer.Buffer)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Collections (java.util.Collections)3 TimeUnit (java.util.concurrent.TimeUnit)3