use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.
the class MetricsContextTest method testFactoryInCluster.
@Test
public void testFactoryInCluster() throws Exception {
AtomicReference<Thread> metricsThread = new AtomicReference<>();
AtomicReference<Context> metricsContext = new AtomicReference<>();
Thread testThread = Thread.currentThread();
VertxMetricsFactory factory = (options) -> {
metricsThread.set(Thread.currentThread());
metricsContext.set(Vertx.currentContext());
return DummyVertxMetrics.INSTANCE;
};
VertxOptions options = new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)).setEventBusOptions(new EventBusOptions());
clusteredVertx(options, onSuccess(vertx -> {
assertSame(testThread, metricsThread.get());
assertNull(metricsContext.get());
testComplete();
}));
await();
}
use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.
the class MetricsContextTest method testFactory.
@Test
public void testFactory() throws Exception {
AtomicReference<Thread> metricsThread = new AtomicReference<>();
AtomicReference<Context> metricsContext = new AtomicReference<>();
VertxMetricsFactory factory = (options) -> {
metricsThread.set(Thread.currentThread());
metricsContext.set(Vertx.currentContext());
return DummyVertxMetrics.INSTANCE;
};
vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
assertNull(metricsContext.get());
}
use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.
the class MetricsContextTest method testEventBusLifecycle.
@Test
public void testEventBusLifecycle() {
AtomicBoolean closeCalled = new AtomicBoolean();
VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {
@Override
public EventBusMetrics createEventBusMetrics() {
return new DummyEventBusMetrics() {
@Override
public void close() {
closeCalled.set(true);
}
};
}
};
Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
vertx.eventBus();
executeInVanillaThread(() -> {
vertx.close(onSuccess(v -> {
assertTrue(closeCalled.get());
testComplete();
}));
});
await();
}
use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.
the class MetricsContextTest method testNetClient.
private void testNetClient(Function<Vertx, Context> contextFactory) throws Exception {
AtomicReference<Thread> expectedThread = new AtomicReference<>();
AtomicReference<Context> expectedContext = new AtomicReference<>();
AtomicBoolean socketConnectedCalled = new AtomicBoolean();
AtomicBoolean socketDisconnectedCalled = new AtomicBoolean();
AtomicBoolean bytesReadCalled = new AtomicBoolean();
AtomicBoolean bytesWrittenCalled = new AtomicBoolean();
AtomicBoolean closeCalled = new AtomicBoolean();
VertxMetricsFactory factory = (options) -> new DummyVertxMetrics() {
@Override
public TCPMetrics createNetClientMetrics(NetClientOptions options) {
return new DummyTCPMetrics() {
@Override
public Void connected(SocketAddress remoteAddress, String remoteName) {
socketConnectedCalled.set(true);
return null;
}
@Override
public void disconnected(Void socketMetric, SocketAddress remoteAddress) {
socketDisconnectedCalled.set(true);
}
@Override
public void bytesRead(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
bytesReadCalled.set(true);
}
@Override
public void bytesWritten(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
bytesWrittenCalled.set(true);
}
@Override
public void close() {
closeCalled.set(true);
}
};
}
};
CountDownLatch latch = new CountDownLatch(1);
Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
Context ctx = contextFactory.apply(vertx);
NetServer server = vertx.createNetServer().connectHandler(so -> {
so.handler(buf -> {
so.write("bye");
});
});
server.listen(1234, "localhost", onSuccess(s -> {
latch.countDown();
}));
awaitLatch(latch);
ctx.runOnContext(v1 -> {
NetClient client = vertx.createNetClient();
expectedThread.set(Thread.currentThread());
expectedContext.set(Vertx.currentContext());
client.connect(1234, "localhost", onSuccess(so -> {
so.handler(buf -> {
so.closeHandler(v -> {
assertTrue(bytesReadCalled.get());
assertTrue(bytesWrittenCalled.get());
assertTrue(socketConnectedCalled.get());
assertTrue(socketDisconnectedCalled.get());
executeInVanillaThread(() -> {
client.close();
vertx.close(v4 -> {
assertTrue(closeCalled.get());
testComplete();
});
});
});
so.close();
});
so.write("hello");
}));
});
await();
}
use of io.vertx.core.metrics.MetricsOptions in project vert.x by eclipse.
the class VertxFactoryTest method testFactoryMetricsOverridesMetaInf.
@Test
public void testFactoryMetricsOverridesMetaInf() {
runWithServiceFromMetaInf(VertxMetricsFactory.class, FakeVertxMetrics.class.getName(), () -> {
FakeVertxMetrics metrics = new FakeVertxMetrics();
MetricsOptions metricsOptions = new MetricsOptions().setEnabled(true);
VertxBuilder factory = new VertxBuilder(new VertxOptions().setMetricsOptions(metricsOptions));
factory.metrics(metrics);
factory.init();
Vertx vertx = factory.vertx();
assertSame(metrics, ((VertxInternal) vertx).metricsSPI());
});
}
Aggregations