Search in sources :

Example 1 with AggregationWindowData

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

the class ViewDataTest method testCumulativeViewData.

@Test
public void testCumulativeViewData() {
    View view = View.create(NAME, DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, TAG_KEYS, CUMULATIVE);
    Timestamp start = Timestamp.fromMillis(1000);
    Timestamp end = Timestamp.fromMillis(2000);
    AggregationWindowData windowData = CumulativeData.create(start, end);
    ViewData viewData = ViewData.create(view, ENTRIES, windowData);
    assertThat(viewData.getView()).isEqualTo(view);
    assertThat(viewData.getAggregationMap()).isEqualTo(ENTRIES);
    assertThat(viewData.getWindowData()).isEqualTo(windowData);
}
Also used : AggregationWindowData(io.opencensus.stats.ViewData.AggregationWindowData) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 2 with AggregationWindowData

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

the class ViewDataTest method testAggregationWindowDataMatch.

@Test
public void testAggregationWindowDataMatch() {
    final Timestamp start = Timestamp.fromMillis(1000);
    final Timestamp end = Timestamp.fromMillis(2000);
    final AggregationWindowData windowData1 = CumulativeData.create(start, end);
    final AggregationWindowData windowData2 = IntervalData.create(end);
    windowData1.match(new Function<CumulativeData, Void>() {

        @Override
        public Void apply(CumulativeData windowData) {
            assertThat(windowData.getStart()).isEqualTo(start);
            assertThat(windowData.getEnd()).isEqualTo(end);
            return null;
        }
    }, new Function<IntervalData, Void>() {

        @Override
        public Void apply(IntervalData windowData) {
            fail("CumulativeData expected.");
            return null;
        }
    }, Functions.<Void>throwIllegalArgumentException());
    windowData2.match(new Function<CumulativeData, Void>() {

        @Override
        public Void apply(CumulativeData windowData) {
            fail("IntervalData expected.");
            return null;
        }
    }, new Function<IntervalData, Void>() {

        @Override
        public Void apply(IntervalData windowData) {
            assertThat(windowData.getEnd()).isEqualTo(end);
            return null;
        }
    }, Functions.<Void>throwIllegalArgumentException());
}
Also used : AggregationWindowData(io.opencensus.stats.ViewData.AggregationWindowData) Timestamp(io.opencensus.common.Timestamp) IntervalData(io.opencensus.stats.ViewData.AggregationWindowData.IntervalData) CumulativeData(io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData) Test(org.junit.Test)

Example 3 with AggregationWindowData

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

the class ViewDataTest method testIntervalViewData.

@Test
public void testIntervalViewData() {
    View view = View.create(NAME, DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, TAG_KEYS, INTERVAL_HOUR);
    Timestamp end = Timestamp.fromMillis(2000);
    AggregationWindowData windowData = IntervalData.create(end);
    ViewData viewData = ViewData.create(view, ENTRIES, windowData);
    assertThat(viewData.getView()).isEqualTo(view);
    assertThat(viewData.getAggregationMap()).isEqualTo(ENTRIES);
    assertThat(viewData.getWindowData()).isEqualTo(windowData);
}
Also used : AggregationWindowData(io.opencensus.stats.ViewData.AggregationWindowData) Timestamp(io.opencensus.common.Timestamp) Test(org.junit.Test)

Example 4 with AggregationWindowData

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

the class ViewManagerImplTest method settingStateToDisabledWillClearStats.

@SuppressWarnings("deprecation")
private void settingStateToDisabledWillClearStats(View view) {
    Timestamp timestamp1 = Timestamp.create(1, 0);
    clock.setTime(timestamp1);
    viewManager.registerView(view);
    statsRecorder.newMeasureMap().put(MEASURE_DOUBLE, 1.1).record(tagger.emptyBuilder().put(KEY, VALUE).build());
    StatsTestUtil.assertAggregationMapEquals(viewManager.getView(view.getName()).getAggregationMap(), ImmutableMap.of(Arrays.asList(VALUE), StatsTestUtil.createAggregationData(view.getAggregation(), view.getMeasure(), 1.1)), EPSILON);
    Timestamp timestamp2 = Timestamp.create(2, 0);
    clock.setTime(timestamp2);
    // This will clear stats.
    statsComponent.setState(StatsCollectionState.DISABLED);
    assertThat(viewManager.getView(view.getName())).isEqualTo(createEmptyViewData(view));
    Timestamp timestamp3 = Timestamp.create(3, 0);
    clock.setTime(timestamp3);
    statsComponent.setState(StatsCollectionState.ENABLED);
    Timestamp timestamp4 = Timestamp.create(4, 0);
    clock.setTime(timestamp4);
    // This ViewData does not have any stats, but it should not be an empty ViewData, since it has
    // non-zero TimeStamps.
    ViewData viewData = viewManager.getView(view.getName());
    assertThat(viewData.getAggregationMap()).isEmpty();
    AggregationWindowData windowData = viewData.getWindowData();
    if (windowData instanceof CumulativeData) {
        assertThat(windowData).isEqualTo(CumulativeData.create(timestamp3, timestamp4));
    } else {
        assertThat(windowData).isEqualTo(IntervalData.create(timestamp4));
    }
}
Also used : StatsTestUtil.createEmptyViewData(io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData) ViewData(io.opencensus.stats.ViewData) AggregationWindowData(io.opencensus.stats.ViewData.AggregationWindowData) Timestamp(io.opencensus.common.Timestamp) CumulativeData(io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData)

Aggregations

Timestamp (io.opencensus.common.Timestamp)4 AggregationWindowData (io.opencensus.stats.ViewData.AggregationWindowData)4 Test (org.junit.Test)3 CumulativeData (io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData)2 StatsTestUtil.createEmptyViewData (io.opencensus.implcore.stats.StatsTestUtil.createEmptyViewData)1 ViewData (io.opencensus.stats.ViewData)1 IntervalData (io.opencensus.stats.ViewData.AggregationWindowData.IntervalData)1