@LuceneTestCase.SuppressFileSystems(value="ExtrasFS") public abstract class ESIntegTestCase extends ESTestCase
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)
Modifier and Type | Class and Description |
---|---|
static interface |
ESIntegTestCase.ClusterScope
Defines a cluster scope for a
ESIntegTestCase subclass. |
protected static class |
ESIntegTestCase.NumShards |
static class |
ESIntegTestCase.Scope
The scope of a test cluster used together with
ESIntegTestCase.ClusterScope annotations on ESIntegTestCase subclasses. |
static interface |
ESIntegTestCase.SuiteScopeTestCase
If a test is annotated with
ESIntegTestCase.SuiteScopeTestCase
the checks and modifications that are applied to the used test cluster are only done after all tests
of this class are executed. |
static interface |
ESIntegTestCase.SuppressLocalMode
If used the test will never run in local mode.
|
static interface |
ESIntegTestCase.SuppressNetworkMode
If used the test will never run in network mode
|
static class |
ESIntegTestCase.TestSeedPlugin |
static interface |
ESIntegTestCase.ThirdParty
Annotation for third-party integration tests.
|
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
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_MAX_NUM_SHARDS
Default maximum number of shards for an index
|
protected static int |
DEFAULT_MIN_NUM_SHARDS
Default minimum number of shards for an index
|
static org.elasticsearch.common.settings.Setting<java.lang.Long> |
INDEX_TEST_SEED_SETTING
Key used to retrieve the index random seed from the index settings on a running node.
|
static java.lang.String |
SUITE_CLUSTER_NODE_PREFIX
node names of the corresponding clusters will start with these prefixes
|
static java.lang.String |
SYSPROP_THIRDPARTY
Property that controls whether ThirdParty Integration tests are run (not the default).
|
static java.lang.String |
TEST_CLUSTER_NODE_PREFIX |
static java.lang.String |
TESTS_CLIENT_RATIO
Key used to set the transport client ratio via the commandline -D"tests.client.ratio"
|
static java.lang.String |
TESTS_CLUSTER
Key used to eventually switch to using an external cluster and provide its transport addresses
|
static java.lang.String |
TESTS_ENABLE_MOCK_MODULES
A boolean value to enable or disable mock modules.
|
checkIndexFailed, failureAndSuccessEvents, logger
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_CODEC, TEST_DIRECTORY, TEST_DOCVALUESFORMAT, TEST_LINE_DOCS_FILE, TEST_NIGHTLY, TEST_POSTINGSFORMAT, TEST_SLOW, TEST_THROTTLING, TEST_WEEKLY, VERBOSE
Constructor and Description |
---|
ESIntegTestCase() |
Modifier and Type | Method and Description |
---|---|
protected org.elasticsearch.client.AdminClient |
admin()
Returns a random admin client.
|
void |
after() |
static void |
afterClass() |
protected void |
afterInternal(boolean afterClass) |
void |
allowNodes(java.lang.String index,
int n)
Restricts the given index to be allocated on
n nodes using the allocation deciders. |
java.util.Set<java.lang.String> |
assertAllShardsOnNodes(java.lang.String index,
java.lang.String... pattern)
Asserts that all shards are allocated on nodes matching the given node pattern.
|
void |
assertConcreteMappingsOnAll(java.lang.String index,
java.lang.String type,
java.lang.String... fieldNames)
Waits till a (pattern) field name mappings concretely exists on all nodes.
|
void |
assertMappingOnMaster(java.lang.String index,
java.lang.String type,
java.lang.String... fieldNames)
Waits for the given mapping type to exists on the master node.
|
void |
assertResultsAndLogOnFailure(long expectedResults,
org.elasticsearch.action.search.SearchResponse searchResponse)
Ensures the result counts are as expected, and logs the results if different
|
void |
before() |
static void |
beforeClass() |
protected void |
beforeIndexDeletion() |
protected void |
beforeInternal() |
protected TestCluster |
buildTestCluster(ESIntegTestCase.Scope scope,
long seed) |
void |
clearDisruptionScheme() |
void |
clearScroll(java.lang.String... scrollIds)
Clears the given scroll Ids
|
static org.elasticsearch.client.Client |
client() |
static org.elasticsearch.client.Client |
client(java.lang.String node) |
static java.lang.Iterable<org.elasticsearch.client.Client> |
clients() |
static TestCluster |
cluster() |
org.elasticsearch.cluster.service.ClusterService |
clusterService() |
void |
createIndex(java.lang.String... names)
Creates one or more indices and asserts that the indices are acknowledged.
|
protected static org.elasticsearch.client.RestClient |
createRestClient(org.apache.http.impl.client.CloseableHttpClient httpClient) |
protected static org.elasticsearch.client.RestClient |
createRestClient(org.apache.http.impl.client.CloseableHttpClient httpClient,
java.lang.String protocol) |
static org.elasticsearch.client.Client |
dataNodeClient() |
protected void |
disableAllocation(java.lang.String... indices)
Syntactic sugar for disabling allocation for
indices |
static void |
disableIndexBlock(java.lang.String index,
java.lang.String block)
Disables an index block for the specified index
|
protected void |
enableAllocation(java.lang.String... indices)
Syntactic sugar for enabling allocation for
indices |
static void |
enableIndexBlock(java.lang.String index,
java.lang.String block)
Enables an index block for the specified index
|
protected void |
ensureClusterSizeConsistency() |
protected void |
ensureClusterStateConsistency()
Verifies that all nodes that have the same version of the cluster state as master have same cluster state
|
org.elasticsearch.cluster.health.ClusterHealthStatus |
ensureGreen(java.lang.String... indices)
Ensures the cluster has a green state via the cluster health API.
|
org.elasticsearch.cluster.health.ClusterHealthStatus |
ensureGreen(org.elasticsearch.common.unit.TimeValue timeout,
java.lang.String... indices)
Ensures the cluster has a green state via the cluster health API.
|
protected org.elasticsearch.cluster.health.ClusterHealthStatus |
ensureSearchable(java.lang.String... indices)
Ensures the cluster is in a searchable state for the given indices.
|
protected void |
ensureStableCluster(int nodeCount) |
protected void |
ensureStableCluster(int nodeCount,
java.lang.String viaNode) |
protected void |
ensureStableCluster(int nodeCount,
org.elasticsearch.common.unit.TimeValue timeValue) |
protected void |
ensureStableCluster(int nodeCount,
org.elasticsearch.common.unit.TimeValue timeValue,
boolean local,
java.lang.String viaNode) |
org.elasticsearch.cluster.health.ClusterHealthStatus |
ensureYellow(java.lang.String... indices)
Ensures the cluster has a yellow state via the cluster health API.
|
protected java.util.Set<java.lang.String> |
excludeTemplates() |
protected org.elasticsearch.common.settings.Settings |
externalClusterClientSettings() |
protected org.elasticsearch.action.admin.indices.flush.FlushResponse |
flush(java.lang.String... indices)
Flush some or all indices in the cluster.
|
protected void |
flushAndRefresh(java.lang.String... indices)
Flushes and refreshes all indices in the cluster
|
protected org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse |
forceMerge()
Waits for all relocations and force merge all indices in the cluster to 1 segment.
|
protected org.elasticsearch.action.get.GetResponse |
get(java.lang.String index,
java.lang.String type,
java.lang.String id)
Syntactic sugar for:
|
protected java.util.function.Function<org.elasticsearch.client.Client,org.elasticsearch.client.Client> |
getClientWrapper()
Returns a function that allows to wrap / filter all clients that are exposed by the test cluster.
|
protected java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> |
getMockPlugins()
Return the mock plugins the cluster should use
|
protected ESIntegTestCase.NumShards |
getNumShards(java.lang.String index) |
protected double |
getPerTestTransportClientRatio()
Returns the transport client ratio from the class level annotation or via
System.getProperty(String) if available. |
protected static org.elasticsearch.client.RestClient |
getRestClient()
Returns an instance of
RestClient pointing to the current test cluster. |
protected org.elasticsearch.action.index.IndexResponse |
index(java.lang.String index,
java.lang.String type,
java.lang.String id,
java.util.Map<java.lang.String,java.lang.Object> source)
Syntactic sugar for:
|
protected org.elasticsearch.action.index.IndexResponse |
index(java.lang.String index,
java.lang.String type,
java.lang.String id,
java.lang.Object... source)
Syntactic sugar for:
|
protected org.elasticsearch.action.index.IndexResponse |
index(java.lang.String index,
java.lang.String type,
java.lang.String id,
java.lang.String source)
Syntactic sugar for:
|
protected org.elasticsearch.action.index.IndexResponse |
index(java.lang.String index,
java.lang.String type,
java.lang.String id,
org.elasticsearch.common.xcontent.XContentBuilder source)
Syntactic sugar for:
|
protected org.elasticsearch.action.index.IndexResponse |
index(java.lang.String index,
java.lang.String type,
org.elasticsearch.common.xcontent.XContentBuilder source)
Syntactic sugar for:
|
protected boolean |
indexExists(java.lang.String index)
Returns
true iff the given index exists otherwise false |
void |
indexRandom(boolean forceRefresh,
boolean dummyDocuments,
boolean maybeFlush,
java.util.List<org.elasticsearch.action.index.IndexRequestBuilder> builders)
Indexes the given
IndexRequestBuilder instances randomly. |
void |
indexRandom(boolean forceRefresh,
boolean dummyDocuments,
org.elasticsearch.action.index.IndexRequestBuilder... builders) |
void |
indexRandom(boolean forceRefresh,
boolean dummyDocuments,
java.util.List<org.elasticsearch.action.index.IndexRequestBuilder> builders)
Indexes the given
IndexRequestBuilder instances randomly. |
void |
indexRandom(boolean forceRefresh,
org.elasticsearch.action.index.IndexRequestBuilder... builders)
Convenience method that forwards to
indexRandom(boolean, List) . |
void |
indexRandom(boolean forceRefresh,
java.util.List<org.elasticsearch.action.index.IndexRequestBuilder> builders)
Indexes the given
IndexRequestBuilder instances randomly. |
org.elasticsearch.common.settings.Settings |
indexSettings()
Returns a settings object used in
createIndex(String...) and prepareCreate(String) and friends. |
static InternalTestCluster |
internalCluster() |
static boolean |
isInternalCluster() |
void |
logClusterState()
Prints the current cluster state as debug logging.
|
void |
logMemoryStats()
Prints current memory stats as info logging.
|
void |
logSegmentsState(java.lang.String... indices)
Prints the segments info for the given indices as debug logging.
|
protected int |
maximumNumberOfReplicas() |
protected int |
maximumNumberOfShards() |
protected int |
minimumNumberOfReplicas() |
protected int |
minimumNumberOfShards() |
protected java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> |
nodePlugins()
Returns a collection of plugins that should be loaded on each node.
|
protected org.elasticsearch.common.settings.Settings |
nodeSettings(int nodeOrdinal)
This method is used to obtain settings for the Nth node in the cluster.
|
protected int |
numberOfReplicas() |
protected int |
numberOfShards() |
protected java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> |
pluginList(java.lang.Class<? extends org.elasticsearch.plugins.Plugin>... plugins)
Helper method to create list of plugins without specifying generic types.
|
protected org.elasticsearch.common.settings.Settings |
prepareBackwardsDataDir(java.nio.file.Path backwardsIndex,
java.lang.Object... settings)
Return settings that could be used to start a node that has the given zipped home directory.
|
org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder |
prepareCreate(java.lang.String index)
Creates a new
CreateIndexRequestBuilder with the settings obtained from indexSettings() . |
org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder |
prepareCreate(java.lang.String index,
int numNodes)
Creates a new
CreateIndexRequestBuilder with the settings obtained from indexSettings() . |
org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder |
prepareCreate(java.lang.String index,
int numNodes,
org.elasticsearch.common.settings.Settings.Builder settingsBuilder)
Creates a new
CreateIndexRequestBuilder with the settings obtained from indexSettings() . |
void |
randomIndexTemplate()
Creates a randomized index template.
|
java.nio.file.Path |
randomRepoPath()
Returns path to a random directory that can be used to create a temporary file system repo
|
static java.nio.file.Path |
randomRepoPath(org.elasticsearch.common.settings.Settings settings)
Returns path to a random directory that can be used to create a temporary file system repo
|
protected org.elasticsearch.action.admin.indices.refresh.RefreshResponse |
refresh(java.lang.String... indices)
Waits for relocations and refreshes all indices in the cluster.
|
static org.elasticsearch.index.Index |
resolveIndex(java.lang.String index) |
protected java.lang.String |
routingKeyForShard(java.lang.String index,
int shard)
Compute a routing key that will route documents to the
shard -th shard
of the provided index. |
static void |
setClusterReadOnly(boolean value)
Sets or unsets the cluster read_only mode
|
void |
setDisruptionScheme(ServiceDisruptionScheme scheme) |
void |
setMinimumMasterNodes(int n)
Sets the cluster's minimum master node and make sure the response is acknowledge.
|
protected org.elasticsearch.common.settings.Settings.Builder |
setRandomIndexSettings(java.util.Random random,
org.elasticsearch.common.settings.Settings.Builder builder) |
protected void |
setupSuiteScopeCluster()
This method is executed iff the test is annotated with
ESIntegTestCase.SuiteScopeTestCase
before the first test of this class is executed. |
protected java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> |
transportClientPlugins()
Returns a collection of plugins that should be loaded when creating a transport client.
|
protected org.elasticsearch.common.settings.Settings |
transportClientSettings()
This method is used to obtain additional settings for clients created by the internal cluster.
|
long |
waitForDocs(long numDocs)
Waits until at least a give number of document is visible for searchers
|
long |
waitForDocs(long numDocs,
BackgroundIndexer indexer)
Waits until at least a give number of document is visible for searchers
|
long |
waitForDocs(long numDocs,
int maxWaitTime,
java.util.concurrent.TimeUnit maxWaitTimeUnit,
BackgroundIndexer indexer)
Waits until at least a give number of document is visible for searchers
|
org.elasticsearch.cluster.health.ClusterHealthStatus |
waitForRelocation()
Waits for all relocating shards to become active using the cluster health API.
|
org.elasticsearch.cluster.health.ClusterHealthStatus |
waitForRelocation(org.elasticsearch.cluster.health.ClusterHealthStatus status)
Waits for all relocating shards to become active and the cluster has reached the given health status
using the cluster health API.
|
void |
waitNoPendingTasksOnAll()
Waits until all nodes have no pending tasks.
|
afterIfFailed, afterIfSuccessful, assertAllIndicesRemovedAndDeletionCompleted, assertArrayEquals, assertBusy, assertBusy, assertEquals, assertionsEnabled, assertPathHasBeenCleared, awaitBusy, awaitBusy, between, createAnalysisService, createAnalysisService, createAnalysisService, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureCleanedUp, frequently, generateRandomStringArray, generateRandomStringArray, getBwcIndicesPath, getDataPath, getSuiteFailureMarker, iterations, maybeSet, newNodeEnvironment, newNodeEnvironment, newTestScriptModule, randomAsciiOfLength, randomAsciiOfLengthBetween, randomBoolean, randomByte, randomDateTimeZone, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomInt, randomInt, randomIntBetween, randomLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, resetCheckIndexStatus, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, settings, shuffleXContent, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths
addVirusChecker, assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertFieldInfosEquals, assertFieldsEquals, assertFieldStatisticsEquals, assertNormsEquals, assertPointsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, asSet, assumeFalse, assumeNoException, assumeTrue, atLeast, atLeast, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, expectThrows, getBaseTempDirForTestClass, getDataInputStream, getOnlyLeafReader, getTestClass, getTestName, 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, 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
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, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
public static final java.lang.String SYSPROP_THIRDPARTY
public static final java.lang.String SUITE_CLUSTER_NODE_PREFIX
public static final java.lang.String TEST_CLUSTER_NODE_PREFIX
public static final java.lang.String TESTS_CLIENT_RATIO
public static final java.lang.String TESTS_CLUSTER
public static final org.elasticsearch.common.settings.Setting<java.lang.Long> INDEX_TEST_SEED_SETTING
public static final java.lang.String TESTS_ENABLE_MOCK_MODULES
ESIntegTestCase
,
Constant Field Valuesprotected static final int DEFAULT_MIN_NUM_SHARDS
protected static final int DEFAULT_MAX_NUM_SHARDS
public static void beforeClass() throws java.lang.Exception
java.lang.Exception
protected final void beforeInternal() throws java.lang.Exception
java.lang.Exception
public void randomIndexTemplate() throws java.io.IOException
java.io.IOException
protected org.elasticsearch.common.settings.Settings.Builder setRandomIndexSettings(java.util.Random random, org.elasticsearch.common.settings.Settings.Builder builder)
protected final void afterInternal(boolean afterClass) throws java.lang.Exception
java.lang.Exception
protected java.util.Set<java.lang.String> excludeTemplates()
protected void beforeIndexDeletion()
public static TestCluster cluster()
public static boolean isInternalCluster()
public static InternalTestCluster internalCluster()
public org.elasticsearch.cluster.service.ClusterService clusterService()
public static org.elasticsearch.client.Client client()
public static org.elasticsearch.client.Client client(@Nullable java.lang.String node)
public static org.elasticsearch.client.Client dataNodeClient()
public static java.lang.Iterable<org.elasticsearch.client.Client> clients()
protected int minimumNumberOfShards()
protected int maximumNumberOfShards()
protected int numberOfShards()
protected int minimumNumberOfReplicas()
protected int maximumNumberOfReplicas()
protected int numberOfReplicas()
public void setDisruptionScheme(ServiceDisruptionScheme scheme)
public void clearDisruptionScheme()
public org.elasticsearch.common.settings.Settings indexSettings()
createIndex(String...)
and prepareCreate(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.public final void createIndex(java.lang.String... names)
public final org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder prepareCreate(java.lang.String index)
CreateIndexRequestBuilder
with the settings obtained from indexSettings()
.public final org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder prepareCreate(java.lang.String index, int numNodes)
CreateIndexRequestBuilder
with the settings obtained from indexSettings()
.
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
.
public org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder prepareCreate(java.lang.String index, int numNodes, org.elasticsearch.common.settings.Settings.Builder settingsBuilder)
CreateIndexRequestBuilder
with the settings obtained from indexSettings()
.
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
.
public void waitNoPendingTasksOnAll() throws java.lang.Exception
java.lang.Exception
public void assertConcreteMappingsOnAll(java.lang.String index, java.lang.String type, java.lang.String... fieldNames) throws java.lang.Exception
java.lang.Exception
public void assertMappingOnMaster(java.lang.String index, java.lang.String type, java.lang.String... fieldNames) throws java.lang.Exception
java.lang.Exception
public void assertResultsAndLogOnFailure(long expectedResults, org.elasticsearch.action.search.SearchResponse searchResponse)
public void allowNodes(java.lang.String index, int n)
n
nodes 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 than n
nodes.public org.elasticsearch.cluster.health.ClusterHealthStatus ensureGreen(java.lang.String... indices)
public org.elasticsearch.cluster.health.ClusterHealthStatus ensureGreen(org.elasticsearch.common.unit.TimeValue timeout, java.lang.String... indices)
timeout
- time out value to set on ClusterHealthRequest
public org.elasticsearch.cluster.health.ClusterHealthStatus waitForRelocation()
public org.elasticsearch.cluster.health.ClusterHealthStatus waitForRelocation(org.elasticsearch.cluster.health.ClusterHealthStatus status)
public long waitForDocs(long numDocs) throws java.lang.InterruptedException
numDocs
- number of documents to wait for.java.lang.InterruptedException
public long waitForDocs(long numDocs, @Nullable BackgroundIndexer indexer) throws java.lang.InterruptedException
numDocs
- number of documents to wait forindexer
- a BackgroundIndexer
. If supplied it will be first checked for documents indexed.
This saves on unneeded searches.java.lang.InterruptedException
public long waitForDocs(long numDocs, int maxWaitTime, java.util.concurrent.TimeUnit maxWaitTimeUnit, @Nullable BackgroundIndexer indexer) throws java.lang.InterruptedException
numDocs
- number of documents to wait formaxWaitTime
- if not progress have been made during this time, fail the testmaxWaitTimeUnit
- the unit in which maxWaitTime is specifiedindexer
- a BackgroundIndexer
. If supplied it will be first checked for documents indexed.
This saves on unneeded searches.java.lang.InterruptedException
public void setMinimumMasterNodes(int n)
public org.elasticsearch.cluster.health.ClusterHealthStatus ensureYellow(java.lang.String... indices)
public void logClusterState()
public void logSegmentsState(java.lang.String... indices) throws java.lang.Exception
java.lang.Exception
public void logMemoryStats()
protected void ensureClusterSizeConsistency()
protected void ensureClusterStateConsistency() throws java.io.IOException
java.io.IOException
protected org.elasticsearch.cluster.health.ClusterHealthStatus ensureSearchable(java.lang.String... indices)
protected void ensureStableCluster(int nodeCount)
protected void ensureStableCluster(int nodeCount, org.elasticsearch.common.unit.TimeValue timeValue)
protected void ensureStableCluster(int nodeCount, @Nullable java.lang.String viaNode)
protected void ensureStableCluster(int nodeCount, org.elasticsearch.common.unit.TimeValue timeValue, boolean local, @Nullable java.lang.String viaNode)
protected final org.elasticsearch.action.index.IndexResponse index(java.lang.String index, java.lang.String type, org.elasticsearch.common.xcontent.XContentBuilder source)
client().prepareIndex(index, type).setSource(source).execute().actionGet();
protected final org.elasticsearch.action.index.IndexResponse index(java.lang.String index, java.lang.String type, java.lang.String id, java.util.Map<java.lang.String,java.lang.Object> source)
client().prepareIndex(index, type).setSource(source).execute().actionGet();
protected final org.elasticsearch.action.get.GetResponse get(java.lang.String index, java.lang.String type, java.lang.String id)
client().prepareGet(index, type, id).execute().actionGet();
protected final org.elasticsearch.action.index.IndexResponse index(java.lang.String index, java.lang.String type, java.lang.String id, org.elasticsearch.common.xcontent.XContentBuilder source)
return client().prepareIndex(index, type, id).setSource(source).execute().actionGet();
protected final org.elasticsearch.action.index.IndexResponse index(java.lang.String index, java.lang.String type, java.lang.String id, java.lang.Object... source)
return client().prepareIndex(index, type, id).setSource(source).execute().actionGet();
protected final org.elasticsearch.action.index.IndexResponse index(java.lang.String index, java.lang.String type, java.lang.String id, java.lang.String source)
return client().prepareIndex(index, type, id).setSource(source).execute().actionGet();
where source is a String.
protected final org.elasticsearch.action.admin.indices.refresh.RefreshResponse refresh(java.lang.String... indices)
waitForRelocation()
protected final void flushAndRefresh(java.lang.String... indices)
protected final org.elasticsearch.action.admin.indices.flush.FlushResponse flush(java.lang.String... indices)
protected org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse forceMerge()
protected boolean indexExists(java.lang.String index)
true
iff the given index exists otherwise false
protected final void enableAllocation(java.lang.String... indices)
indices
protected final void disableAllocation(java.lang.String... indices)
indices
protected org.elasticsearch.client.AdminClient admin()
public void indexRandom(boolean forceRefresh, org.elasticsearch.action.index.IndexRequestBuilder... builders) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
indexRandom(boolean, List)
.java.lang.InterruptedException
java.util.concurrent.ExecutionException
public void indexRandom(boolean forceRefresh, boolean dummyDocuments, org.elasticsearch.action.index.IndexRequestBuilder... builders) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public void indexRandom(boolean forceRefresh, java.util.List<org.elasticsearch.action.index.IndexRequestBuilder> builders) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
IndexRequestBuilder
instances 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.forceRefresh
- if true all involved indices are refreshed once the documents are indexed. Additionally if true
some 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.java.lang.InterruptedException
java.util.concurrent.ExecutionException
indexRandom(boolean, boolean, java.util.List)
public void indexRandom(boolean forceRefresh, boolean dummyDocuments, java.util.List<org.elasticsearch.action.index.IndexRequestBuilder> builders) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
IndexRequestBuilder
instances randomly. It shuffles the given builders and either
indexes they 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.forceRefresh
- if true all involved indices are refreshed once the documents are indexed.dummyDocuments
- if true some 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.java.lang.InterruptedException
java.util.concurrent.ExecutionException
public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean maybeFlush, java.util.List<org.elasticsearch.action.index.IndexRequestBuilder> builders) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
IndexRequestBuilder
instances randomly. It shuffles the given builders and either
indexes they 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.forceRefresh
- if true all involved indices are refreshed once the documents are indexed.dummyDocuments
- if true some 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
- if true this method may randomly execute full flushes after index operations.builders
- the documents to index.java.lang.InterruptedException
java.util.concurrent.ExecutionException
public static void disableIndexBlock(java.lang.String index, java.lang.String block)
public static void enableIndexBlock(java.lang.String index, java.lang.String block)
public static void setClusterReadOnly(boolean value)
public void clearScroll(java.lang.String... scrollIds)
protected org.elasticsearch.common.settings.Settings nodeSettings(int nodeOrdinal)
protected java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> nodePlugins()
protected java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> transportClientPlugins()
@SafeVarargs protected final java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> pluginList(java.lang.Class<? extends org.elasticsearch.plugins.Plugin>... plugins)
protected org.elasticsearch.common.settings.Settings transportClientSettings()
protected org.elasticsearch.common.settings.Settings externalClusterClientSettings()
protected TestCluster buildTestCluster(ESIntegTestCase.Scope scope, long seed) throws java.io.IOException
java.io.IOException
protected java.util.function.Function<org.elasticsearch.client.Client,org.elasticsearch.client.Client> getClientWrapper()
Function.identity()
.protected java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> getMockPlugins()
protected double getPerTestTransportClientRatio()
System.getProperty(String)
if available. If both are not available this will
return a random ratio in the interval [0..1]public java.nio.file.Path randomRepoPath()
public static java.nio.file.Path randomRepoPath(org.elasticsearch.common.settings.Settings settings)
protected ESIntegTestCase.NumShards getNumShards(java.lang.String index)
public java.util.Set<java.lang.String> assertAllShardsOnNodes(java.lang.String index, java.lang.String... pattern)
public final void before() throws java.lang.Exception
java.lang.Exception
public final void after() throws java.lang.Exception
java.lang.Exception
public static void afterClass() throws java.lang.Exception
java.lang.Exception
protected java.lang.String routingKeyForShard(java.lang.String index, int shard)
shard
-th shard
of the provided index.protected org.elasticsearch.common.settings.Settings prepareBackwardsDataDir(java.nio.file.Path backwardsIndex, java.lang.Object... settings) throws java.io.IOException
java.io.IOException
protected static org.elasticsearch.client.RestClient getRestClient()
RestClient
pointing 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.protected static org.elasticsearch.client.RestClient createRestClient(org.apache.http.impl.client.CloseableHttpClient httpClient)
protected static org.elasticsearch.client.RestClient createRestClient(org.apache.http.impl.client.CloseableHttpClient httpClient, java.lang.String protocol)
protected void setupSuiteScopeCluster() throws java.lang.Exception
ESIntegTestCase.SuiteScopeTestCase
before the first test of this class is executed.java.lang.Exception
ESIntegTestCase.SuiteScopeTestCase
public static org.elasticsearch.index.Index resolveIndex(java.lang.String index)