Class TestCluster

java.lang.Object
org.elasticsearch.test.TestCluster
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
ExternalTestCluster, InternalTestCluster

public abstract class TestCluster extends Object implements Closeable
Base test cluster that exposes the basis to run tests against any elasticsearch cluster, whose layout (e.g. number of nodes) is predefined and cannot be changed during the tests execution
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.apache.logging.log4j.Logger
     
    protected Random
     
    protected double
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    TestCluster​(long seed)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    This method should be executed during tear down, after each test (but after assertAfterTest)
    void
    This method checks all the things that need to be checked after each test
    void
    Assertions that should run before the cluster is wiped should be called in this method
    void
    beforeTest​(Random random, double transportClientRatio)
    This method should be executed before each test to reset the cluster to its initial state.
    abstract org.elasticsearch.client.Client
    Returns a client connected to any node in the cluster
    abstract void
    Closes the current cluster
    abstract void
    Ensures that any breaker statistics are reset to 0.
    abstract Iterable<org.elasticsearch.client.Client>
    Returns an Iterable over all clients in this test cluster
    abstract String
    Returns the cluster name
    abstract org.elasticsearch.common.io.stream.NamedWriteableRegistry
    Returns this clusters NamedWriteableRegistry this is needed to deserialize binary content from this cluster that might include custom named writeables
    Returns the http addresses of the nodes within the cluster.
    abstract int
    Returns the number of data and master eligible nodes in the cluster.
    abstract int
    Returns the number of data nodes in the cluster.
    long
     
    abstract int
    Returns the number of nodes in the cluster.
    void
    wipe​(Set<String> excludeTemplates)
    Wipes any data that a test can leave behind: indices, templates (except exclude templates) and repositories
    void
    Removes all templates, except the templates defined in the exclude
    void
    wipeIndices​(String... indices)
    Deletes the given indices from the tests cluster.
    void
    wipeRepositories​(String... repositories)
    Deletes repositories, supports wildcard notation.
    void
    wipeTemplates​(String... templates)
    Deletes index templates, support wildcard notation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

      protected final org.apache.logging.log4j.Logger logger
    • random

      protected Random random
    • transportClientRatio

      protected double transportClientRatio
  • Constructor Details

    • TestCluster

      public TestCluster(long seed)
  • Method Details

    • seed

      public long seed()
    • beforeTest

      public void beforeTest(Random random, double transportClientRatio) throws IOException, InterruptedException
      This method should be executed before each test to reset the cluster to its initial state.
      Throws:
      IOException
      InterruptedException
    • wipe

      public void wipe(Set<String> excludeTemplates)
      Wipes any data that a test can leave behind: indices, templates (except exclude templates) and repositories
    • beforeIndexDeletion

      public void beforeIndexDeletion() throws Exception
      Assertions that should run before the cluster is wiped should be called in this method
      Throws:
      Exception
    • assertAfterTest

      public void assertAfterTest() throws Exception
      This method checks all the things that need to be checked after each test
      Throws:
      Exception
    • afterTest

      public abstract void afterTest() throws IOException
      This method should be executed during tear down, after each test (but after assertAfterTest)
      Throws:
      IOException
    • client

      public abstract org.elasticsearch.client.Client client()
      Returns a client connected to any node in the cluster
    • size

      public abstract int size()
      Returns the number of nodes in the cluster.
    • numDataNodes

      public abstract int numDataNodes()
      Returns the number of data nodes in the cluster.
    • numDataAndMasterNodes

      public abstract int numDataAndMasterNodes()
      Returns the number of data and master eligible nodes in the cluster.
    • httpAddresses

      public abstract InetSocketAddress[] httpAddresses()
      Returns the http addresses of the nodes within the cluster. Can be used to run REST tests against the test cluster.
    • close

      public abstract void close() throws IOException
      Closes the current cluster
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • wipeIndices

      public void wipeIndices(String... indices)
      Deletes the given indices from the tests cluster. If no index name is passed to this method all indices are removed.
    • wipeAllTemplates

      public void wipeAllTemplates(Set<String> exclude)
      Removes all templates, except the templates defined in the exclude
    • wipeTemplates

      public void wipeTemplates(String... templates)
      Deletes index templates, support wildcard notation. If no template name is passed to this method all templates are removed.
    • wipeRepositories

      public void wipeRepositories(String... repositories)
      Deletes repositories, supports wildcard notation.
    • ensureEstimatedStats

      public abstract void ensureEstimatedStats()
      Ensures that any breaker statistics are reset to 0. The implementation is specific to the test cluster, because the act of checking some breaker stats can increase them.
    • getClusterName

      public abstract String getClusterName()
      Returns the cluster name
    • getClients

      public abstract Iterable<org.elasticsearch.client.Client> getClients()
      Returns an Iterable over all clients in this test cluster
    • getNamedWriteableRegistry

      public abstract org.elasticsearch.common.io.stream.NamedWriteableRegistry getNamedWriteableRegistry()
      Returns this clusters NamedWriteableRegistry this is needed to deserialize binary content from this cluster that might include custom named writeables