Search in sources :

Example 1 with MeanData

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

the class StatszZPageHandlerTest method assertContainsViewData.

private static void assertContainsViewData(OutputStream output, ViewData viewData) {
    View view = viewData.getView();
    assertThat(output.toString()).contains(view.getName().asString());
    assertThat(output.toString()).contains(view.getDescription());
    assertThat(output.toString()).contains(view.getMeasure().getName());
    for (TagKey tagKey : view.getColumns()) {
        assertThat(output.toString()).contains(tagKey.getName());
    }
    String aggregationType = view.getAggregation().match(Functions.returnConstant("Sum"), Functions.returnConstant("Count"), Functions.returnConstant("Distribution"), Functions.returnConstant("Last Value"), new Function<Aggregation, String>() {

        @Override
        public String apply(Aggregation arg) {
            if (arg instanceof Aggregation.Mean) {
                return "Mean";
            }
            throw new AssertionError();
        }
    });
    assertThat(output.toString()).contains(aggregationType);
    for (Map.Entry<List<TagValue>, AggregationData> /*@Nullable*/
    entry : viewData.getAggregationMap().entrySet()) {
        List<TagValue> tagValues = entry.getKey();
        for (TagValue tagValue : tagValues) {
            String tagValueStr = tagValue == null ? "" : tagValue.asString();
            assertThat(output.toString()).contains(tagValueStr);
        }
        entry.getValue().match(Functions.</*@Nullable*/
        Void>throwAssertionError(), Functions.</*@Nullable*/
        Void>throwAssertionError(), Functions.</*@Nullable*/
        Void>throwAssertionError(), new Function<AggregationData.DistributionData, Void>() {

            @Override
            public Void apply(AggregationData.DistributionData arg) {
                assertThat(output.toString()).contains(String.valueOf(arg.getCount()));
                assertThat(output.toString()).contains(String.valueOf(arg.getMax()));
                assertThat(output.toString()).contains(String.valueOf(arg.getMin()));
                assertThat(output.toString()).contains(String.valueOf(arg.getMean()));
                assertThat(output.toString()).contains(String.valueOf(arg.getSumOfSquaredDeviations()));
                return null;
            }
        }, Functions.</*@Nullable*/
        Void>throwAssertionError(), Functions.</*@Nullable*/
        Void>throwAssertionError(), new Function<AggregationData, Void>() {

            @Override
            public Void apply(AggregationData arg) {
                if (arg instanceof MeanData) {
                    MeanData meanData = (MeanData) arg;
                    assertThat(output.toString()).contains(String.valueOf(meanData.getCount()));
                    assertThat(output.toString()).contains(String.valueOf(meanData.getMean()));
                    return null;
                }
                throw new AssertionError();
            }
        });
    }
}
Also used : AggregationData(io.opencensus.stats.AggregationData) MeanData(io.opencensus.stats.AggregationData.MeanData) View(io.opencensus.stats.View) Aggregation(io.opencensus.stats.Aggregation) TagKey(io.opencensus.tags.TagKey) List(java.util.List) TagValue(io.opencensus.tags.TagValue) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Aggregation (io.opencensus.stats.Aggregation)1 AggregationData (io.opencensus.stats.AggregationData)1 MeanData (io.opencensus.stats.AggregationData.MeanData)1 View (io.opencensus.stats.View)1 TagKey (io.opencensus.tags.TagKey)1 TagValue (io.opencensus.tags.TagValue)1 List (java.util.List)1 Map (java.util.Map)1