Search in sources :

Example 16 with DeploymentOptions

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

the class HATest method testSimpleFailover.

@Test
public void testSimpleFailover() throws Exception {
    startNodes(2, new VertxOptions().setHAEnabled(true));
    DeploymentOptions options = new DeploymentOptions().setHa(true);
    JsonObject config = new JsonObject().put("foo", "bar");
    options.setConfig(config);
    CountDownLatch latch = new CountDownLatch(1);
    vertices[0].deployVerticle("java:" + HAVerticle1.class.getName(), options, ar -> {
        assertTrue(ar.succeeded());
        assertEquals(1, vertices[0].deploymentIDs().size());
        assertEquals(0, vertices[1].deploymentIDs().size());
        latch.countDown();
    });
    awaitLatch(latch);
    kill(0);
    waitUntil(() -> vertices[1].deploymentIDs().size() == 1);
    checkDeploymentExists(1, "java:" + HAVerticle1.class.getName(), options);
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) JsonObject(io.vertx.core.json.JsonObject) CountDownLatch(java.util.concurrent.CountDownLatch) VertxOptions(io.vertx.core.VertxOptions) Test(org.junit.Test)

Example 17 with DeploymentOptions

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

the class NamedWorkerPoolTest method testDeployUsingNamedPool.

@Test
public void testDeployUsingNamedPool() throws Exception {
    AtomicReference<Thread> thread = new AtomicReference<>();
    String poolName = "vert.x-" + TestUtils.randomAlphaString(10);
    vertx.deployVerticle(new AbstractVerticle() {

        @Override
        public void start() throws Exception {
            vertx.executeBlocking(fut -> {
                thread.set(Thread.currentThread());
                assertTrue(Context.isOnVertxThread());
                assertTrue(Context.isOnWorkerThread());
                assertFalse(Context.isOnEventLoopThread());
                assertTrue(Thread.currentThread().getName().startsWith(poolName + "-"));
                fut.complete();
            }, onSuccess(v -> {
                vertx.undeploy(context.deploymentID());
            }));
        }
    }, new DeploymentOptions().setWorkerPoolName(poolName), onSuccess(v -> {
    }));
    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 18 with DeploymentOptions

use of io.vertx.core.DeploymentOptions in project java-chassis by ServiceComb.

the class VertxUtils method deployVerticle.

public static <T extends AbstractVerticle> void deployVerticle(Vertx vertx, Class<T> cls, int instanceCount) {
    DeploymentOptions options = new DeploymentOptions().setInstances(instanceCount);
    vertx.deployVerticle(cls.getName(), options);
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions)

Example 19 with DeploymentOptions

use of io.vertx.core.DeploymentOptions in project java-chassis by ServiceComb.

the class VertxUtils method createClientDeployOptions.

public static <CLIENT_POOL, CLIENT_OPTIONS> DeploymentOptions createClientDeployOptions(ClientPoolManager<CLIENT_POOL> clientMgr, int instanceCount, int poolCountPerVerticle, CLIENT_OPTIONS clientOptions) {
    DeploymentOptions options = new DeploymentOptions().setInstances(instanceCount);
    SimpleJsonObject config = new SimpleJsonObject();
    config.put(AbstractClientVerticle.CLIENT_MGR, clientMgr);
    config.put(AbstractClientVerticle.POOL_COUNT, poolCountPerVerticle);
    config.put(AbstractClientVerticle.CLIENT_OPTIONS, clientOptions);
    options.setConfig(config);
    return options;
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions)

Example 20 with DeploymentOptions

use of io.vertx.core.DeploymentOptions in project java-chassis by ServiceComb.

the class HighwayTransport method init.

public boolean init() throws Exception {
    HighwayCodec.setHighwayTransport(this);
    DeploymentOptions deployOptions = new DeploymentOptions().setInstances(HighwayConfig.getServerThreadCount());
    setListenAddressWithoutSchema(HighwayConfig.getAddress(), Collections.singletonMap(TcpConst.LOGIN, "true"));
    SimpleJsonObject json = new SimpleJsonObject();
    json.put(ENDPOINT_KEY, getEndpoint());
    deployOptions.setConfig(json);
    return VertxUtils.blockDeploy(transportVertx, HighwayServerVerticle.class, deployOptions);
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) SimpleJsonObject(io.servicecomb.foundation.vertx.SimpleJsonObject)

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