use of com.hazelcast.internal.metrics.MetricDescriptor 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);
}
use of com.hazelcast.internal.metrics.MetricDescriptor 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);
}
use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.
the class MetricsCompatibilityFileGenerator method generateBlob.
private static byte[] generateBlob() {
DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
MetricsCompressor compressor = new MetricsCompressor();
MetricDescriptor metric1 = supplier.get().withPrefix("prefix").withMetric("deltaMetric1").withDiscriminator("ds", "dsName1").withUnit(COUNT);
compressor.addLong(metric1, 42);
MetricDescriptor metric2 = metric1.copy().withMetric("deltaMetric2");
compressor.addDouble(metric2, -4.2);
// use a 254 byte string to test long words in the dictionary
String longPrefix = Stream.generate(() -> "a").limit(MetricsDictionary.MAX_WORD_LENGTH - 1).collect(Collectors.joining());
MetricDescriptor metric3 = supplier.get().withPrefix(longPrefix).withMetric("longPrefixMetric").withUnit(BYTES);
compressor.addLong(metric3, Integer.MAX_VALUE);
return compressor.getBlobAndReset();
}
use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.
the class MetricsCompressorTest method testTwoMetrics_differentExcludedTargets.
@Test
public void testTwoMetrics_differentExcludedTargets() {
DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
MetricsCompressor compressor = new MetricsCompressor();
MetricDescriptor metric1 = supplier.get().withPrefix("prefix").withMetric("metricName").withExcludedTarget(JMX);
MetricDescriptor metric2 = metric1.copy().withExcludedTarget(MANAGEMENT_CENTER);
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();
}
use of com.hazelcast.internal.metrics.MetricDescriptor in project hazelcast by hazelcast.
the class MetricsCompressorTest method testSingleMetricWithoutPrefix.
@Test
public void testSingleMetricWithoutPrefix() {
DefaultMetricDescriptorSupplier supplier = new DefaultMetricDescriptorSupplier();
MetricsCompressor compressor = new MetricsCompressor();
MetricDescriptor originalMetric = supplier.get().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();
}
Aggregations