Search in sources :

Example 16 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vertx-openshift-it by cescoffier.

the class EventBusSenderVerticle method createHealthChecks.

private HealthChecks createHealthChecks() {
    return HealthChecks.create(vertx).register("ispn-cluster-status", future -> {
        VertxInternal vertxInternal = (VertxInternal) vertx;
        InfinispanClusterManager clusterManager = (InfinispanClusterManager) vertxInternal.getClusterManager();
        EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) clusterManager.getCacheContainer();
        Health health = cacheManager.getHealth();
        HealthStatus healthStatus = health.getClusterHealth().getHealthStatus();
        Status status = new Status().setOk(healthStatus == HealthStatus.HEALTHY).setData(JsonObject.mapFrom(health));
        future.complete(status);
    });
}
Also used : Status(io.vertx.ext.healthchecks.Status) HealthStatus(org.infinispan.health.HealthStatus) VertxInternal(io.vertx.core.impl.VertxInternal) Health(org.infinispan.health.Health) InfinispanClusterManager(io.vertx.ext.cluster.infinispan.InfinispanClusterManager) HealthStatus(org.infinispan.health.HealthStatus) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 17 with VertxInternal

use of io.vertx.core.impl.VertxInternal in project vertx-openshift-it by cescoffier.

the class AsyncMapVerticle method createHealthChecks.

private HealthChecks createHealthChecks() {
    return HealthChecks.create(vertx).register("ispn-cluster-status", future -> {
        VertxInternal vertxInternal = (VertxInternal) vertx;
        InfinispanClusterManager clusterManager = (InfinispanClusterManager) vertxInternal.getClusterManager();
        EmbeddedCacheManager cacheManager = (EmbeddedCacheManager) clusterManager.getCacheContainer();
        Health health = cacheManager.getHealth();
        HealthStatus healthStatus = health.getClusterHealth().getHealthStatus();
        Status status = new Status().setOk(healthStatus == HealthStatus.HEALTHY).setData(JsonObject.mapFrom(health));
        future.complete(status);
    });
}
Also used : Status(io.vertx.ext.healthchecks.Status) HealthStatus(org.infinispan.health.HealthStatus) VertxInternal(io.vertx.core.impl.VertxInternal) Health(org.infinispan.health.Health) InfinispanClusterManager(io.vertx.ext.cluster.infinispan.InfinispanClusterManager) HealthStatus(org.infinispan.health.HealthStatus) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager)

Example 18 with VertxInternal

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

the class TimerTest method testTimerOnContext.

@Test
public void testTimerOnContext() {
    disableThreadChecks();
    ContextInternal ctx1 = ((VertxInternal) vertx).createEventLoopContext();
    waitFor(2);
    ContextInternal ctx2 = ((VertxInternal) vertx).createEventLoopContext();
    assertNotSame(ctx1, ctx2);
    ctx2.runOnContext(v -> {
        vertx.setTimer(10, l -> {
            assertSame(ctx2, vertx.getOrCreateContext());
            complete();
        });
        ctx1.setTimer(10, l -> {
            assertSame(ctx1, vertx.getOrCreateContext());
            complete();
        });
    });
    await();
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) ContextInternal(io.vertx.core.impl.ContextInternal) Test(org.junit.Test)

Example 19 with VertxInternal

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

the class VertxTest method testCloseHookFailure2.

@Test
public void testCloseHookFailure2() throws Exception {
    AtomicInteger closedCount = new AtomicInteger();
    class Hook implements Closeable {

        @Override
        public void close(Promise<Void> completion) {
            if (closedCount.incrementAndGet() == 1) {
                completion.handle(Future.succeededFuture());
                throw new RuntimeException();
            } else {
                completion.handle(Future.succeededFuture());
            }
        }
    }
    VertxInternal vertx = (VertxInternal) Vertx.vertx();
    vertx.addCloseHook(new Hook());
    vertx.addCloseHook(new Hook());
    // Now undeploy
    vertx.close(ar -> {
        assertTrue(ar.succeeded());
        assertEquals(2, closedCount.get());
        testComplete();
    });
    await();
}
Also used : VertxInternal(io.vertx.core.impl.VertxInternal) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 20 with VertxInternal

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

the class VertxTest method testFinalizeHttpClient.

@Test
public void testFinalizeHttpClient() throws Exception {
    VertxInternal vertx = (VertxInternal) Vertx.vertx();
    try {
        CountDownLatch latch = new CountDownLatch(1);
        AtomicReference<NetSocket> socketRef = new AtomicReference<>();
        vertx.createNetServer().connectHandler(socketRef::set).listen(8080, "localhost").onComplete(onSuccess(server -> latch.countDown()));
        awaitLatch(latch);
        AtomicBoolean closed = new AtomicBoolean();
        // No keep alive so the connection is not held in the pool ????
        CloseFuture closeFuture = new CloseFuture();
        closeFuture.future().onComplete(ar -> closed.set(true));
        HttpClient client = vertx.createHttpClient(new HttpClientOptions().setKeepAlive(false), closeFuture);
        vertx.addCloseHook(closeFuture);
        client.request(HttpMethod.GET, 8080, "localhost", "/").compose(HttpClientRequest::send).onComplete(onFailure(err -> {
        }));
        WeakReference<HttpClient> ref = new WeakReference<>(client);
        closeFuture = null;
        client = null;
        assertWaitUntil(() -> socketRef.get() != null);
        for (int i = 0; i < 10; i++) {
            Thread.sleep(10);
            RUNNER.runSystemGC();
            assertFalse(closed.get());
            assertNotNull(ref.get());
        }
        socketRef.get().close();
        long now = System.currentTimeMillis();
        while (true) {
            assertTrue(System.currentTimeMillis() - now < 20_000);
            RUNNER.runSystemGC();
            if (ref.get() == null) {
                assertTrue(closed.get());
                break;
            }
        }
    } finally {
        vertx.close(ar -> {
            testComplete();
        });
    }
    await();
}
Also used : NetSocket(io.vertx.core.net.NetSocket) VertxInternal(io.vertx.core.impl.VertxInternal) URL(java.net.URL) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) NetClientOptions(io.vertx.core.net.NetClientOptions) TimeUnit(java.util.concurrent.TimeUnit) HttpClientRequest(io.vertx.core.http.HttpClientRequest) RepeatRule(io.vertx.test.core.RepeatRule) OptionsBuilder(org.openjdk.jmh.runner.options.OptionsBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) Repeat(io.vertx.test.core.Repeat) URLClassLoader(java.net.URLClassLoader) Rule(org.junit.Rule) AsyncTestBase(io.vertx.test.core.AsyncTestBase) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpMethod(io.vertx.core.http.HttpMethod) CloseFuture(io.vertx.core.impl.CloseFuture) HttpClientOptions(io.vertx.core.http.HttpClientOptions) NetClient(io.vertx.core.net.NetClient) Runner(org.openjdk.jmh.runner.Runner) WeakReference(java.lang.ref.WeakReference) HttpClient(io.vertx.core.http.HttpClient) NetSocket(io.vertx.core.net.NetSocket) CloseFuture(io.vertx.core.impl.CloseFuture) VertxInternal(io.vertx.core.impl.VertxInternal) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) HttpClientOptions(io.vertx.core.http.HttpClientOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpClient(io.vertx.core.http.HttpClient) WeakReference(java.lang.ref.WeakReference) Test(org.junit.Test)

Aggregations

VertxInternal (io.vertx.core.impl.VertxInternal)100 Test (org.junit.Test)73 CountDownLatch (java.util.concurrent.CountDownLatch)46 VertxOptions (io.vertx.core.VertxOptions)30 JsonObject (io.vertx.core.json.JsonObject)29 Buffer (io.vertx.core.buffer.Buffer)28 File (java.io.File)27 AtomicReference (java.util.concurrent.atomic.AtomicReference)27 VertxException (io.vertx.core.VertxException)24 HttpClient (io.vertx.core.http.HttpClient)24 NetClient (io.vertx.core.net.NetClient)24 TimeUnit (java.util.concurrent.TimeUnit)24 NetServerOptions (io.vertx.core.net.NetServerOptions)23 InetAddress (java.net.InetAddress)23 Channel (io.netty.channel.Channel)22 InetSocketAddress (java.net.InetSocketAddress)22 CompletableFuture (java.util.concurrent.CompletableFuture)22 NetServer (io.vertx.core.net.NetServer)21 ChannelFuture (io.netty.channel.ChannelFuture)20 Bootstrap (io.netty.bootstrap.Bootstrap)19