Convert InternalAggTestCase to AbstractNamedWriteableTestCase (#55250)

Some aggregations, such as the Terms* family, will use an alternate
class to represent unmapped shard results (while the rest of the aggs
use the same object but with some form of "empty" or "nullish" values
to represent unmapped).

This was problematic with AbstractWireSerializingTestCase because it
expects the instanceReader to always match the original class.  Instead,
we need to use the NamedWriteable version so that the registry
can be consulted for the proper deserialization reader.
This commit is contained in:
Zachary Tong 2020-04-17 15:32:38 -04:00 committed by Zachary Tong
parent a5b545b2a0
commit f46b567563
56 changed files with 108 additions and 352 deletions

View File

@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.matrix;
import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;

View File

@ -19,17 +19,18 @@
package org.elasticsearch.search.aggregations.matrix.stats;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.MockBigArrays;
import org.elasticsearch.common.util.MockPageCacheRecycler;
import org.elasticsearch.common.xcontent.ContextParser;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.search.aggregations.matrix.MatrixAggregationPlugin;
import org.elasticsearch.search.aggregations.matrix.stats.InternalMatrixStats.Fields;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.PipelineTree;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -48,6 +49,11 @@ public class InternalMatrixStatsTests extends InternalAggregationTestCase<Intern
private String[] fields;
private boolean hasMatrixStatsResults;
@Override
protected SearchPlugin registerPlugin() {
return new MatrixAggregationPlugin();
}
@Override
public void setUp() throws Exception {
super.setUp();
@ -80,11 +86,6 @@ public class InternalMatrixStatsTests extends InternalAggregationTestCase<Intern
return new InternalMatrixStats(name, 1L, runningStats, matrixStatsResults, metadata);
}
@Override
protected Writeable.Reader<InternalMatrixStats> instanceReader() {
return InternalMatrixStats::new;
}
@Override
protected InternalMatrixStats mutateInstance(InternalMatrixStats instance) {
String name = instance.getName();

View File

@ -20,9 +20,10 @@
package org.elasticsearch.join.aggregations;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.NamedXContentRegistry.Entry;
import org.elasticsearch.join.ParentJoinPlugin;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase;
@ -34,6 +35,11 @@ import java.util.Map;
public class InternalChildrenTests extends InternalSingleBucketAggregationTestCase<InternalChildren> {
@Override
protected SearchPlugin registerPlugin() {
return new ParentJoinPlugin();
}
@Override
protected List<NamedXContentRegistry.Entry> getNamedXContents() {
List<Entry> extendedNamedXContents = new ArrayList<>(super.getNamedXContents());
@ -53,11 +59,6 @@ public class InternalChildrenTests extends InternalSingleBucketAggregationTestCa
// Nothing extra to assert
}
@Override
protected Reader<InternalChildren> instanceReader() {
return InternalChildren::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedChildren.class;

View File

@ -20,8 +20,9 @@
package org.elasticsearch.join.aggregations;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.xcontent.NamedXContentRegistry.Entry;
import org.elasticsearch.join.ParentJoinPlugin;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase;
@ -33,6 +34,11 @@ import java.util.Map;
public class InternalParentTests extends InternalSingleBucketAggregationTestCase<InternalParent> {
@Override
protected SearchPlugin registerPlugin() {
return new ParentJoinPlugin();
}
@Override
protected List<Entry> getNamedXContents() {
List<Entry> extendedNamedXContents = new ArrayList<>(super.getNamedXContents());
@ -52,11 +58,6 @@ public class InternalParentTests extends InternalSingleBucketAggregationTestCase
// Nothing extra to assert
}
@Override
protected Reader<InternalParent> instanceReader() {
return InternalParent::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedParent.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.adjacency;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation;
import org.elasticsearch.test.InternalMultiBucketAggregationTestCase;
@ -94,11 +93,6 @@ public class InternalAdjacencyMatrixTests extends InternalMultiBucketAggregation
assertEquals(expectedCounts, actualCounts);
}
@Override
protected Reader<InternalAdjacencyMatrix> instanceReader() {
return InternalAdjacencyMatrix::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedAdjacencyMatrix.class;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.bucket.composite;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.search.DocValueFormat;
@ -105,11 +104,6 @@ public class InternalCompositeTests extends InternalMultiBucketAggregationTestCa
types = null;
}
@Override
protected Writeable.Reader<InternalComposite> instanceReader() {
return InternalComposite::new;
}
@Override
protected Class<ParsedComposite> implementationClass() {
return ParsedComposite.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.filter;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
@ -39,11 +38,6 @@ public class InternalFilterTests extends InternalSingleBucketAggregationTestCase
// Nothing extra to assert
}
@Override
protected Reader<InternalFilter> instanceReader() {
return InternalFilter::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedFilter.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.filter;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation;
import org.elasticsearch.search.aggregations.bucket.filter.InternalFilters.InternalBucket;
@ -80,11 +79,6 @@ public class InternalFiltersTests extends InternalMultiBucketAggregationTestCase
assertEquals(expectedCounts, actualCounts);
}
@Override
protected Reader<InternalFilters> instanceReader() {
return InternalFilters::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedFilters.class;

View File

@ -18,7 +18,6 @@
*/
package org.elasticsearch.search.aggregations.bucket.geogrid;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.geometry.utils.Geohash;
import org.elasticsearch.search.aggregations.InternalAggregations;
@ -33,11 +32,6 @@ public class GeoHashGridTests extends GeoGridTestCase<InternalGeoHashGridBucket,
return new InternalGeoHashGrid(name, size, buckets, metadata);
}
@Override
protected Writeable.Reader<InternalGeoHashGrid> instanceReader() {
return InternalGeoHashGrid::new;
}
@Override
protected InternalGeoHashGridBucket createInternalGeoGridBucket(Long key, long docCount, InternalAggregations aggregations) {
return new InternalGeoHashGridBucket(key, docCount, aggregations);

View File

@ -18,7 +18,6 @@
*/
package org.elasticsearch.search.aggregations.bucket.geogrid;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.aggregations.InternalAggregations;
import java.util.List;
@ -32,11 +31,6 @@ public class GeoTileGridTests extends GeoGridTestCase<InternalGeoTileGridBucket,
return new InternalGeoTileGrid(name, size, buckets, metadata);
}
@Override
protected Writeable.Reader<InternalGeoTileGrid> instanceReader() {
return InternalGeoTileGrid::new;
}
@Override
protected InternalGeoTileGridBucket createInternalGeoGridBucket(Long key, long docCount, InternalAggregations aggregations) {
return new InternalGeoTileGridBucket(key, docCount, aggregations);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.global;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
@ -39,11 +38,6 @@ public class InternalGlobalTests extends InternalSingleBucketAggregationTestCase
// Nothing extra to assert
}
@Override
protected Reader<InternalGlobal> instanceReader() {
return InternalGlobal::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedGlobal.class;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.bucket.histogram;
import org.elasticsearch.common.Rounding;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.search.DocValueFormat;
@ -239,11 +238,6 @@ public class InternalAutoDateHistogramTests extends InternalMultiBucketAggregati
return bucketCount;
}
@Override
protected Writeable.Reader<InternalAutoDateHistogram> instanceReader() {
return InternalAutoDateHistogram::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedAutoDateHistogram.class;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.bucket.histogram;
import org.elasticsearch.common.Rounding;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.BucketOrder;
@ -142,11 +141,6 @@ public class InternalDateHistogramTests extends InternalMultiBucketAggregationTe
assertEquals(expectedCounts, actualCounts);
}
@Override
protected Writeable.Reader<InternalDateHistogram> instanceReader() {
return InternalDateHistogram::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedDateHistogram.class;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.bucket.histogram;
import org.apache.lucene.util.TestUtil;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.InternalAggregations;
@ -149,11 +148,6 @@ public class InternalHistogramTests extends InternalMultiBucketAggregationTestCa
assertEquals(expectedCounts, actualCounts);
}
@Override
protected Reader<InternalHistogram> instanceReader() {
return InternalHistogram::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedHistogram.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.missing;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
@ -39,11 +38,6 @@ public class InternalMissingTests extends InternalSingleBucketAggregationTestCas
// Nothing extra to assert
}
@Override
protected Reader<InternalMissing> instanceReader() {
return InternalMissing::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedMissing.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.nested;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.ParsedAggregation;
@ -41,11 +40,6 @@ public class InternalNestedTests extends InternalSingleBucketAggregationTestCase
// Nothing extra to assert
}
@Override
protected Reader<InternalNested> instanceReader() {
return InternalNested::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedNested.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.nested;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.ParsedAggregation;
@ -41,11 +40,6 @@ public class InternalReverseNestedTests extends InternalSingleBucketAggregationT
// Nothing extra to assert
}
@Override
protected Reader<InternalReverseNested> instanceReader() {
return InternalReverseNested::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {
return ParsedReverseNested.class;

View File

@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.bucket.range;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation;
@ -86,11 +85,6 @@ public class InternalBinaryRangeTests extends InternalRangeTestCase<InternalBina
return new InternalBinaryRange(name, format, keyed, buckets, metadata);
}
@Override
protected Writeable.Reader<InternalBinaryRange> instanceReader() {
return InternalBinaryRange::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedBinaryRange.class;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.bucket.range;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation;
@ -90,11 +89,6 @@ public class InternalDateRangeTests extends InternalRangeTestCase<InternalDateRa
return new InternalDateRange(name, buckets, format, keyed, metadata);
}
@Override
protected Writeable.Reader<InternalDateRange> instanceReader() {
return InternalDateRange::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedDateRange.class;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.bucket.range;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation;
import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation;
@ -61,11 +60,6 @@ public class InternalGeoDistanceTests extends InternalRangeTestCase<InternalGeoD
geoDistanceRanges = Collections.unmodifiableList(listOfRanges);
}
@Override
protected Writeable.Reader<InternalGeoDistance> instanceReader() {
return InternalGeoDistance::new;
}
@Override
protected InternalGeoDistance createTestInstance(String name,
Map<String, Object> metadata,

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.bucket.range;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation;
@ -90,11 +89,6 @@ public class InternalRangeTests extends InternalRangeTestCase<InternalRange> {
return new InternalRange<>(name, buckets, format, keyed, metadata);
}
@Override
protected Writeable.Reader<InternalRange> instanceReader() {
return InternalRange::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedRange.class;

View File

@ -18,7 +18,6 @@
*/
package org.elasticsearch.search.aggregations.bucket.sampler;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase;
import org.elasticsearch.search.aggregations.bucket.ParsedSingleBucketAggregation;
@ -38,10 +37,6 @@ public class InternalSamplerTests extends InternalSingleBucketAggregationTestCas
// Nothing extra to assert
}
@Override
protected Writeable.Reader<InternalSampler> instanceReader() {
return InternalSampler::new;
}
@Override
protected Class<? extends ParsedSingleBucketAggregation> implementationClass() {

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.significant;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation;
@ -64,11 +63,6 @@ public class SignificantLongTermsTests extends InternalSignificantTermsTestCase
supersetSize, significanceHeuristic, buckets);
}
@Override
protected Writeable.Reader<InternalSignificantTerms<?, ?>> instanceReader() {
return SignificantLongTerms::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedSignificantLongTerms.class;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.bucket.significant;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation;
@ -57,11 +56,6 @@ public class SignificantStringTermsTests extends InternalSignificantTermsTestCas
supersetSize, significanceHeuristic, buckets);
}
@Override
protected Writeable.Reader<InternalSignificantTerms<?, ?>> instanceReader() {
return SignificantStringTerms::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedSignificantStringTerms.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.terms;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.InternalAggregations;
@ -58,11 +57,6 @@ public class DoubleTermsTests extends InternalTermsTestCase {
metadata, format, shardSize, showTermDocCountError, otherDocCount, buckets, docCountError);
}
@Override
protected Reader<InternalTerms<?, ?>> instanceReader() {
return DoubleTerms::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedDoubleTerms.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.terms;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.InternalAggregations;
@ -58,11 +57,6 @@ public class LongTermsTests extends InternalTermsTestCase {
metadata, format, shardSize, showTermDocCountError, otherDocCount, buckets, docCountError);
}
@Override
protected Reader<InternalTerms<?, ?>> instanceReader() {
return LongTerms::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedLongTerms.class;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.bucket.terms;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.InternalAggregations;
@ -59,11 +58,6 @@ public class StringTermsTests extends InternalTermsTestCase {
metadata, format, shardSize, showTermDocCountError, otherDocCount, buckets, docCountError);
}
@Override
protected Reader<InternalTerms<?, ?>> instanceReader() {
return StringTerms::new;
}
@Override
protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
return ParsedStringTerms.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.ParsedAggregation;
@ -39,11 +38,6 @@ public class InternalAvgTests extends InternalAggregationTestCase<InternalAvg> {
return new InternalAvg(name, randomDoubleBetween(0, 100000, true), count, formatter, metadata);
}
@Override
protected Reader<InternalAvg> instanceReader() {
return InternalAvg::new;
}
@Override
protected void assertReduced(InternalAvg reduced, List<InternalAvg> inputs) {
double sum = 0;

View File

@ -20,8 +20,6 @@
package org.elasticsearch.search.aggregations.metrics;
import com.carrotsearch.hppc.BitMixer;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.MockBigArrays;
@ -67,11 +65,6 @@ public class InternalCardinalityTests extends InternalAggregationTestCase<Intern
return new InternalCardinality(name, hllpp, metadata);
}
@Override
protected Reader<InternalCardinality> instanceReader() {
return InternalCardinality::new;
}
@Override
protected void assertReduced(InternalCardinality reduced, List<InternalCardinality> inputs) {
HyperLogLogPlusPlus[] algos = inputs.stream().map(InternalCardinality::getState)

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.ParsedAggregation;
@ -110,11 +109,6 @@ public class InternalExtendedStatsTests extends InternalAggregationTestCase<Inte
}
}
@Override
protected Writeable.Reader<InternalExtendedStats> instanceReader() {
return InternalExtendedStats::new;
}
@Override
protected InternalExtendedStats mutateInstance(InternalExtendedStats instance) {
String name = instance.getName();

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -95,11 +94,6 @@ public class InternalGeoBoundsTests extends InternalAggregationTestCase<Internal
assertEquals(aggregation.bottomRight(), parsed.bottomRight());
}
@Override
protected Writeable.Reader<InternalGeoBounds> instanceReader() {
return InternalGeoBounds::new;
}
@Override
protected InternalGeoBounds mutateInstance(InternalGeoBounds instance) {
String name = instance.getName();

View File

@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.metrics;
import org.apache.lucene.geo.GeoEncodingUtils;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
import org.elasticsearch.test.geo.RandomGeoGenerator;
@ -49,11 +48,6 @@ public class InternalGeoCentroidTests extends InternalAggregationTestCase<Intern
return new InternalGeoCentroid(name, centroid, count, Collections.emptyMap());
}
@Override
protected Writeable.Reader<InternalGeoCentroid> instanceReader() {
return InternalGeoCentroid::new;
}
@Override
protected void assertReduced(InternalGeoCentroid reduced, List<InternalGeoCentroid> inputs) {
double lonSum = 0;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.HdrHistogram.DoubleHistogram;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import java.util.Arrays;
@ -51,11 +50,6 @@ public class InternalHDRPercentilesRanksTests extends InternalPercentilesRanksTe
assertEquals(totalCount, reduced.state.getTotalCount());
}
@Override
protected Reader<InternalHDRPercentileRanks> instanceReader() {
return InternalHDRPercentileRanks::new;
}
@Override
protected Class<? extends ParsedPercentiles> implementationClass() {
return ParsedHDRPercentileRanks.class;

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.HdrHistogram.DoubleHistogram;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import java.util.Arrays;
@ -54,11 +53,6 @@ public class InternalHDRPercentilesTests extends InternalPercentilesTestCase<Int
assertEquals(totalCount, reduced.state.getTotalCount());
}
@Override
protected Writeable.Reader<InternalHDRPercentiles> instanceReader() {
return InternalHDRPercentiles::new;
}
@Override
protected Class<? extends ParsedPercentiles> implementationClass() {
return ParsedHDRPercentiles.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -37,11 +36,6 @@ public class InternalMaxTests extends InternalAggregationTestCase<InternalMax> {
return new InternalMax(name, value, formatter, metadata);
}
@Override
protected Reader<InternalMax> instanceReader() {
return InternalMax::new;
}
@Override
protected void assertReduced(InternalMax reduced, List<InternalMax> inputs) {
assertEquals(inputs.stream().mapToDouble(InternalMax::value).max().getAsDouble(), reduced.value(), 0);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -68,11 +67,6 @@ public class InternalMedianAbsoluteDeviationTests extends InternalAggregationTes
assertEquals(internalMAD.getMedianAbsoluteDeviation(), parsedMAD.getMedianAbsoluteDeviation(), 0);
}
@Override
protected Writeable.Reader<InternalMedianAbsoluteDeviation> instanceReader() {
return InternalMedianAbsoluteDeviation::new;
}
@Override
protected InternalMedianAbsoluteDeviation mutateInstance(InternalMedianAbsoluteDeviation instance) throws IOException {
String name = instance.getName();

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -36,11 +35,6 @@ public class InternalMinTests extends InternalAggregationTestCase<InternalMin> {
return new InternalMin(name, value, formatter, metadata);
}
@Override
protected Reader<InternalMin> instanceReader() {
return InternalMin::new;
}
@Override
protected void assertReduced(InternalMin reduced, List<InternalMin> inputs) {
assertEquals(inputs.stream().mapToDouble(InternalMin::value).min().getAsDouble(), reduced.value(), 0);

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.script.MockScriptEngine;
import org.elasticsearch.script.Script;
@ -132,11 +131,6 @@ public class InternalScriptedMetricTests extends InternalAggregationTestCase<Int
}
}
@Override
protected Reader<InternalScriptedMetric> instanceReader() {
return InternalScriptedMetric::new;
}
@Override
protected void assertFromXContent(InternalScriptedMetric aggregation, ParsedAggregation parsedAggregation) {
assertTrue(parsedAggregation instanceof ParsedScriptedMetric);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.search.aggregations.pipeline.InternalStatsBucket;
@ -46,11 +45,6 @@ public class InternalStatsBucketTests extends InternalStatsTests {
// no test since reduce operation is unsupported
}
@Override
protected Writeable.Reader<InternalStats> instanceReader() {
return InternalStatsBucket::new;
}
@Override
protected void assertFromXContent(InternalStats aggregation, ParsedAggregation parsedAggregation) {
super.assertFromXContent(aggregation, parsedAggregation);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent;
@ -145,11 +144,6 @@ public class InternalStatsTests extends InternalAggregationTestCase<InternalStat
}
}
@Override
protected Writeable.Reader<InternalStats> instanceReader() {
return InternalStats::new;
}
@Override
protected InternalStats mutateInstance(InternalStats instance) {
String name = instance.getName();

View File

@ -18,7 +18,6 @@
*/
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.ParsedAggregation;
@ -38,11 +37,6 @@ public class InternalSumTests extends InternalAggregationTestCase<InternalSum> {
return new InternalSum(name, value, formatter, metadata);
}
@Override
protected Writeable.Reader<InternalSum> instanceReader() {
return InternalSum::new;
}
@Override
protected void assertReduced(InternalSum reduced, List<InternalSum> inputs) {
double expectedSum = inputs.stream().mapToDouble(InternalSum::getValue).sum();

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import java.util.Arrays;
@ -62,11 +61,6 @@ public class InternalTDigestPercentilesRanksTests extends InternalPercentilesRan
}
}
@Override
protected Reader<InternalTDigestPercentileRanks> instanceReader() {
return InternalTDigestPercentileRanks::new;
}
@Override
protected Class<? extends ParsedPercentiles> implementationClass() {
return ParsedTDigestPercentileRanks.class;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import java.util.Arrays;
@ -58,11 +57,6 @@ public class InternalTDigestPercentilesTests extends InternalPercentilesTestCase
}
}
@Override
protected Writeable.Reader<InternalTDigestPercentiles> instanceReader() {
return InternalTDigestPercentiles::new;
}
@Override
protected Class<? extends ParsedPercentiles> implementationClass() {
return ParsedTDigestPercentiles.class;

View File

@ -31,7 +31,6 @@ import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.lucene.search.TopDocsAndMaxScore;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.common.xcontent.ToXContent;
@ -304,11 +303,6 @@ public class InternalTopHitsTests extends InternalAggregationTestCase<InternalTo
}
}
@Override
protected Reader<InternalTopHits> instanceReader() {
return InternalTopHits::new;
}
private SortField[] randomSortFields() {
SortField[] sortFields = new SortField[between(1, 5)];
Set<String> usedSortFields = new HashSet<>();

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -39,11 +38,6 @@ public class InternalValueCountTests extends InternalAggregationTestCase<Interna
assertEquals(inputs.stream().mapToLong(InternalValueCount::getValue).sum(), reduced.getValue(), 0);
}
@Override
protected Writeable.Reader<InternalValueCount> instanceReader() {
return InternalValueCount::new;
}
@Override
protected void assertFromXContent(InternalValueCount valueCount, ParsedAggregation parsedAggregation) {
assertEquals(valueCount.getValue(), ((ParsedValueCount) parsedAggregation).getValue(), 0);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.metrics;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -40,11 +39,6 @@ public class InternalWeightedAvgTests extends InternalAggregationTestCase<Intern
formatter, metadata);
}
@Override
protected Reader<InternalWeightedAvg> instanceReader() {
return InternalWeightedAvg::new;
}
@Override
protected void assertReduced(InternalWeightedAvg reduced, List<InternalWeightedAvg> inputs) {
double sum = 0;

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.pipeline;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -52,11 +51,6 @@ public class InternalBucketMetricValueTests extends InternalAggregationTestCase<
// no test since reduce operation is unsupported
}
@Override
protected Reader<InternalBucketMetricValue> instanceReader() {
return InternalBucketMetricValue::new;
}
@Override
protected void assertFromXContent(InternalBucketMetricValue bucketMetricValue, ParsedAggregation parsedAggregation) {
BucketMetricValue parsed = ((BucketMetricValue) parsedAggregation);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.pipeline;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -49,11 +48,6 @@ public class InternalDerivativeTests extends InternalAggregationTestCase<Interna
// no test since reduce operation is unsupported
}
@Override
protected Reader<InternalDerivative> instanceReader() {
return InternalDerivative::new;
}
@Override
protected void assertFromXContent(InternalDerivative derivative, ParsedAggregation parsedAggregation) {
ParsedDerivative parsed = ((ParsedDerivative) parsedAggregation);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.pipeline;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.search.aggregations.metrics.InternalExtendedStats;
@ -48,11 +47,6 @@ public class InternalExtendedStatsBucketTests extends InternalExtendedStatsTests
// no test since reduce operation is unsupported
}
@Override
protected Writeable.Reader<InternalExtendedStats> instanceReader() {
return InternalExtendedStatsBucket::new;
}
@Override
protected void assertFromXContent(InternalExtendedStats aggregation, ParsedAggregation parsedAggregation) {
super.assertFromXContent(aggregation, parsedAggregation);

View File

@ -20,7 +20,6 @@
package org.elasticsearch.search.aggregations.pipeline;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.json.JsonXContent;
@ -75,11 +74,6 @@ public class InternalPercentilesBucketTests extends InternalAggregationTestCase<
// no test since reduce operation is unsupported
}
@Override
protected Writeable.Reader<InternalPercentilesBucket> instanceReader() {
return InternalPercentilesBucket::new;
}
@Override
protected final void assertFromXContent(InternalPercentilesBucket aggregation, ParsedAggregation parsedAggregation) {
assertTrue(parsedAggregation instanceof ParsedPercentilesBucket);

View File

@ -19,7 +19,6 @@
package org.elasticsearch.search.aggregations.pipeline;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -48,11 +47,6 @@ public class InternalSimpleValueTests extends InternalAggregationTestCase<Intern
// no test since reduce operation is unsupported
}
@Override
protected Reader<InternalSimpleValue> instanceReader() {
return InternalSimpleValue::new;
}
@Override
protected void assertFromXContent(InternalSimpleValue simpleValue, ParsedAggregation parsedAggregation) {
ParsedSimpleValue parsed = ((ParsedSimpleValue) parsedAggregation);

View File

@ -35,6 +35,8 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.DocValueFormat;
@ -166,7 +168,13 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
public abstract class InternalAggregationTestCase<T extends InternalAggregation> extends AbstractWireSerializingTestCase<T> {
/**
* Implementors of this test case should be aware that the aggregation under test needs to be registered
* in the test's namedWriteableRegistry. Core aggregations are registered already, but non-core
* aggs should override {@link InternalAggregationTestCase#registerPlugin()} so that the NamedWriteables
* can be extracted from the AggregatorSpecs in the plugin (as well as any other custom NamedWriteables)
*/
public abstract class InternalAggregationTestCase<T extends InternalAggregation> extends AbstractNamedWriteableTestCase<T> {
/**
* Builds an {@link InternalAggregation.ReduceContextBuilder} that is valid but empty.
*/
@ -205,8 +213,7 @@ public abstract class InternalAggregationTestCase<T extends InternalAggregation>
}
};
private final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(
new SearchModule(Settings.EMPTY, false, emptyList()).getNamedWriteables());
private final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(getNamedWriteables());
private final NamedXContentRegistry namedXContentRegistry = new NamedXContentRegistry(getNamedXContents());
@ -274,6 +281,44 @@ public abstract class InternalAggregationTestCase<T extends InternalAggregation>
return namedXContents;
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return namedXContentRegistry;
}
@Override
protected final NamedWriteableRegistry getNamedWriteableRegistry() {
return namedWriteableRegistry;
}
/**
* Implementors can override this if they want to provide a custom list of namedWriteables. If the implementor
* _just_ wants to register in namedWriteables provided by a plugin, prefer overriding
* {@link InternalAggregationTestCase#registerPlugin()} instead because that route handles the automatic
* conversion of AggSpecs into namedWriteables.
*/
protected List<NamedWriteableRegistry.Entry> getNamedWriteables() {
SearchPlugin plugin = registerPlugin();
SearchModule searchModule
= new SearchModule(Settings.EMPTY, false, plugin == null ? emptyList() : Collections.singletonList(plugin));
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>(searchModule.getNamedWriteables());
// Modules/plugins may have extra namedwriteables that are not added by agg specs
if (plugin != null) {
entries.addAll(((Plugin) plugin).getNamedWriteables());
}
return entries;
}
/**
* If a test needs to register additional aggregation specs for namedWriteable, etc, this method
* can be overridden by the implementor.
*/
protected SearchPlugin registerPlugin() {
return null;
}
protected abstract T createTestInstance(String name, Map<String, Object> metadata);
/** Return an instance on an unmapped field. */
@ -282,6 +327,12 @@ public abstract class InternalAggregationTestCase<T extends InternalAggregation>
return createTestInstance(name, metadata);
}
@Override
protected final Class<T> categoryClass() {
return (Class<T>) InternalAggregation.class;
}
/**
* Generate a list of inputs to reduce. Defaults to calling
* {@link #createTestInstance(String)} and
@ -330,7 +381,7 @@ public abstract class InternalAggregationTestCase<T extends InternalAggregation>
* partial reduce. And to simulate cross cluster search.
*/
if (randomBoolean()) {
reduced = copyInstance(reduced);
reduced = copyNamedWriteable(reduced, getNamedWriteableRegistry(), categoryClass());
}
toReduce = new ArrayList<>(toReduce.subList(r, inputs.size()));
toReduce.add(reduced);
@ -381,16 +432,6 @@ public abstract class InternalAggregationTestCase<T extends InternalAggregation>
return createUnmappedInstance(name, metadata);
}
@Override
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return namedWriteableRegistry;
}
@Override
protected NamedXContentRegistry xContentRegistry() {
return namedXContentRegistry;
}
public final void testFromXContent() throws IOException {
final T aggregation = createTestInstance();
final ParsedAggregation parsedAggregation = parseAndAssert(aggregation, randomBoolean(), false);

View File

@ -10,13 +10,15 @@ import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.search.aggregations.metrics.TDigestState;
import org.elasticsearch.test.InternalAggregationTestCase;
import org.elasticsearch.xpack.analytics.AnalyticsPlugin;
import java.io.IOException;
import java.util.ArrayList;
@ -25,6 +27,12 @@ import java.util.List;
import java.util.Map;
public class InternalBoxplotTests extends InternalAggregationTestCase<InternalBoxplot> {
@Override
protected SearchPlugin registerPlugin() {
return new AnalyticsPlugin(Settings.EMPTY);
}
@Override
protected InternalBoxplot createTestInstance(String name, Map<String, Object> metadata) {
int numValues = frequently() ? randomInt(100) : 0;
@ -37,11 +45,6 @@ public class InternalBoxplotTests extends InternalAggregationTestCase<InternalBo
return new InternalBoxplot(name, state, formatter, metadata);
}
@Override
protected Writeable.Reader<InternalBoxplot> instanceReader() {
return InternalBoxplot::new;
}
@Override
protected void assertReduced(InternalBoxplot reduced, List<InternalBoxplot> inputs) {
TDigestState expected = new TDigestState(reduced.state().compression());

View File

@ -8,13 +8,15 @@ package org.elasticsearch.xpack.analytics.stringstats;
import org.elasticsearch.client.analytics.ParsedStringStats;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.InternalAggregationTestCase;
import org.elasticsearch.xpack.analytics.AnalyticsPlugin;
import java.io.IOException;
import java.util.ArrayList;
@ -30,6 +32,12 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
public class InternalStringStatsTests extends InternalAggregationTestCase<InternalStringStats> {
@Override
protected SearchPlugin registerPlugin() {
return new AnalyticsPlugin(Settings.EMPTY);
}
@Override
protected List<NamedXContentRegistry.Entry> getNamedXContents() {
List<NamedXContentRegistry.Entry> result = new ArrayList<>(super.getNamedXContents());
@ -103,11 +111,6 @@ public class InternalStringStatsTests extends InternalAggregationTestCase<Intern
DocValueFormat.RAW, instance.getMetadata());
}
@Override
protected Reader<InternalStringStats> instanceReader() {
return InternalStringStats::new;
}
@Override
protected void assertFromXContent(InternalStringStats aggregation, ParsedAggregation parsedAggregation) throws IOException {
ParsedStringStats parsed = (ParsedStringStats) parsedAggregation;

View File

@ -9,16 +9,18 @@ package org.elasticsearch.xpack.analytics.topmetrics;
import org.elasticsearch.client.analytics.ParsedTopMetrics;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.search.sort.SortValue;
import org.elasticsearch.test.InternalAggregationTestCase;
import org.elasticsearch.xpack.analytics.AnalyticsPlugin;
import java.io.IOException;
import java.time.ZoneId;
@ -55,6 +57,11 @@ public class InternalTopMetricsTests extends InternalAggregationTestCase<Interna
private final InternalTopMetrics.MetricValue metricOneLong =
new InternalTopMetrics.MetricValue(DocValueFormat.RAW, SortValue.from(1));
@Override
protected SearchPlugin registerPlugin() {
return new AnalyticsPlugin(Settings.EMPTY);
}
public void testEmptyIsNotMapped() {
InternalTopMetrics empty = InternalTopMetrics.buildEmptyAggregation(
randomAlphaOfLength(5), randomMetricNames(between(1, 5)), null);
@ -262,11 +269,6 @@ public class InternalTopMetricsTests extends InternalAggregationTestCase<Interna
return new InternalTopMetrics(name, sortOrder, metricNames, size, topMetrics, instance.getMetadata());
}
@Override
protected Reader<InternalTopMetrics> instanceReader() {
return InternalTopMetrics::new;
}
/**
* An extra test for parsing dates from xcontent because we can't random
* into {@link DocValueFormat.DateTime} because it doesn't

View File

@ -9,13 +9,11 @@ package org.elasticsearch.xpack.analytics.ttest;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.test.InternalAggregationTestCase;
@ -27,10 +25,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.util.Collections.emptyList;
public class InternalTTestTests extends InternalAggregationTestCase<InternalTTest> {
@Override
protected SearchPlugin registerPlugin() {
return new AnalyticsPlugin(Settings.EMPTY);
}
@Override
protected InternalTTest createTestInstance(String name, Map<String, Object> metadata) {
TTestState state = randomState(Long.MAX_VALUE, randomFrom(TTestType.values()), randomIntBetween(1, 2));
@ -64,11 +65,6 @@ public class InternalTTestTests extends InternalAggregationTestCase<InternalTTes
return new TTestStats(randomLongBetween(0, maxCount), randomDouble(), randomDouble());
}
@Override
protected Writeable.Reader<InternalTTest> instanceReader() {
return InternalTTest::new;
}
@Override
protected void assertReduced(InternalTTest reduced, List<InternalTTest> inputs) {
TTestState expected = reduced.state.reduce(inputs.stream().map(a -> a.state));
@ -128,13 +124,4 @@ public class InternalTTestTests extends InternalAggregationTestCase<InternalTTes
));
return extendedNamedXContents;
}
@Override
protected NamedWriteableRegistry getNamedWriteableRegistry() {
List<NamedWriteableRegistry.Entry> entries = new ArrayList<>();
entries.addAll(new SearchModule(Settings.EMPTY, false, emptyList()).getNamedWriteables());
entries.addAll(new AnalyticsPlugin(Settings.EMPTY).getNamedWriteables());
return new NamedWriteableRegistry(entries);
}
}