Class ESIntegTestCase
- Direct Known Subclasses:
AbstractGeoTestCase,AbstractIndexRecoveryIntegTestCase,AbstractNumericTestCase,AbstractRerankerIT,AbstractSearchCancellationTestCase,AbstractSnapshotIntegTestCase,AbstractTermsTestCase,BaseShapeIntegTestCase,DiskUsageIntegTestCase,ESBlobStoreRepositoryIntegTestCase,GeoBoundingBoxQueryIntegTestCase
ESIntegTestCase is an abstract base class to run integration
tests against a JVM private Elasticsearch Cluster. The test class supports 2 different
cluster scopes.
ESIntegTestCase.Scope.TEST- uses a new cluster for each individual test method.ESIntegTestCase.Scope.SUITE- uses a cluster shared across all test methods in the same suite
The most common test scope is ESIntegTestCase.Scope.SUITE which shares a cluster per test suite.
If the test methods need specific node settings or change persistent and/or transient cluster settings ESIntegTestCase.Scope.TEST
should be used. To configure a scope for the test cluster the ESIntegTestCase.ClusterScope annotation
should be used, here is an example:
@NodeScope(scope=Scope.TEST) public class SomeIT extends ESIntegTestCase {
public void testMethod() {}
}
If no ESIntegTestCase.ClusterScope annotation is present on an integration test the default scope is ESIntegTestCase.Scope.SUITE
A test cluster creates a set of nodes in the background before the test starts. The number of nodes in the cluster is
determined at random and can change across tests. The ESIntegTestCase.ClusterScope allows configuring the initial number of nodes
that are created before the tests start.
@NodeScope(scope=Scope.SUITE, numDataNodes=3)
public class SomeIT extends ESIntegTestCase {
public void testMethod() {}
}
Note, the ESIntegTestCase uses randomized settings on a cluster and index level. For instance
each test might use different directory implementation for each test or will return a random client to one of the
nodes in the cluster for each call to client(). Test failures might only be reproducible if the correct
system properties are passed to the test execution environment.
This class supports the following system properties (passed with -Dkey=value to the application)
- -D"tests.enable_mock_modules" - a boolean value to enable or disable mock modules. This is useful to test the system without asserting modules that to make sure they don't hide any bugs in production.
- - a random seed used to initialize the index random context.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic @interfaceDefines a cluster scope for aESIntegTestCasesubclass.protected static classstatic enumThe scope of a test cluster used together withESIntegTestCase.ClusterScopeannotations onESIntegTestCasesubclasses.static @interfaceIf a test is annotated withESIntegTestCase.SuiteScopeTestCasethe checks and modifications that are applied to the used test cluster are only done after all tests of this class are executed.static final classNested classes/interfaces inherited from class org.elasticsearch.test.ESTestCase
ESTestCase.DeprecationWarning, ESTestCase.GeohashGenerator, ESTestCase.TestAnalysis, ESTestCase.WithoutSecurityManagerNested classes/interfaces inherited from class org.apache.lucene.tests.util.LuceneTestCase
org.apache.lucene.tests.util.LuceneTestCase.AwaitsFix, org.apache.lucene.tests.util.LuceneTestCase.BadApple, 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
FieldsModifier and TypeFieldDescriptionprotected static final intDefault maximum number of shards for an indexprotected static final intDefault minimum number of shards for an indexKey used to retrieve the index random seed from the index settings on a running node.static final Stringnode names of the corresponding clusters will start with these prefixesstatic final Stringstatic final StringKey used to eventually switch to using an external cluster and provide its transport addressesstatic final StringKey used to eventually switch to using an external cluster and provide the cluster namestatic final StringA boolean value to enable or disable mock modules.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, SAFE_AWAIT_TIMEOUT, TEST_REQUEST_TIMEOUT, TEST_WORKER_SYS_PROPERTY, TEST_WORKER_VM_ID, UNSIGNED_LONG_MAXFields 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_BADAPPLES, SYSPROP_FAILFAST, SYSPROP_MAXFAILURES, SYSPROP_MONSTER, SYSPROP_NIGHTLY, 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_THROTTLING, TEST_WEEKLY, VERBOSE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanReturnstrueif this test cluster can use theMockFSIndexStoretest plugin.protected booleanReturnstrueiff this test cluster should use a dummy http transportprotected booleanReturnstrueif this test cluster can use a mock internal engine.protected booleanIff this returns true mock transport implementations are used for the test runs.protected static AdminClientadmin()Returns a random admin client.static voidvoidallowNodes(String index, int n) Restricts the given index to be allocated onnnodes using the allocation deciders.assertAllShardsOnNodes(String index, String... pattern) Asserts that all shards are allocated on nodes matching the given node pattern.voidassertResultsAndLogOnFailure(long expectedResults, SearchResponse searchResponse) Ensures the result counts are as expected, and logs the results if differentvoidassertSortedSegments(String indexName, org.apache.lucene.search.Sort expectedIndexSort) Asserts that all segments are sorted with the providedSort.protected booleanprotected voidawaitClusterState(Predicate<ClusterState> statePredicate) static voidawaitClusterState(org.apache.logging.log4j.Logger logger, String viaNode, Predicate<ClusterState> statePredicate) static voidawaitClusterState(org.apache.logging.log4j.Logger logger, Predicate<ClusterState> statePredicate) static voidprotected voidprotected final voidprotected TestClusterbuildTestCluster(ESIntegTestCase.Scope scope, long seed) final voidstatic voidclearScroll(String... scrollIds) Clears the given scroll Idsstatic Clientclient()static Clientclients()static TestClustercluster()protected static ClusterAdminClientReturns a random cluster admin client.final voidcreateIndex(String... names) Creates one or more indices and asserts that the indices are acknowledged.final voidcreateIndex(String name, int shards, int replicas) creates an index with the given shard and replica countsfinal voidcreateIndex(String name, Settings indexSettings) creates an index with the given settingprotected static RestClientprotected static RestClientcreateRestClient(String node) protected static RestClientcreateRestClient(List<NodeInfo> nodes, RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) protected static RestClientcreateRestClient(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) static Clientprotected final voiddisableAllocation(String... indices) Syntactic sugar for disabling allocation forindicesstatic voiddisableIndexBlock(String index, String block) Disables an index block for the specified indexprotected final voiddoEnsureClusterStateConsistency(NamedWriteableRegistry namedWriteableRegistry) protected final voidenableAllocation(String... indices) Syntactic sugar for enabling allocation forindicesprotected booleanprotected booleanWhether we'd like to enable inter-segment search concurrency and increase the likelihood of leveraging it, by creating multiple slices with a low amount of documents in them, which would not be allowed in production.static voidenableIndexBlock(String index, String block) Enables an index block for the specified indexprotected final booleanWhether or not we check after each test whether it has left warnings behind.protected voidprotected voidprotected voidVerifies that all nodes that have the same version of the cluster state as master have same cluster stateprotected voidEnsures that all nodes in the cluster are connected to each other.ensureGreen(String... indices) Ensures the cluster has a green state via the cluster health API.ensureGreen(org.elasticsearch.core.TimeValue timeout, String... indices) Ensures the cluster has a green state via the cluster health API.Ensures the cluster has a red state via the cluster health API.protected ClusterHealthStatusensureSearchable(String... indices) Ensures the cluster is in a searchable state for the given indices.protected voidensureStableCluster(int nodeCount) protected voidensureStableCluster(int nodeCount, String viaNode) protected voidensureStableCluster(int nodeCount, org.elasticsearch.core.TimeValue timeValue) protected voidensureStableCluster(int nodeCount, org.elasticsearch.core.TimeValue timeValue, boolean local, String viaNode) ensureYellow(String... indices) Ensures the cluster has a yellow state via the cluster health API.ensureYellowAndNoInitializingShards(String... indices) Ensures the cluster has a yellow state via the cluster health API and ensures the that cluster has no initializing shards for the given indicesstatic List<PersistentTasksCustomMetadata.PersistentTask<?>> findTasks(ClusterState clusterState, String taskName) Retrieves the persistent tasks with the requested task name from the given cluster state.static List<PersistentTasksCustomMetadata.PersistentTask<?>> findTasks(ClusterState clusterState, Set<String> taskNames) Retrieves the persistent tasks with the requested task names from the given cluster state.protected final BroadcastResponseFlush some or all indices in the cluster.protected final voidflushAndRefresh(String... indices) Flushes and refreshes all indices in the clusterprotected booleanprotected BroadcastResponseWaits for all relocations and force merge all indices in the cluster to 1 segment.protected booleanOverride to return true in tests that cannot handle multiple data paths.protected static org.elasticsearch.core.ReleasablefullyAllocateCircuitBreakerOnNode(String targetNode, String breakerName) Allocate the entire capacity of a circuit breaker on a specific nodeReturns a function that allows to wrap / filter all clients that are exposed by the test cluster.static PendingClusterTasksResponsestatic PendingClusterTasksResponsegetClusterPendingTasks(Client client) getDataStreamBackingIndexNames(String dataStreamName) Returns a list of the data stream's backing index names.protected Collection<Class<? extends Plugin>> Return the mock plugins the cluster should usestatic Stringprotected ESIntegTestCase.NumShardsgetNumShards(String index) protected static RestClientReturns an instance ofRestClientpointing to the current test cluster.protected final DocWriteResponseSyntactic sugar for:protected final DocWriteResponseSyntactic sugar for:protected final DocWriteResponseSyntactic sugar for:protected final DocWriteResponseSyntactic sugar for:protected final DocWriteResponseSyntactic sugar for:protected static booleanindexExists(String index) Returnstrueiff the given index exists otherwisefalsestatic booleanindexExists(String index, Client client) Returnstrueiff the given index exists otherwisefalsevoidindexRandom(boolean forceRefresh, boolean dummyDocuments, boolean maybeFlush, List<IndexRequestBuilder> builders) Indexes the givenIndexRequestBuilderinstances randomly.voidindexRandom(boolean forceRefresh, boolean dummyDocuments, List<IndexRequestBuilder> builders) Indexes the givenIndexRequestBuilderinstances randomly.voidindexRandom(boolean forceRefresh, boolean dummyDocuments, IndexRequestBuilder... builders) voidindexRandom(boolean forceRefresh, String index, int numDocs) voidindexRandom(boolean forceRefresh, List<IndexRequestBuilder> builders) Indexes the givenIndexRequestBuilderinstances randomly.voidindexRandom(boolean forceRefresh, IndexRequestBuilder... builders) Convenience method that forwards toindexRandom(boolean, List).Returns a settings object used increateIndex(String...)andprepareCreate(String)and friends.protected static IndicesAdminClientReturns a random indices admin client.static booleanstatic InternalTestClusterstatic booleanprotected static NetworkDisruptionisolateMasterDisruption(NetworkDisruption.NetworkLinkDisruptionType disruptionType) Creates a disruption that isolates the current master node from all other nodes in the cluster.voidPrints the current cluster state as debug logging.protected intprotected intprotected intprotected intprotected PathnodeConfigPath(int nodeOrdinal) protected Collection<Class<? extends Plugin>> Returns a collection of plugins that should be loaded on each node.protected SettingsnodeSettings(int nodeOrdinal, Settings otherSettings) This method is used to obtain settings for theNth node in the cluster.protected intprotected intprepareCreate(String index) Creates a newCreateIndexRequestBuilderwith the settings obtained fromindexSettings().prepareCreate(String index, int numNodes) Creates a newCreateIndexRequestBuilderwith the settings obtained fromindexSettings().prepareCreate(String index, int numNodes, Settings.Builder settingsBuilder) Creates a newCreateIndexRequestBuilderwith the settings obtained fromindexSettings().prepareCreate(String index, Settings.Builder settingsBuilder) Creates a newCreateIndexRequestBuilderwith the settings obtained fromindexSettings(), augmented by the given builderprotected static IndexRequestBuilderprepareIndex(String index) static SearchRequestBuilderprepareSearch(String... indices) static PathReturns path to a random directory that can be used to create a temporary file system repostatic PathrandomRepoPath(Settings settings) Returns path to a random directory that can be used to create a temporary file system repoprotected final BroadcastResponseWaits for relocations and refreshes all indices in the cluster.static voidstatic StringresolveCustomDataPath(String index) static IndexresolveIndex(String index) protected voidrestartNodesOnBrokenClusterState(ClusterState.Builder clusterStateBuilder) protected StringroutingKeyForShard(String index, int shard) Compute a routing key that will route documents to theshard-th shard of the provided index.static <T extends ActionResponse>
TsafeExecute(ActionType<T> action, ActionRequest request) Execute the givenActionRequestusing the givenActionTypeand a default node client, wait for it to complete with a timeout ofESTestCase.SAFE_AWAIT_TIMEOUT, and then return the result.static voidsetClusterReadOnly(boolean value) Sets or unsets the cluster read_only modevoidprotected Settings.BuildersetRandomIndexSettings(Random random, Settings.Builder builder) static voidsetReplicaCount(int replicas, String index) protected voidThis method is executed iff the test is annotated withESIntegTestCase.SuiteScopeTestCasebefore the first test of this class is executed.final voidstatic voidupdateClusterSettings(Settings.Builder persistentSettings) Sets cluster persistent settingsstatic voidupdateIndexSettings(Settings.Builder settingsBuilder, String... index) updates the settings for an indexstatic DiscoveryNodewaitAndGetHealthNode(InternalTestCluster internalCluster) Waits for the health node to be assigned and returns the node that it is assigned to.voidwaitForDocs(long numDocs, BackgroundIndexer indexer) Waits until at least a give number of document is visible for searchersWaits for all relocating shards to become active using the cluster health API.waitForRelocation(ClusterHealthStatus status) Waits for all relocating shards to become active and the cluster has reached the given health status using the cluster health API.voidWaits until all nodes have no pending tasks.protected org.elasticsearch.xcontent.NamedXContentRegistryTheNamedXContentRegistryto use for this test.Methods inherited from class org.elasticsearch.test.ESTestCase
after, afterIfFailed, afterIfSuccessful, allBreakersMemoryReleased, asInstanceOf, assertArrayEquals, assertBusy, assertBusy, assertCriticalWarnings, assertEquals, assertLeakDetected, assertSettingDeprecationsAndWarnings, assertThat, assertThat, assertWarnings, assertWarnings, before, between, buildEnvSettings, buildNewFakeTransportAddress, captureLoggingLevel, checkStaticState, compatibleMediaType, copyInstance, copyNamedWriteable, copyNamedWriteable, copyWriteable, copyWriteable, createDefaultIndexAnalyzers, createParser, createParser, createParser, createParser, createParser, createParser, createParserWithCompatibilityFor, createTestAnalysis, createTestAnalysis, createTestAnalysis, createThreadPool, ensureAllContextsReleased, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureNoWarnings, ensureSupportedLocale, expectThrows, expectThrows, fail, fail, filteredWarnings, flushThreadPoolExecutor, frequently, generateRandomStringArray, generateRandomStringArray, getDataPath, getPortRange, getResourceDataPath, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, getWorkerBasePort, indexSettings, indexSettings, initTestSeed, isTurkishLocale, iterations, maybeRestoreClassSecurityManager, maybeSet, maybeStashClassSecurityManager, mockScript, newEnvironment, newEnvironment, newLimitedBreaker, newNodeEnvironment, newNodeEnvironment, parserConfig, randomAlphanumericOfLength, randomAlphaOfLength, randomAlphaOfLengthBetween, randomAlphaOfLengthOrNull, randomArray, randomArray, randomBigInteger, randomBoolean, randomByte, randomByteArrayOfLength, randomByteBetween, randomBytesBetween, randomByteSizeValue, randomBytesReference, randomCompatibleMediaType, randomDateFormatterPattern, randomDouble, randomDoubleBetween, randomDoubles, randomDoubles, randomExecutor, randomFloat, randomFloatBetween, randomFloatOrNull, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomIdentifier, randomInstantBetween, randomInt, randomInt, randomIntBetween, randomIntOrNull, randomInts, randomInts, randomIp, randomList, randomList, randomLong, randomLongBetween, randomLongOrNull, randomLongs, randomLongs, randomMap, randomMillisUpToYear9999, randomNegativeInt, randomNonEmptySubsetOf, randomNonNegativeByte, randomNonNegativeInt, randomNonNegativeIntOrNull, randomNonNegativeLong, randomNonNegativeLongOrNull, randomOptionalBoolean, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomSecretKey, randomSecureStringOfLength, randomSet, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomUnsignedLongBetween, randomUUID, randomValueOtherThan, randomValueOtherThanMany, randomVendorType, randomZone, removeHeaderWarningAppender, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, restoreLoggingLevel, runInParallel, safeAcquire, safeAcquire, safeAwait, safeAwait, safeAwait, safeAwait, safeAwait, safeAwaitAndUnwrapFailure, safeAwaitFailure, safeAwaitFailure, safeAwaitFailure, safeAwaitFailure, safeExecute, safeGet, safeGet, safeSleep, safeSleep, scaledRandomIntBetween, secureRandom, secureRandom, secureRandomFips, secureRandomFips, secureRandomNonFips, secureRandomNonFips, setContentType, setFileSystem, setHeaderWarningAppender, settings, shuffledList, shuffleMap, shuffleXContent, shuffleXContent, skipTestWaitingForLuceneFix, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, startInParallel, terminate, terminate, tmpPaths, toShuffledXContent, waitUntil, waitUntil, writableRegistryMethods 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, 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, getJvmForkArguments, 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, 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, tearDown, usually, usually, wrapReaderMethods 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
-
Field Details
-
SUITE_CLUSTER_NODE_PREFIX
node names of the corresponding clusters will start with these prefixes- See Also:
-
TEST_CLUSTER_NODE_PREFIX
- See Also:
-
TESTS_CLUSTER
Key used to eventually switch to using an external cluster and provide its transport addresses- See Also:
-
TESTS_CLUSTER_NAME
Key used to eventually switch to using an external cluster and provide the cluster name- See Also:
-
INDEX_TEST_SEED_SETTING
Key used to retrieve the index random seed from the index settings on a running node. The value of this seed can be used to initialize a random context for a specific index. It's set once per test via a generic index template. -
TESTS_ENABLE_MOCK_MODULES
A boolean value to enable or disable mock modules. This is useful to test the system without asserting modules that to make sure they don't hide any bugs in production.- See Also:
-
DEFAULT_MIN_NUM_SHARDS
protected static final int DEFAULT_MIN_NUM_SHARDSDefault minimum number of shards for an index- See Also:
-
DEFAULT_MAX_NUM_SHARDS
protected static final int DEFAULT_MAX_NUM_SHARDSDefault maximum number of shards for an index- See Also:
-
-
Constructor Details
-
ESIntegTestCase
public ESIntegTestCase()
-
-
Method Details
-
beforeClass
- Throws:
Exception
-
enableWarningsCheck
protected final boolean enableWarningsCheck()Description copied from class:ESTestCaseWhether 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 usingESTestCase.assertWarnings(String...).- Overrides:
enableWarningsCheckin classESTestCase
-
beforeInternal
- Throws:
Exception
-
setRandomIndexSettings
-
excludeTemplates
- Returns:
- An exclude set of index templates that will not be removed in between tests.
-
beforeIndexDeletion
- Throws:
Exception
-
cluster
-
isInternalCluster
public static boolean isInternalCluster() -
internalCluster
-
clusterService
-
client
-
client
-
dataNodeClient
-
safeExecute
Execute the givenActionRequestusing the givenActionTypeand a default node client, wait for it to complete with a timeout ofESTestCase.SAFE_AWAIT_TIMEOUT, and then return the result. An exceptional response, timeout or interrupt triggers a test failure. -
clients
-
minimumNumberOfShards
protected int minimumNumberOfShards() -
maximumNumberOfShards
protected int maximumNumberOfShards() -
numberOfShards
protected int numberOfShards() -
minimumNumberOfReplicas
protected int minimumNumberOfReplicas() -
maximumNumberOfReplicas
protected int maximumNumberOfReplicas() -
numberOfReplicas
protected int numberOfReplicas() -
setDisruptionScheme
-
isolateMasterDisruption
protected static NetworkDisruption isolateMasterDisruption(NetworkDisruption.NetworkLinkDisruptionType disruptionType) Creates a disruption that isolates the current master node from all other nodes in the cluster.- Parameters:
disruptionType- type of disruption to create- Returns:
- disruption
-
indexSettings
Returns a settings object used increateIndex(String...)andprepareCreate(String)and friends. This method can be overwritten by subclasses to set defaults for the indices that are created by the test. By default it returns a settings object that sets a random number of shards. Number of shards and replicas can be controlled through specific methods. -
createIndex
Creates one or more indices and asserts that the indices are acknowledged. -
createIndex
creates an index with the given setting -
createIndex
creates an index with the given shard and replica counts -
prepareCreate
Creates a newCreateIndexRequestBuilderwith the settings obtained fromindexSettings(). -
prepareCreate
Creates a newCreateIndexRequestBuilderwith the settings obtained fromindexSettings(). The index that is created with this builder will only be allowed to allocate on the number of nodes passed to this method.This method uses allocation deciders to filter out certain nodes to allocate the created index on. It defines allocation rules based on
index.routing.allocation.exclude._name. -
prepareCreate
Creates a newCreateIndexRequestBuilderwith the settings obtained fromindexSettings(), augmented by the given builder -
prepareCreate
public CreateIndexRequestBuilder prepareCreate(String index, int numNodes, Settings.Builder settingsBuilder) Creates a newCreateIndexRequestBuilderwith the settings obtained fromindexSettings(). The index that is created with this builder will only be allowed to allocate on the number of nodes passed to this method.This method uses allocation deciders to filter out certain nodes to allocate the created index on. It defines allocation rules based on
index.routing.allocation.exclude._name. -
updateIndexSettings
updates the settings for an index -
setReplicaCount
-
getDataStreamBackingIndexNames
Returns a list of the data stream's backing index names. -
waitNoPendingTasksOnAll
Waits until all nodes have no pending tasks.- Throws:
Exception
-
assertResultsAndLogOnFailure
Ensures the result counts are as expected, and logs the results if different -
allowNodes
Restricts the given index to be allocated onnnodes using the allocation deciders. Yet if the shards can't be allocated on any other node shards for this index will remain allocated on more thannnodes. -
ensureGreen
Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations. It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating are now allocated and started. -
ensureGreen
Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations. It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating are now allocated and started.- Parameters:
timeout- time out value to set onClusterHealthRequest
-
ensureYellow
Ensures the cluster has a yellow state via the cluster health API. -
ensureRed
Ensures the cluster has a red state via the cluster health API. -
ensureYellowAndNoInitializingShards
Ensures the cluster has a yellow state via the cluster health API and ensures the that cluster has no initializing shards for the given indices -
waitForRelocation
Waits for all relocating shards to become active using the cluster health API. -
waitForRelocation
Waits for all relocating shards to become active and the cluster has reached the given health status using the cluster health API. -
getClusterPendingTasks
-
getClusterPendingTasks
-
awaitClusterState
- Throws:
Exception
-
awaitClusterState
public static void awaitClusterState(org.apache.logging.log4j.Logger logger, Predicate<ClusterState> statePredicate) throws Exception - Throws:
Exception
-
awaitClusterState
public static void awaitClusterState(org.apache.logging.log4j.Logger logger, String viaNode, Predicate<ClusterState> statePredicate) throws Exception - Throws:
Exception
-
getNodeId
-
waitForDocs
Waits until at least a give number of document is visible for searchers- Parameters:
numDocs- number of documents to wait forindexer- aBackgroundIndexer. It will be first checked for documents indexed. This saves on unneeded searches.- Throws:
Exception
-
prepareSearch
-
findTasks
public static List<PersistentTasksCustomMetadata.PersistentTask<?>> findTasks(ClusterState clusterState, String taskName) Retrieves the persistent tasks with the requested task name from the given cluster state. -
findTasks
public static List<PersistentTasksCustomMetadata.PersistentTask<?>> findTasks(ClusterState clusterState, Set<String> taskNames) Retrieves the persistent tasks with the requested task names from the given cluster state. -
waitAndGetHealthNode
Waits for the health node to be assigned and returns the node that it is assigned to. Returns null if the health node is not assigned in due time. -
logClusterState
public void logClusterState()Prints the current cluster state as debug logging. -
ensureClusterSizeConsistency
protected void ensureClusterSizeConsistency() -
ensureClusterStateConsistency
Verifies that all nodes that have the same version of the cluster state as master have same cluster state- Throws:
IOException
-
doEnsureClusterStateConsistency
-
ensureClusterStateCanBeReadByNodeTool
- Throws:
IOException
-
refreshClusterInfo
public static void refreshClusterInfo() -
ensureSearchable
Ensures the cluster is in a searchable state for the given indices. This means a searchable copy of each shard is available on the cluster. -
ensureStableCluster
protected void ensureStableCluster(int nodeCount) -
ensureStableCluster
protected void ensureStableCluster(int nodeCount, org.elasticsearch.core.TimeValue timeValue) -
ensureStableCluster
-
ensureStableCluster
protected void ensureStableCluster(int nodeCount, org.elasticsearch.core.TimeValue timeValue, boolean local, @Nullable String viaNode) -
ensureFullyConnectedCluster
protected void ensureFullyConnectedCluster()Ensures that all nodes in the cluster are connected to each other. Some network disruptions may leave nodes that are not the master disconnected from each other.NodeConnectionsServicewill eventually reconnect but it's handy to be able to ensure this happens faster -
prepareIndex
-
index
protected final DocWriteResponse index(String index, org.elasticsearch.xcontent.XContentBuilder source) Syntactic sugar for:client().prepareIndex(index).setSource(source).get();
-
index
Syntactic sugar for:client().prepareIndex(index).setSource(source).get();
-
index
protected final DocWriteResponse index(String index, String id, org.elasticsearch.xcontent.XContentBuilder source) Syntactic sugar for:return client().prepareIndex(index).setId(id).setSource(source).get();
-
indexDoc
Syntactic sugar for:return client().prepareIndex(index).setId(id).setSource(source).get();
-
index
Syntactic sugar for:return client().prepareIndex(index).setId(id).setSource(source).get();
where source is a JSON String.
-
refresh
Waits for relocations and refreshes all indices in the cluster.- See Also:
-
flushAndRefresh
Flushes and refreshes all indices in the cluster -
flush
Flush some or all indices in the cluster. -
forceMerge
Waits for all relocations and force merge all indices in the cluster to 1 segment. -
indexExists
Returnstrueiff the given index exists otherwisefalse -
indexExists
Returnstrueiff the given index exists otherwisefalse -
enableAllocation
Syntactic sugar for enabling allocation forindices -
disableAllocation
Syntactic sugar for disabling allocation forindices -
admin
Returns a random admin client. This client can be pointing to any of the nodes in the cluster. -
clusterAdmin
Returns a random cluster admin client. This client can be pointing to any of the nodes in the cluster. -
indicesAdmin
Returns a random indices admin client. This client can be pointing to any of the nodes in the cluster. -
indexRandom
-
indexRandom
Convenience method that forwards toindexRandom(boolean, List). -
indexRandom
public void indexRandom(boolean forceRefresh, boolean dummyDocuments, IndexRequestBuilder... builders) -
indexRandom
Indexes the givenIndexRequestBuilderinstances randomly. It shuffles the given builders and either indexes them in a blocking or async fashion. This is very useful to catch problems that relate to internal document ids or index segment creations. Some features might have bug when a given document is the first or the last in a segment or if only one document is in a segment etc. This method prevents issues like this by randomizing the index layout.- Parameters:
forceRefresh- iftrueall involved indices are refreshed once the documents are indexed. Additionally iftruesome empty dummy documents are may be randomly inserted into the document list and deleted once all documents are indexed. This is useful to produce deleted documents on the server side.builders- the documents to index.- See Also:
-
indexRandom
public void indexRandom(boolean forceRefresh, boolean dummyDocuments, List<IndexRequestBuilder> builders) Indexes the givenIndexRequestBuilderinstances randomly. It shuffles the given builders and either indexes them in a blocking or async fashion. This is very useful to catch problems that relate to internal document ids or index segment creations. Some features might have bug when a given document is the first or the last in a segment or if only one document is in a segment etc. This method prevents issues like this by randomizing the index layout.- Parameters:
forceRefresh- iftrueall involved indices are refreshed once the documents are indexed.dummyDocuments- iftruesome empty dummy documents may be randomly inserted into the document list and deleted once all documents are indexed. This is useful to produce deleted documents on the server side.builders- the documents to index.
-
indexRandom
public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean maybeFlush, List<IndexRequestBuilder> builders) Indexes the givenIndexRequestBuilderinstances randomly. It shuffles the given builders and either indexes them in a blocking or async fashion. This is very useful to catch problems that relate to internal document ids or index segment creations. Some features might have bug when a given document is the first or the last in a segment or if only one document is in a segment etc. This method prevents issues like this by randomizing the index layout.- Parameters:
forceRefresh- iftrueall involved indices are refreshed once the documents are indexed.dummyDocuments- iftruesome empty dummy documents may be randomly inserted into the document list and deleted once all documents are indexed. This is useful to produce deleted documents on the server side.maybeFlush- iftruethis method may randomly execute full flushes after index operations.builders- the documents to index.
-
disableIndexBlock
Disables an index block for the specified index -
enableIndexBlock
Enables an index block for the specified index -
setClusterReadOnly
public static void setClusterReadOnly(boolean value) Sets or unsets the cluster read_only mode -
updateClusterSettings
Sets cluster persistent settings -
clearScroll
Clears the given scroll Ids -
nodeSettings
This method is used to obtain settings for theNth node in the cluster. Nodes in this cluster are associated with an ordinal number such that nodes can be started with specific configurations. This method might be called multiple times with the same ordinal and is expected to return the same value for each invocation. In other words subclasses must ensure this method is idempotent. -
nodeConfigPath
-
nodePlugins
Returns a collection of plugins that should be loaded on each node. -
buildTestCluster
- Throws:
IOException
-
addMockTransportService
protected boolean addMockTransportService()Iff this returns true mock transport implementations are used for the test runs. Otherwise not mock transport impls are used. The default istrue. -
enableConcurrentSearch
protected boolean enableConcurrentSearch()Whether we'd like to enable inter-segment search concurrency and increase the likelihood of leveraging it, by creating multiple slices with a low amount of documents in them, which would not be allowed in production. Default is true, can be disabled if it causes problems in specific tests. -
addMockHttpTransport
protected boolean addMockHttpTransport()Returnstrueiff this test cluster should use a dummy http transport -
addMockInternalEngine
protected boolean addMockInternalEngine()Returnstrueif this test cluster can use a mock internal engine. Defaults to true. -
addMockFSIndexStore
protected boolean addMockFSIndexStore()Returnstrueif this test cluster can use theMockFSIndexStoretest plugin. Defaults to true. -
getClientWrapper
Returns a function that allows to wrap / filter all clients that are exposed by the test cluster. This is useful for debugging or request / response pre and post processing. It also allows to intercept all calls done by the test framework. By default this method returns an identity functionFunction.identity(). -
getMockPlugins
Return the mock plugins the cluster should use -
randomRepoPath
Returns path to a random directory that can be used to create a temporary file system repo -
randomRepoPath
Returns path to a random directory that can be used to create a temporary file system repo -
getNumShards
-
assertAllShardsOnNodes
Asserts that all shards are allocated on nodes matching the given node pattern. -
assertSortedSegments
Asserts that all segments are sorted with the providedSort. -
setupTestCluster
- Throws:
Exception
-
cleanUpCluster
- Throws:
Exception
-
enableBigArraysReleasedCheck
protected boolean enableBigArraysReleasedCheck()- Overrides:
enableBigArraysReleasedCheckin classESTestCase
-
afterClass
- Throws:
Exception
-
routingKeyForShard
Compute a routing key that will route documents to theshard-th shard of the provided index. -
xContentRegistry
protected org.elasticsearch.xcontent.NamedXContentRegistry xContentRegistry()Description copied from class:ESTestCaseTheNamedXContentRegistryto use for this test. Subclasses should override and use liberally.- Overrides:
xContentRegistryin classESTestCase
-
forbidPrivateIndexSettings
protected boolean forbidPrivateIndexSettings() -
forceSingleDataPath
protected boolean forceSingleDataPath()Override to return true in tests that cannot handle multiple data paths. -
getRestClient
Returns an instance ofRestClientpointing to the current test cluster. Creates a new client if the method is invoked for the first time in the context of the current test scope. The returned client gets automatically closed when needed, it shouldn't be closed as part of tests otherwise it cannot be reused by other tests anymore. -
createRestClient
-
createRestClient
-
createRestClient
protected static RestClient createRestClient(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) -
createRestClient
protected static RestClient createRestClient(List<NodeInfo> nodes, RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) -
setupSuiteScopeCluster
This method is executed iff the test is annotated withESIntegTestCase.SuiteScopeTestCasebefore the first test of this class is executed.- Throws:
Exception- See Also:
-
autoManageVotingExclusions
protected boolean autoManageVotingExclusions() -
resolveIndex
-
resolveCustomDataPath
-
inFipsJvm
public static boolean inFipsJvm() -
restartNodesOnBrokenClusterState
protected void restartNodesOnBrokenClusterState(ClusterState.Builder clusterStateBuilder) throws Exception - Throws:
Exception
-
fullyAllocateCircuitBreakerOnNode
protected static org.elasticsearch.core.Releasable fullyAllocateCircuitBreakerOnNode(String targetNode, String breakerName) Allocate the entire capacity of a circuit breaker on a specific node- Parameters:
targetNode- The node on which to allocatebreakerName- The circuit breaker to allocate- Returns:
- A
Releasablewhich will de-allocate the amount allocated
-