Class InternalAggregationTestCase<T extends org.elasticsearch.search.aggregations.InternalAggregation>

java.lang.Object
org.junit.Assert
org.apache.lucene.util.LuceneTestCase
Direct Known Subclasses:
InternalMultiBucketAggregationTestCase, InternalSingleBucketAggregationTestCase

public abstract class InternalAggregationTestCase<T extends org.elasticsearch.search.aggregations.InternalAggregation>
extends AbstractNamedWriteableTestCase<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 registerPlugin() so that the NamedWriteables can be extracted from the AggregatorSpecs in the plugin (as well as any other custom NamedWriteables)
  • Field Details

  • Constructor Details

  • Method Details

    • emptyReduceContextBuilder

      public static org.elasticsearch.search.aggregations.InternalAggregation.ReduceContextBuilder emptyReduceContextBuilder()
      Builds an InternalAggregation.ReduceContextBuilder that is valid but empty.
    • emptyReduceContextBuilder

      public static org.elasticsearch.search.aggregations.InternalAggregation.ReduceContextBuilder emptyReduceContextBuilder​(org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.PipelineTree pipelineTree)
      Builds an InternalAggregation.ReduceContextBuilder that is valid and nearly empty except that it contain PipelineAggregators.
    • getDefaultNamedXContents

      public static java.util.List<org.elasticsearch.common.xcontent.NamedXContentRegistry.Entry> getDefaultNamedXContents()
    • getNamedXContents

      protected java.util.List<org.elasticsearch.common.xcontent.NamedXContentRegistry.Entry> getNamedXContents()
    • xContentRegistry

      protected org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry()
      Description copied from class: ESTestCase
      The NamedXContentRegistry to use for this test. Subclasses should override and use liberally.
      Overrides:
      xContentRegistry in class ESTestCase
    • getNamedWriteableRegistry

      protected final org.elasticsearch.common.io.stream.NamedWriteableRegistry getNamedWriteableRegistry()
      Description copied from class: AbstractWireTestCase
      Get the NamedWriteableRegistry to use when de-serializing the object. Override this method if you need to register NamedWriteables for the test object to de-serialize. By default this will return a NamedWriteableRegistry with no registered NamedWriteables
      Specified by:
      getNamedWriteableRegistry in class AbstractNamedWriteableTestCase<T extends org.elasticsearch.search.aggregations.InternalAggregation>
    • getNamedWriteables

      protected java.util.List<org.elasticsearch.common.io.stream.NamedWriteableRegistry.Entry> getNamedWriteables()
      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 registerPlugin() instead because that route handles the automatic conversion of AggSpecs into namedWriteables.
    • registerPlugin

      protected org.elasticsearch.plugins.SearchPlugin registerPlugin()
      If a test needs to register additional aggregation specs for namedWriteable, etc, this method can be overridden by the implementor.
    • createTestInstance

      protected abstract T createTestInstance​(java.lang.String name, java.util.Map<java.lang.String,​java.lang.Object> metadata)
    • createUnmappedInstance

      protected T createUnmappedInstance​(java.lang.String name, java.util.Map<java.lang.String,​java.lang.Object> metadata)
      Return an instance on an unmapped field.
    • categoryClass

      protected final java.lang.Class<T> categoryClass()
      Description copied from class: AbstractNamedWriteableTestCase
      The type of NamedWriteable to read.
      Specified by:
      categoryClass in class AbstractNamedWriteableTestCase<T extends org.elasticsearch.search.aggregations.InternalAggregation>
    • randomResultsToReduce

      protected java.util.List<T> randomResultsToReduce​(java.lang.String name, int size)
      Generate a list of inputs to reduce. Defaults to calling createTestInstance(String) and createUnmappedInstance(String) but should be overridden if it isn't realistic to reduce test instances.
    • testReduceRandom

      public void testReduceRandom() throws java.io.IOException
      Throws:
      java.io.IOException
    • doAssertReducedMultiBucketConsumer

      protected void doAssertReducedMultiBucketConsumer​(org.elasticsearch.search.aggregations.Aggregation agg, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer)
    • mockScriptService

      protected org.elasticsearch.script.ScriptService mockScriptService()
      overwrite in tests that need it
    • assertReduced

      protected abstract void assertReduced​(T reduced, java.util.List<T> inputs)
    • createTestInstance

      public final T createTestInstance()
      Description copied from class: AbstractWireTestCase
      Creates a random test instance to use in the tests. This method will be called multiple times during test execution and should return a different random instance each time it is called.
      Specified by:
      createTestInstance in class AbstractWireTestCase<T extends org.elasticsearch.search.aggregations.InternalAggregation>
    • createUnmappedInstance

      protected final T createUnmappedInstance​(java.lang.String name)
      Return an instance on an unmapped field.
    • testFromXContent

      public final void testFromXContent() throws java.io.IOException
      Throws:
      java.io.IOException
    • testFromXContentWithRandomFields

      public final void testFromXContentWithRandomFields() throws java.io.IOException
      Throws:
      java.io.IOException
    • testMergePipelineTreeForBWCSerialization

      public void testMergePipelineTreeForBWCSerialization()
    • testMergePipelineTreeTwice

      public void testMergePipelineTreeTwice()
    • randomPipelineTree

      public static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.PipelineTree randomPipelineTree​(org.elasticsearch.search.aggregations.InternalAggregation aggregation)
    • randomPipelineAggregators

      public static java.util.List<org.elasticsearch.search.aggregations.pipeline.PipelineAggregator> randomPipelineAggregators()
    • assertFromXContent

      protected abstract void assertFromXContent​(T aggregation, org.elasticsearch.search.aggregations.ParsedAggregation parsedAggregation) throws java.io.IOException
      Throws:
      java.io.IOException
    • parseAndAssert

      protected <P extends org.elasticsearch.search.aggregations.ParsedAggregation> P parseAndAssert​(org.elasticsearch.search.aggregations.InternalAggregation aggregation, boolean shuffled, boolean addRandomFields) throws java.io.IOException
      Throws:
      java.io.IOException
    • excludePathsFromXContentInsertion

      protected java.util.function.Predicate<java.lang.String> excludePathsFromXContentInsertion()
      Overwrite this in your test if other than the basic xContent paths should be excluded during insertion of random fields
    • randomNumericDocValueFormat

      protected static org.elasticsearch.search.DocValueFormat randomNumericDocValueFormat()
      Returns:
      a random DocValueFormat that can be used in aggregations which compute numbers.
    • assertMultiBucketConsumer

      public static void assertMultiBucketConsumer​(org.elasticsearch.search.aggregations.Aggregation agg, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer)