Class AggregatorTestCase

java.lang.Object
org.junit.Assert
org.apache.lucene.tests.util.LuceneTestCase
org.opensearch.test.OpenSearchTestCase
org.opensearch.search.aggregations.AggregatorTestCase
Direct Known Subclasses:
BaseCompositeAggregatorTestCase

public abstract class AggregatorTestCase extends OpenSearchTestCase
Base class for testing Aggregator implementations. Provides helpers for constructing and searching an Aggregator implementation based on a provided AggregationBuilder instance.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
    Wrapper around Aggregator class Maintains a count for times collect() is invoked - number of documents visited
    static class 
     

    Nested classes/interfaces inherited from class org.apache.lucene.tests.util.LuceneTestCase

    org.apache.lucene.tests.util.LuceneTestCase.AwaitsFix, org.apache.lucene.tests.util.LuceneTestCase.Concurrency, org.apache.lucene.tests.util.LuceneTestCase.Monster, org.apache.lucene.tests.util.LuceneTestCase.Nightly, org.apache.lucene.tests.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.tests.util.LuceneTestCase.SuppressFileSystems, org.apache.lucene.tests.util.LuceneTestCase.SuppressFsync, org.apache.lucene.tests.util.LuceneTestCase.SuppressReproduceLine, org.apache.lucene.tests.util.LuceneTestCase.SuppressSysoutChecks, org.apache.lucene.tests.util.LuceneTestCase.SuppressTempFileChecks, org.apache.lucene.tests.util.LuceneTestCase.ThrowingConsumer<T>, org.apache.lucene.tests.util.LuceneTestCase.ThrowingRunnable, org.apache.lucene.tests.util.LuceneTestCase.Weekly
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final org.opensearch.common.TriConsumer<org.apache.lucene.document.Document, String, String>
     
    protected static final org.opensearch.common.TriConsumer<org.apache.lucene.document.Document, String, String>
     
    protected org.opensearch.search.aggregations.support.ValuesSourceRegistry
     

    Fields inherited from class org.apache.lucene.tests.util.LuceneTestCase

    assertsAreEnabled, classRules, DEFAULT_LINE_DOCS_FILE, INFOSTREAM, JENKINS_LARGE_LINE_DOCS_FILE, LEAVE_TEMPORARY, MAYBE_CACHE_POLICY, RANDOM_MULTIPLIER, ruleChain, suiteFailureMarker, SYSPROP_AWAITSFIX, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_MONSTER, SYSPROP_NIGHTLY, SYSPROP_WEEKLY, TEST_ASSERTS_ENABLED, TEST_AWAITSFIX, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_MONSTER, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_THROTTLING, TEST_WEEKLY, VERBOSE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Hook for checking things after all Aggregators have been closed.
    static org.opensearch.search.aggregations.AggregationBuilder
    Request an aggregation that returns the CardinalityUpperBound that was passed to its ctor.
    protected org.opensearch.search.aggregations.AggregationBuilder
    createAggBuilderForTypeTest(org.opensearch.index.mapper.MappedFieldType fieldType, String fieldName)
    This method is invoked each time a field type is tested in testSupportedFieldTypes().
    protected <A extends org.opensearch.search.aggregations.Aggregator>
    A
    createAggregator(org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.Aggregator>
    A
    createAggregator(org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.Aggregator>
    A
    createAggregator(org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.Aggregator>
    A
    createAggregator(org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.Aggregator>
    A
    createAggregator(org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.Aggregator>
    A
    createAggregator(org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.opensearch.search.internal.SearchContext searchContext)
     
    protected <A extends org.opensearch.search.aggregations.Aggregator>
    A
    createAggregatorWithCustomizableSearchContext(org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, Consumer<org.opensearch.search.internal.SearchContext> customizeSearchContext, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    createCountingAggregator(org.apache.lucene.search.Query query, org.opensearch.index.query.QueryBuilder queryBuilder, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.index.codec.composite.CompositeIndexFieldInfo starTree, LinkedHashMap<org.opensearch.index.compositeindex.datacube.Dimension, org.opensearch.index.mapper.MappedFieldType> supportedDimensions, List<org.opensearch.index.compositeindex.datacube.Metric> supportedMetrics, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.search.aggregations.AggregatorFactory aggregatorFactory, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected org.opensearch.index.IndexSettings
     
    protected org.opensearch.search.internal.SearchContext
    createSearchContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.core.indices.breaker.CircuitBreakerService circuitBreakerService, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected org.opensearch.search.internal.SearchContext
    createSearchContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
    Create a SearchContext for testing an Aggregator.
    protected org.opensearch.search.internal.SearchContext
    createSearchContextWithStarTreeContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.opensearch.index.query.QueryBuilder queryBuilder, org.opensearch.index.codec.composite.CompositeIndexFieldInfo starTree, LinkedHashMap<org.opensearch.index.compositeindex.datacube.Dimension, org.opensearch.index.mapper.MappedFieldType> supportedDimensions, List<org.opensearch.index.compositeindex.datacube.Metric> supportedMetrics, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.search.aggregations.AggregatorFactory aggregatorFactory, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.Aggregator>
    A
    createStreamAggregator(org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected org.opensearch.index.mapper.DateFieldMapper.DateFieldType
    dateField(String name, org.opensearch.index.mapper.DateFieldMapper.Resolution resolution)
    Make a DateFieldMapper.DateFieldType for a date.
    protected void
    doAssertReducedMultiBucketConsumer(org.opensearch.search.aggregations.Aggregation agg, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer)
     
    protected org.opensearch.index.mapper.NumberFieldMapper.NumberFieldType
    Make a NumberFieldMapper.NumberFieldType for a double.
    protected org.opensearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType
    Make a GeoPointFieldMapper.GeoPointFieldType for a geo_point.
    protected Map<String, org.opensearch.index.mapper.MappedFieldType>
    getFieldAliases(org.opensearch.index.mapper.MappedFieldType... fieldTypes)
    Allows subclasses to provide alternate names for the provided field type, which can be useful when testing aggregations on field aliases.
    protected org.opensearch.common.TriFunction<org.opensearch.index.mapper.MappedFieldType, String, Supplier<org.opensearch.search.lookup.SearchLookup>, org.opensearch.index.fielddata.IndexFieldData<?>>
    getIndexFieldDataLookup(org.opensearch.index.mapper.MapperService mapperService, org.opensearch.core.indices.breaker.CircuitBreakerService circuitBreakerService)
    Sub-tests that need a more complex index field data provider can override this
    protected org.opensearch.script.ScriptService
    Sub-tests that need scripting can override this method to provide a script service and pre-baked scripts
    protected List<org.opensearch.plugins.SearchPlugin>
    Test cases should override this if they have plugins that need to be loaded, e.g.
    protected List<org.opensearch.search.aggregations.support.ValuesSourceType>
    Implementors should return a list of ValuesSourceType that the aggregator supports.
    void
     
    protected org.opensearch.index.mapper.KeywordFieldMapper.KeywordFieldType
    Make a DateFieldMapper.DateFieldType for a date.
    protected org.opensearch.index.mapper.NumberFieldMapper.NumberFieldType
    Make a NumberFieldMapper.NumberFieldType for a long.
    protected org.opensearch.index.mapper.MapperService
    sub-tests that need a more complex mock can overwrite this
    protected static org.apache.lucene.index.IndexReader
    maybeWrapReaderEs(org.apache.lucene.index.DirectoryReader reader)
    Added to randomly run with more assertions on the index reader level, like LuceneTestCase.wrapReader(IndexReader), which can't be used because it also wraps in the IndexReader with other implementations that we can't handle.
    protected static org.apache.lucene.search.IndexSearcher
    newIndexSearcher(org.apache.lucene.index.IndexReader indexReader)
    Added to randomly run with more assertions on the index searcher level, like LuceneTestCase.newSearcher(IndexReader), which can't be used because it also wraps in the IndexSearcher's IndexReader with other implementations that we can't handle.
    protected org.opensearch.index.query.QueryShardContext
    queryShardContextMock(org.apache.lucene.search.IndexSearcher searcher, org.opensearch.index.mapper.MapperService mapperService, org.opensearch.index.IndexSettings indexSettings, org.opensearch.core.indices.breaker.CircuitBreakerService circuitBreakerService, org.opensearch.common.util.BigArrays bigArrays)
    sub-tests that need a more complex mock can overwrite this
    protected org.opensearch.index.mapper.RangeFieldMapper.RangeFieldType
    rangeField(String name, org.opensearch.index.mapper.RangeType rangeType)
    Make a NumberFieldMapper.NumberFieldType for a range.
    protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, boolean shardFanOut, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, int maxBucket, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, int maxBucket, boolean hasNested, boolean shardFanOut, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
    Collects all documents that match the provided query Query and returns the reduced InternalAggregation.
    protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, int maxBucket, boolean shardFanOut, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator>
    A
    searchAndReduce(org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator>
    A
    searchAndReduceCounting(int expectedCount, org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, int maxBucket, boolean hasNested, boolean shardFanOut, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
    Collects all documents that match the provided query Query and returns the reduced InternalAggregation.
    protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator>
    A
    searchAndReduceStarTree(org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.index.query.QueryBuilder queryBuilder, org.opensearch.search.aggregations.AggregationBuilder builder, org.opensearch.index.codec.composite.CompositeIndexFieldInfo compositeIndexFieldInfo, LinkedHashMap<org.opensearch.index.compositeindex.datacube.Dimension, org.opensearch.index.mapper.MappedFieldType> supportedDimensions, List<org.opensearch.index.compositeindex.datacube.Metric> supportedMetrics, int maxBucket, boolean hasNested, org.opensearch.search.aggregations.AggregatorFactory aggregatorFactory, boolean assertCollectorEarlyTermination, boolean skipReducedMultiBucketConsumerAssertion, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator>
    A
    searchAndReduceStarTree(org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.index.query.QueryBuilder queryBuilder, org.opensearch.search.aggregations.AggregationBuilder builder, org.opensearch.index.codec.composite.CompositeIndexFieldInfo compositeIndexFieldInfo, LinkedHashMap<org.opensearch.index.compositeindex.datacube.Dimension, org.opensearch.index.mapper.MappedFieldType> supportedDimensions, List<org.opensearch.index.compositeindex.datacube.Metric> supportedMetrics, int maxBucket, boolean hasNested, org.opensearch.search.aggregations.AggregatorFactory aggregatorFactory, boolean assertCollectorEarlyTermination, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    protected <T extends org.opensearch.search.aggregations.AggregationBuilder, V extends org.opensearch.search.aggregations.InternalAggregation>
    void
    testCase(T aggregationBuilder, org.apache.lucene.search.Query query, org.opensearch.common.CheckedConsumer<org.apache.lucene.tests.index.RandomIndexWriter, IOException> buildIndex, Consumer<V> verify, org.opensearch.index.mapper.MappedFieldType... fieldTypes)
     
    void
    This test will validate that an aggregator succeeds or fails to run against all the field types that are registered in IndicesModule (e.g.
    protected List<String>
    A method that allows implementors to specifically denylist particular field types (based on their content_name).
    protected org.apache.lucene.index.IndexReader
    wrapDirectoryReader(org.apache.lucene.index.DirectoryReader reader)
    Override to wrap the DirectoryReader for aggs like NestedAggregationBuilder.
    protected static org.apache.lucene.index.DirectoryReader
    wrapInMockESDirectoryReader(org.apache.lucene.index.DirectoryReader directoryReader)
     

    Methods inherited from class org.opensearch.test.OpenSearchTestCase

    after, afterIfFailed, afterIfSuccessful, allowedWarnings, assertArrayEquals, assertBusy, assertBusy, assertBusyWithFixedSleepTime, assertEquals, assertNoDeprecationWarnings, assertSettingDeprecationsAndWarnings, assertSettingDeprecationsAndWarnings, assertWarnings, assertWarnings, before, between, buildEnvSettings, buildNewFakeTransportAddress, checkStaticState, clearAdditionalRoles, copyInstance, copyNamedWriteable, copyNamedWriteable, copyWriteable, copyWriteable, createDefaultIndexAnalyzers, createParser, createParser, createParser, createParser, createParser, createParser, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableJodaDeprecationWarningsCheck, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureSupportedLocale, frequently, generateRandomStringArray, generateRandomStringArray, getBasePort, getBasePort, getDataPath, getPortRange, getShardLevelBlobPath, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, inFipsJvm, iterations, maybeSet, mockScript, newNodeEnvironment, newNodeEnvironment, persistedStateRegistry, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBigInteger, randomBoolean, randomByte, randomByteArrayOfLength, randomDateFormatterPattern, randomDateTimeZone, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomIp, randomList, randomList, randomLong, randomLongBetween, randomNonNegativeInt, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomUnsignedLong, randomValueOtherThan, randomValueOtherThanMany, randomZone, remoteIndexSettings, removeHeaderWarningAppender, replaceUnicodeControlCharacters, replaceUnicodeControlCharacters, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, setHeaderWarningAppender, settings, shuffleMap, shuffleXContent, shuffleXContent, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, tearDown, terminate, terminate, tmpPaths, toShuffledXContent, toShuffledXContent, waitUntil, waitUntil, warmIndexSettings, writableRegistry, xContentRegistry

    Methods inherited from class org.apache.lucene.tests.util.LuceneTestCase

    addVirusChecker, assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertDoubleUlpEquals, assertFieldInfosEquals, assertFloatUlpEquals, assertNormsEquals, assertPointsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, assertThat, assertThat, asSet, assumeFalse, assumeNoException, assumeTrue, atLeast, atLeast, callStackContains, callStackContains, callStackContainsAnyOf, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, ensureSaneIWCOnNightly, expectThrows, expectThrows, expectThrows, expectThrowsAnyOf, expectThrowsAnyOf, getDataInputStream, getJvmForkArguments, getOnlyLeafReader, getTestClass, getTestName, isTestThread, localeForLanguageTag, maybeChangeLiveIndexWriterConfig, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newBytesRef, newDirectory, newDirectory, newDirectory, newDirectory, newDirectory, newField, newField, newFSDirectory, newFSDirectory, newIndexWriterConfig, newIndexWriterConfig, newIndexWriterConfig, newIOContext, newIOContext, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newLogMergePolicy, newMaybeVirusCheckingDirectory, newMaybeVirusCheckingFSDirectory, newMergePolicy, newMergePolicy, newMergePolicy, newMockDirectory, newMockDirectory, newMockDirectory, newMockFSDirectory, newMockFSDirectory, newSearcher, newSearcher, newSearcher, newSearcher, newSearcher, newSnapshotIndexWriterConfig, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, randomVectorFormat, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, runWithRestrictedPermissions, setIndexWriterMaxDocs, setUp, setupCPUCoreCount, setUpExecutorService, shutdownExecutorService, slowFileExists, usually, usually, wrapReader

    Methods inherited from class org.junit.Assert

    assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThrows, assertThrows, assertTrue, assertTrue, fail, fail

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • valuesSourceRegistry

      protected org.opensearch.search.aggregations.support.ValuesSourceRegistry valuesSourceRegistry
    • ADD_SORTED_SET_FIELD_NOT_INDEXED

      protected static final org.opensearch.common.TriConsumer<org.apache.lucene.document.Document, String, String> ADD_SORTED_SET_FIELD_NOT_INDEXED
    • ADD_SORTED_SET_FIELD_INDEXED

      protected static final org.opensearch.common.TriConsumer<org.apache.lucene.document.Document, String, String> ADD_SORTED_SET_FIELD_INDEXED
  • Constructor Details

    • AggregatorTestCase

      public AggregatorTestCase()
  • Method Details

    • getFieldAliases

      protected Map<String, org.opensearch.index.mapper.MappedFieldType> getFieldAliases(org.opensearch.index.mapper.MappedFieldType... fieldTypes)
      Allows subclasses to provide alternate names for the provided field type, which can be useful when testing aggregations on field aliases.
    • initValuesSourceRegistry

      public void initValuesSourceRegistry()
    • getSearchPlugins

      protected List<org.opensearch.plugins.SearchPlugin> getSearchPlugins()
      Test cases should override this if they have plugins that need to be loaded, e.g. the plugins their aggregators are in.
    • createAggregator

      protected <A extends org.opensearch.search.aggregations.Aggregator> A createAggregator(org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createAggregator

      protected <A extends org.opensearch.search.aggregations.Aggregator> A createAggregator(org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createAggregator

      protected <A extends org.opensearch.search.aggregations.Aggregator> A createAggregator(org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createAggregator

      protected <A extends org.opensearch.search.aggregations.Aggregator> A createAggregator(org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createAggregator

      protected <A extends org.opensearch.search.aggregations.Aggregator> A createAggregator(org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createStreamAggregator

      protected <A extends org.opensearch.search.aggregations.Aggregator> A createStreamAggregator(org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createAggregatorWithCustomizableSearchContext

      protected <A extends org.opensearch.search.aggregations.Aggregator> A createAggregatorWithCustomizableSearchContext(org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, Consumer<org.opensearch.search.internal.SearchContext> customizeSearchContext, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createAggregator

      protected <A extends org.opensearch.search.aggregations.Aggregator> A createAggregator(org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.opensearch.search.internal.SearchContext searchContext) throws IOException
      Throws:
      IOException
    • createCountingAggregator

      protected AggregatorTestCase.CountingAggregator createCountingAggregator(org.apache.lucene.search.Query query, org.opensearch.index.query.QueryBuilder queryBuilder, org.opensearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.opensearch.index.codec.composite.CompositeIndexFieldInfo starTree, LinkedHashMap<org.opensearch.index.compositeindex.datacube.Dimension, org.opensearch.index.mapper.MappedFieldType> supportedDimensions, List<org.opensearch.index.compositeindex.datacube.Metric> supportedMetrics, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.search.aggregations.AggregatorFactory aggregatorFactory, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createSearchContext

      protected org.opensearch.search.internal.SearchContext createSearchContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Create a SearchContext for testing an Aggregator.
      Throws:
      IOException
    • createSearchContextWithStarTreeContext

      protected org.opensearch.search.internal.SearchContext createSearchContextWithStarTreeContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.opensearch.index.query.QueryBuilder queryBuilder, org.opensearch.index.codec.composite.CompositeIndexFieldInfo starTree, LinkedHashMap<org.opensearch.index.compositeindex.datacube.Dimension, org.opensearch.index.mapper.MappedFieldType> supportedDimensions, List<org.opensearch.index.compositeindex.datacube.Metric> supportedMetrics, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.search.aggregations.AggregatorFactory aggregatorFactory, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createSearchContext

      protected org.opensearch.search.internal.SearchContext createSearchContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer, org.opensearch.core.indices.breaker.CircuitBreakerService circuitBreakerService, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • createIndexSettings

      protected org.opensearch.index.IndexSettings createIndexSettings()
    • mapperServiceMock

      protected org.opensearch.index.mapper.MapperService mapperServiceMock()
      sub-tests that need a more complex mock can overwrite this
    • queryShardContextMock

      protected org.opensearch.index.query.QueryShardContext queryShardContextMock(org.apache.lucene.search.IndexSearcher searcher, org.opensearch.index.mapper.MapperService mapperService, org.opensearch.index.IndexSettings indexSettings, org.opensearch.core.indices.breaker.CircuitBreakerService circuitBreakerService, org.opensearch.common.util.BigArrays bigArrays)
      sub-tests that need a more complex mock can overwrite this
    • getIndexFieldDataLookup

      protected org.opensearch.common.TriFunction<org.opensearch.index.mapper.MappedFieldType, String, Supplier<org.opensearch.search.lookup.SearchLookup>, org.opensearch.index.fielddata.IndexFieldData<?>> getIndexFieldDataLookup(org.opensearch.index.mapper.MapperService mapperService, org.opensearch.core.indices.breaker.CircuitBreakerService circuitBreakerService)
      Sub-tests that need a more complex index field data provider can override this
    • getMockScriptService

      protected org.opensearch.script.ScriptService getMockScriptService()
      Sub-tests that need scripting can override this method to provide a script service and pre-baked scripts
    • searchAndReduce

      protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator> A searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, boolean shardFanOut, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • searchAndReduce

      protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator> A searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • searchAndReduce

      protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator> A searchAndReduce(org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • searchAndReduce

      protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator> A searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, int maxBucket, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • searchAndReduce

      protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator> A searchAndReduce(org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, int maxBucket, boolean shardFanOut, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • searchAndReduce

      protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator> A searchAndReduce(org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, int maxBucket, boolean hasNested, boolean shardFanOut, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Collects all documents that match the provided query Query and returns the reduced InternalAggregation.

      Half the time it aggregates each leaf individually and reduces all results together. The other half the time it aggregates across the entire index at once and runs a final reduction on the single resulting agg.

      Throws:
      IOException
    • searchAndReduceCounting

      protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator> A searchAndReduceCounting(int expectedCount, org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.search.aggregations.AggregationBuilder builder, int maxBucket, boolean hasNested, boolean shardFanOut, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Collects all documents that match the provided query Query and returns the reduced InternalAggregation.

      Half the time it aggregates each leaf individually and reduces all results together. The other half the time it aggregates across the entire index at once and runs a final reduction on the single resulting agg. The difference between this method and <A,C>searchAndReduce(org.apache.lucene.search.IndexSearcher,org.apache.lucene.search.Query,org.opensearch.search.aggregations.AggregationBuilder,boolean,org.opensearch.index.mapper.MappedFieldType...) is that this method also asserts the the number of documents match the expectedCount.

      Throws:
      IOException
    • searchAndReduceStarTree

      protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator> A searchAndReduceStarTree(org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.index.query.QueryBuilder queryBuilder, org.opensearch.search.aggregations.AggregationBuilder builder, org.opensearch.index.codec.composite.CompositeIndexFieldInfo compositeIndexFieldInfo, LinkedHashMap<org.opensearch.index.compositeindex.datacube.Dimension, org.opensearch.index.mapper.MappedFieldType> supportedDimensions, List<org.opensearch.index.compositeindex.datacube.Metric> supportedMetrics, int maxBucket, boolean hasNested, org.opensearch.search.aggregations.AggregatorFactory aggregatorFactory, boolean assertCollectorEarlyTermination, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • searchAndReduceStarTree

      protected <A extends org.opensearch.search.aggregations.InternalAggregation, C extends org.opensearch.search.aggregations.Aggregator> A searchAndReduceStarTree(org.opensearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.opensearch.index.query.QueryBuilder queryBuilder, org.opensearch.search.aggregations.AggregationBuilder builder, org.opensearch.index.codec.composite.CompositeIndexFieldInfo compositeIndexFieldInfo, LinkedHashMap<org.opensearch.index.compositeindex.datacube.Dimension, org.opensearch.index.mapper.MappedFieldType> supportedDimensions, List<org.opensearch.index.compositeindex.datacube.Metric> supportedMetrics, int maxBucket, boolean hasNested, org.opensearch.search.aggregations.AggregatorFactory aggregatorFactory, boolean assertCollectorEarlyTermination, boolean skipReducedMultiBucketConsumerAssertion, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • doAssertReducedMultiBucketConsumer

      protected void doAssertReducedMultiBucketConsumer(org.opensearch.search.aggregations.Aggregation agg, org.opensearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer)
    • testCase

      protected <T extends org.opensearch.search.aggregations.AggregationBuilder, V extends org.opensearch.search.aggregations.InternalAggregation> void testCase(T aggregationBuilder, org.apache.lucene.search.Query query, org.opensearch.common.CheckedConsumer<org.apache.lucene.tests.index.RandomIndexWriter, IOException> buildIndex, Consumer<V> verify, org.opensearch.index.mapper.MappedFieldType... fieldTypes) throws IOException
      Throws:
      IOException
    • wrapDirectoryReader

      protected org.apache.lucene.index.IndexReader wrapDirectoryReader(org.apache.lucene.index.DirectoryReader reader) throws IOException
      Override to wrap the DirectoryReader for aggs like NestedAggregationBuilder.
      Throws:
      IOException
    • wrapInMockESDirectoryReader

      protected static org.apache.lucene.index.DirectoryReader wrapInMockESDirectoryReader(org.apache.lucene.index.DirectoryReader directoryReader) throws IOException
      Throws:
      IOException
    • newIndexSearcher

      protected static org.apache.lucene.search.IndexSearcher newIndexSearcher(org.apache.lucene.index.IndexReader indexReader)
      Added to randomly run with more assertions on the index searcher level, like LuceneTestCase.newSearcher(IndexReader), which can't be used because it also wraps in the IndexSearcher's IndexReader with other implementations that we can't handle. (e.g. ParallelCompositeReader)
    • maybeWrapReaderEs

      protected static org.apache.lucene.index.IndexReader maybeWrapReaderEs(org.apache.lucene.index.DirectoryReader reader) throws IOException
      Added to randomly run with more assertions on the index reader level, like LuceneTestCase.wrapReader(IndexReader), which can't be used because it also wraps in the IndexReader with other implementations that we can't handle. (e.g. ParallelCompositeReader)
      Throws:
      IOException
    • getSupportedValuesSourceTypes

      protected List<org.opensearch.search.aggregations.support.ValuesSourceType> getSupportedValuesSourceTypes()
      Implementors should return a list of ValuesSourceType that the aggregator supports. This is used to test the matrix of supported/unsupported field types against the aggregator and verify it works (or doesn't) as expected.

      If this method is implemented, createAggBuilderForTypeTest(MappedFieldType, String) should be implemented as well.

      Returns:
      list of supported ValuesSourceTypes
    • createAggBuilderForTypeTest

      protected org.opensearch.search.aggregations.AggregationBuilder createAggBuilderForTypeTest(org.opensearch.index.mapper.MappedFieldType fieldType, String fieldName)
      This method is invoked each time a field type is tested in testSupportedFieldTypes(). The field type and name are provided, and the implementor is expected to return an AggBuilder accordingly. The AggBuilder should be returned even if the aggregation does not support the field type, because the test will check if an exception is thrown in that case.

      The list of supported types are provided by getSupportedValuesSourceTypes(), which must also be implemented.

      Parameters:
      fieldType - the type of the field that will be tested
      fieldName - the name of the field that will be test
      Returns:
      an aggregation builder to test against the field
    • unsupportedMappedFieldTypes

      protected List<String> unsupportedMappedFieldTypes()
      A method that allows implementors to specifically denylist particular field types (based on their content_name). This is needed in some areas where the ValuesSourceType is not granular enough, for example integer values vs floating points, or `keyword` bytes vs `binary` bytes (which are not searchable)

      This is a denylist instead of an allowlist because there are vastly more field types than ValuesSourceTypes, and it's expected that these unsupported cases are exceptional rather than common

    • testSupportedFieldTypes

      public void testSupportedFieldTypes() throws IOException
      This test will validate that an aggregator succeeds or fails to run against all the field types that are registered in IndicesModule (e.g. all the core field types). An aggregator is provided by the implementor class, and it is executed against each field type in turn. If an exception is thrown when the field is supported, that will fail the test. Similarly, if an exception _is not_ thrown when a field is unsupported, that will also fail the test.

      Exception types/messages are not currently checked, just presence/absence of an exception.

      Throws:
      IOException
    • afterClose

      protected void afterClose()
      Hook for checking things after all Aggregators have been closed.
    • dateField

      protected org.opensearch.index.mapper.DateFieldMapper.DateFieldType dateField(String name, org.opensearch.index.mapper.DateFieldMapper.Resolution resolution)
      Make a DateFieldMapper.DateFieldType for a date.
    • doubleField

      protected org.opensearch.index.mapper.NumberFieldMapper.NumberFieldType doubleField(String name)
      Make a NumberFieldMapper.NumberFieldType for a double.
    • geoPointField

      protected org.opensearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType geoPointField(String name)
      Make a GeoPointFieldMapper.GeoPointFieldType for a geo_point.
    • keywordField

      protected org.opensearch.index.mapper.KeywordFieldMapper.KeywordFieldType keywordField(String name)
      Make a DateFieldMapper.DateFieldType for a date.
    • longField

      protected org.opensearch.index.mapper.NumberFieldMapper.NumberFieldType longField(String name)
      Make a NumberFieldMapper.NumberFieldType for a long.
    • rangeField

      protected org.opensearch.index.mapper.RangeFieldMapper.RangeFieldType rangeField(String name, org.opensearch.index.mapper.RangeType rangeType)
      Make a NumberFieldMapper.NumberFieldType for a range.
    • aggCardinality

      public static org.opensearch.search.aggregations.AggregationBuilder aggCardinality(String name)
      Request an aggregation that returns the CardinalityUpperBound that was passed to its ctor.