use of io.opencensus.metrics.LongCumulative.LongPoint in project instrumentation-java by census-instrumentation.
the class LongCumulativeImplTest method pointImpl_InstanceOf.
@Test
public void pointImpl_InstanceOf() {
LongPoint longPoint = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
assertThat(longPoint).isInstanceOf(LongCumulativeImpl.PointImpl.class);
}
use of io.opencensus.metrics.LongCumulative.LongPoint in project instrumentation-java by census-instrumentation.
the class LongCumulativeImplTest method getOrCreateTimeSeries.
@Test
public void getOrCreateTimeSeries() {
LongPoint point = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
point.add(100);
LongPoint point1 = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
point1.add(500);
assertThat(point).isSameInstanceAs(point1);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
Metric metric = longCumulativeMetric.getMetric(testClock);
assertThat(metric).isEqualTo(Metric.createWithOneTimeSeries(METRIC_DESCRIPTOR, TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(600), endTime), START_TIME)));
}
use of io.opencensus.metrics.LongCumulative.LongPoint in project instrumentation-java by census-instrumentation.
the class LongCumulativeImplTest method multipleMetrics_GetMetric.
@Test
public void multipleMetrics_GetMetric() {
LongPoint longPoint = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
longPoint.add(1);
longPoint.add(2);
LongPoint defaultPoint = longCumulativeMetric.getDefaultTimeSeries();
defaultPoint.add(100);
LongPoint longPoint1 = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES1);
longPoint1.add(-100);
longPoint1.add(-20);
testClock.advanceTime(ONE_MINUTE);
Timestamp endTime = testClock.now();
List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(3), endTime), START_TIME));
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.longValue(100), endTime), START_TIME));
expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES1, Point.create(Value.longValue(0), endTime), START_TIME));
Metric metric = longCumulativeMetric.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.LongCumulative.LongPoint in project instrumentation-java by census-instrumentation.
the class LongCumulativeImplTest 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"));
LongCumulativeImpl longCumulative = new LongCumulativeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS, START_TIME);
LongPoint defaultPoint1 = longCumulative.getDefaultTimeSeries();
LongPoint defaultPoint2 = longCumulative.getDefaultTimeSeries();
LongPoint longPoint1 = longCumulative.getOrCreateTimeSeries(labelValues);
LongPoint longPoint2 = longCumulative.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).testEquals();
longCumulative.clear();
LongPoint newDefaultPointAfterClear = longCumulative.getDefaultTimeSeries();
LongPoint newLongPointAfterClear = longCumulative.getOrCreateTimeSeries(labelValues);
longCumulative.removeTimeSeries(labelValues);
LongPoint newLongPointAfterRemove = longCumulative.getOrCreateTimeSeries(labelValues);
new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).addEqualityGroup(newDefaultPointAfterClear).addEqualityGroup(newLongPointAfterClear).addEqualityGroup(newLongPointAfterRemove).testEquals();
}
use of io.opencensus.metrics.LongCumulative.LongPoint in project instrumentation-java by census-instrumentation.
the class LongCumulativeImplTest method getOrCreateTimeSeries_IgnoreNegativePointValues.
@Test
public void getOrCreateTimeSeries_IgnoreNegativePointValues() {
LongPoint point = longCumulativeMetric.getOrCreateTimeSeries(LABEL_VALUES);
point.add(-100);
point.add(25);
point.add(-33);
testClock.advanceTime(ONE_MINUTE);
Metric metric = longCumulativeMetric.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.longValue(25));
}
Aggregations