use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.
the class LongGaugeImplTest method testEquals.
@Test
public void testEquals() {
List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
List<LabelValue> labelValues = Arrays.asList(LabelValue.create("value1"), LabelValue.create("value2"));
LongGaugeImpl longGauge = new LongGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS);
LongPoint defaultPoint1 = longGauge.getDefaultTimeSeries();
LongPoint defaultPoint2 = longGauge.getDefaultTimeSeries();
LongPoint longPoint1 = longGauge.getOrCreateTimeSeries(labelValues);
LongPoint longPoint2 = longGauge.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).testEquals();
longGauge.clear();
LongPoint newDefaultPointAfterClear = longGauge.getDefaultTimeSeries();
LongPoint newLongPointAfterClear = longGauge.getOrCreateTimeSeries(labelValues);
longGauge.removeTimeSeries(labelValues);
LongPoint newLongPointAfterRemove = longGauge.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).addEqualityGroup(newDefaultPointAfterClear).addEqualityGroup(newLongPointAfterClear).addEqualityGroup(newLongPointAfterRemove).testEquals();
}
use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.
the class LongGaugeImplTest method multipleMetrics_GetMetric.
@Test
public void multipleMetrics_GetMetric() {
LongPoint longPoint = longGaugeMetric.getOrCreateTimeSeries(LABEL_VALUES);
longPoint.add(1);
longPoint.add(2);
LongPoint defaultPoint = longGaugeMetric.getDefaultTimeSeries();
defaultPoint.set(100);
LongPoint longPoint1 = longGaugeMetric.getOrCreateTimeSeries(LABEL_VALUES1);
longPoint1.add(-100);
longPoint1.add(-20);
List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(3), TEST_TIME), null));
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.longValue(100), TEST_TIME), null));
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES1, Point.create(Value.longValue(-120), TEST_TIME), null));
Metric metric = longGaugeMetric.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(3);
assertThat(metric.getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeriesList);
}
use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.
the class MetricRegistryImplTest method shouldReturnSameObjectOnMultipleRegisterCall.
@Test
public void shouldReturnSameObjectOnMultipleRegisterCall() {
LongGauge longGauge = metricRegistry.addLongGauge(NAME, METRIC_OPTIONS);
LongPoint longPoint = longGauge.getOrCreateTimeSeries(LABEL_VALUES);
longPoint.set(200);
LongGauge longGauge1 = metricRegistry.addLongGauge(NAME, METRIC_OPTIONS);
LongPoint longPoint1 = longGauge1.getOrCreateTimeSeries(Collections.singletonList(LABEL_VALUE_2));
longPoint1.set(300);
assertThat(longGauge).isEqualTo(longGauge1);
Collection<Metric> metricCollections = metricRegistry.getMetricProducer().getMetrics();
assertThat(metricCollections.size()).isEqualTo(1);
assertThat(metricCollections).containsExactly(Metric.create(LONG_METRIC_DESCRIPTOR, Arrays.asList(TimeSeries.createWithOnePoint(Arrays.asList(LABEL_VALUE, LABEL_VALUE_2), Point.create(Value.longValue(200), TEST_TIME), null), TimeSeries.createWithOnePoint(Arrays.asList(LABEL_VALUE_2, LABEL_VALUE_2), Point.create(Value.longValue(300), TEST_TIME), null))));
}
Aggregations