Search in sources :

Example 1 with LongPoint

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);
}
Also used : LongPoint(io.opencensus.metrics.LongCumulative.LongPoint) Test(org.junit.Test)

Example 2 with LongPoint

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)));
}
Also used : Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongCumulative.LongPoint) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 3 with LongPoint

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);
}
Also used : TimeSeries(io.opencensus.metrics.export.TimeSeries) ArrayList(java.util.ArrayList) Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongCumulative.LongPoint) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 4 with LongPoint

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();
}
Also used : LabelValue(io.opencensus.metrics.LabelValue) EqualsTester(com.google.common.testing.EqualsTester) LabelKey(io.opencensus.metrics.LabelKey) LongPoint(io.opencensus.metrics.LongCumulative.LongPoint) Test(org.junit.Test)

Example 5 with LongPoint

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));
}
Also used : Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongCumulative.LongPoint) Test(org.junit.Test)

Aggregations

LongPoint (io.opencensus.metrics.LongCumulative.LongPoint)8 Test (org.junit.Test)8 Metric (io.opencensus.metrics.export.Metric)6 Timestamp (io.opencensus.common.Timestamp)4 LabelKey (io.opencensus.metrics.LabelKey)2 LabelValue (io.opencensus.metrics.LabelValue)2 TimeSeries (io.opencensus.metrics.export.TimeSeries)2 ArrayList (java.util.ArrayList)2 EqualsTester (com.google.common.testing.EqualsTester)1 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)1