Search in sources :

Example 1 with CumulativeData

use of io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData 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 2 with CumulativeData

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

the class ViewDataTest method aggregationAndAggregationDataMismatch.

private void aggregationAndAggregationDataMismatch(View view, Map<List<TagValue>, ? extends AggregationData> entries) {
    CumulativeData cumulativeData = CumulativeData.create(Timestamp.fromMillis(1000), Timestamp.fromMillis(2000));
    Aggregation aggregation = view.getAggregation();
    AggregationData aggregationData = entries.values().iterator().next();
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Aggregation and AggregationData types mismatch. " + "Aggregation: " + aggregation.getClass().getSimpleName() + " AggregationData: " + aggregationData.getClass().getSimpleName());
    ViewData.create(view, entries, cumulativeData);
}
Also used : CumulativeData(io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData)

Example 3 with CumulativeData

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

the class ViewDataTest method preventWindowAndAggregationWindowDataMismatch.

@Test
public void preventWindowAndAggregationWindowDataMismatch() {
    CumulativeData cumulativeData = CumulativeData.create(Timestamp.fromMillis(1000), Timestamp.fromMillis(2000));
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("AggregationWindow and AggregationWindowData types mismatch. " + "AggregationWindow: " + INTERVAL_HOUR.getClass().getSimpleName() + " AggregationWindowData: " + cumulativeData.getClass().getSimpleName());
    ViewData.create(View.create(NAME, DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, TAG_KEYS, INTERVAL_HOUR), ENTRIES, cumulativeData);
}
Also used : CumulativeData(io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData) Test(org.junit.Test)

Example 4 with CumulativeData

use of io.opencensus.stats.ViewData.AggregationWindowData.CumulativeData 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

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