Search in sources :

Example 11 with LongPoint

use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.

the class LongGaugeImplTest 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"));
    LongGaugeImpl longGauge = new LongGaugeImpl(METRIC_NAME, METRIC_DESCRIPTION, METRIC_UNIT, labelKeys, EMPTY_CONSTANT_LABELS);
    LongPoint defaultPoint1 = longGauge.getDefaultTimeSeries();
    LongPoint defaultPoint2 = longGauge.getDefaultTimeSeries();
    LongPoint longPoint1 = longGauge.getOrCreateTimeSeries(labelValues);
    LongPoint longPoint2 = longGauge.getOrCreateTimeSeries(labelValues);
    new EqualsTester().addEqualityGroup(defaultPoint1, defaultPoint2).addEqualityGroup(longPoint1, longPoint2).testEquals();
    longGauge.clear();
    LongPoint newDefaultPointAfterClear = longGauge.getDefaultTimeSeries();
    LongPoint newLongPointAfterClear = longGauge.getOrCreateTimeSeries(labelValues);
    longGauge.removeTimeSeries(labelValues);
    LongPoint newLongPointAfterRemove = longGauge.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.LongGauge.LongPoint) Test(org.junit.Test)

Example 12 with LongPoint

use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.

the class LongGaugeImplTest method multipleMetrics_GetMetric.

@Test
public void multipleMetrics_GetMetric() {
    LongPoint longPoint = longGaugeMetric.getOrCreateTimeSeries(LABEL_VALUES);
    longPoint.add(1);
    longPoint.add(2);
    LongPoint defaultPoint = longGaugeMetric.getDefaultTimeSeries();
    defaultPoint.set(100);
    LongPoint longPoint1 = longGaugeMetric.getOrCreateTimeSeries(LABEL_VALUES1);
    longPoint1.add(-100);
    longPoint1.add(-20);
    List<TimeSeries> expectedTimeSeriesList = new ArrayList<TimeSeries>();
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES, Point.create(Value.longValue(3), TEST_TIME), null));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(DEFAULT_LABEL_VALUES, Point.create(Value.longValue(100), TEST_TIME), null));
    expectedTimeSeriesList.add(TimeSeries.createWithOnePoint(LABEL_VALUES1, Point.create(Value.longValue(-120), TEST_TIME), null));
    Metric metric = longGaugeMetric.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.LongGauge.LongPoint) Test(org.junit.Test)

Example 13 with LongPoint

use of io.opencensus.metrics.LongGauge.LongPoint in project instrumentation-java by census-instrumentation.

the class MetricRegistryImplTest method shouldReturnSameObjectOnMultipleRegisterCall.

@Test
public void shouldReturnSameObjectOnMultipleRegisterCall() {
    LongGauge longGauge = metricRegistry.addLongGauge(NAME, METRIC_OPTIONS);
    LongPoint longPoint = longGauge.getOrCreateTimeSeries(LABEL_VALUES);
    longPoint.set(200);
    LongGauge longGauge1 = metricRegistry.addLongGauge(NAME, METRIC_OPTIONS);
    LongPoint longPoint1 = longGauge1.getOrCreateTimeSeries(Collections.singletonList(LABEL_VALUE_2));
    longPoint1.set(300);
    assertThat(longGauge).isEqualTo(longGauge1);
    Collection<Metric> metricCollections = metricRegistry.getMetricProducer().getMetrics();
    assertThat(metricCollections.size()).isEqualTo(1);
    assertThat(metricCollections).containsExactly(Metric.create(LONG_METRIC_DESCRIPTOR, Arrays.asList(TimeSeries.createWithOnePoint(Arrays.asList(LABEL_VALUE, LABEL_VALUE_2), Point.create(Value.longValue(200), TEST_TIME), null), TimeSeries.createWithOnePoint(Arrays.asList(LABEL_VALUE_2, LABEL_VALUE_2), Point.create(Value.longValue(300), TEST_TIME), null))));
}
Also used : DerivedLongGauge(io.opencensus.metrics.DerivedLongGauge) LongGauge(io.opencensus.metrics.LongGauge) Metric(io.opencensus.metrics.export.Metric) LongPoint(io.opencensus.metrics.LongGauge.LongPoint) Test(org.junit.Test)

Aggregations

LongPoint (io.opencensus.metrics.LongGauge.LongPoint)13 Test (org.junit.Test)11 Metric (io.opencensus.metrics.export.Metric)9 LabelKey (io.opencensus.metrics.LabelKey)3 LabelValue (io.opencensus.metrics.LabelValue)3 DerivedLongGauge (io.opencensus.metrics.DerivedLongGauge)2 LongGauge (io.opencensus.metrics.LongGauge)2 TimeSeries (io.opencensus.metrics.export.TimeSeries)2 ArrayList (java.util.ArrayList)2 EqualsTester (com.google.common.testing.EqualsTester)1 Scope (io.opencensus.common.Scope)1 DerivedDoubleGauge (io.opencensus.metrics.DerivedDoubleGauge)1 DoubleGauge (io.opencensus.metrics.DoubleGauge)1 DoublePoint (io.opencensus.metrics.DoubleGauge.DoublePoint)1 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)1