use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleGaugeImplTest method getOrCreateTimeSeries.
@Test
public void getOrCreateTimeSeries() {
DoublePoint point = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
point.add(100);
DoublePoint point1 = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
point1.set(500);
Metric metric = doubleGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.create(METRIC_DESCRIPTOR, Collections.singletonList(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(500), TEST_TIME), null))));
assertThat(point).isSameInstanceAs(point1);
}
use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleGaugeImplTest method clear.
@Test
public void clear() {
DoublePoint doublePoint = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
doublePoint.add(-11);
DoublePoint defaultPoint = doubleGauge.getDefaultTimeSeries();
defaultPoint.set(100);
Metric metric = doubleGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(2);
doubleGauge.clear();
assertThat(doubleGauge.getMetric(testClock)).isNull();
}
use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleGaugeImplTest 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"));
DoubleGaugeImpl doubleGauge = new DoubleGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS);
DoublePoint defaultPoint1 = doubleGauge.getDefaultTimeSeries();
DoublePoint defaultPoint2 = doubleGauge.getDefaultTimeSeries();
DoublePoint doublePoint1 = doubleGauge.getOrCreateTimeSeries(labelValues);
DoublePoint doublePoint2 = doubleGauge.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(doublePoint1, doublePoint2).testEquals();
doubleGauge.clear();
DoublePoint newDefaultPointAfterClear = doubleGauge.getDefaultTimeSeries();
DoublePoint newDoublePointAfterClear = doubleGauge.getOrCreateTimeSeries(labelValues);
doubleGauge.removeTimeSeries(labelValues);
DoublePoint newDoublePointAfterRemove = doubleGauge.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(doublePoint1, doublePoint2).addEqualityGroup(newDefaultPointAfterClear).addEqualityGroup(newDoublePointAfterClear).addEqualityGroup(newDoublePointAfterRemove).testEquals();
}
use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleGaugeImplTest method setDefaultLabelValues.
@Test
public void setDefaultLabelValues() {
List<LabelKey> labelKeys = Arrays.asList(LabelKey.create("key1", "desc"), LabelKey.create("key2", "desc"));
DoubleGaugeImpl doubleGauge = new DoubleGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS);
DoublePoint defaultPoint = doubleGauge.getDefaultTimeSeries();
defaultPoint.set(-230);
Metric metric = doubleGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
assertThat(metric.getTimeSeriesList().get(0).getLabelValues().size()).isEqualTo(2);
assertThat(metric.getTimeSeriesList().get(0).getLabelValues().get(0)).isEqualTo(UNSET_VALUE);
assertThat(metric.getTimeSeriesList().get(0).getLabelValues().get(1)).isEqualTo(UNSET_VALUE);
}
use of io.opencensus.metrics.DoubleGauge.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleGaugeImplTest method multipleMetrics_GetMetric.
@Test
public void multipleMetrics_GetMetric() {
DoublePoint doublePoint = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES);
doublePoint.add(1);
doublePoint.add(2);
DoublePoint defaultPoint = doubleGauge.getDefaultTimeSeries();
defaultPoint.set(100);
DoublePoint doublePoint1 = doubleGauge.getOrCreateTimeSeries(LABEL_VALUES1);
doublePoint1.add(-100);
doublePoint1.add(-20);
List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(3), TEST_TIME), null));
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.doubleValue(100), TEST_TIME), null));
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES1, Point.create(Value.doubleValue(-120), TEST_TIME), null));
Metric metric = doubleGauge.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(3);
assertThat(metric.getTimeSeriesList()).containsExactlyElementsIn(expectedTimeSeriesList);
}
Aggregations