Package org.elasticsearch.test
Class ESTestCase
java.lang.Object
org.junit.Assert
org.apache.lucene.util.LuceneTestCase
org.elasticsearch.test.ESTestCase
- Direct Known Subclasses:
AbstractAsyncBulkByScrollActionTestCase
,AbstractBlobContainerRetriesTestCase
,AbstractBootstrapCheckTestCase
,AbstractBuilderTestCase
,AbstractBytesReferenceTestCase
,AbstractCoordinatorTestCase
,AbstractMultiClustersTestCase
,AbstractSchemaValidationTestCase
,AbstractSimpleTransportTestCase
,AbstractWireTestCase
,AbstractXContentTestCase
,AggregatorTestCase
,AnalysisFactoryTestCase
,BasePipelineAggregationTestCase
,CommandTestCase
,EngineTestCase
,ESAllocationTestCase
,ESIndexInputTestCase
,ESIntegTestCase
,ESRestTestCase
,ESSingleNodeTestCase
,FieldTypeTestCase
,IndexShardTestCase
,MapperServiceTestCase
,ModuleTestCase
,RestActionTestCase
,RestClientBuilderTestCase
@Listeners({ReproduceInfoPrinter.class,LoggingListener.class}) @SuppressSysoutChecks(bugUrl="we log a lot on purpose") @SuppressCodecs({"SimpleText","Memory","CheapBastard","Direct","Compressing","FST50","FSTOrd50","TestBloomFilteredLucenePostings","MockRandom","BlockTreeOrds","LuceneFixedGap","LuceneVarGapFixedInterval","LuceneVarGapDocFreqInterval","Lucene50"}) @SuppressReproduceLine public abstract class ESTestCase extends org.apache.lucene.util.LuceneTestCase
Base testcase for randomized unit testing with Elasticsearch
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ESTestCase.GeohashGenerator
static class
ESTestCase.TestAnalysis
This cute helper class just holds all analysis building blocks that are used to build IndexAnalyzers.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
Fields Modifier and Type Field Description static java.util.List<java.lang.Exception>
checkIndexFailures
MockFSDirectoryService sets this:protected static org.elasticsearch.common.io.stream.NamedWriteableRegistry
DEFAULT_NAMED_WRITABLE_REGISTRY
static java.lang.String
DEFAULT_TEST_WORKER_ID
org.junit.rules.RuleChain
failureAndSuccessEvents
static java.lang.String
FIPS_SYSPROP
protected static java.util.List<java.lang.String>
JAVA_TIMEZONE_IDS
protected static java.util.List<java.lang.String>
JAVA_ZONE_IDS
protected static java.util.List<java.lang.String>
JODA_TIMEZONE_IDS
protected org.apache.logging.log4j.Logger
logger
static int
MIN_PRIVATE_PORT
static java.lang.String
TEST_WORKER_SYS_PROPERTY
static java.lang.String
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
Constructors Constructor Description ESTestCase()
-
Method Summary
Modifier and Type Method Description void
after()
protected void
afterIfFailed(java.util.List<java.lang.Throwable> errors)
Called when a test fails, supplying the errors it generated.protected void
afterIfSuccessful()
called after a test is finished, but only if successfulprotected void
allowedWarnings(java.lang.String... allowedWarnings)
Allow the given warnings, but don't require their presence.static void
assertArrayEquals(java.lang.StackTraceElement[] expected, java.lang.StackTraceElement[] actual)
Compares two stack traces, ignoring module (which is not yet serialized)static void
assertBusy(org.elasticsearch.common.CheckedRunnable<java.lang.Exception> codeBlock)
Runs the code block for 10 seconds waiting for no assertion to trip.static void
assertBusy(org.elasticsearch.common.CheckedRunnable<java.lang.Exception> codeBlock, long maxWaitTime, java.util.concurrent.TimeUnit unit)
Runs the code block for the provided interval, waiting for no assertions to trip.static void
assertEquals(java.lang.StackTraceElement expected, java.lang.StackTraceElement actual)
Compares two stack trace elements, ignoring module (which is not yet serialized)protected void
assertSettingDeprecationsAndWarnings(java.lang.String[] settings, java.lang.String... warnings)
protected void
assertSettingDeprecationsAndWarnings(org.elasticsearch.common.settings.Setting<?>[] settings, java.lang.String... warnings)
Convenience method to assert warnings for settings deprecations and general deprecation warnings.protected void
assertWarnings(boolean stripXContentPosition, java.lang.String... expectedWarnings)
protected void
assertWarnings(java.lang.String... expectedWarnings)
void
before()
static int
between(int min, int max)
An alias forrandomIntBetween(int, int)
.org.elasticsearch.common.settings.Settings
buildEnvSettings(org.elasticsearch.common.settings.Settings settings)
static org.elasticsearch.common.transport.TransportAddress
buildNewFakeTransportAddress()
Generates a new transport address usingTransportAddress.META_ADDRESS
with an incrementing port number.protected static void
checkStaticState(boolean afterClass)
static void
clearAdditionalRoles()
protected static <T> T
copyInstance(T original, org.elasticsearch.common.io.stream.NamedWriteableRegistry namedWriteableRegistry, org.elasticsearch.common.io.stream.Writeable.Writer<T> writer, org.elasticsearch.common.io.stream.Writeable.Reader<T> reader, org.elasticsearch.Version version)
static <T extends org.elasticsearch.common.io.stream.NamedWriteable>
TcopyNamedWriteable(T original, org.elasticsearch.common.io.stream.NamedWriteableRegistry namedWriteableRegistry, java.lang.Class<T> categoryClass)
Create a copy of an originalNamedWriteable
object by running it through aBytesStreamOutput
and reading it in again using a providedWriteable.Reader
.static <T extends org.elasticsearch.common.io.stream.NamedWriteable>
TcopyNamedWriteable(T original, org.elasticsearch.common.io.stream.NamedWriteableRegistry namedWriteableRegistry, java.lang.Class<T> categoryClass, org.elasticsearch.Version version)
Same ascopyNamedWriteable(NamedWriteable, NamedWriteableRegistry, Class)
but also allows to provide aVersion
argument which will be used to write and read back the object.static <T extends org.elasticsearch.common.io.stream.Writeable>
TcopyWriteable(T original, org.elasticsearch.common.io.stream.NamedWriteableRegistry namedWriteableRegistry, org.elasticsearch.common.io.stream.Writeable.Reader<T> reader)
Create a copy of an originalWriteable
object by running it through aBytesStreamOutput
and reading it in again using a providedWriteable.Reader
.static <T extends org.elasticsearch.common.io.stream.Writeable>
TcopyWriteable(T original, org.elasticsearch.common.io.stream.NamedWriteableRegistry namedWriteableRegistry, org.elasticsearch.common.io.stream.Writeable.Reader<T> reader, org.elasticsearch.Version version)
Same ascopyWriteable(Writeable, NamedWriteableRegistry, Writeable.Reader)
but also allows to provide aVersion
argument which will be used to write and read back the object.protected org.elasticsearch.index.analysis.IndexAnalyzers
createDefaultIndexAnalyzers()
Creates an IndexAnalyzers with a single default analyzerprotected org.elasticsearch.common.xcontent.XContentParser
createParser(org.elasticsearch.common.xcontent.NamedXContentRegistry namedXContentRegistry, org.elasticsearch.common.xcontent.XContent xContent, org.elasticsearch.common.bytes.BytesReference data)
Create a newXContentParser
.protected org.elasticsearch.common.xcontent.XContentParser
createParser(org.elasticsearch.common.xcontent.XContentBuilder builder)
Create a newXContentParser
.protected org.elasticsearch.common.xcontent.XContentParser
createParser(org.elasticsearch.common.xcontent.XContent xContent, byte[] data)
Create a newXContentParser
.protected org.elasticsearch.common.xcontent.XContentParser
createParser(org.elasticsearch.common.xcontent.XContent xContent, java.io.InputStream data)
Create a newXContentParser
.protected org.elasticsearch.common.xcontent.XContentParser
createParser(org.elasticsearch.common.xcontent.XContent xContent, java.lang.String data)
Create a newXContentParser
.protected org.elasticsearch.common.xcontent.XContentParser
createParser(org.elasticsearch.common.xcontent.XContent xContent, org.elasticsearch.common.bytes.BytesReference data)
Create a newXContentParser
.static ESTestCase.TestAnalysis
createTestAnalysis(org.elasticsearch.index.Index index, org.elasticsearch.common.settings.Settings nodeSettings, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.plugins.AnalysisPlugin... analysisPlugins)
Creates an TestAnalysis with all the default analyzers configured.static ESTestCase.TestAnalysis
createTestAnalysis(org.elasticsearch.index.Index index, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.plugins.AnalysisPlugin... analysisPlugins)
Creates an TestAnalysis with all the default analyzers configured.static ESTestCase.TestAnalysis
createTestAnalysis(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.common.settings.Settings nodeSettings, org.elasticsearch.plugins.AnalysisPlugin... analysisPlugins)
Creates an TestAnalysis with all the default analyzers configured.protected boolean
enableJodaDeprecationWarningsCheck()
protected boolean
enableWarningsCheck()
Whether or not we check after each test whether it has left warnings behind.void
ensureAllSearchContextsReleased()
void
ensureCheckIndexPassed()
static void
ensureSupportedLocale()
protected java.util.List<java.lang.String>
filteredWarnings()
static boolean
frequently()
The exact opposite ofLuceneTestCase.rarely()
.static java.lang.String[]
generateRandomStringArray(int maxArraySize, int stringSize, boolean allowNull)
static java.lang.String[]
generateRandomStringArray(int maxArraySize, int stringSize, boolean allowNull, boolean allowEmpty)
protected static int
getBasePort()
java.nio.file.Path
getDataPath(java.lang.String relativePath)
Returns aPath
pointing to the class path relative resource given as the first argument.static java.lang.String
getPortRange()
Returns a unique port range for this JVM starting from the computed base portstatic org.apache.lucene.util.TestRuleMarkFailure
getSuiteFailureMarker()
Returns the suite failure marker: internal use only!static java.lang.Class<? extends org.elasticsearch.plugins.Plugin>
getTestTransportPlugin()
static java.lang.String
getTestTransportType()
static boolean
inFipsJvm()
static int
iterations(int min, int max)
Returns a "scaled" number of iterations for loops which can have a variable iteration count.static <T> void
maybeSet(java.util.function.Consumer<T> consumer, T value)
helper to randomly perform onconsumer
withvalue
static org.elasticsearch.script.Script
mockScript(java.lang.String id)
Create a "mock" script for use either withMockScriptEngine
or anywhere where you need a script but don't really care about its contents.org.elasticsearch.env.Environment
newEnvironment()
org.elasticsearch.env.Environment
newEnvironment(org.elasticsearch.common.settings.Settings settings)
org.elasticsearch.env.NodeEnvironment
newNodeEnvironment()
org.elasticsearch.env.NodeEnvironment
newNodeEnvironment(org.elasticsearch.common.settings.Settings settings)
static java.lang.String
randomAlphaOfLength(int codeUnits)
static java.lang.String
randomAlphaOfLengthBetween(int minCodeUnits, int maxCodeUnits)
static <T> T[]
randomArray(int minArraySize, int maxArraySize, java.util.function.IntFunction<T[]> arrayConstructor, java.util.function.Supplier<T> valueConstructor)
static <T> T[]
randomArray(int maxArraySize, java.util.function.IntFunction<T[]> arrayConstructor, java.util.function.Supplier<T> valueConstructor)
static java.math.BigInteger
randomBigInteger()
Returns a random BigInteger uniformly distributed over the range 0 to (2^64 - 1) inclusive Currently BigIntegers are only used for unsigned_long field type, where the max value is 2^64 - 1.static boolean
randomBoolean()
static byte
randomByte()
static byte[]
randomByteArrayOfLength(int size)
Helper method to create a byte array of a given length populated with random byte valuesstatic java.lang.String
randomDateFormatterPattern()
Generate a random valid date formatter pattern.static org.joda.time.DateTimeZone
randomDateTimeZone()
generate a random DateTimeZone from the ones available in joda librarystatic double
randomDouble()
static double
randomDoubleBetween(double start, double end, boolean lowerInclusive)
Returns a double value in the interval [start, end) if lowerInclusive is set to true, (start, end) otherwise.static float
randomFloat()
static <T> T
randomFrom(java.util.Collection<T> collection)
Pick a random object from the given collection.static <T> T
randomFrom(java.util.List<T> list)
Pick a random object from the given list.static <T> T
randomFrom(java.util.Random random, java.util.Collection<T> collection)
Pick a random object from the given collection.static <T> T
randomFrom(java.util.Random random, T... array)
Pick a random object from the given array.static <T> T
randomFrom(T... array)
Pick a random object from the given array.static java.lang.String
randomGeohash(int minPrecision, int maxPrecision)
static int
randomInt()
static int
randomInt(int max)
A random integer from 0..max (inclusive).static int
randomIntBetween(int min, int max)
A random integer frommin
tomax
(inclusive).protected static java.net.InetAddress
randomIp(boolean v4)
static <T> java.util.List<T>
randomList(int minListSize, int maxListSize, java.util.function.Supplier<T> valueConstructor)
static <T> java.util.List<T>
randomList(int maxListSize, java.util.function.Supplier<T> valueConstructor)
static long
randomLong()
static long
randomLongBetween(long min, long max)
A random long number between min (inclusive) and max (inclusive).static byte
randomNonNegativeByte()
static long
randomNonNegativeLong()
static java.lang.String
randomPositiveTimeValue()
static java.lang.String
randomRealisticUnicodeOfCodepointLength(int codePoints)
static java.lang.String
randomRealisticUnicodeOfCodepointLengthBetween(int minCodePoints, int maxCodePoints)
static java.lang.String
randomRealisticUnicodeOfLength(int codeUnits)
static java.lang.String
randomRealisticUnicodeOfLengthBetween(int minCodeUnits, int maxCodeUnits)
static short
randomShort()
static <T> java.util.List<T>
randomSubsetOf(int size, java.util.Collection<T> collection)
Returns size random valuesstatic <T> java.util.List<T>
randomSubsetOf(int size, T... values)
Returns size random valuesstatic <T> java.util.List<T>
randomSubsetOf(java.util.Collection<T> collection)
Returns a random subset of values (including a potential empty list, or the full original list)static java.lang.String
randomTimeValue()
static java.lang.String
randomTimeValue(int lower, int upper)
static java.lang.String
randomTimeValue(int lower, int upper, java.lang.String... suffixes)
static java.util.TimeZone
randomTimeZone()
generate a random TimeZone from the ones available in java.utilstatic java.lang.String
randomUnicodeOfCodepointLength(int codePoints)
static java.lang.String
randomUnicodeOfCodepointLengthBetween(int minCodePoints, int maxCodePoints)
static java.lang.String
randomUnicodeOfLength(int codeUnits)
static java.lang.String
randomUnicodeOfLengthBetween(int minCodeUnits, int maxCodeUnits)
static <T> java.util.Set<T>
randomUnique(java.util.function.Supplier<T> supplier, int targetCount)
Builds a set of unique items.static <T> T
randomValueOtherThan(T input, java.util.function.Supplier<T> randomSupplier)
helper to get a random value in a certain range that's different from the inputstatic <T> T
randomValueOtherThanMany(java.util.function.Predicate<T> input, java.util.function.Supplier<T> randomSupplier)
helper to get a random value in a certain range that's different from the inputstatic java.time.ZoneId
randomZone()
generate a random TimeZone from the ones available in java.timevoid
removeHeaderWarningAppender()
void
resetCheckIndexStatus()
static void
resetPortCounter()
static void
restoreContentType()
static void
restoreFileSystem()
static int
scaledRandomIntBetween(int min, int max)
Returns a "scaled" random number between min and max (inclusive).static void
setContentType()
static void
setFileSystem()
void
setHeaderWarningAppender()
static org.elasticsearch.common.settings.Settings.Builder
settings(org.elasticsearch.Version version)
Return consistent index settings for the provided index version.static java.util.LinkedHashMap<java.lang.String,java.lang.Object>
shuffleMap(java.util.LinkedHashMap<java.lang.String,java.lang.Object> map, java.util.Set<java.lang.String> exceptFields)
protected org.elasticsearch.common.xcontent.XContentBuilder
shuffleXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, java.lang.String... exceptFieldNames)
Randomly shuffles the fields inside objects in theXContentBuilder
passed in.static org.elasticsearch.common.xcontent.XContentBuilder
shuffleXContent(org.elasticsearch.common.xcontent.XContentParser parser, boolean prettyPrint, java.lang.String... exceptFieldNames)
Randomly shuffles the fields inside objects parsed using theXContentParser
passed in.protected static long
spinForAtLeastNMilliseconds(long ms)
protected static long
spinForAtLeastOneMillisecond()
static boolean
terminate(java.util.concurrent.ExecutorService... services)
static boolean
terminate(org.elasticsearch.threadpool.ThreadPool threadPool)
java.lang.String[]
tmpPaths()
Returns a random number of temporary paths.protected org.elasticsearch.common.bytes.BytesReference
toShuffledXContent(org.elasticsearch.common.xcontent.ToXContent toXContent, org.elasticsearch.common.xcontent.XContentType xContentType, org.elasticsearch.common.xcontent.ToXContent.Params params, boolean humanReadable, java.lang.String... exceptFieldNames)
Returns the bytes that represent the XContent output of the providedToXContent
object, using the providedXContentType
.static boolean
waitUntil(java.util.function.BooleanSupplier breakSupplier)
Periodically execute the supplied function until it returns true, or a timeout is reached.static boolean
waitUntil(java.util.function.BooleanSupplier breakSupplier, long maxWaitTime, java.util.concurrent.TimeUnit unit)
Periodically execute the supplied function until it returns true, or until the specified maximum wait time has elapsed.protected org.elasticsearch.common.io.stream.NamedWriteableRegistry
writableRegistry()
TheNamedWriteableRegistry
to use for this test.protected org.elasticsearch.common.xcontent.NamedXContentRegistry
xContentRegistry()
TheNamedXContentRegistry
to use for this test.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, getBaseTempDirForTestClass, getDataInputStream, getOnlyLeafReader, getTestClass, getTestName, hasWorkingMMapOnWindows, isTestThread, localeForLanguageTag, maybeChangeLiveIndexWriterConfig, maybeWrapReader, newAlcoholicMergePolicy, newAlcoholicMergePolicy, 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, newStringField, newStringField, newStringField, newStringField, newTextField, newTextField, newTieredMergePolicy, newTieredMergePolicy, overrideDefaultQueryCache, overrideTestDefaultQueryCache, random, randomLocale, randomTimeZone, rarely, rarely, replaceMaxFailureRule, resetDefaultQueryCache, restoreCPUCoreCount, restoreIndexWriterMaxDocs, restoreSpins, runWithRestrictedPermissions, setIndexWriterMaxDocs, setUp, setupCPUCoreCount, setupSpins, 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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
JODA_TIMEZONE_IDS
protected static final java.util.List<java.lang.String> JODA_TIMEZONE_IDS -
JAVA_TIMEZONE_IDS
protected static final java.util.List<java.lang.String> JAVA_TIMEZONE_IDS -
JAVA_ZONE_IDS
protected static final java.util.List<java.lang.String> JAVA_ZONE_IDS -
MIN_PRIVATE_PORT
public static final int MIN_PRIVATE_PORT- See Also:
- Constant Field Values
-
TEST_WORKER_VM_ID
public static final java.lang.String TEST_WORKER_VM_ID -
TEST_WORKER_SYS_PROPERTY
public static final java.lang.String TEST_WORKER_SYS_PROPERTY- See Also:
- Constant Field Values
-
DEFAULT_TEST_WORKER_ID
public static final java.lang.String DEFAULT_TEST_WORKER_ID- See Also:
- Constant Field Values
-
FIPS_SYSPROP
public static final java.lang.String FIPS_SYSPROP- See Also:
- Constant Field Values
-
logger
protected final org.apache.logging.log4j.Logger logger -
failureAndSuccessEvents
public org.junit.rules.RuleChain failureAndSuccessEvents -
checkIndexFailures
public static final java.util.List<java.lang.Exception> checkIndexFailuresMockFSDirectoryService sets this: -
DEFAULT_NAMED_WRITABLE_REGISTRY
protected static final org.elasticsearch.common.io.stream.NamedWriteableRegistry DEFAULT_NAMED_WRITABLE_REGISTRY
-
-
Constructor Details
-
ESTestCase
public ESTestCase()
-
-
Method Details
-
resetPortCounter
public static void resetPortCounter() -
buildNewFakeTransportAddress
public static org.elasticsearch.common.transport.TransportAddress buildNewFakeTransportAddress()Generates a new transport address usingTransportAddress.META_ADDRESS
with an incrementing port number. The port number starts at 0 and is reset after each test suite run. -
afterIfFailed
protected void afterIfFailed(java.util.List<java.lang.Throwable> errors)Called when a test fails, supplying the errors it generated. Not called when the test fails because assumptions are violated. -
afterIfSuccessful
protected void afterIfSuccessful() throws java.lang.Exceptioncalled after a test is finished, but only if successful- Throws:
java.lang.Exception
-
setFileSystem
public static void setFileSystem() throws java.lang.Exception- Throws:
java.lang.Exception
-
restoreFileSystem
public static void restoreFileSystem() throws java.lang.Exception- Throws:
java.lang.Exception
-
setContentType
public static void setContentType() throws java.lang.Exception- Throws:
java.lang.Exception
-
restoreContentType
public static void restoreContentType() -
ensureSupportedLocale
public static void ensureSupportedLocale() -
setHeaderWarningAppender
public void setHeaderWarningAppender() -
removeHeaderWarningAppender
public void removeHeaderWarningAppender() -
before
public final void before() -
clearAdditionalRoles
public static void clearAdditionalRoles() -
enableWarningsCheck
protected boolean enableWarningsCheck()Whether or not we check after each test whether it has left warnings behind. That happens if any deprecated feature or syntax was used by the test and the test didn't assert on it usingassertWarnings(String...)
. -
enableJodaDeprecationWarningsCheck
protected boolean enableJodaDeprecationWarningsCheck() -
after
public final void after() throws java.lang.Exception- Throws:
java.lang.Exception
-
filteredWarnings
protected java.util.List<java.lang.String> filteredWarnings() -
assertSettingDeprecationsAndWarnings
protected final void assertSettingDeprecationsAndWarnings(org.elasticsearch.common.settings.Setting<?>[] settings, java.lang.String... warnings)Convenience method to assert warnings for settings deprecations and general deprecation warnings.- Parameters:
settings
- the settings that are expected to be deprecatedwarnings
- other expected general deprecation warnings
-
assertSettingDeprecationsAndWarnings
protected final void assertSettingDeprecationsAndWarnings(java.lang.String[] settings, java.lang.String... warnings) -
assertWarnings
protected final void assertWarnings(java.lang.String... expectedWarnings) -
allowedWarnings
protected final void allowedWarnings(java.lang.String... allowedWarnings)Allow the given warnings, but don't require their presence. -
assertWarnings
protected final void assertWarnings(boolean stripXContentPosition, java.lang.String... expectedWarnings) -
checkStaticState
protected static void checkStaticState(boolean afterClass) throws java.lang.Exception- Throws:
java.lang.Exception
-
ensureAllSearchContextsReleased
public final void ensureAllSearchContextsReleased() throws java.lang.Exception- Throws:
java.lang.Exception
-
resetCheckIndexStatus
public final void resetCheckIndexStatus() throws java.lang.Exception- Throws:
java.lang.Exception
-
ensureCheckIndexPassed
public final void ensureCheckIndexPassed() -
scaledRandomIntBetween
public static int scaledRandomIntBetween(int min, int max)Returns a "scaled" random number between min and max (inclusive).- See Also:
RandomizedTest.scaledRandomIntBetween(int, int)
-
randomIntBetween
public static int randomIntBetween(int min, int max)A random integer frommin
tomax
(inclusive).- See Also:
scaledRandomIntBetween(int, int)
-
randomLongBetween
public static long randomLongBetween(long min, long max)A random long number between min (inclusive) and max (inclusive). -
iterations
public static int iterations(int min, int max)Returns a "scaled" number of iterations for loops which can have a variable iteration count. This method is effectively an alias toscaledRandomIntBetween(int, int)
. -
between
public static int between(int min, int max)An alias forrandomIntBetween(int, int)
.- See Also:
scaledRandomIntBetween(int, int)
-
frequently
public static boolean frequently()The exact opposite ofLuceneTestCase.rarely()
. -
randomBoolean
public static boolean randomBoolean() -
randomByte
public static byte randomByte() -
randomNonNegativeByte
public static byte randomNonNegativeByte() -
randomByteArrayOfLength
public static byte[] randomByteArrayOfLength(int size)Helper method to create a byte array of a given length populated with random byte values- See Also:
randomByte()
-
randomShort
public static short randomShort() -
randomInt
public static int randomInt() -
randomNonNegativeLong
public static long randomNonNegativeLong()- Returns:
- a
long
between0
andLong.MAX_VALUE
(inclusive) chosen uniformly at random.
-
randomFloat
public static float randomFloat() -
randomDouble
public static double randomDouble() -
randomDoubleBetween
public static double randomDoubleBetween(double start, double end, boolean lowerInclusive)Returns a double value in the interval [start, end) if lowerInclusive is set to true, (start, end) otherwise.- Parameters:
start
- lower bound of interval to draw uniformly distributed random numbers fromend
- upper boundlowerInclusive
- whether or not to include lower end of the interval
-
randomLong
public static long randomLong() -
randomBigInteger
public static java.math.BigInteger randomBigInteger()Returns a random BigInteger uniformly distributed over the range 0 to (2^64 - 1) inclusive Currently BigIntegers are only used for unsigned_long field type, where the max value is 2^64 - 1. Modify this random generator if a wider range for BigIntegers is necessary.- Returns:
- a random bigInteger in the range [0 ; 2^64 - 1]
-
randomInt
public static int randomInt(int max)A random integer from 0..max (inclusive). -
randomFrom
@SafeVarargs public static <T> T randomFrom(T... array)Pick a random object from the given array. The array must not be empty. -
randomFrom
@SafeVarargs public static <T> T randomFrom(java.util.Random random, T... array)Pick a random object from the given array. The array must not be empty. -
randomFrom
public static <T> T randomFrom(java.util.List<T> list)Pick a random object from the given list. -
randomFrom
public static <T> T randomFrom(java.util.Collection<T> collection)Pick a random object from the given collection. -
randomFrom
public static <T> T randomFrom(java.util.Random random, java.util.Collection<T> collection)Pick a random object from the given collection. -
randomAlphaOfLengthBetween
public static java.lang.String randomAlphaOfLengthBetween(int minCodeUnits, int maxCodeUnits) -
randomAlphaOfLength
public static java.lang.String randomAlphaOfLength(int codeUnits) -
randomUnicodeOfLengthBetween
public static java.lang.String randomUnicodeOfLengthBetween(int minCodeUnits, int maxCodeUnits) -
randomUnicodeOfLength
public static java.lang.String randomUnicodeOfLength(int codeUnits) -
randomUnicodeOfCodepointLengthBetween
public static java.lang.String randomUnicodeOfCodepointLengthBetween(int minCodePoints, int maxCodePoints) -
randomUnicodeOfCodepointLength
public static java.lang.String randomUnicodeOfCodepointLength(int codePoints) -
randomRealisticUnicodeOfLengthBetween
public static java.lang.String randomRealisticUnicodeOfLengthBetween(int minCodeUnits, int maxCodeUnits) -
randomRealisticUnicodeOfLength
public static java.lang.String randomRealisticUnicodeOfLength(int codeUnits) -
randomRealisticUnicodeOfCodepointLengthBetween
public static java.lang.String randomRealisticUnicodeOfCodepointLengthBetween(int minCodePoints, int maxCodePoints) -
randomRealisticUnicodeOfCodepointLength
public static java.lang.String randomRealisticUnicodeOfCodepointLength(int codePoints) -
generateRandomStringArray
public static java.lang.String[] generateRandomStringArray(int maxArraySize, int stringSize, boolean allowNull, boolean allowEmpty)- Parameters:
maxArraySize
- The maximum number of elements in the random arraystringSize
- The length of each String in the arrayallowNull
- Whether the returned array may be nullallowEmpty
- Whether the returned array may be empty (have zero elements)
-
generateRandomStringArray
public static java.lang.String[] generateRandomStringArray(int maxArraySize, int stringSize, boolean allowNull) -
randomArray
public static <T> T[] randomArray(int maxArraySize, java.util.function.IntFunction<T[]> arrayConstructor, java.util.function.Supplier<T> valueConstructor) -
randomArray
public static <T> T[] randomArray(int minArraySize, int maxArraySize, java.util.function.IntFunction<T[]> arrayConstructor, java.util.function.Supplier<T> valueConstructor) -
randomList
public static <T> java.util.List<T> randomList(int maxListSize, java.util.function.Supplier<T> valueConstructor) -
randomList
public static <T> java.util.List<T> randomList(int minListSize, int maxListSize, java.util.function.Supplier<T> valueConstructor) -
randomTimeValue
public static java.lang.String randomTimeValue(int lower, int upper, java.lang.String... suffixes) -
randomTimeValue
public static java.lang.String randomTimeValue(int lower, int upper) -
randomTimeValue
public static java.lang.String randomTimeValue() -
randomPositiveTimeValue
public static java.lang.String randomPositiveTimeValue() -
randomDateTimeZone
public static org.joda.time.DateTimeZone randomDateTimeZone()generate a random DateTimeZone from the ones available in joda library -
randomTimeZone
public static java.util.TimeZone randomTimeZone()generate a random TimeZone from the ones available in java.util -
randomZone
public static java.time.ZoneId randomZone()generate a random TimeZone from the ones available in java.time -
randomDateFormatterPattern
public static java.lang.String randomDateFormatterPattern()Generate a random valid date formatter pattern. -
maybeSet
public static <T> void maybeSet(java.util.function.Consumer<T> consumer, T value)helper to randomly perform onconsumer
withvalue
-
randomValueOtherThan
public static <T> T randomValueOtherThan(T input, java.util.function.Supplier<T> randomSupplier)helper to get a random value in a certain range that's different from the input -
randomValueOtherThanMany
public static <T> T randomValueOtherThanMany(java.util.function.Predicate<T> input, java.util.function.Supplier<T> randomSupplier)helper to get a random value in a certain range that's different from the input -
assertBusy
public static void assertBusy(org.elasticsearch.common.CheckedRunnable<java.lang.Exception> codeBlock) throws java.lang.ExceptionRuns the code block for 10 seconds waiting for no assertion to trip.- Throws:
java.lang.Exception
-
assertBusy
public static void assertBusy(org.elasticsearch.common.CheckedRunnable<java.lang.Exception> codeBlock, long maxWaitTime, java.util.concurrent.TimeUnit unit) throws java.lang.ExceptionRuns the code block for the provided interval, waiting for no assertions to trip.- Throws:
java.lang.Exception
-
waitUntil
public static boolean waitUntil(java.util.function.BooleanSupplier breakSupplier) throws java.lang.InterruptedExceptionPeriodically execute the supplied function until it returns true, or a timeout is reached. This version uses a timeout of 10 seconds. If at all possible, useassertBusy(CheckedRunnable)
instead.- Parameters:
breakSupplier
- determines whether to return immediately or continue waiting.- Returns:
- the last value returned by
breakSupplier
- Throws:
java.lang.InterruptedException
- if any sleep calls were interrupted.
-
waitUntil
public static boolean waitUntil(java.util.function.BooleanSupplier breakSupplier, long maxWaitTime, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedExceptionPeriodically execute the supplied function until it returns true, or until the specified maximum wait time has elapsed. If at all possible, useassertBusy(CheckedRunnable)
instead.- Parameters:
breakSupplier
- determines whether to return immediately or continue waiting.maxWaitTime
- the maximum amount of time to waitunit
- the unit of tie formaxWaitTime
- Returns:
- the last value returned by
breakSupplier
- Throws:
java.lang.InterruptedException
- if any sleep calls were interrupted.
-
terminate
public static boolean terminate(java.util.concurrent.ExecutorService... services) -
terminate
public static boolean terminate(org.elasticsearch.threadpool.ThreadPool threadPool) -
getDataPath
public java.nio.file.Path getDataPath(java.lang.String relativePath)Returns aPath
pointing to the class path relative resource given as the first argument. In contrast togetClass().getResource(...).getFile()
this method will not return URL encoded paths if the parent path contains spaces or other non-standard characters.- Overrides:
getDataPath
in classorg.apache.lucene.util.LuceneTestCase
-
tmpPaths
public java.lang.String[] tmpPaths()Returns a random number of temporary paths. -
newNodeEnvironment
public org.elasticsearch.env.NodeEnvironment newNodeEnvironment() throws java.io.IOException- Throws:
java.io.IOException
-
buildEnvSettings
public org.elasticsearch.common.settings.Settings buildEnvSettings(org.elasticsearch.common.settings.Settings settings) -
newNodeEnvironment
public org.elasticsearch.env.NodeEnvironment newNodeEnvironment(org.elasticsearch.common.settings.Settings settings) throws java.io.IOException- Throws:
java.io.IOException
-
newEnvironment
public org.elasticsearch.env.Environment newEnvironment() -
newEnvironment
public org.elasticsearch.env.Environment newEnvironment(org.elasticsearch.common.settings.Settings settings) -
settings
public static org.elasticsearch.common.settings.Settings.Builder settings(org.elasticsearch.Version version)Return consistent index settings for the provided index version. -
randomSubsetOf
public static <T> java.util.List<T> randomSubsetOf(int size, T... values)Returns size random values -
randomSubsetOf
public static <T> java.util.List<T> randomSubsetOf(java.util.Collection<T> collection)Returns a random subset of values (including a potential empty list, or the full original list) -
randomSubsetOf
public static <T> java.util.List<T> randomSubsetOf(int size, java.util.Collection<T> collection)Returns size random values -
randomUnique
public static <T> java.util.Set<T> randomUnique(java.util.function.Supplier<T> supplier, int targetCount)Builds a set of unique items. Usually you'll get the requested count but you might get less than that number if the supplier returns lots of repeats. Make sure that the items properly implement equals and hashcode. -
randomGeohash
public static java.lang.String randomGeohash(int minPrecision, int maxPrecision) -
getTestTransportType
public static java.lang.String getTestTransportType() -
getTestTransportPlugin
public static java.lang.Class<? extends org.elasticsearch.plugins.Plugin> getTestTransportPlugin() -
toShuffledXContent
protected final org.elasticsearch.common.bytes.BytesReference toShuffledXContent(org.elasticsearch.common.xcontent.ToXContent toXContent, org.elasticsearch.common.xcontent.XContentType xContentType, org.elasticsearch.common.xcontent.ToXContent.Params params, boolean humanReadable, java.lang.String... exceptFieldNames) throws java.io.IOExceptionReturns the bytes that represent the XContent output of the providedToXContent
object, using the providedXContentType
. Wraps the output into a new anonymous object according to the value returned by theToXContent.isFragment()
method returns. Shuffles the keys to make sure that parsing never relies on keys ordering.- Throws:
java.io.IOException
-
shuffleXContent
protected final org.elasticsearch.common.xcontent.XContentBuilder shuffleXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, java.lang.String... exceptFieldNames) throws java.io.IOExceptionRandomly shuffles the fields inside objects in theXContentBuilder
passed in. Recursively goes through inner objects and also shuffles them. Exceptions for this recursive shuffling behavior can be made by passing in the names of fields which internally should stay untouched.- Throws:
java.io.IOException
-
shuffleXContent
public static org.elasticsearch.common.xcontent.XContentBuilder shuffleXContent(org.elasticsearch.common.xcontent.XContentParser parser, boolean prettyPrint, java.lang.String... exceptFieldNames) throws java.io.IOExceptionRandomly shuffles the fields inside objects parsed using theXContentParser
passed in. Recursively goes through inner objects and also shuffles them. Exceptions for this recursive shuffling behavior can be made by passing in the names of fields which internally should stay untouched.- Throws:
java.io.IOException
-
shuffleMap
public static java.util.LinkedHashMap<java.lang.String,java.lang.Object> shuffleMap(java.util.LinkedHashMap<java.lang.String,java.lang.Object> map, java.util.Set<java.lang.String> exceptFields) -
copyWriteable
public static <T extends org.elasticsearch.common.io.stream.Writeable> T copyWriteable(T original, org.elasticsearch.common.io.stream.NamedWriteableRegistry namedWriteableRegistry, org.elasticsearch.common.io.stream.Writeable.Reader<T> reader) throws java.io.IOExceptionCreate a copy of an originalWriteable
object by running it through aBytesStreamOutput
and reading it in again using a providedWriteable.Reader
. The stream that is wrapped around theStreamInput
potentially need to use aNamedWriteableRegistry
, so this needs to be provided too (although it can be empty if the object that is streamed doesn't contain anyNamedWriteable
objects itself.- Throws:
java.io.IOException
-
copyWriteable
public static <T extends org.elasticsearch.common.io.stream.Writeable> T copyWriteable(T original, org.elasticsearch.common.io.stream.NamedWriteableRegistry namedWriteableRegistry, org.elasticsearch.common.io.stream.Writeable.Reader<T> reader, org.elasticsearch.Version version) throws java.io.IOExceptionSame ascopyWriteable(Writeable, NamedWriteableRegistry, Writeable.Reader)
but also allows to provide aVersion
argument which will be used to write and read back the object.- Throws:
java.io.IOException
-
copyNamedWriteable
public static <T extends org.elasticsearch.common.io.stream.NamedWriteable> T copyNamedWriteable(T original, org.elasticsearch.common.io.stream.NamedWriteableRegistry namedWriteableRegistry, java.lang.Class<T> categoryClass) throws java.io.IOExceptionCreate a copy of an originalNamedWriteable
object by running it through aBytesStreamOutput
and reading it in again using a providedWriteable.Reader
.- Throws:
java.io.IOException
-
copyNamedWriteable
public static <T extends org.elasticsearch.common.io.stream.NamedWriteable> T copyNamedWriteable(T original, org.elasticsearch.common.io.stream.NamedWriteableRegistry namedWriteableRegistry, java.lang.Class<T> categoryClass, org.elasticsearch.Version version) throws java.io.IOExceptionSame ascopyNamedWriteable(NamedWriteable, NamedWriteableRegistry, Class)
but also allows to provide aVersion
argument which will be used to write and read back the object.- Throws:
java.io.IOException
-
copyInstance
protected static <T> T copyInstance(T original, org.elasticsearch.common.io.stream.NamedWriteableRegistry namedWriteableRegistry, org.elasticsearch.common.io.stream.Writeable.Writer<T> writer, org.elasticsearch.common.io.stream.Writeable.Reader<T> reader, org.elasticsearch.Version version) throws java.io.IOException- Throws:
java.io.IOException
-
createParser
protected final org.elasticsearch.common.xcontent.XContentParser createParser(org.elasticsearch.common.xcontent.XContentBuilder builder) throws java.io.IOExceptionCreate a newXContentParser
.- Throws:
java.io.IOException
-
createParser
protected final org.elasticsearch.common.xcontent.XContentParser createParser(org.elasticsearch.common.xcontent.XContent xContent, java.lang.String data) throws java.io.IOExceptionCreate a newXContentParser
.- Throws:
java.io.IOException
-
createParser
protected final org.elasticsearch.common.xcontent.XContentParser createParser(org.elasticsearch.common.xcontent.XContent xContent, java.io.InputStream data) throws java.io.IOExceptionCreate a newXContentParser
.- Throws:
java.io.IOException
-
createParser
protected final org.elasticsearch.common.xcontent.XContentParser createParser(org.elasticsearch.common.xcontent.XContent xContent, byte[] data) throws java.io.IOExceptionCreate a newXContentParser
.- Throws:
java.io.IOException
-
createParser
protected final org.elasticsearch.common.xcontent.XContentParser createParser(org.elasticsearch.common.xcontent.XContent xContent, org.elasticsearch.common.bytes.BytesReference data) throws java.io.IOExceptionCreate a newXContentParser
.- Throws:
java.io.IOException
-
createParser
protected final org.elasticsearch.common.xcontent.XContentParser createParser(org.elasticsearch.common.xcontent.NamedXContentRegistry namedXContentRegistry, org.elasticsearch.common.xcontent.XContent xContent, org.elasticsearch.common.bytes.BytesReference data) throws java.io.IOExceptionCreate a newXContentParser
.- Throws:
java.io.IOException
-
xContentRegistry
protected org.elasticsearch.common.xcontent.NamedXContentRegistry xContentRegistry()TheNamedXContentRegistry
to use for this test. Subclasses should override and use liberally. -
writableRegistry
protected org.elasticsearch.common.io.stream.NamedWriteableRegistry writableRegistry()TheNamedWriteableRegistry
to use for this test. Subclasses should override and use liberally. -
mockScript
public static org.elasticsearch.script.Script mockScript(java.lang.String id)Create a "mock" script for use either withMockScriptEngine
or anywhere where you need a script but don't really care about its contents. -
getSuiteFailureMarker
public static org.apache.lucene.util.TestRuleMarkFailure getSuiteFailureMarker()Returns the suite failure marker: internal use only! -
assertArrayEquals
public static void assertArrayEquals(java.lang.StackTraceElement[] expected, java.lang.StackTraceElement[] actual)Compares two stack traces, ignoring module (which is not yet serialized) -
assertEquals
public static void assertEquals(java.lang.StackTraceElement expected, java.lang.StackTraceElement actual)Compares two stack trace elements, ignoring module (which is not yet serialized) -
spinForAtLeastOneMillisecond
protected static long spinForAtLeastOneMillisecond() -
spinForAtLeastNMilliseconds
protected static long spinForAtLeastNMilliseconds(long ms) -
createDefaultIndexAnalyzers
protected org.elasticsearch.index.analysis.IndexAnalyzers createDefaultIndexAnalyzers()Creates an IndexAnalyzers with a single default analyzer -
createTestAnalysis
public static ESTestCase.TestAnalysis createTestAnalysis(org.elasticsearch.index.Index index, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.plugins.AnalysisPlugin... analysisPlugins) throws java.io.IOExceptionCreates an TestAnalysis with all the default analyzers configured.- Throws:
java.io.IOException
-
createTestAnalysis
public static ESTestCase.TestAnalysis createTestAnalysis(org.elasticsearch.index.Index index, org.elasticsearch.common.settings.Settings nodeSettings, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.plugins.AnalysisPlugin... analysisPlugins) throws java.io.IOExceptionCreates an TestAnalysis with all the default analyzers configured.- Throws:
java.io.IOException
-
createTestAnalysis
public static ESTestCase.TestAnalysis createTestAnalysis(org.elasticsearch.index.IndexSettings indexSettings, org.elasticsearch.common.settings.Settings nodeSettings, org.elasticsearch.plugins.AnalysisPlugin... analysisPlugins) throws java.io.IOExceptionCreates an TestAnalysis with all the default analyzers configured.- Throws:
java.io.IOException
-
inFipsJvm
public static boolean inFipsJvm() -
getPortRange
public static java.lang.String getPortRange()Returns a unique port range for this JVM starting from the computed base port -
getBasePort
protected static int getBasePort() -
randomIp
protected static java.net.InetAddress randomIp(boolean v4)
-