Search in sources :

Example 6 with Vertx

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

the class ContextTest method testGettingContextContextUnderContextAnotherInstanceShouldReturnDifferentContext.

@Test
public void testGettingContextContextUnderContextAnotherInstanceShouldReturnDifferentContext() throws Exception {
    Vertx other = vertx();
    Context context = vertx.getOrCreateContext();
    context.runOnContext(v -> {
        Context otherContext = other.getOrCreateContext();
        assertNotSame(otherContext, context);
        testComplete();
    });
    await();
}
Also used : Context(io.vertx.core.Context) Vertx(io.vertx.core.Vertx) Test(org.junit.Test)

Example 7 with Vertx

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

the class FileResolverTestBase method testDeleteCacheDir.

@Test
public void testDeleteCacheDir() throws Exception {
    Vertx vertx2 = vertx();
    FileResolver resolver2 = new FileResolver(vertx2);
    File file = resolver2.resolveFile(webRoot + "/somefile.html");
    assertTrue(file.exists());
    File cacheDir = file.getParentFile().getParentFile();
    assertTrue(cacheDir.exists());
    resolver2.close(onSuccess(res -> {
        assertFalse(cacheDir.exists());
        vertx2.close(res2 -> {
            testComplete();
        });
    }));
    await();
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) Files(java.nio.file.Files) Vertx(io.vertx.core.Vertx) StandardOpenOption(java.nio.file.StandardOpenOption) Test(org.junit.Test) Random(java.util.Random) File(java.io.File) ArrayList(java.util.ArrayList) FileResolver(io.vertx.core.impl.FileResolver) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) HttpMethod(io.vertx.core.http.HttpMethod) HttpServerOptions(io.vertx.core.http.HttpServerOptions) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Assert(org.junit.Assert) Vertx(io.vertx.core.Vertx) FileResolver(io.vertx.core.impl.FileResolver) File(java.io.File) Test(org.junit.Test)

Example 8 with Vertx

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

the class EventBusExamples method example12.

public void example12() {
    VertxOptions options = new VertxOptions();
    Vertx.clusteredVertx(options, res -> {
        if (res.succeeded()) {
            Vertx vertx = res.result();
            EventBus eventBus = vertx.eventBus();
            System.out.println("We now have a clustered event bus: " + eventBus);
        } else {
            System.out.println("Failed: " + res.cause());
        }
    });
}
Also used : EventBus(io.vertx.core.eventbus.EventBus) Vertx(io.vertx.core.Vertx) VertxOptions(io.vertx.core.VertxOptions)

Example 9 with Vertx

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

the class RunCommandTest 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);
    }
    FakeClusterManager.reset();
}
Also used : Vertx(io.vertx.core.Vertx) After(org.junit.After)

Example 10 with Vertx

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

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