Class AggregatorTestCase
java.lang.Object
org.junit.Assert
org.apache.lucene.util.LuceneTestCase
org.elasticsearch.test.ESTestCase
org.elasticsearch.search.aggregations.AggregatorTestCase
- Direct Known Subclasses:
GeoGridAggregatorTestCase
Base class for testing
Aggregator
implementations.
Provides helpers for constructing and searching an Aggregator
implementation based on a provided
AggregationBuilder
instance.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Nested classes/interfaces inherited from class org.elasticsearch.test.ESTestCase
ESTestCase.DeprecationWarning, ESTestCase.GeohashGenerator, ESTestCase.TestAnalysis
Nested classes/interfaces inherited from class org.apache.lucene.util.LuceneTestCase
org.apache.lucene.util.LuceneTestCase.AwaitsFix, org.apache.lucene.util.LuceneTestCase.BadApple, org.apache.lucene.util.LuceneTestCase.Monster, org.apache.lucene.util.LuceneTestCase.Nightly, org.apache.lucene.util.LuceneTestCase.Slow, org.apache.lucene.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.util.LuceneTestCase.SuppressFileSystems, org.apache.lucene.util.LuceneTestCase.SuppressFsync, org.apache.lucene.util.LuceneTestCase.SuppressReproduceLine, org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks, org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks, org.apache.lucene.util.LuceneTestCase.ThrowingRunnable, org.apache.lucene.util.LuceneTestCase.Weekly
-
Field Summary
Modifier and TypeFieldDescriptionprotected org.elasticsearch.search.aggregations.support.ValuesSourceRegistry
Fields inherited from class org.elasticsearch.test.ESTestCase
checkIndexFailures, DEFAULT_TEST_WORKER_ID, failureAndSuccessEvents, FIPS_SYSPROP, JAVA_TIMEZONE_IDS, JAVA_ZONE_IDS, logger, MIN_PRIVATE_PORT, TEST_WORKER_SYS_PROPERTY, TEST_WORKER_VM_ID
Fields inherited from class org.apache.lucene.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_BADAPPLES, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_MONSTER, SYSPROP_NIGHTLY, SYSPROP_SLOW, SYSPROP_WEEKLY, TEST_ASSERTS_ENABLED, TEST_AWAITSFIX, TEST_BADAPPLES, TEST_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_MONSTER, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_SLOW, TEST_THROTTLING, TEST_WEEKLY, VERBOSE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
Hook for checking things after allAggregator
s have been closed.static org.elasticsearch.search.aggregations.AggregationBuilder
Request an aggregation that returns theCardinalityUpperBound
that was passed to its ctor.protected org.elasticsearch.index.mapper.FieldMapper
buildMockFieldMapper
(org.elasticsearch.index.mapper.MappedFieldType ft) Build aFieldMapper
to create theMappingLookup
used for the aggs.void
protected org.elasticsearch.search.aggregations.AggregationBuilder
createAggBuilderForTypeTest
(org.elasticsearch.index.mapper.MappedFieldType fieldType, String fieldName) This method is invoked each time a field type is tested intestSupportedFieldTypes()
.protected org.elasticsearch.search.aggregations.support.AggregationContext
createAggregationContext
(org.apache.lucene.search.IndexSearcher indexSearcher, org.apache.lucene.search.Query query, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) Create a AggregationContext for testing anAggregator
.protected org.elasticsearch.search.aggregations.support.AggregationContext
createAggregationContext
(org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.elasticsearch.indices.breaker.CircuitBreakerService breakerService, long bytesToPreallocate, int maxBucket, boolean isInSortOrderExecutionRequired, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) Create a AggregationContext for testing anAggregator
.protected <A extends org.elasticsearch.search.aggregations.Aggregator>
AcreateAggregator
(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher searcher, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) protected <A extends org.elasticsearch.search.aggregations.Aggregator>
AcreateAggregator
(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.search.aggregations.support.AggregationContext context) protected org.elasticsearch.indices.analysis.AnalysisModule
protected org.elasticsearch.index.IndexSettings
protected org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType
Make a DateFieldMapper.DateFieldType for adate
.protected <R extends org.elasticsearch.search.aggregations.InternalAggregation>
voiddebugTestCase
(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.apache.lucene.search.Query query, org.apache.lucene.search.IndexSearcher searcher, org.elasticsearch.common.TriConsumer<R, Class<? extends org.elasticsearch.search.aggregations.Aggregator>, Map<String, Map<String, Object>>> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) Execute and aggregation and collect itsdebug
information.protected <R extends org.elasticsearch.search.aggregations.InternalAggregation>
voiddebugTestCase
(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, IOException> buildIndex, org.elasticsearch.common.TriConsumer<R, Class<? extends org.elasticsearch.search.aggregations.Aggregator>, Map<String, Map<String, Object>>> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) Execute and aggregation and collect itsdebug
information.protected void
doAssertReducedMultiBucketConsumer
(org.elasticsearch.search.aggregations.Aggregation agg, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer) protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType
doubleField
(String name) Make a NumberFieldMapper.NumberFieldType for adouble
.protected org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType
geoPointField
(String name) Make a GeoPointFieldMapper.GeoPointFieldType for ageo_point
.protected org.elasticsearch.script.ScriptService
Sub-tests that need scripting can override this method to provide a script service and pre-baked scriptsprotected List<org.elasticsearch.plugins.SearchPlugin>
Test cases should override this if they have plugins that need to be loaded, e.g.protected List<org.elasticsearch.search.aggregations.support.ValuesSourceType>
Implementors should return a list ofValuesSourceType
that the aggregator supports.void
final void
protected org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType
keywordField
(String name) Make a DateFieldMapper.DateFieldType for adate
.protected org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType
Make a NumberFieldMapper.NumberFieldType for along
.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, likeLuceneTestCase.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, likeLuceneTestCase.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 List<org.elasticsearch.index.mapper.ObjectMapper>
ObjectMapper
s to add to the lookup.protected org.elasticsearch.index.mapper.RangeFieldMapper.RangeFieldType
rangeField
(String name, org.elasticsearch.index.mapper.RangeType rangeType) Make a NumberFieldMapper.NumberFieldType for arange
.protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,
C extends org.elasticsearch.search.aggregations.Aggregator>
AsearchAndReduce
(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,
C extends org.elasticsearch.search.aggregations.Aggregator>
AsearchAndReduce
(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,
C extends org.elasticsearch.search.aggregations.Aggregator>
AsearchAndReduce
(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, boolean splitLeavesIntoSeparateAggregators, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) Collects all documents that match the provided queryQuery
and returns the reducedInternalAggregation
.protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,
C extends org.elasticsearch.search.aggregations.Aggregator>
AsearchAndReduce
(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) Collects all documents that match the provided queryQuery
and returns the reducedInternalAggregation
.protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,
C extends org.elasticsearch.search.aggregations.Aggregator>
AsearchAndReduce
(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) protected <T extends org.elasticsearch.search.aggregations.AggregationBuilder,
V extends org.elasticsearch.search.aggregations.InternalAggregation>
voidtestCase
(T aggregationBuilder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, IOException> buildIndex, Consumer<V> verify, org.elasticsearch.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 inIndicesModule
(e.g.A method that allows implementors to specifically blacklist particular field types (based on their content_name).protected <T extends org.elasticsearch.search.aggregations.AggregationBuilder,
V extends org.elasticsearch.search.aggregations.InternalAggregation>
voidverifyOutputFieldNames
(T aggregationBuilder, V agg) protected void
withAggregator
(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, IOException> buildIndex, org.elasticsearch.common.CheckedBiConsumer<org.apache.lucene.search.IndexSearcher, org.elasticsearch.search.aggregations.Aggregator, IOException> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) protected void
withIndex
(org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, IOException> buildIndex, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.search.IndexSearcher, IOException> consume) protected void
withNonMergingIndex
(org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, IOException> buildIndex, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.search.IndexSearcher, IOException> consume) protected org.apache.lucene.index.IndexReader
wrapDirectoryReader
(org.apache.lucene.index.DirectoryReader reader) Override to wrap the DirectoryReader for aggs likeNestedAggregationBuilder
.protected static org.apache.lucene.index.DirectoryReader
wrapInMockESDirectoryReader
(org.apache.lucene.index.DirectoryReader directoryReader) protected final org.elasticsearch.common.io.stream.NamedWriteableRegistry
TheNamedWriteableRegistry
to use for this test.Methods inherited from class org.elasticsearch.test.ESTestCase
after, afterIfFailed, afterIfSuccessful, assertArrayEquals, assertBusy, assertBusy, assertCriticalWarnings, assertEquals, assertSettingDeprecationsAndWarnings, assertWarnings, assertWarnings, before, between, buildEnvSettings, buildNewFakeTransportAddress, checkStaticState, compatibleMediaType, copyInstance, copyNamedWriteable, copyNamedWriteable, copyWriteable, copyWriteable, createDefaultIndexAnalyzers, createParser, createParser, createParser, createParser, createParser, createParser, createParserWithCompatibilityFor, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureNoWarnings, ensureSupportedLocale, filteredWarnings, frequently, generateRandomStringArray, generateRandomStringArray, getBasePort, getDataPath, getPortRange, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, inFipsJvm, iterations, maybeSet, mockScript, newEnvironment, newEnvironment, newNodeEnvironment, newNodeEnvironment, parserConfig, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBigInteger, randomBoolean, randomByte, randomByteArrayOfLength, randomCompatibleMediaType, randomDateFormatterPattern, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomIp, randomList, randomList, randomLong, randomLongBetween, randomMap, randomMillisUpToYear9999, randomNonNegativeByte, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, randomVendorType, randomZone, removeHeaderWarningAppender, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, setHeaderWarningAppender, settings, shuffleMap, shuffleXContent, shuffleXContent, skipTestWaitingForLuceneFix, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths, toShuffledXContent, waitUntil, waitUntil, xContentRegistry
Methods inherited from class org.apache.lucene.util.LuceneTestCase
addVirusChecker, assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertFieldInfosEquals, assertNormsEquals, assertPointsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, asSet, assumeFalse, assumeNoException, assumeTrue, assumeWorkingMMapOnWindows, atLeast, atLeast, callStackContains, callStackContains, callStackContainsAnyOf, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, ensureSaneIWCOnNightly, expectThrows, expectThrows, expectThrows, expectThrowsAnyOf, expectThrowsAnyOf, getDataInputStream, getOnlyLeafReader, getTestClass, getTestName, hasWorkingMMapOnWindows, 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, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, runWithRestrictedPermissions, setIndexWriterMaxDocs, setUp, setupCPUCoreCount, slowFileExists, tearDown, 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, assertThat, assertThat, assertTrue, assertTrue, fail, fail
-
Field Details
-
valuesSourceRegistry
protected org.elasticsearch.search.aggregations.support.ValuesSourceRegistry valuesSourceRegistry
-
-
Constructor Details
-
AggregatorTestCase
public AggregatorTestCase()
-
-
Method Details
-
initPlugins
public final void initPlugins() -
initAnalysisRegistry
- Throws:
Exception
-
createAnalysisModule
- Returns:
- a new analysis module. Tests that require a fully constructed analysis module (used to create an analysis registry) should override this method
- Throws:
Exception
-
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.elasticsearch.search.aggregations.Aggregator> A createAggregator(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.IndexSearcher searcher, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException - Throws:
IOException
-
createAggregator
protected <A extends org.elasticsearch.search.aggregations.Aggregator> A createAggregator(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.search.aggregations.support.AggregationContext context) throws IOException - Throws:
IOException
-
createAggregationContext
protected org.elasticsearch.search.aggregations.support.AggregationContext createAggregationContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.apache.lucene.search.Query query, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException Create a AggregationContext for testing anAggregator
. While AggregationContext isReleasable
the caller is not responsible for releasing it. Instead, it is released automatically in incleanupReleasables()
.- Throws:
IOException
-
createAggregationContext
protected org.elasticsearch.search.aggregations.support.AggregationContext createAggregationContext(org.apache.lucene.search.IndexSearcher indexSearcher, org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.Query query, org.elasticsearch.indices.breaker.CircuitBreakerService breakerService, long bytesToPreallocate, int maxBucket, boolean isInSortOrderExecutionRequired, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException Create a AggregationContext for testing anAggregator
. While AggregationContext isReleasable
the caller is not responsible for releasing it. Instead, it is released automatically in incleanupReleasables()
.- Throws:
IOException
-
buildMockFieldMapper
protected org.elasticsearch.index.mapper.FieldMapper buildMockFieldMapper(org.elasticsearch.index.mapper.MappedFieldType ft) Build aFieldMapper
to create theMappingLookup
used for the aggs.protected
so subclasses can have it. -
objectMappers
ObjectMapper
s to add to the lookup. By default we don't need anyObjectMapper
s but testing nested objects will require adding some. -
createIndexSettings
protected org.elasticsearch.index.IndexSettings createIndexSettings() -
getMockScriptService
protected org.elasticsearch.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.elasticsearch.search.aggregations.InternalAggregation,C extends org.elasticsearch.search.aggregations.Aggregator> A searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException - Throws:
IOException
-
searchAndReduce
protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,C extends org.elasticsearch.search.aggregations.Aggregator> A searchAndReduce(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException - Throws:
IOException
-
searchAndReduce
protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,C extends org.elasticsearch.search.aggregations.Aggregator> A searchAndReduce(org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException - Throws:
IOException
-
searchAndReduce
protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,C extends org.elasticsearch.search.aggregations.Aggregator> A searchAndReduce(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException Collects all documents that match the provided queryQuery
and returns the reducedInternalAggregation
.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
-
searchAndReduce
protected <A extends org.elasticsearch.search.aggregations.InternalAggregation,C extends org.elasticsearch.search.aggregations.Aggregator> A searchAndReduce(org.elasticsearch.index.IndexSettings indexSettings, org.apache.lucene.search.IndexSearcher searcher, org.apache.lucene.search.Query query, org.elasticsearch.search.aggregations.AggregationBuilder builder, int maxBucket, boolean splitLeavesIntoSeparateAggregators, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException Collects all documents that match the provided queryQuery
and returns the reducedInternalAggregation
. It runs the aggregation as well using a circuit breaker that randomly throwsCircuitBreakingException
in order to mak sure the implementation does not leak.- Parameters:
splitLeavesIntoSeparateAggregators
- If true this creates a newAggregator
for each leaf as though it were a separate index. If false this aggregates all leaves together, like we do in production.- Throws:
IOException
-
doAssertReducedMultiBucketConsumer
protected void doAssertReducedMultiBucketConsumer(org.elasticsearch.search.aggregations.Aggregation agg, org.elasticsearch.search.aggregations.MultiBucketConsumerService.MultiBucketConsumer bucketConsumer) -
testCase
protected <T extends org.elasticsearch.search.aggregations.AggregationBuilder,V extends org.elasticsearch.search.aggregations.InternalAggregation> void testCase(T aggregationBuilder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, IOException> buildIndex, Consumer<V> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) throws IOException- Throws:
IOException
-
withIndex
protected void withIndex(org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, IOException> buildIndex, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.search.IndexSearcher, throws IOExceptionIOException> consume) - Throws:
IOException
-
withNonMergingIndex
protected void withNonMergingIndex(org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, IOException> buildIndex, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.search.IndexSearcher, throws IOExceptionIOException> consume) - Throws:
IOException
-
debugTestCase
protected <R extends org.elasticsearch.search.aggregations.InternalAggregation> void debugTestCase(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, IOException> buildIndex, org.elasticsearch.common.TriConsumer<R, throws IOExceptionClass<? extends org.elasticsearch.search.aggregations.Aggregator>, Map<String, Map<String, Object>>> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) Execute and aggregation and collect itsdebug
information. UnliketestCase(T, org.apache.lucene.search.Query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, java.io.IOException>, java.util.function.Consumer<V>, org.elasticsearch.index.mapper.MappedFieldType...)
this doesn't randomly create anAggregator
per leaf and perform partial reductions. It always creates a singleAggregator
so we can get consistent debug info.- Throws:
IOException
-
debugTestCase
protected <R extends org.elasticsearch.search.aggregations.InternalAggregation> void debugTestCase(org.elasticsearch.search.aggregations.AggregationBuilder builder, org.apache.lucene.search.Query query, org.apache.lucene.search.IndexSearcher searcher, org.elasticsearch.common.TriConsumer<R, Class<? extends org.elasticsearch.search.aggregations.Aggregator>, throws IOExceptionMap<String, Map<String, Object>>> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) Execute and aggregation and collect itsdebug
information. UnliketestCase(T, org.apache.lucene.search.Query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, java.io.IOException>, java.util.function.Consumer<V>, org.elasticsearch.index.mapper.MappedFieldType...)
this doesn't randomly create anAggregator
per leaf and perform partial reductions. It always creates a singleAggregator
so we can get consistent debug info.- Throws:
IOException
-
withAggregator
protected void withAggregator(org.elasticsearch.search.aggregations.AggregationBuilder aggregationBuilder, org.apache.lucene.search.Query query, org.elasticsearch.core.CheckedConsumer<org.apache.lucene.index.RandomIndexWriter, IOException> buildIndex, org.elasticsearch.common.CheckedBiConsumer<org.apache.lucene.search.IndexSearcher, throws IOExceptionorg.elasticsearch.search.aggregations.Aggregator, IOException> verify, org.elasticsearch.index.mapper.MappedFieldType... fieldTypes) - Throws:
IOException
-
verifyOutputFieldNames
protected <T extends org.elasticsearch.search.aggregations.AggregationBuilder,V extends org.elasticsearch.search.aggregations.InternalAggregation> void verifyOutputFieldNames(T aggregationBuilder, V agg) 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 likeNestedAggregationBuilder
.- 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, likeLuceneTestCase.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, likeLuceneTestCase.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.elasticsearch.search.aggregations.support.ValuesSourceType> getSupportedValuesSourceTypes()Implementors should return a list ofValuesSourceType
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.elasticsearch.search.aggregations.AggregationBuilder createAggBuilderForTypeTest(org.elasticsearch.index.mapper.MappedFieldType fieldType, String fieldName) This method is invoked each time a field type is tested intestSupportedFieldTypes()
. 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 bygetSupportedValuesSourceTypes()
, which must also be implemented.- Parameters:
fieldType
- the type of the field that will be testedfieldName
- the name of the field that will be test- Returns:
- an aggregation builder to test against the field
-
unsupportedMappedFieldTypes
A method that allows implementors to specifically blacklist 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 blacklist instead of a whitelist because there are vastly more field types than ValuesSourceTypes, and it's expected that these unsupported cases are exceptional rather than common -
testSupportedFieldTypes
This test will validate that an aggregator succeeds or fails to run against all the field types that are registered inIndicesModule
(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
-
cleanupReleasables
public void cleanupReleasables() -
afterClose
protected void afterClose()Hook for checking things after allAggregator
s have been closed. -
dateField
protected org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType dateField(String name, org.elasticsearch.index.mapper.DateFieldMapper.Resolution resolution) Make a DateFieldMapper.DateFieldType for adate
. -
doubleField
Make a NumberFieldMapper.NumberFieldType for adouble
. -
geoPointField
protected org.elasticsearch.index.mapper.GeoPointFieldMapper.GeoPointFieldType geoPointField(String name) Make a GeoPointFieldMapper.GeoPointFieldType for ageo_point
. -
keywordField
protected org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType keywordField(String name) Make a DateFieldMapper.DateFieldType for adate
. -
longField
Make a NumberFieldMapper.NumberFieldType for along
. -
rangeField
protected org.elasticsearch.index.mapper.RangeFieldMapper.RangeFieldType rangeField(String name, org.elasticsearch.index.mapper.RangeType rangeType) Make a NumberFieldMapper.NumberFieldType for arange
. -
writableRegistry
protected final org.elasticsearch.common.io.stream.NamedWriteableRegistry writableRegistry()Description copied from class:ESTestCase
TheNamedWriteableRegistry
to use for this test. Subclasses should override and use liberally.- Overrides:
writableRegistry
in classESTestCase
-
aggCardinalityUpperBound
public static org.elasticsearch.search.aggregations.AggregationBuilder aggCardinalityUpperBound(String name) Request an aggregation that returns theCardinalityUpperBound
that was passed to its ctor.
-