use of org.apache.ignite.spi.metric.ReadOnlyMetricManager in project ignite by apache.
the class MetricsSelfTest method testAddBeforeRemoveCompletes.
/**
*/
@Test
public void testAddBeforeRemoveCompletes() throws Exception {
MetricExporterSpi checkSpi = new NoopMetricExporterSpi() {
private ReadOnlyMetricManager registry;
private Set<String> names = new HashSet<>();
@Override
public void spiStart(@Nullable String igniteInstanceName) throws IgniteSpiException {
registry.addMetricRegistryCreationListener(mreg -> {
assertFalse(mreg.name() + " should be unique", names.contains(mreg.name()));
names.add(mreg.name());
});
registry.addMetricRegistryRemoveListener(mreg -> names.remove(mreg.name()));
}
@Override
public void setMetricRegistry(ReadOnlyMetricManager registry) {
this.registry = registry;
}
};
CountDownLatch rmvStarted = new CountDownLatch(1);
CountDownLatch rmvCompleted = new CountDownLatch(1);
MetricExporterSpi blockingSpi = new NoopMetricExporterSpi() {
private ReadOnlyMetricManager registry;
@Override
public void spiStart(@Nullable String igniteInstanceName) throws IgniteSpiException {
registry.addMetricRegistryRemoveListener(mreg -> {
rmvStarted.countDown();
try {
rmvCompleted.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
}
@Override
public void setMetricRegistry(ReadOnlyMetricManager registry) {
this.registry = registry;
}
};
IgniteConfiguration cfg = new IgniteConfiguration().setMetricExporterSpi(blockingSpi, checkSpi);
GridTestKernalContext ctx = new GridTestKernalContext(log(), cfg);
ctx.start();
// Add metric registry.
ctx.metric().registry("test");
// Removes it async, blockingSpi will block remove procedure.
IgniteInternalFuture rmvFut = runAsync(() -> ctx.metric().remove("test"));
rmvStarted.await();
CountDownLatch addStarted = new CountDownLatch(1);
IgniteInternalFuture addFut = runAsync(() -> {
addStarted.countDown();
ctx.metric().registry("test");
});
// Waiting for creation to start.
addStarted.await();
Thread.sleep(100);
// Complete removal.
rmvCompleted.countDown();
rmvFut.get(getTestTimeout());
addFut.get(getTestTimeout());
}
Aggregations