|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.search.aggregations.bucket.children; |
| 21 | + |
| 22 | +import org.elasticsearch.common.io.stream.Writeable.Reader; |
| 23 | +import org.elasticsearch.search.DocValueFormat; |
| 24 | +import org.elasticsearch.search.aggregations.InternalAggregation; |
| 25 | +import org.elasticsearch.search.aggregations.InternalAggregationTestCase; |
| 26 | +import org.elasticsearch.search.aggregations.InternalAggregations; |
| 27 | +import org.elasticsearch.search.aggregations.metrics.max.InternalMax; |
| 28 | +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; |
| 29 | + |
| 30 | +import java.util.ArrayList; |
| 31 | +import java.util.List; |
| 32 | +import java.util.Map; |
| 33 | + |
| 34 | +public class InternalChildrenTests extends InternalAggregationTestCase<InternalChildren> { |
| 35 | + |
| 36 | + @Override |
| 37 | + protected InternalChildren createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, |
| 38 | + Map<String, Object> metaData) { |
| 39 | + // we shouldn't use the full long range here since we sum doc count on reduce, and don't want to overflow the long range there |
| 40 | + long docCount = randomIntBetween(0, Integer.MAX_VALUE); |
| 41 | + int numAggregations = randomIntBetween(0, 20); |
| 42 | + List<InternalAggregation> aggs = new ArrayList<>(numAggregations); |
| 43 | + for (int i = 0; i < numAggregations; i++) { |
| 44 | + aggs.add(new InternalMax(randomAsciiOfLength(5), randomDouble(), |
| 45 | + randomFrom(DocValueFormat.BOOLEAN, DocValueFormat.GEOHASH, DocValueFormat.IP, DocValueFormat.RAW), pipelineAggregators, |
| 46 | + metaData)); |
| 47 | + } |
| 48 | + // don't randomize the name parameter, since InternalSingleBucketAggregation#doReduce asserts its the same for all reduced aggs |
| 49 | + return new InternalChildren("childAgg", docCount, new InternalAggregations(aggs), pipelineAggregators, metaData); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + protected void assertReduced(InternalChildren reduced, List<InternalChildren> inputs) { |
| 54 | + long expectedDocCount = 0; |
| 55 | + for (Children input : inputs) { |
| 56 | + expectedDocCount += input.getDocCount(); |
| 57 | + } |
| 58 | + assertEquals(expectedDocCount, reduced.getDocCount()); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + protected Reader<InternalChildren> instanceReader() { |
| 63 | + return InternalChildren::new; |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments