Search in sources :

Example 1 with COUNT

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());
}
Also used : QuickTest(com.hazelcast.test.annotation.QuickTest) MANDATORY(com.hazelcast.internal.metrics.ProbeLevel.MANDATORY) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) Math.round(java.lang.Math.round) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction) LongGauge(com.hazelcast.internal.metrics.LongGauge) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) WeakReference(java.lang.ref.WeakReference) LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) Before(org.junit.Before) INFO(com.hazelcast.internal.metrics.ProbeLevel.INFO) Logger(com.hazelcast.logging.Logger) COUNT(com.hazelcast.internal.metrics.ProbeUnit.COUNT) Probe(com.hazelcast.internal.metrics.Probe) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Assert.assertNull(org.junit.Assert.assertNull) BYTES(com.hazelcast.internal.metrics.ProbeUnit.BYTES) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with COUNT

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());
}
Also used : QuickTest(com.hazelcast.test.annotation.QuickTest) MANDATORY(com.hazelcast.internal.metrics.ProbeLevel.MANDATORY) RunWith(org.junit.runner.RunWith) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) Math.round(java.lang.Math.round) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction) LongGauge(com.hazelcast.internal.metrics.LongGauge) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) WeakReference(java.lang.ref.WeakReference) LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) Before(org.junit.Before) INFO(com.hazelcast.internal.metrics.ProbeLevel.INFO) Logger(com.hazelcast.logging.Logger) COUNT(com.hazelcast.internal.metrics.ProbeUnit.COUNT) Probe(com.hazelcast.internal.metrics.Probe) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Assert.assertNull(org.junit.Assert.assertNull) BYTES(com.hazelcast.internal.metrics.ProbeUnit.BYTES) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with COUNT

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);
}
Also used : INFO(com.hazelcast.internal.metrics.ProbeLevel.INFO) Logger(com.hazelcast.logging.Logger) COUNT(com.hazelcast.internal.metrics.ProbeUnit.COUNT) QuickTest(com.hazelcast.test.annotation.QuickTest) Probe(com.hazelcast.internal.metrics.Probe) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) MANDATORY(com.hazelcast.internal.metrics.ProbeLevel.MANDATORY) RunWith(org.junit.runner.RunWith) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) Test(org.junit.Test) DoubleGauge(com.hazelcast.internal.metrics.DoubleGauge) Category(org.junit.experimental.categories.Category) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) Assert.assertNull(org.junit.Assert.assertNull) BYTES(com.hazelcast.internal.metrics.ProbeUnit.BYTES) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) WeakReference(java.lang.ref.WeakReference) Assert.assertEquals(org.junit.Assert.assertEquals) LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) DoubleGauge(com.hazelcast.internal.metrics.DoubleGauge) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with COUNT

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);
}
Also used : INFO(com.hazelcast.internal.metrics.ProbeLevel.INFO) Logger(com.hazelcast.logging.Logger) COUNT(com.hazelcast.internal.metrics.ProbeUnit.COUNT) QuickTest(com.hazelcast.test.annotation.QuickTest) Probe(com.hazelcast.internal.metrics.Probe) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) MANDATORY(com.hazelcast.internal.metrics.ProbeLevel.MANDATORY) RunWith(org.junit.runner.RunWith) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) Test(org.junit.Test) DoubleGauge(com.hazelcast.internal.metrics.DoubleGauge) Category(org.junit.experimental.categories.Category) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) Assert.assertNull(org.junit.Assert.assertNull) BYTES(com.hazelcast.internal.metrics.ProbeUnit.BYTES) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) WeakReference(java.lang.ref.WeakReference) Assert.assertEquals(org.junit.Assert.assertEquals) LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) DoubleGauge(com.hazelcast.internal.metrics.DoubleGauge) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

DoubleProbeFunction (com.hazelcast.internal.metrics.DoubleProbeFunction)4 DynamicMetricsProvider (com.hazelcast.internal.metrics.DynamicMetricsProvider)4 LongProbeFunction (com.hazelcast.internal.metrics.LongProbeFunction)4 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)4 MetricsCollectionContext (com.hazelcast.internal.metrics.MetricsCollectionContext)4 Probe (com.hazelcast.internal.metrics.Probe)4 INFO (com.hazelcast.internal.metrics.ProbeLevel.INFO)4 MANDATORY (com.hazelcast.internal.metrics.ProbeLevel.MANDATORY)4 BYTES (com.hazelcast.internal.metrics.ProbeUnit.BYTES)4 COUNT (com.hazelcast.internal.metrics.ProbeUnit.COUNT)4 MetricsCollector (com.hazelcast.internal.metrics.collectors.MetricsCollector)4 Logger (com.hazelcast.logging.Logger)4 HazelcastSerialClassRunner (com.hazelcast.test.HazelcastSerialClassRunner)4 HazelcastTestSupport (com.hazelcast.test.HazelcastTestSupport)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 WeakReference (java.lang.ref.WeakReference)4 Assert.assertEquals (org.junit.Assert.assertEquals)4 Assert.assertNull (org.junit.Assert.assertNull)4 Before (org.junit.Before)4 Test (org.junit.Test)4