Cover missing case in top_metrics test (#52517)

The top_metrics test assumed that it'd never end up *only* reducing
unmapped results. But, rarely, it does. This handles that case in the
test.

Closes #52462
This commit is contained in:
Nik Everett 2020-02-21 09:49:17 -05:00 committed by GitHub
parent e5b21a3fc6
commit ed957f35a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 6 deletions

View File

@ -27,6 +27,7 @@ import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import static java.util.Collections.emptyList;
@ -166,16 +167,23 @@ public class InternalTopMetricsTests extends InternalAggregationTestCase<Interna
@Override
protected void assertReduced(InternalTopMetrics reduced, List<InternalTopMetrics> inputs) {
InternalTopMetrics first = inputs.get(0);
InternalTopMetrics winner = inputs.stream()
Optional<InternalTopMetrics> winner = inputs.stream()
.filter(tm -> tm.isMapped())
.min((lhs, rhs) -> first.getSortOrder().reverseMul() * lhs.getSortValue().compareTo(rhs.getSortValue()))
.get();
.min((lhs, rhs) -> first.getSortOrder().reverseMul() * lhs.getSortValue().compareTo(rhs.getSortValue()));
assertThat(reduced.getName(), equalTo(first.getName()));
assertThat(reduced.getSortValue(), equalTo(winner.getSortValue()));
assertThat(reduced.getSortFormat(), equalTo(winner.getSortFormat()));
assertThat(reduced.getSortOrder(), equalTo(first.getSortOrder()));
assertThat(reduced.getMetricValue(), equalTo(winner.getMetricValue()));
assertThat(reduced.getMetricName(), equalTo(first.getMetricName()));
if (winner.isPresent()) {
assertThat(reduced.getSortValue(), equalTo(winner.get().getSortValue()));
assertThat(reduced.getSortFormat(), equalTo(winner.get().getSortFormat()));
assertThat(reduced.getMetricValue(), equalTo(winner.get().getMetricValue()));
} else {
// Reduced only unmapped metrics
assertThat(reduced.getSortValue(), equalTo(first.getSortValue()));
assertThat(reduced.getSortFormat(), equalTo(first.getSortFormat()));
assertThat(reduced.getMetricValue(), equalTo(first.getMetricValue()));
}
}
private static SortValue randomSortValue() {