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();
}
});
}
}
Aggregations