Search in sources :

Example 51 with MetricDescriptor

use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.

the class MetricsCompressorTest method testNewUnitIsConvertedToTag.

@Test
public void testNewUnitIsConvertedToTag() {
    boolean isNewUnitIntroduced = false;
    ProbeUnit aNewUnit = null;
    for (ProbeUnit unit : ProbeUnit.values()) {
        if (unit.isNewUnit()) {
            isNewUnitIntroduced = true;
            aNewUnit = unit;
        }
    }
    assumeTrue(isNewUnitIntroduced);
    MetricDescriptor originalMetric = supplier.get().withPrefix("prefix").withMetric("metricName").withDiscriminator("ds", "dsName1").withUnit(aNewUnit).withTag("tag0", "tag0Value");
    compressor.addLong(originalMetric, 42L);
    byte[] blob = compressor.getBlobAndReset();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    MetricsCompressor.extractMetrics(blob, metricConsumerMock, supplierSpy);
    MetricDescriptor expectedMetric = supplier.get().withPrefix("prefix").withMetric("metricName").withDiscriminator("ds", "dsName1").withUnit(null).withTag("tag0", "tag0Value").withTag("metric-unit", aNewUnit.name());
    verify(metricConsumerMock).consumeLong(expectedMetric, 42L);
    verifyNoMoreInteractions(metricConsumerMock);
    verify(supplierSpy, only()).get();
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ProbeUnit(com.hazelcast.internal.metrics.ProbeUnit) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 52 with MetricDescriptor

use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.

the class MetricsCompressorTest method testModifyingExtractedDoesntImpactExtraction.

@Test
public void testModifyingExtractedDoesntImpactExtraction() {
    DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
    MetricsCompressor compressor = new MetricsCompressor();
    MetricDescriptor metric1 = supplier.get().withPrefix("prefix").withMetric("metricName").withDiscriminator("name", "objName").withUnit(PERCENT).withTag("tag0", "tag0Value").withTag("tag1", "tag1Value").withExcludedTarget(JMX);
    MetricDescriptor sameMetric = metric1.copy();
    compressor.addLong(metric1, 42L);
    compressor.addLong(sameMetric, 43L);
    byte[] blob = compressor.getBlobAndReset();
    MetricConsumer metricConsumer = new MetricConsumer() {

        @Override
        public void consumeLong(MetricDescriptor descriptor, long value) {
            if (value == 42L) {
                descriptor.reset().withPrefix("modifiedPrefix").withMetric("modifiedMetric").withDiscriminator("name", "modifiedName").withUnit(BYTES).withTag("modifiedTag0", "modifiedTag0Value").withTag("modifiedTag1", "modifiedTag1Value").withExcludedTarget(DIAGNOSTICS);
            }
        }

        @Override
        public void consumeDouble(MetricDescriptor descriptor, double value) {
        }
    };
    MetricConsumer metricConsumerSpy = spy(metricConsumer);
    MetricsCompressor.extractMetrics(blob, metricConsumerSpy, supplierSpy);
    verify(metricConsumerSpy).consumeLong(sameMetric, 43L);
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 53 with MetricDescriptor

use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.

the class MetricsCompressorTest method testTwoMetrics_sameExcludedTargets.

@Test
public void testTwoMetrics_sameExcludedTargets() {
    DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
    MetricsCompressor compressor = new MetricsCompressor();
    MetricDescriptor metric1 = supplier.get().withPrefix("prefix").withMetric("metricName").withExcludedTarget(JMX).withExcludedTarget(MANAGEMENT_CENTER);
    MetricDescriptor metric2 = metric1.copy();
    compressor.addLong(metric1, 42L);
    compressor.addLong(metric2, 43L);
    byte[] blob = compressor.getBlobAndReset();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    MetricsCompressor.extractMetrics(blob, metricConsumerMock, supplierSpy);
    verify(metricConsumerMock).consumeLong(metric1, 42L);
    verify(metricConsumerMock).consumeLong(metric2, 43L);
    verifyNoMoreInteractions(metricConsumerMock);
    verify(supplierSpy, times(2)).get();
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 54 with MetricDescriptor

use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.

the class MetricsCompressorTest method testSingleLongMetric.

@Test
public void testSingleLongMetric() {
    MetricDescriptor originalMetric = supplier.get().withPrefix("prefix").withMetric("metricName").withDiscriminator("ds", "dsName1").withUnit(COUNT).withTag("tag0", "tag0Value");
    compressor.addLong(originalMetric, 42L);
    byte[] blob = compressor.getBlobAndReset();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    MetricsCompressor.extractMetrics(blob, metricConsumerMock, supplierSpy);
    verify(metricConsumerMock).consumeLong(originalMetric, 42L);
    verifyNoMoreInteractions(metricConsumerMock);
    verify(supplierSpy, only()).get();
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 55 with MetricDescriptor

use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.

the class MetricsCompressorTest method testSingleDoubleMetric.

@Test
public void testSingleDoubleMetric() {
    MetricDescriptor originalMetric = supplier.get().withPrefix("prefix").withMetric("metricName").withDiscriminator("ds", "dsName1").withUnit(COUNT).withTag("tag0", "tag0Value");
    compressor.addDouble(originalMetric, 42.42D);
    byte[] blob = compressor.getBlobAndReset();
    MetricConsumer metricConsumerMock = mock(MetricConsumer.class);
    MetricsCompressor.extractMetrics(blob, metricConsumerMock, supplierSpy);
    verify(metricConsumerMock).consumeDouble(originalMetric, 42.42D);
    verifyNoMoreInteractions(metricConsumerMock);
    verify(supplierSpy, only()).get();
}
Also used : MetricConsumer(com.hazelcast.internal.metrics.MetricConsumer) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)58 QuickTest (com.hazelcast.test.annotation.QuickTest)27 Test (org.junit.Test)27 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 MetricConsumer (com.hazelcast.internal.metrics.MetricConsumer)19 CPGroupId (com.hazelcast.cp.CPGroupId)7 MetricsRegistry (com.hazelcast.internal.metrics.MetricsRegistry)6 Map (java.util.Map)4 MetricsCollector (com.hazelcast.internal.metrics.collectors.MetricsCollector)3 InOrder (org.mockito.InOrder)3 ClientStatistics (com.hazelcast.client.impl.statistics.ClientStatistics)2 DynamicMetricsProvider (com.hazelcast.internal.metrics.DynamicMetricsProvider)2 ProbeUnit (com.hazelcast.internal.metrics.ProbeUnit)2 UUID (java.util.UUID)2 Client (com.hazelcast.client.Client)1 ClientEngine (com.hazelcast.client.impl.ClientEngine)1 ClientContext (com.hazelcast.client.impl.spi.ClientContext)1 ProxyManager (com.hazelcast.client.impl.spi.ProxyManager)1 Member (com.hazelcast.cluster.Member)1 IAtomicLong (com.hazelcast.cp.IAtomicLong)1