use of com.hazelcast.internal.metrics.ProbeUnit.COUNT in project hazelcast by hazelcast.
the class LongGaugeImplTest method whenCacheDynamicMetricValueReplacedWithCachedMetricSource.
@Test
public void whenCacheDynamicMetricValueReplacedWithCachedMetricSource() {
LongGaugeImpl longGauge = metricsRegistry.newLongGauge("foo.longField");
// provide concrete value
DynamicMetricsProvider concreteProvider = (descriptor, context) -> context.collect(descriptor.withPrefix("foo"), "longField", INFO, COUNT, 142);
metricsRegistry.registerDynamicMetricsProvider(concreteProvider);
// needed to collect dynamic metrics and update the gauge created from them
metricsRegistry.collect(mock(MetricsCollector.class));
assertEquals(142, longGauge.read());
metricsRegistry.deregisterDynamicMetricsProvider(concreteProvider);
// provide metric source to be cached
SomeObject someObject = new SomeObject();
someObject.longField = 42;
metricsRegistry.registerDynamicMetricsProvider(someObject);
// needed to collect dynamic metrics and update the gauge created from them
metricsRegistry.collect(mock(MetricsCollector.class));
assertEquals(42, longGauge.read());
}
use of com.hazelcast.internal.metrics.ProbeUnit.COUNT in project hazelcast by hazelcast.
the class LongGaugeImplTest method whenNotVisitedWithCachedValueReadsDefault.
@Test
public void whenNotVisitedWithCachedValueReadsDefault() {
DynamicMetricsProvider concreteProvider = (descriptor, context) -> context.collect(descriptor.withPrefix("foo"), "longField", INFO, COUNT, 42);
metricsRegistry.registerDynamicMetricsProvider(concreteProvider);
LongGaugeImpl longGauge = metricsRegistry.newLongGauge("foo.longField");
// needed to collect dynamic metrics and update the gauge created from them
metricsRegistry.collect(mock(MetricsCollector.class));
assertEquals(42, longGauge.read());
// clears the cached metric source
metricsRegistry.deregisterDynamicMetricsProvider(concreteProvider);
metricsRegistry.collect(mock(MetricsCollector.class));
assertEquals(LongGaugeImpl.DEFAULT_VALUE, longGauge.read());
}
use of com.hazelcast.internal.metrics.ProbeUnit.COUNT in project hazelcast by hazelcast.
the class DoubleGaugeImplTest method whenCacheDynamicMetricValueReplacedWithCachedMetricSource.
@Test
public void whenCacheDynamicMetricValueReplacedWithCachedMetricSource() {
DoubleGauge doubleGauge = metricsRegistry.newDoubleGauge("foo.doubleField");
// provide concrete value
DynamicMetricsProvider concreteProvider = (descriptor, context) -> context.collect(descriptor.withPrefix("foo"), "doubleField", INFO, COUNT, 142.42D);
metricsRegistry.registerDynamicMetricsProvider(concreteProvider);
// needed to collect dynamic metrics and update the gauge created from them
metricsRegistry.collect(mock(MetricsCollector.class));
assertEquals(142.42D, doubleGauge.read(), 10E-6);
metricsRegistry.deregisterDynamicMetricsProvider(concreteProvider);
// provide metric source to be cached
SomeObject someObject = new SomeObject();
someObject.doubleField = 42.42D;
metricsRegistry.registerDynamicMetricsProvider(someObject);
// needed to collect dynamic metrics and update the gauge created from them
metricsRegistry.collect(mock(MetricsCollector.class));
assertEquals(42.42D, doubleGauge.read(), 10E-6);
}
use of com.hazelcast.internal.metrics.ProbeUnit.COUNT in project hazelcast by hazelcast.
the class DoubleGaugeImplTest method whenNotVisitedWithCachedValueReadsDefault.
@Test
public void whenNotVisitedWithCachedValueReadsDefault() {
DynamicMetricsProvider concreteProvider = (descriptor, context) -> context.collect(descriptor.withPrefix("foo"), "doubleField", INFO, COUNT, 42.42D);
metricsRegistry.registerDynamicMetricsProvider(concreteProvider);
DoubleGauge doubleGauge = metricsRegistry.newDoubleGauge("foo.doubleField");
// needed to collect dynamic metrics and update the gauge created from them
metricsRegistry.collect(mock(MetricsCollector.class));
assertEquals(42.42D, doubleGauge.read(), 10E-6);
// clears the cached metric source
metricsRegistry.deregisterDynamicMetricsProvider(concreteProvider);
metricsRegistry.collect(mock(MetricsCollector.class));
assertEquals(DoubleGaugeImpl.DEFAULT_VALUE, doubleGauge.read(), 10E-6);
}
Aggregations