Search in sources :

Example 6 with DeploymentOptions

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

the class ContextTest method testWorkerExecuteFromIo.

@Test
public void testWorkerExecuteFromIo() throws Exception {
    AtomicReference<ContextInternal> workerContext = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    vertx.deployVerticle(new AbstractVerticle() {

        @Override
        public void start() throws Exception {
            workerContext.set((ContextInternal) context);
            latch.countDown();
        }
    }, new DeploymentOptions().setWorker(true));
    awaitLatch(latch);
    workerContext.get().nettyEventLoop().execute(() -> {
        assertNull(Vertx.currentContext());
        workerContext.get().executeFromIO(() -> {
            assertSame(workerContext.get(), Vertx.currentContext());
            assertTrue(Context.isOnWorkerThread());
            testComplete();
        });
    });
    await();
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) AtomicReference(java.util.concurrent.atomic.AtomicReference) ContextInternal(io.vertx.core.impl.ContextInternal) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractVerticle(io.vertx.core.AbstractVerticle) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Test(org.junit.Test)

Example 7 with DeploymentOptions

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

the class ComplexHATest method deployRandomVerticles.

protected void deployRandomVerticles(Runnable runner) {
    int toDeploy = 0;
    AtomicInteger deployCount = new AtomicInteger();
    List<Integer> numbersToDeploy = new ArrayList<>();
    for (int i = 0; i < aliveNodes.size(); i++) {
        int numToDeploy = random.nextInt(maxVerticlesPerNode + 1);
        numbersToDeploy.add(numToDeploy);
        toDeploy += numToDeploy;
    }
    int index = 0;
    for (int pos : aliveNodes) {
        Vertx v = vertices[pos];
        int numToDeploy = numbersToDeploy.get(index);
        index++;
        for (int j = 0; j < numToDeploy; j++) {
            JsonObject config = new JsonObject();
            config.put("foo", TestUtils.randomAlphaString(100));
            DeploymentOptions options = new DeploymentOptions().setHa(true).setConfig(config);
            String verticleName = "java:io.vertx.test.core.HAVerticle" + (random.nextInt(3) + 1);
            v.deployVerticle(verticleName, options, ar -> {
                assertTrue(ar.succeeded());
                deployCount.incrementAndGet();
            });
        }
    }
    int ttoDeploy = toDeploy;
    eventLoopWaitUntil(() -> ttoDeploy == deployCount.get(), () -> {
        totDeployed += ttoDeploy;
        runner.run();
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeploymentOptions(io.vertx.core.DeploymentOptions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) JsonObject(io.vertx.core.json.JsonObject) Vertx(io.vertx.core.Vertx)

Example 8 with DeploymentOptions

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

the class ClasspathHandlerTest method testCPInBareCommand.

@Test
public void testCPInBareCommand() {
    bare = new BareCommand();
    bare.setExecutionContext(new ExecutionContext(bare, null, null));
    bare.setClasspath("." + File.pathSeparator + "target/externals");
    bare.setQuorum(1);
    bare.run();
    waitUntil(() -> bare.vertx != null);
    // Do reproduce the verticle fail-over, set the TCCL
    final ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(bare.createClassloader());
        bare.vertx.deployVerticle(VERTICLE, new DeploymentOptions().setHa(true));
    } finally {
        Thread.currentThread().setContextClassLoader(originalClassloader);
    }
    waitUntil(() -> {
        try {
            return getHttpCode() == 200;
        } catch (IOException e) {
            return false;
        }
    });
}
Also used : ExecutionContext(io.vertx.core.spi.launcher.ExecutionContext) DeploymentOptions(io.vertx.core.DeploymentOptions) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with DeploymentOptions

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

the class HATest method testQuorumWithHaGroups.

@Test
public void testQuorumWithHaGroups() throws Exception {
    vertx1 = startVertx("group1", 2);
    vertx2 = startVertx("group2", 2);
    vertx1.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx1.deploymentIDs().contains(ar.result()));
    });
    // Wait a little while
    Thread.sleep(500);
    //Should not be deployed yet
    assertTrue(vertx1.deploymentIDs().isEmpty());
    vertx3 = startVertx("group1", 2);
    // Now should deploy
    waitUntil(() -> vertx1.deploymentIDs().size() == 1);
    vertx2.deployVerticle("java:" + HAVerticle1.class.getName(), new DeploymentOptions().setHa(true), ar -> {
        assertTrue(ar.succeeded());
        assertTrue(vertx2.deploymentIDs().contains(ar.result()));
    });
    // Wait a little while
    Thread.sleep(500);
    //Should not be deployed yet
    assertTrue(vertx2.deploymentIDs().isEmpty());
    vertx4 = startVertx("group2", 2);
    // Now should deploy
    waitUntil(() -> vertx2.deploymentIDs().size() == 1);
    // Noow stop vertx4
    CountDownLatch latch = new CountDownLatch(1);
    vertx4.close(ar -> {
        latch.countDown();
    });
    awaitLatch(latch);
    waitUntil(() -> vertx2.deploymentIDs().isEmpty());
    assertTrue(vertx1.deploymentIDs().size() == 1);
    CountDownLatch latch2 = new CountDownLatch(1);
    vertx3.close(ar -> {
        latch2.countDown();
    });
    awaitLatch(latch2);
    waitUntil(() -> vertx1.deploymentIDs().isEmpty());
}
Also used : DeploymentOptions(io.vertx.core.DeploymentOptions) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 10 with DeploymentOptions

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

the class WebsocketTest method testRaceConditionWithWebsocketClientWorker.

@Test
public void testRaceConditionWithWebsocketClientWorker() throws Exception {
    CompletableFuture<Context> fut = new CompletableFuture<>();
    vertx.deployVerticle(new AbstractVerticle() {

        @Override
        public void start() throws Exception {
            fut.complete(context);
        }
    }, new DeploymentOptions().setWorker(true), ar -> {
        if (ar.failed()) {
            fut.completeExceptionally(ar.cause());
        }
    });
    testRaceConditionWithWebsocketClient(fut.get());
}
Also used : Context(io.vertx.core.Context) DeploymentOptions(io.vertx.core.DeploymentOptions) AbstractVerticle(io.vertx.core.AbstractVerticle) WebSocketHandshakeException(io.netty.handler.codec.http.websocketx.WebSocketHandshakeException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) 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