use of com.hazelcast.internal.metrics.MetricsRegistry in project hazelcast by hazelcast.
the class DynamicMetricsCollectionTest method testDirectLongProveLevelFilters.
@Test
public void testDirectLongProveLevelFilters() {
MetricsCollector collectorMock = mock(MetricsCollector.class);
MetricsRegistry metricsRegistry = new MetricsRegistryImpl(Logger.getLogger(MetricsRegistryImpl.class), MANDATORY);
metricsRegistry.registerDynamicMetricsProvider((descriptor, context) -> context.collect(descriptor.withPrefix("test"), "someMetric", INFO, BYTES, 42));
metricsRegistry.collect(collectorMock);
MetricDescriptor expectedDescriptor = metricsRegistry.newMetricDescriptor().withPrefix("test").withUnit(BYTES).withMetric("someMetric");
verify(collectorMock, never()).collectLong(expectedDescriptor, 42);
}
use of com.hazelcast.internal.metrics.MetricsRegistry in project hazelcast by hazelcast.
the class DynamicMetricsCollectionTest method testDirectDoubleProveLevelFilters.
@Test
public void testDirectDoubleProveLevelFilters() {
MetricsCollector collectorMock = mock(MetricsCollector.class);
MetricsRegistry metricsRegistry = new MetricsRegistryImpl(Logger.getLogger(MetricsRegistryImpl.class), MANDATORY);
metricsRegistry.registerDynamicMetricsProvider((descriptor, context) -> context.collect(descriptor.withPrefix("test"), "someMetric", INFO, BYTES, 42.42D));
metricsRegistry.collect(collectorMock);
MetricDescriptor expectedDescriptor = metricsRegistry.newMetricDescriptor().withPrefix("test").withUnit(BYTES).withMetric("someMetric");
verify(collectorMock, never()).collectDouble(expectedDescriptor, 42.42D);
}
use of com.hazelcast.internal.metrics.MetricsRegistry in project hazelcast by hazelcast.
the class DynamicMetricsCollectionTest method testDynamicProviderExceptionsAreNotPropagated.
@RequireAssertEnabled
@Test
public void testDynamicProviderExceptionsAreNotPropagated() {
MetricsCollector collectorMock = mock(MetricsCollector.class);
MetricsRegistry metricsRegistry = new MetricsRegistryImpl(Logger.getLogger(MetricsRegistryImpl.class), MANDATORY);
metricsRegistry.registerDynamicMetricsProvider((taggerSupplier, context) -> {
throw new RuntimeException("Intentionally failing metrics collection");
});
// we just expect there is no exception apart from AssertionError,
// which is for testing only
Assert.assertThrows(AssertionError.class, () -> metricsRegistry.collect(collectorMock));
}
use of com.hazelcast.internal.metrics.MetricsRegistry in project hazelcast by hazelcast.
the class DynamicMetricsCollectionTest method testDirectDouble.
@Test
public void testDirectDouble() {
CapturingCollector capturingCollector = new CapturingCollector();
MetricsRegistry metricsRegistry = new MetricsRegistryImpl(Logger.getLogger(MetricsRegistryImpl.class), INFO);
metricsRegistry.registerDynamicMetricsProvider((descriptor, context) -> context.collect(descriptor.withPrefix("test"), "someMetric", INFO, BYTES, 42.42D));
metricsRegistry.collect(capturingCollector);
MetricDescriptor expectedDescriptor = metricsRegistry.newMetricDescriptor().withPrefix("test").withUnit(BYTES).withMetric("someMetric");
Number number = capturingCollector.captures().get(expectedDescriptor).singleCapturedValue();
assertInstanceOf(Double.class, number);
assertEquals(42.42D, number.doubleValue(), 10E-6);
}
use of com.hazelcast.internal.metrics.MetricsRegistry in project hazelcast by hazelcast.
the class DynamicMetricsCollectionTest method testExtractingFromObject.
@Test
public void testExtractingFromObject() {
SourceObject source = new SourceObject();
source.longField = 42;
source.doubleField = 42.42D;
CapturingCollector collector = new CapturingCollector();
MetricsRegistry registry = new MetricsRegistryImpl(Logger.getLogger(MetricsRegistryImpl.class), INFO);
registry.registerDynamicMetricsProvider((descriptor, context) -> {
context.collect(descriptor.withPrefix("test"), source);
});
registry.collect(collector);
assertEquals(42L, collector.captures().get(registry.newMetricDescriptor().withPrefix("test").withMetric("longField").withUnit(COUNT)).singleCapturedValue());
assertEquals(42.42D, collector.captures().get(registry.newMetricDescriptor().withPrefix("test").withMetric("doubleField").withUnit(COUNT)).singleCapturedValue());
assertEquals(43L, collector.captures().get(registry.newMetricDescriptor().withPrefix("test").withMetric("longMethod").withUnit(COUNT)).singleCapturedValue());
assertEquals(43.52D, collector.captures().get(registry.newMetricDescriptor().withPrefix("test").withMetric("doubleMethod").withUnit(COUNT)).singleCapturedValue());
}
Aggregations