use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class StatsRecorderImplTest method recordTwice.
@Test
public void recordTwice() {
View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
viewManager.registerView(view);
MeasureMap statsRecord = statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0);
statsRecord.record(new SimpleTagContext(Tag.create(KEY, VALUE)));
statsRecord.record(new SimpleTagContext(Tag.create(KEY, VALUE_2)));
ViewData viewData = viewManager.getView(VIEW_NAME);
// There should be two entries.
StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0), Arrays.asList(VALUE_2), StatsTestUtil.createAggregationData(Sum.create(), MEASURE_DOUBLE, 1.0)), 1e-6);
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class StatsRecorderImplTest method record_CurrentContextNotSet.
@Test
public void record_CurrentContextNotSet() {
View view = View.create(VIEW_NAME, "description", MEASURE_DOUBLE, Sum.create(), Arrays.asList(KEY), Cumulative.create());
viewManager.registerView(view);
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.0).record();
ViewData viewData = viewManager.getView(VIEW_NAME);
// record() should have used the default TagContext, so the tag value should be null.
assertThat(viewData.getAggregationMap().keySet()).containsExactly(Arrays.asList((TagValue) null));
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testRecordCumulativeMultipleTagValues.
@Test
public void testRecordCumulativeMultipleTagValues() {
viewManager.registerView(createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY)));
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 10.0).record(tagger.emptyBuilder().put(KEY, VALUE).build());
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 30.0).record(tagger.emptyBuilder().put(KEY, VALUE_2).build());
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 50.0).record(tagger.emptyBuilder().put(KEY, VALUE_2).build());
ViewData viewData = viewManager.getView(VIEW_NAME);
assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 10.0), Arrays.asList(VALUE_2), createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 30.0, 50.0)), EPSILON);
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class MeasureToViewMapTest method testRegisterAndGetView.
@Test
public void testRegisterAndGetView() {
MeasureToViewMap measureToViewMap = new MeasureToViewMap();
TestClock clock = TestClock.create(Timestamp.create(10, 20));
measureToViewMap.registerView(VIEW, clock);
clock.setTime(Timestamp.create(30, 40));
ViewData viewData = measureToViewMap.getView(VIEW_NAME, clock, State.ENABLED);
assertThat(viewData.getView()).isEqualTo(VIEW);
assertThat(viewData.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(10, 20), Timestamp.create(30, 40)));
assertThat(viewData.getAggregationMap()).isEmpty();
}
use of io.opencensus.stats.ViewData in project instrumentation-java by census-instrumentation.
the class ViewManagerImplTest method testMultipleViewSameMeasure.
@Test
public void testMultipleViewSameMeasure() {
final View view1 = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY));
final View view2 = createCumulativeView(VIEW_NAME_2, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY));
clock.setTime(Timestamp.create(1, 1));
viewManager.registerView(view1);
clock.setTime(Timestamp.create(2, 2));
viewManager.registerView(view2);
statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 5.0).record(tagger.emptyBuilder().put(KEY, VALUE).build());
clock.setTime(Timestamp.create(3, 3));
ViewData viewData1 = viewManager.getView(VIEW_NAME);
clock.setTime(Timestamp.create(4, 4));
ViewData viewData2 = viewManager.getView(VIEW_NAME_2);
assertThat(viewData1.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 1), Timestamp.create(3, 3)));
StatsTestUtil.assertAggregationMapEquals(viewData1.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 5.0)), EPSILON);
assertThat(viewData2.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(2, 2), Timestamp.create(4, 4)));
StatsTestUtil.assertAggregationMapEquals(viewData2.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, MEASURE_DOUBLE, 5.0)), EPSILON);
}
Aggregations