Search in sources :

Example 21 with MetricsRegistry

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);
}
Also used : MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with MetricsRegistry

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);
}
Also used : MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with MetricsRegistry

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));
}
Also used : MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) RequireAssertEnabled(com.hazelcast.test.RequireAssertEnabled) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with MetricsRegistry

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);
}
Also used : MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 25 with MetricsRegistry

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());
}
Also used : MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MetricsRegistry (com.hazelcast.internal.metrics.MetricsRegistry)29 QuickTest (com.hazelcast.test.annotation.QuickTest)16 Test (org.junit.Test)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)6 MetricsCollector (com.hazelcast.internal.metrics.collectors.MetricsCollector)4 Config (com.hazelcast.config.Config)2 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)2 ExecutionService (com.hazelcast.spi.impl.executionservice.ExecutionService)2 CacheConfig (com.hazelcast.config.CacheConfig)1 ConfigAccessor.getActiveMemberNetworkConfig (com.hazelcast.config.ConfigAccessor.getActiveMemberNetworkConfig)1 MemberAddressProviderConfig (com.hazelcast.config.MemberAddressProviderConfig)1 HazelcastThreadGroup (com.hazelcast.instance.HazelcastThreadGroup)1 Node (com.hazelcast.instance.Node)1 ProtocolType (com.hazelcast.instance.ProtocolType)1 Node (com.hazelcast.instance.impl.Node)1 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)1 IOThreadingModel (com.hazelcast.internal.networking.IOThreadingModel)1 Networking (com.hazelcast.internal.networking.Networking)1