use of io.opencensus.metrics.DoubleCumulative.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleCumulativeImplTest method clear.
@Test
public void clear() {
DoublePoint doublePoint = doubleCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
doublePoint.add(100);
Metric metric = doubleCumulativeMetric.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
doubleCumulativeMetric.clear();
assertThat(doubleCumulativeMetric.getMetric(testClock)).isNull();
}
use of io.opencensus.metrics.DoubleCumulative.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleCumulativeImplTest 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"));
DoubleCumulativeImpl doubleCumulative = new DoubleCumulativeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS, START_TIME);
DoublePoint defaultPoint1 = doubleCumulative.getDefaultTimeSeries();
DoublePoint defaultPoint2 = doubleCumulative.getDefaultTimeSeries();
DoublePoint doublePoint1 = doubleCumulative.getOrCreateTimeSeries(labelValues);
DoublePoint doublePoint2 = doubleCumulative.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(doublePoint1, doublePoint2).testEquals();
doubleCumulative.clear();
DoublePoint newDefaultPointAfterClear = doubleCumulative.getDefaultTimeSeries();
DoublePoint newDoublePointAfterClear = doubleCumulative.getOrCreateTimeSeries(labelValues);
doubleCumulative.removeTimeSeries(labelValues);
DoublePoint newDoublePointAfterRemove = doubleCumulative.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(doublePoint1, doublePoint2).addEqualityGroup(newDefaultPointAfterClear).addEqualityGroup(newDoublePointAfterClear).addEqualityGroup(newDoublePointAfterRemove).testEquals();
}
use of io.opencensus.metrics.DoubleCumulative.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleCumulativeImplTest method getOrCreateTimeSeries_IgnoreNegativePointValues.
@Test
public void getOrCreateTimeSeries_IgnoreNegativePointValues() {
DoublePoint point = doubleCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
point.add(-100);
point.add(25);
point.add(-33);
testClock.advanceTime(ONE_MINUTE);
Metric metric = doubleCumulativeMetric.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR);
assertThat(metric.getTimeSeriesList().size()).isEqualTo(1);
assertThat(metric.getTimeSeriesList().get(0).getPoints().size()).isEqualTo(1);
assertThat(metric.getTimeSeriesList().get(0).getPoints().get(0).getValue()).isEqualTo(Value.doubleValue(25));
}
use of io.opencensus.metrics.DoubleCumulative.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleCumulativeImplTest method getDefaultTimeSeries.
@Test
public void getDefaultTimeSeries() {
DoublePoint point = doubleCumulativeMetric.getDefaultTimeSeries();
point.add(100);
DoublePoint point1 = doubleCumulativeMetric.getDefaultTimeSeries();
point1.add(-100);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
Metric metric = doubleCumulativeMetric.getMetric(testClock);
assertThat(metric).isNotNull();
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.doubleValue(100), endTime), START_TIME)));
assertThat(point).isSameInstanceAs(point1);
}
use of io.opencensus.metrics.DoubleCumulative.DoublePoint in project instrumentation-java by census-instrumentation.
the class DoubleCumulativeImplTest method getOrCreateTimeSeries.
@Test
public void getOrCreateTimeSeries() {
DoublePoint point = doubleCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
point.add(100);
DoublePoint point1 = doubleCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
point1.add(500);
assertThat(point).isSameInstanceAs(point1);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
Metric metric = doubleCumulativeMetric.getMetric(testClock);
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.doubleValue(600), endTime), START_TIME)));
}
Aggregations