use of io.vertx.core.metrics.impl.DummyVertxMetrics in project vert.x by eclipse.
the class MetricsContextTest method testDatagram.
private void testDatagram(Function<Vertx, Context> contextFactory, BiConsumer<Thread, Context> checker) {
AtomicReference<Thread> expectedThread = new AtomicReference<>();
AtomicReference<Context> expectedContext = new AtomicReference<>();
AtomicBoolean listening = new AtomicBoolean();
AtomicBoolean bytesReadCalled = new AtomicBoolean();
AtomicBoolean bytesWrittenCalled = new AtomicBoolean();
AtomicBoolean closeCalled = new AtomicBoolean();
VertxMetricsFactory factory = (vertx, options) -> new DummyVertxMetrics() {
@Override
public DatagramSocketMetrics createMetrics(DatagramSocket socket, DatagramSocketOptions options) {
return new DummyDatagramMetrics() {
@Override
public void listening(String localName, SocketAddress localAddress) {
listening.set(true);
checker.accept(expectedThread.get(), expectedContext.get());
}
@Override
public void bytesRead(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
bytesReadCalled.set(true);
checker.accept(expectedThread.get(), expectedContext.get());
}
@Override
public void bytesWritten(Void socketMetric, SocketAddress remoteAddress, long numberOfBytes) {
bytesWrittenCalled.set(true);
checker.accept(expectedThread.get(), expectedContext.get());
}
@Override
public void close() {
closeCalled.set(true);
}
@Override
public boolean isEnabled() {
return true;
}
};
}
};
Vertx vertx = vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(factory)));
Context ctx = contextFactory.apply(vertx);
ctx.runOnContext(v1 -> {
expectedThread.set(Thread.currentThread());
expectedContext.set(Vertx.currentContext());
DatagramSocket socket = vertx.createDatagramSocket();
socket.listen(1234, "localhost", ar1 -> {
assertTrue(ar1.succeeded());
checker.accept(expectedThread.get(), expectedContext.get());
socket.handler(packet -> {
assertTrue(listening.get());
assertTrue(bytesReadCalled.get());
assertTrue(bytesWrittenCalled.get());
executeInVanillaThread(() -> {
socket.close(ar2 -> {
assertTrue(closeCalled.get());
assertTrue(ar2.succeeded());
testComplete();
});
});
});
socket.send(Buffer.buffer("msg"), 1234, "localhost", ar2 -> {
assertTrue(ar2.succeeded());
});
});
});
await();
}
use of io.vertx.core.metrics.impl.DummyVertxMetrics in project vert.x by eclipse.
the class MetricsContextTest method testEventBusLifecycle.
@Test
public void testEventBusLifecycle() {
AtomicBoolean closeCalled = new AtomicBoolean();
VertxMetricsFactory factory = (vertx, options) -> new DummyVertxMetrics() {
@Override
public EventBusMetrics createMetrics(EventBus eventBus) {
return new DummyEventBusMetrics() {
@Override
public boolean isEnabled() {
return true;
}
@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.impl.DummyVertxMetrics in project vert.x by eclipse.
the class MetricsOptionsTest method testSetMetricsInstance.
@Test
public void testSetMetricsInstance() {
DummyVertxMetrics metrics = DummyVertxMetrics.INSTANCE;
vertx.close();
vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MetricsOptions().setEnabled(true).setFactory(new SimpleVertxMetricsFactory<>(metrics))));
assertSame(metrics, ((VertxInternal) vertx).metricsSPI());
}
Aggregations