Class ESRestTestCase

    • Field Detail

      • 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
    • Constructor Detail

      • ESRestTestCase

        public ESRestTestCase()
    • 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 a Response 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
      • 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 on Version.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.0
        Creates 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 using ESTestCase.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 using ESTestCase.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 client
        taskFilter - 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
      • preserveIndicesUponCompletion

        protected boolean preserveIndicesUponCompletion()
        Returns whether to preserve the indices created during this test on completion of this test. Defaults to false. 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 also preserveSnapshotsUponCompletion().
      • preserveSnapshotsUponCompletion

        protected boolean preserveSnapshotsUponCompletion()
        Returns whether to preserve the snapshots in repositories on completion of this test. Defaults to not preserving snapshots. Only works for fs 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