|
27 | 27 | import java.util.ArrayList;
|
28 | 28 | import java.util.List;
|
29 | 29 | import java.util.Map;
|
| 30 | +import java.util.Optional; |
30 | 31 | import java.util.function.Predicate;
|
31 | 32 |
|
32 | 33 | import static java.util.Collections.emptyList;
|
@@ -166,16 +167,23 @@ protected void assertFromXContent(InternalTopMetrics aggregation, ParsedAggregat
|
166 | 167 | @Override
|
167 | 168 | protected void assertReduced(InternalTopMetrics reduced, List<InternalTopMetrics> inputs) {
|
168 | 169 | InternalTopMetrics first = inputs.get(0);
|
169 |
| - InternalTopMetrics winner = inputs.stream() |
| 170 | + Optional<InternalTopMetrics> winner = inputs.stream() |
170 | 171 | .filter(tm -> tm.isMapped())
|
171 |
| - .min((lhs, rhs) -> first.getSortOrder().reverseMul() * lhs.getSortValue().compareTo(rhs.getSortValue())) |
172 |
| - .get(); |
| 172 | + .min((lhs, rhs) -> first.getSortOrder().reverseMul() * lhs.getSortValue().compareTo(rhs.getSortValue())); |
| 173 | + |
173 | 174 | assertThat(reduced.getName(), equalTo(first.getName()));
|
174 |
| - assertThat(reduced.getSortValue(), equalTo(winner.getSortValue())); |
175 |
| - assertThat(reduced.getSortFormat(), equalTo(winner.getSortFormat())); |
176 | 175 | assertThat(reduced.getSortOrder(), equalTo(first.getSortOrder()));
|
177 |
| - assertThat(reduced.getMetricValue(), equalTo(winner.getMetricValue())); |
178 | 176 | assertThat(reduced.getMetricName(), equalTo(first.getMetricName()));
|
| 177 | + if (winner.isPresent()) { |
| 178 | + assertThat(reduced.getSortValue(), equalTo(winner.get().getSortValue())); |
| 179 | + assertThat(reduced.getSortFormat(), equalTo(winner.get().getSortFormat())); |
| 180 | + assertThat(reduced.getMetricValue(), equalTo(winner.get().getMetricValue())); |
| 181 | + } else { |
| 182 | + // Reduced only unmapped metrics |
| 183 | + assertThat(reduced.getSortValue(), equalTo(first.getSortValue())); |
| 184 | + assertThat(reduced.getSortFormat(), equalTo(first.getSortFormat())); |
| 185 | + assertThat(reduced.getMetricValue(), equalTo(first.getMetricValue())); |
| 186 | + } |
179 | 187 | }
|
180 | 188 |
|
181 | 189 | private static SortValue randomSortValue() {
|
|
0 commit comments