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

    • InternalAggregationTestCase

      public InternalAggregationTestCase()
  • Method Details

    • emptyReduceContextBuilder

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

      public static org.elasticsearch.search.aggregations.AggregationReduceContext.Builder emptyReduceContextBuilder(org.elasticsearch.search.aggregations.AggregatorFactories.Builder aggs)
      Builds an AggregationReduceContext that is valid and nearly empty except that it contains the provided builders.
    • mockReduceContext

      public static org.elasticsearch.search.aggregations.AggregationReduceContext.Builder mockReduceContext(org.elasticsearch.search.aggregations.AggregationBuilder agg)
      Builds an AggregationReduceContext to reduce the provided aggregation.
    • getDefaultNamedXContents

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

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

      protected org.elasticsearch.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 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(String name, Map<String,Object> metadata)
    • createUnmappedInstance

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

      protected final 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 InternalAggregationTestCase.BuilderAndToReduce<T> randomResultsToReduce(String name, int size)
      Generate a list of inputs to reduce. Defaults to calling createTestInstance(String) and createUnmappedInstance(String) and mockBuilder(List) but should be overridden if it isn't realistic to reduce test instances against mocked builders.
    • mockBuilder

      protected final org.elasticsearch.search.aggregations.AggregationBuilder mockBuilder(List<? extends org.elasticsearch.search.aggregations.InternalAggregation> results)
    • testReduceRandom

      public void testReduceRandom() throws IOException
      Throws:
      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, 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>
    • createTestMetadata

      public final Map<String,Object> createTestMetadata()
    • createUnmappedInstance

      protected final T createUnmappedInstance(String name)
      Return an instance on an unmapped field.
    • createTestInstanceForXContent

      public T createTestInstanceForXContent()
    • testFromXContent

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

      public final void testFromXContentWithRandomFields() throws IOException
      Throws:
      IOException
    • assertFromXContent

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

      public final void testConcurrentToXContent() throws IOException, InterruptedException, ExecutionException
      Calls ToXContent.toXContent(org.elasticsearch.xcontent.XContentBuilder, org.elasticsearch.xcontent.ToXContent.Params) on many threads and verifies that they produce the same result. Async search sometimes does this to aggregation responses and, in general, we think it's reasonable for everything that can convert itself to json to be able to do so concurrently.
      Throws:
      IOException
      InterruptedException
      ExecutionException
    • parseAndAssert

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

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

      public static org.elasticsearch.search.DocValueFormat randomNumericDocValueFormat()
      A random DocValueFormat that can be used in aggregations which compute numbers.
    • randomDateDocValueFormat

      public static org.elasticsearch.search.DocValueFormat randomDateDocValueFormat()
      A random DocValueFormat that can be used in aggregations which compute dates.
    • assertMultiBucketConsumer

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