Package org.elasticsearch.test.rest
Class ESRestTestCase
- java.lang.Object
-
- org.junit.Assert
-
- org.apache.lucene.util.LuceneTestCase
-
- org.elasticsearch.test.ESTestCase
-
- org.elasticsearch.test.rest.ESRestTestCase
-
- Direct Known Subclasses:
AbstractFullClusterRestartTestCase
,ESClientYamlSuiteTestCase
,JsonLogsIntegTestCase
public abstract class ESRestTestCase extends ESTestCase
Superclass for tests that interact with an external test cluster using Elasticsearch'sRestClient
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ESRestTestCase.VersionSensitiveWarningsHandler
Helper class to check warnings in REST responses with sensitivity to versions used in the target cluster.-
Nested classes/interfaces inherited from class org.elasticsearch.test.ESTestCase
ESTestCase.GeohashGenerator, ESTestCase.TestAnalysis
-
Nested classes/interfaces inherited from class org.apache.lucene.util.LuceneTestCase
org.apache.lucene.util.LuceneTestCase.AwaitsFix, org.apache.lucene.util.LuceneTestCase.BadApple, org.apache.lucene.util.LuceneTestCase.Monster, org.apache.lucene.util.LuceneTestCase.Nightly, org.apache.lucene.util.LuceneTestCase.Slow, org.apache.lucene.util.LuceneTestCase.SuppressCodecs, org.apache.lucene.util.LuceneTestCase.SuppressFileSystems, org.apache.lucene.util.LuceneTestCase.SuppressFsync, org.apache.lucene.util.LuceneTestCase.SuppressReproduceLine, org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks, org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks, org.apache.lucene.util.LuceneTestCase.ThrowingRunnable, org.apache.lucene.util.LuceneTestCase.Weekly
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLIENT_PATH_PREFIX
static java.lang.String
CLIENT_SOCKET_TIMEOUT
static java.lang.String
TRUSTSTORE_PASSWORD
static java.lang.String
TRUSTSTORE_PATH
-
Fields inherited from class org.elasticsearch.test.ESTestCase
checkIndexFailed, failureAndSuccessEvents, JAVA_TIMEZONE_IDS, JAVA_ZONE_IDS, JODA_TIMEZONE_IDS, logger
-
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 ESRestTestCase()
-
Method Summary
Modifier and Type Method Description protected static RestClient
adminClient()
Get the client used for test administrative actions.protected static boolean
aliasExists(java.lang.String alias)
protected static boolean
aliasExists(java.lang.String index, java.lang.String alias)
static RequestOptions
allowTypesRemovalWarnings()
Deprecated.this method is only required while we deprecate types and can be removed in 8.0protected static void
assertOK(Response response)
protected RestClient
buildClient(Settings settings, org.apache.http.HttpHost[] hosts)
protected org.apache.http.HttpHost
buildHttpHost(java.lang.String host, int port)
Construct an HttpHost from the given host and portvoid
cleanUpCluster()
Clean up after the test case.protected static RestClient
client()
Get the client used for ordinary api calls while writing a teststatic void
closeClients()
protected static void
closeIndex(java.lang.String index)
protected static void
configureClient(RestClientBuilder builder, Settings settings)
protected static void
createIndex(java.lang.String name, Settings settings)
protected static void
createIndex(java.lang.String name, Settings settings, java.lang.String mapping)
protected static void
createIndex(java.lang.String name, Settings settings, java.lang.String mapping, java.lang.String aliases)
protected static void
deleteIndex(java.lang.String name)
protected static void
ensureGreen(java.lang.String index)
checks that the specific index is green.protected static void
ensureNoInitializingShards()
waits until all shard initialization is completed.static java.util.Map<java.lang.String,java.lang.Object>
entityAsMap(Response response)
Convert the entity from aResponse
into a map of maps.static RequestOptions
expectVersionSpecificWarnings(java.util.function.Consumer<ESRestTestCase.VersionSensitiveWarningsHandler> expectationsSetter)
static RequestOptions
expectWarnings(java.lang.String... warnings)
Creates request options designed to be used when making a call that can return warnings, for example a deprecated request.protected static java.util.Map<java.lang.String,java.lang.Object>
getAlias(java.lang.String index, java.lang.String alias)
protected static java.util.Map<java.lang.String,java.lang.Object>
getAsMap(java.lang.String endpoint)
protected java.util.List<org.apache.http.HttpHost>
getClusterHosts()
Get the list of hosts in the cluster.protected static java.util.Map<java.lang.String,java.lang.Object>
getIndexSettings(java.lang.String index)
protected java.lang.String
getProtocol()
Override this to switch to testing https.static boolean
hasXPack()
Does any node in the cluster being tested have x-pack installed?protected static boolean
indexExists(java.lang.String index)
void
initClient()
protected static void
openIndex(java.lang.String index)
protected boolean
preserveClusterSettings()
Controls whether or not to preserve cluster settings upon completion of the test.protected boolean
preserveClusterUponCompletion()
Returns whether to preserve the state of the cluster upon completion of this test.protected boolean
preserveILMPoliciesUponCompletion()
Returns whether to preserve ILM Policies of this test.protected boolean
preserveIndicesUponCompletion()
Returns whether to preserve the indices created during this test on completion of this test.protected boolean
preserveReposUponCompletion()
Returns whether to preserve the repositories on completion of this test.protected boolean
preserveRollupJobsUponCompletion()
Returns whether to preserve the rollup jobs of this test.protected boolean
preserveSnapshotsUponCompletion()
Returns whether to preserve the snapshots in repositories on completion of this test.protected boolean
preserveTemplatesUponCompletion()
Controls whether or not to preserve templates upon completion of this test.protected Settings
restAdminSettings()
Returns the REST client settings used for admin actions like cleaning up after the test has completed.protected Settings
restClientSettings()
Used to obtain settings for the REST client that is used to send REST requests.protected static void
updateIndexSettings(java.lang.String index, Settings.Builder settings)
static void
waitForPendingTasks(RestClient adminClient)
Wait for outstanding tasks to complete.static void
waitForPendingTasks(RestClient adminClient, java.util.function.Predicate<java.lang.String> taskFilter)
Wait for outstanding tasks to complete.-
Methods inherited from class org.elasticsearch.test.ESTestCase
after, afterIfFailed, afterIfSuccessful, assertAllIndicesRemovedAndDeletionCompleted, assertArrayEquals, assertBusy, assertBusy, assertEquals, assertEqualsWithErrorMessageFromXContent, assertPathHasBeenCleared, assertSettingDeprecationsAndWarnings, assertSettingDeprecationsAndWarnings, assertWarnings, awaitBusy, awaitBusy, before, between, buildEnvSettings, buildNewFakeTransportAddress, checkStaticState, copyInstance, copyStreamable, copyWriteable, copyWriteable, createParser, createParser, createParser, createParser, createParser, createTestAnalysis, createTestAnalysis, createTestAnalysis, enableWarningsCheck, ensureAllSearchContextsReleased, ensureCheckIndexPassed, ensureSupportedLocale, frequently, generateRandomStringArray, generateRandomStringArray, getBwcIndicesPath, getDataPath, getSuiteFailureMarker, getTestTransportPlugin, getTestTransportType, inFipsJvm, iterations, maybeSet, mockScript, newNodeEnvironment, newNodeEnvironment, newTestIndicesModule, newTestScriptModule, randomAlphaOfLength, randomAlphaOfLengthBetween, randomArray, randomArray, randomBoolean, randomByte, randomByteArrayOfLength, randomDateTimeZone, randomDouble, randomDoubleBetween, randomFloat, randomFrom, randomFrom, randomFrom, randomFrom, randomFrom, randomGeohash, randomInt, randomInt, randomIntBetween, randomLong, randomLongBetween, randomNonNegativeLong, randomPositiveTimeValue, randomRealisticUnicodeOfCodepointLength, randomRealisticUnicodeOfCodepointLengthBetween, randomRealisticUnicodeOfLength, randomRealisticUnicodeOfLengthBetween, randomShort, randomSubsetOf, randomSubsetOf, randomSubsetOf, randomTimeValue, randomTimeValue, randomTimeValue, randomTimeZone, randomUnicodeOfCodepointLength, randomUnicodeOfCodepointLengthBetween, randomUnicodeOfLength, randomUnicodeOfLengthBetween, randomUnique, randomValueOtherThan, randomValueOtherThanMany, randomZone, resetCheckIndexStatus, resetPortCounter, restoreContentType, restoreFileSystem, scaledRandomIntBetween, setContentType, setFileSystem, settings, shuffleMap, shuffleXContent, shuffleXContent, spinForAtLeastNMilliseconds, spinForAtLeastOneMillisecond, terminate, terminate, tmpPaths, toShuffledXContent, toShuffledXContent, writableRegistry, xContentRegistry
-
Methods inherited from class org.apache.lucene.util.LuceneTestCase
addVirusChecker, assertDeletedDocsEquals, assertDocsAndPositionsEnumEquals, assertDocsEnumEquals, assertDocsSkippingEquals, assertDocValuesEquals, assertDocValuesEquals, assertFieldInfosEquals, assertNormsEquals, assertPointsEquals, assertPositionsSkippingEquals, assertReaderEquals, assertReaderStatisticsEquals, assertStoredFieldEquals, assertStoredFieldsEquals, assertTermsEnumEquals, assertTermsEquals, assertTermsEquals, assertTermsStatisticsEquals, assertTermStatsEquals, assertTermVectorsEquals, asSet, assumeFalse, assumeNoException, assumeTrue, assumeWorkingMMapOnWindows, atLeast, atLeast, closeAfterSuite, closeAfterTest, collate, createTempDir, createTempDir, createTempFile, createTempFile, dumpArray, dumpIterator, 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
-
-
-
-
Field Detail
-
TRUSTSTORE_PATH
public static final java.lang.String TRUSTSTORE_PATH
- See Also:
- Constant Field Values
-
TRUSTSTORE_PASSWORD
public static final java.lang.String TRUSTSTORE_PASSWORD
- See Also:
- Constant Field Values
-
CLIENT_SOCKET_TIMEOUT
public static final java.lang.String CLIENT_SOCKET_TIMEOUT
- See Also:
- Constant Field Values
-
CLIENT_PATH_PREFIX
public static final java.lang.String CLIENT_PATH_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
entityAsMap
public static java.util.Map<java.lang.String,java.lang.Object> entityAsMap(Response response) throws java.io.IOException
Convert the entity from aResponse
into a map of maps.- Throws:
java.io.IOException
-
hasXPack
public static boolean hasXPack()
Does any node in the cluster being tested have x-pack installed?
-
initClient
public void initClient() throws java.io.IOException
- Throws:
java.io.IOException
-
expectVersionSpecificWarnings
public static RequestOptions expectVersionSpecificWarnings(java.util.function.Consumer<ESRestTestCase.VersionSensitiveWarningsHandler> expectationsSetter)
-
expectWarnings
public static RequestOptions expectWarnings(java.lang.String... warnings)
Creates request options designed to be used when making a call that can return warnings, for example a deprecated request. The options will ensure that the given warnings are returned if all nodes are onVersion.CURRENT
and will allow (but not require) the warnings if any node is running an older version.- Parameters:
warnings
- The expected warnings.
-
allowTypesRemovalWarnings
@Deprecated public static RequestOptions allowTypesRemovalWarnings()
Deprecated.this method is only required while we deprecate types and can be removed in 8.0Creates RequestOptions designed to ignore [types removal] warnings but nothing else
-
buildHttpHost
protected org.apache.http.HttpHost buildHttpHost(java.lang.String host, int port)
Construct an HttpHost from the given host and port
-
cleanUpCluster
public final void cleanUpCluster() throws java.lang.Exception
Clean up after the test case.- Throws:
java.lang.Exception
-
closeClients
public static void closeClients() throws java.io.IOException
- Throws:
java.io.IOException
-
client
protected static RestClient client()
Get the client used for ordinary api calls while writing a test
-
adminClient
protected static RestClient adminClient()
Get the client used for test administrative actions. Do not use this while writing a test. Only use it for cleaning up after tests.
-
waitForPendingTasks
public static void waitForPendingTasks(RestClient adminClient) throws java.lang.Exception
Wait for outstanding tasks to complete. The specified admin client is used to check the outstanding tasks and this is done usingESTestCase.assertBusy(CheckedRunnable)
to give a chance to any outstanding tasks to complete.- Parameters:
adminClient
- the admin client- Throws:
java.lang.Exception
- if an exception is thrown while checking the outstanding tasks
-
waitForPendingTasks
public static void waitForPendingTasks(RestClient adminClient, java.util.function.Predicate<java.lang.String> taskFilter) throws java.lang.Exception
Wait for outstanding tasks to complete. The specified admin client is used to check the outstanding tasks and this is done usingESTestCase.assertBusy(CheckedRunnable)
to give a chance to any outstanding tasks to complete. The specified filter is used to filter out outstanding tasks that are expected to be there.- Parameters:
adminClient
- the admin clienttaskFilter
- predicate used to filter tasks that are expected to be there- Throws:
java.lang.Exception
- if an exception is thrown while checking the outstanding tasks
-
preserveClusterUponCompletion
protected boolean preserveClusterUponCompletion()
Returns whether to preserve the state of the cluster upon completion of this test. Defaults to false. If true, overrides the value ofpreserveIndicesUponCompletion()
,preserveTemplatesUponCompletion()
,preserveReposUponCompletion()
,preserveSnapshotsUponCompletion()
,preserveRollupJobsUponCompletion()
, andpreserveILMPoliciesUponCompletion()
.- Returns:
- true if the state of the cluster should be preserved
-
preserveIndicesUponCompletion
protected boolean preserveIndicesUponCompletion()
Returns whether to preserve the indices created during this test on completion of this test. Defaults tofalse
. Override this method if indices should be preserved after the test, with the assumption that some other process or test will clean up the indices afterward. This is useful if the data directory and indices need to be preserved between test runs (for example, when testing rolling upgrades).
-
preserveTemplatesUponCompletion
protected boolean preserveTemplatesUponCompletion()
Controls whether or not to preserve templates upon completion of this test. The default implementation is to delete not preserve templates.- Returns:
- whether or not to preserve templates
-
preserveClusterSettings
protected boolean preserveClusterSettings()
Controls whether or not to preserve cluster settings upon completion of the test. The default implementation is to remove all cluster settings.- Returns:
- true if cluster settings should be preserved and otherwise false
-
preserveReposUponCompletion
protected boolean preserveReposUponCompletion()
Returns whether to preserve the repositories on completion of this test. Defaults to not preserving repos. See alsopreserveSnapshotsUponCompletion()
.
-
preserveSnapshotsUponCompletion
protected boolean preserveSnapshotsUponCompletion()
Returns whether to preserve the snapshots in repositories on completion of this test. Defaults to not preserving snapshots. Only works forfs
repositories.
-
preserveRollupJobsUponCompletion
protected boolean preserveRollupJobsUponCompletion()
Returns whether to preserve the rollup jobs of this test. Defaults to not preserving them. Only runs at all if xpack is installed on the cluster being tested.
-
preserveILMPoliciesUponCompletion
protected boolean preserveILMPoliciesUponCompletion()
Returns whether to preserve ILM Policies of this test. Defaults to not preserviing them. Only runs at all if xpack is installed on the cluster being tested.
-
restClientSettings
protected Settings restClientSettings()
Used to obtain settings for the REST client that is used to send REST requests.
-
restAdminSettings
protected Settings restAdminSettings()
Returns the REST client settings used for admin actions like cleaning up after the test has completed.
-
getClusterHosts
protected final java.util.List<org.apache.http.HttpHost> getClusterHosts()
Get the list of hosts in the cluster.
-
getProtocol
protected java.lang.String getProtocol()
Override this to switch to testing https.
-
buildClient
protected RestClient buildClient(Settings settings, org.apache.http.HttpHost[] hosts) throws java.io.IOException
- Throws:
java.io.IOException
-
configureClient
protected static void configureClient(RestClientBuilder builder, Settings settings) throws java.io.IOException
- Throws:
java.io.IOException
-
assertOK
protected static void assertOK(Response response)
-
ensureGreen
protected static void ensureGreen(java.lang.String index) throws java.io.IOException
checks that the specific index is green. we force a selection of an index as the tests share a cluster and often leave indices in an non green state- Parameters:
index
- index to test for- Throws:
java.io.IOException
-
ensureNoInitializingShards
protected static void ensureNoInitializingShards() throws java.io.IOException
waits until all shard initialization is completed. This is a handy alternative to ensureGreen as it relates to all shards in the cluster and doesn't require to know how many nodes/replica there are.- Throws:
java.io.IOException
-
createIndex
protected static void createIndex(java.lang.String name, Settings settings) throws java.io.IOException
- Throws:
java.io.IOException
-
createIndex
protected static void createIndex(java.lang.String name, Settings settings, java.lang.String mapping) throws java.io.IOException
- Throws:
java.io.IOException
-
createIndex
protected static void createIndex(java.lang.String name, Settings settings, java.lang.String mapping, java.lang.String aliases) throws java.io.IOException
- Throws:
java.io.IOException
-
deleteIndex
protected static void deleteIndex(java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
updateIndexSettings
protected static void updateIndexSettings(java.lang.String index, Settings.Builder settings) throws java.io.IOException
- Throws:
java.io.IOException
-
getIndexSettings
protected static java.util.Map<java.lang.String,java.lang.Object> getIndexSettings(java.lang.String index) throws java.io.IOException
- Throws:
java.io.IOException
-
indexExists
protected static boolean indexExists(java.lang.String index) throws java.io.IOException
- Throws:
java.io.IOException
-
closeIndex
protected static void closeIndex(java.lang.String index) throws java.io.IOException
- Throws:
java.io.IOException
-
openIndex
protected static void openIndex(java.lang.String index) throws java.io.IOException
- Throws:
java.io.IOException
-
aliasExists
protected static boolean aliasExists(java.lang.String alias) throws java.io.IOException
- Throws:
java.io.IOException
-
aliasExists
protected static boolean aliasExists(java.lang.String index, java.lang.String alias) throws java.io.IOException
- Throws:
java.io.IOException
-
getAlias
protected static java.util.Map<java.lang.String,java.lang.Object> getAlias(java.lang.String index, java.lang.String alias) throws java.io.IOException
- Throws:
java.io.IOException
-
getAsMap
protected static java.util.Map<java.lang.String,java.lang.Object> getAsMap(java.lang.String endpoint) throws java.io.IOException
- Throws:
java.io.IOException
-
-