Search in sources :

Example 1 with MetricsCollector

use of com.hazelcast.internal.metrics.collectors.MetricsCollector in project hazelcast by hazelcast.

the class DynamicMetricsCollectionTest method testExtractingFromObjectProveLevelFilters.

@Test
public void testExtractingFromObjectProveLevelFilters() {
    SourceObject source = new SourceObject();
    source.longField = 42;
    source.doubleField = 42.42D;
    MetricsCollector collectorMock = mock(MetricsCollector.class);
    MetricsRegistry registry = new MetricsRegistryImpl(Logger.getLogger(MetricsRegistryImpl.class), MANDATORY);
    registry.registerDynamicMetricsProvider((descriptor, context) -> context.collect(descriptor.withPrefix("test"), source));
    registry.collect(collectorMock);
    verify(collectorMock, never()).collectLong(registry.newMetricDescriptor().withPrefix("test").withMetric("longField"), 42);
    verify(collectorMock, never()).collectDouble(registry.newMetricDescriptor().withPrefix("test").withMetric("doubleField"), 42.42D);
    verify(collectorMock, never()).collectLong(registry.newMetricDescriptor().withPrefix("test").withMetric("longMethod"), 43);
    verify(collectorMock, never()).collectDouble(registry.newMetricDescriptor().withPrefix("test").withMetric("doubleMethod"), 43.52D);
}
Also used : MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) MetricsRegistry(com.hazelcast.internal.metrics.MetricsRegistry) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with MetricsCollector

use of com.hazelcast.internal.metrics.collectors.MetricsCollector in project hazelcast by hazelcast.

the class RenderTest method whenException.

@Test
public void whenException() {
    MetricsCollector renderer = mock(MetricsCollector.class);
    final ExpectedRuntimeException ex = new ExpectedRuntimeException();
    metricsRegistry.registerStaticProbe(this, "foo", ProbeLevel.MANDATORY, (LongProbeFunction<RenderTest>) source -> {
        throw ex;
    });
    metricsRegistry.collect(renderer);
    verify(renderer).collectException(metricDescriptor("foo"), ex);
    verifyNoMoreInteractions(renderer);
}
Also used : MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) Logger(com.hazelcast.logging.Logger) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) MetricsCollector(com.hazelcast.internal.metrics.collectors.MetricsCollector) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) Mockito.verify(org.mockito.Mockito.verify) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) DoubleProbeFunction(com.hazelcast.internal.metrics.DoubleProbeFunction) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) DEFAULT_DESCRIPTOR_SUPPLIER(com.hazelcast.internal.metrics.impl.DefaultMetricDescriptorSupplier.DEFAULT_DESCRIPTOR_SUPPLIER) ProbeLevel(com.hazelcast.internal.metrics.ProbeLevel) LongProbeFunction(com.hazelcast.internal.metrics.LongProbeFunction) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with MetricsCollector

use of com.hazelcast.internal.metrics.collectors.MetricsCollector 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 4 with MetricsCollector

use of com.hazelcast.internal.metrics.collectors.MetricsCollector 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 5 with MetricsCollector

use of com.hazelcast.internal.metrics.collectors.MetricsCollector 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)

Aggregations

MetricsCollector (com.hazelcast.internal.metrics.collectors.MetricsCollector)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 MetricsRegistry (com.hazelcast.internal.metrics.MetricsRegistry)4 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)3 DoubleProbeFunction (com.hazelcast.internal.metrics.DoubleProbeFunction)1 LongProbeFunction (com.hazelcast.internal.metrics.LongProbeFunction)1 ProbeLevel (com.hazelcast.internal.metrics.ProbeLevel)1 DEFAULT_DESCRIPTOR_SUPPLIER (com.hazelcast.internal.metrics.impl.DefaultMetricDescriptorSupplier.DEFAULT_DESCRIPTOR_SUPPLIER)1 Logger (com.hazelcast.logging.Logger)1 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)1 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)1 RequireAssertEnabled (com.hazelcast.test.RequireAssertEnabled)1 Before (org.junit.Before)1 Category (org.junit.experimental.categories.Category)1 RunWith (org.junit.runner.RunWith)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.verifyNoMoreInteractions (org.mockito.Mockito.verifyNoMoreInteractions)1