use of org.opensearch.search.aggregations.support.AggregationUsageService in project OpenSearch by opensearch-project.
the class UsageServiceTests method testAggsUsage.
@SuppressWarnings("unchecked")
public void testAggsUsage() throws Exception {
AggregationUsageService.Builder builder = new AggregationUsageService.Builder();
builder.registerAggregationUsage("a", "x");
builder.registerAggregationUsage("a", "y");
builder.registerAggregationUsage("b", "x");
builder.registerAggregationUsage("c");
builder.registerAggregationUsage("b", "y");
builder.registerAggregationUsage("a", "z");
AggregationUsageService usageService = builder.build();
usageService.incAggregationUsage("a", "x");
for (int i = 0; i < 2; i++) {
usageService.incAggregationUsage("a", "y");
}
for (int i = 0; i < 3; i++) {
usageService.incAggregationUsage("a", "z");
}
for (int i = 0; i < 4; i++) {
usageService.incAggregationUsage("b", "x");
}
for (int i = 0; i < 5; i++) {
usageService.incAggregationUsage("b", "y");
}
for (int i = 0; i < 6; i++) {
usageService.incAggregationUsage("c", OTHER_SUBTYPE);
}
Map<String, Object> aggsUsage = usageService.getUsageStats();
assertThat(aggsUsage, notNullValue());
assertThat(aggsUsage.size(), equalTo(3));
assertThat(((Map<String, Object>) aggsUsage.get("a")).get("x"), equalTo(1L));
assertThat(((Map<String, Object>) aggsUsage.get("a")).get("y"), equalTo(2L));
assertThat(((Map<String, Object>) aggsUsage.get("a")).get("z"), equalTo(3L));
assertThat(((Map<String, Object>) aggsUsage.get("b")).get("x"), equalTo(4L));
assertThat(((Map<String, Object>) aggsUsage.get("b")).get("y"), equalTo(5L));
assertThat(((Map<String, Object>) aggsUsage.get("c")).get(OTHER_SUBTYPE), equalTo(6L));
}
Aggregations