Search in sources :

Example 21 with Vertx

use of io.vertx.core.Vertx in project chuidiang-ejemplos by chuidiang.

the class VertxMain method main.

public static void main(String[] args) {
    Vertx vertx = Vertx.factory.vertx();
    vertx.deployVerticle(new Verticle1());
    vertx.deployVerticle(new Verticle2());
    vertx.deployVerticle(new WebServerVerticle());
}
Also used : Vertx(io.vertx.core.Vertx)

Example 22 with Vertx

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

the class ComplexHATest method undeployRandomVerticles.

protected void undeployRandomVerticles(Runnable runner) {
    int toUndeploy = 0;
    AtomicInteger undeployCount = new AtomicInteger();
    for (int pos : aliveNodes) {
        Vertx v = vertices[pos];
        int deployedNum = v.deploymentIDs().size();
        int numToUnDeploy = random.nextInt(deployedNum + 1);
        List<String> deployed = new ArrayList<>(v.deploymentIDs());
        int ii = pos;
        for (int j = 0; j < numToUnDeploy; j++) {
            int depPos = random.nextInt(deployed.size());
            String depID = deployed.remove(depPos);
            toUndeploy++;
            v.undeploy(depID, onSuccess(d -> {
                undeployCount.incrementAndGet();
            }));
        }
    }
    int totUndeployed = toUndeploy;
    eventLoopWaitUntil(() -> totUndeployed == undeployCount.get(), () -> {
        totDeployed -= totUndeployed;
        runner.run();
    });
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) ConcurrentHashSet(io.vertx.core.impl.ConcurrentHashSet) ClusterManager(io.vertx.core.spi.cluster.ClusterManager) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions) Set(java.util.Set) Test(org.junit.Test) Random(java.util.Random) FakeClusterManager(io.vertx.test.fakecluster.FakeClusterManager) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Deployment(io.vertx.core.impl.Deployment) DeploymentOptions(io.vertx.core.DeploymentOptions) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JsonObject(io.vertx.core.json.JsonObject) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Vertx(io.vertx.core.Vertx)

Example 23 with Vertx

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

the class LauncherExtensibilityTest method testThatCustomLauncherCanUpdateConfigurationWhenNoneArePassed.

@Test
public void testThatCustomLauncherCanUpdateConfigurationWhenNoneArePassed() throws IOException {
    long time = System.nanoTime();
    Launcher myLauncher = new Launcher() {

        @Override
        protected String getMainVerticle() {
            return HttpTestVerticle.class.getName();
        }

        @Override
        public void afterStartingVertx(Vertx vertx) {
            LauncherExtensibilityTest.this.vertx = vertx;
        }

        @Override
        public void afterConfigParsed(JsonObject config) {
            config.put("time", time);
        }
    };
    myLauncher.dispatch(new String[0]);
    waitUntil(() -> {
        try {
            return RunCommandTest.getHttpCode() == 200;
        } catch (IOException e) {
            return false;
        }
    });
    assertThat(RunCommandTest.getContent().getJsonObject("conf").getLong("time")).isEqualTo(time);
}
Also used : Launcher(io.vertx.core.Launcher) JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) RunCommandTest(io.vertx.core.impl.launcher.commands.RunCommandTest)

Example 24 with Vertx

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

the class LauncherExtensibilityTest method testThatCustomLauncherCanUpdateConfiguration.

@Test
public void testThatCustomLauncherCanUpdateConfiguration() throws IOException {
    long time = System.nanoTime();
    Launcher myLauncher = new Launcher() {

        @Override
        protected String getMainVerticle() {
            return HttpTestVerticle.class.getName();
        }

        @Override
        public void afterStartingVertx(Vertx vertx) {
            LauncherExtensibilityTest.this.vertx = vertx;
        }

        @Override
        public void afterConfigParsed(JsonObject config) {
            config.put("time", time);
        }
    };
    myLauncher.dispatch(new String[] { "-conf=\"{\"time\":345667}" });
    waitUntil(() -> {
        try {
            return RunCommandTest.getHttpCode() == 200;
        } catch (IOException e) {
            return false;
        }
    });
    assertThat(RunCommandTest.getContent().getJsonObject("conf").getLong("time")).isEqualTo(time);
}
Also used : Launcher(io.vertx.core.Launcher) JsonObject(io.vertx.core.json.JsonObject) IOException(java.io.IOException) Vertx(io.vertx.core.Vertx) Test(org.junit.Test) RunCommandTest(io.vertx.core.impl.launcher.commands.RunCommandTest)

Example 25 with Vertx

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

the class RedeployTest method tearDown.

@After
public void tearDown() throws InterruptedException {
    super.tearDown();
    final RunCommand run = (RunCommand) cli.getExistingCommandInstance("run");
    if (run != null) {
        Vertx vertx = run.vertx;
        close(vertx);
        run.stopBackgroundApplication(null);
        run.shutdownRedeployment();
    }
    FakeClusterManager.reset();
    waitForTermination();
}
Also used : Vertx(io.vertx.core.Vertx) After(org.junit.After)

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