Search in sources :

Example 1 with DoublePoint

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

Example 2 with DoublePoint

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

Example 3 with DoublePoint

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

Example 4 with DoublePoint

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

Example 5 with DoublePoint

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

Aggregations

DoublePoint (io.opencensus.metrics.DoubleCumulative.DoublePoint)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