Search in sources :

Example 36 with View

use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method testGetCumulativeViewDataWithoutBucketBoundaries.

@Test
public void testGetCumulativeViewDataWithoutBucketBoundaries() {
    View view = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, MEAN, Arrays.asList(KEY));
    clock.setTime(Timestamp.create(1, 0));
    viewManager.registerView(view);
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(KEY, VALUE).build());
    clock.setTime(Timestamp.create(3, 0));
    ViewData viewData = viewManager.getView(VIEW_NAME);
    assertThat(viewData.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 0), Timestamp.create(3, 0)));
    StatsTestUtil.assertAggregationMapEquals(viewData.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(MEAN, MEASURE_DOUBLE, 1.1)), EPSILON);
}
Also used : StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) Test(org.junit.Test)

Example 37 with View

use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method testRegisterAndGetIntervalView.

@Test
public void testRegisterAndGetIntervalView() {
    View intervalView = View.create(VIEW_NAME, VIEW_DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), INTERVAL);
    viewManager.registerView(intervalView);
    assertThat(viewManager.getView(VIEW_NAME).getView()).isEqualTo(intervalView);
    assertThat(viewManager.getView(VIEW_NAME).getAggregationMap()).isEmpty();
    assertThat(viewManager.getView(VIEW_NAME).getWindowData()).isInstanceOf(IntervalData.class);
}
Also used : View(io.opencensus.stats.View) Test(org.junit.Test)

Example 38 with View

use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method testMultipleViews_DifferentMeasures.

private void testMultipleViews_DifferentMeasures(Measure measure1, Measure measure2, double value1, double value2) {
    final View view1 = createCumulativeView(VIEW_NAME, measure1, DISTRIBUTION, Arrays.asList(KEY));
    final View view2 = createCumulativeView(VIEW_NAME_2, measure2, DISTRIBUTION, Arrays.asList(KEY));
    clock.setTime(Timestamp.create(1, 0));
    viewManager.registerView(view1);
    clock.setTime(Timestamp.create(2, 0));
    viewManager.registerView(view2);
    TagContext tags = tagger.emptyBuilder().put(KEY, VALUE).build();
    MeasureMap measureMap = statsRecorder.newMeasureMap();
    putToMeasureMap(measureMap, measure1, value1);
    putToMeasureMap(measureMap, measure2, value2);
    measureMap.record(tags);
    clock.setTime(Timestamp.create(3, 0));
    ViewData viewData1 = viewManager.getView(VIEW_NAME);
    clock.setTime(Timestamp.create(4, 0));
    ViewData viewData2 = viewManager.getView(VIEW_NAME_2);
    assertThat(viewData1.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(1, 0), Timestamp.create(3, 0)));
    StatsTestUtil.assertAggregationMapEquals(viewData1.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, measure1, value1)), EPSILON);
    assertThat(viewData2.getWindowData()).isEqualTo(CumulativeData.create(Timestamp.create(2, 0), Timestamp.create(4, 0)));
    StatsTestUtil.assertAggregationMapEquals(viewData2.getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(DISTRIBUTION, measure2, value2)), EPSILON);
}
Also used : TagContext(io.opencensus.tags.TagContext) StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) View(io.opencensus.stats.View) MeasureMap(io.opencensus.stats.MeasureMap)

Example 39 with View

use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method registerDifferentViewWithSameNameWithStatsDisabled.

@Test
@SuppressWarnings("deprecation")
public void registerDifferentViewWithSameNameWithStatsDisabled() {
    statsComponent.setState(StatsCollectionState.DISABLED);
    View view1 = View.create(VIEW_NAME, "View description.", MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE);
    View view2 = View.create(VIEW_NAME, "This is a different description.", MEASURE_DOUBLE, DISTRIBUTION, Arrays.asList(KEY), CUMULATIVE);
    testFailedToRegisterView(view1, view2, "A different view with the same name is already registered");
}
Also used : View(io.opencensus.stats.View) Test(org.junit.Test)

Example 40 with View

use of io.opencensus.stats.View in project instrumentation-java by census-instrumentation.

the class ViewManagerImplTest method settingStateToDisabledWillClearStats_Cumulative.

@Test
public void settingStateToDisabledWillClearStats_Cumulative() {
    View cumulativeView = createCumulativeView(VIEW_NAME, MEASURE_DOUBLE, MEAN, Arrays.asList(KEY));
    settingStateToDisabledWillClearStats(cumulativeView);
}
Also used : View(io.opencensus.stats.View) Test(org.junit.Test)

Aggregations

View (io.opencensus.stats.View)45 Test (org.junit.Test)31 ViewData (io.opencensus.stats.ViewData)18 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)15 SimpleTagContext (io.opencensus.implcore.stats.StatsTestUtil.SimpleTagContext)6 Aggregation (io.opencensus.stats.Aggregation)5 TagContext (io.opencensus.tags.TagContext)5 Timestamp (io.opencensus.common.Timestamp)3 AggregationData (io.opencensus.stats.AggregationData)3 Measure (io.opencensus.stats.Measure)3 MeasureMap (io.opencensus.stats.MeasureMap)3 TagKey (io.opencensus.tags.TagKey)3 TagValue (io.opencensus.tags.TagValue)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CurrentState (io.opencensus.implcore.internal.CurrentState)2 DistributionData (io.opencensus.stats.AggregationData.DistributionData)2 MeasureDouble (io.opencensus.stats.Measure.MeasureDouble)2 ViewManager (io.opencensus.stats.ViewManager)2 ImmutableList (com.google.common.collect.ImmutableList)1