|
119 | 119 | import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder; |
120 | 120 | import org.elasticsearch.search.aggregations.metrics.TopHitsAggregationBuilder; |
121 | 121 | import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder; |
122 | | -import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; |
123 | | -import org.elasticsearch.search.aggregations.pipeline.ParsedSimpleValue; |
124 | | -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; |
| 122 | +import org.elasticsearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder; |
| 123 | +import org.elasticsearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregationBuilder; |
125 | 124 | import org.elasticsearch.search.aggregations.pipeline.InternalBucketMetricValue; |
| 125 | +import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; |
126 | 126 | import org.elasticsearch.search.aggregations.pipeline.ParsedBucketMetricValue; |
| 127 | +import org.elasticsearch.search.aggregations.pipeline.ParsedDerivative; |
| 128 | +import org.elasticsearch.search.aggregations.pipeline.ParsedExtendedStatsBucket; |
127 | 129 | import org.elasticsearch.search.aggregations.pipeline.ParsedPercentilesBucket; |
128 | | -import org.elasticsearch.search.aggregations.pipeline.PercentilesBucketPipelineAggregationBuilder; |
| 130 | +import org.elasticsearch.search.aggregations.pipeline.ParsedSimpleValue; |
129 | 131 | import org.elasticsearch.search.aggregations.pipeline.ParsedStatsBucket; |
| 132 | +import org.elasticsearch.search.aggregations.pipeline.PercentilesBucketPipelineAggregationBuilder; |
| 133 | +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; |
130 | 134 | import org.elasticsearch.search.aggregations.pipeline.StatsBucketPipelineAggregationBuilder; |
131 | | -import org.elasticsearch.search.aggregations.pipeline.ExtendedStatsBucketPipelineAggregationBuilder; |
132 | | -import org.elasticsearch.search.aggregations.pipeline.ParsedExtendedStatsBucket; |
133 | | -import org.elasticsearch.search.aggregations.pipeline.DerivativePipelineAggregationBuilder; |
134 | | -import org.elasticsearch.search.aggregations.pipeline.ParsedDerivative; |
135 | 135 |
|
136 | 136 | import java.io.IOException; |
137 | 137 | import java.util.ArrayList; |
|
151 | 151 | import static org.elasticsearch.test.XContentTestUtils.insertRandomFields; |
152 | 152 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent; |
153 | 153 | import static org.hamcrest.Matchers.equalTo; |
| 154 | +import static org.hamcrest.Matchers.lessThanOrEqualTo; |
154 | 155 |
|
155 | 156 | public abstract class InternalAggregationTestCase<T extends InternalAggregation> extends AbstractWireSerializingTestCase<T> { |
156 | 157 | public static final int DEFAULT_MAX_BUCKETS = 100000; |
@@ -267,7 +268,14 @@ public void testReduceRandom() { |
267 | 268 | new InternalAggregation.ReduceContext(bigArrays, mockScriptService, bucketConsumer,false); |
268 | 269 | @SuppressWarnings("unchecked") |
269 | 270 | T reduced = (T) inputs.get(0).reduce(internalAggregations, context); |
270 | | - assertMultiBucketConsumer(reduced, bucketConsumer); |
| 271 | + int initialBucketCount = 0; |
| 272 | + for (InternalAggregation internalAggregation : internalAggregations) { |
| 273 | + initialBucketCount += countInnerBucket(internalAggregation); |
| 274 | + } |
| 275 | + int reducedBucketCount = countInnerBucket(reduced); |
| 276 | + //check that non final reduction never adds buckets |
| 277 | + assertThat(reducedBucketCount, lessThanOrEqualTo(initialBucketCount)); |
| 278 | + assertMultiBucketConsumer(reducedBucketCount, bucketConsumer); |
271 | 279 | toReduce = new ArrayList<>(toReduce.subList(r, toReduceSize)); |
272 | 280 | toReduce.add(reduced); |
273 | 281 | } |
@@ -332,14 +340,14 @@ protected NamedXContentRegistry xContentRegistry() { |
332 | 340 |
|
333 | 341 | public final void testFromXContent() throws IOException { |
334 | 342 | final T aggregation = createTestInstance(); |
335 | | - final Aggregation parsedAggregation = parseAndAssert(aggregation, randomBoolean(), false); |
336 | | - assertFromXContent(aggregation, (ParsedAggregation) parsedAggregation); |
| 343 | + final ParsedAggregation parsedAggregation = parseAndAssert(aggregation, randomBoolean(), false); |
| 344 | + assertFromXContent(aggregation, parsedAggregation); |
337 | 345 | } |
338 | 346 |
|
339 | 347 | public final void testFromXContentWithRandomFields() throws IOException { |
340 | 348 | final T aggregation = createTestInstance(); |
341 | | - final Aggregation parsedAggregation = parseAndAssert(aggregation, randomBoolean(), true); |
342 | | - assertFromXContent(aggregation, (ParsedAggregation) parsedAggregation); |
| 349 | + final ParsedAggregation parsedAggregation = parseAndAssert(aggregation, randomBoolean(), true); |
| 350 | + assertFromXContent(aggregation, parsedAggregation); |
343 | 351 | } |
344 | 352 |
|
345 | 353 | protected abstract void assertFromXContent(T aggregation, ParsedAggregation parsedAggregation) throws IOException; |
@@ -423,6 +431,10 @@ protected static DocValueFormat randomNumericDocValueFormat() { |
423 | 431 | } |
424 | 432 |
|
425 | 433 | public static void assertMultiBucketConsumer(Aggregation agg, MultiBucketConsumer bucketConsumer) { |
426 | | - assertThat(bucketConsumer.getCount(), equalTo(countInnerBucket(agg))); |
| 434 | + assertMultiBucketConsumer(countInnerBucket(agg), bucketConsumer); |
| 435 | + } |
| 436 | + |
| 437 | + private static void assertMultiBucketConsumer(int innerBucketCount, MultiBucketConsumer bucketConsumer) { |
| 438 | + assertThat(bucketConsumer.getCount(), equalTo(innerBucketCount)); |
427 | 439 | } |
428 | 440 | } |
0 commit comments