Package org.elasticsearch.test
Class TestCluster
- java.lang.Object
-
- org.elasticsearch.test.TestCluster
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
ExternalTestCluster,InternalTestCluster
public abstract class TestCluster extends java.lang.Object implements java.io.CloseableBase 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.Loggerloggerprotected java.util.Randomrandomprotected doubletransportClientRatio
-
Constructor Summary
Constructors Constructor Description TestCluster(long seed)
-
Method Summary
Modifier and Type Method Description abstract voidafterTest()This method should be executed during tear down, after each test (but after assertAfterTest)voidassertAfterTest()This method checks all the things that need to be checked after each testvoidbeforeIndexDeletion()Assertions that should run before the cluster is wiped should be called in this methodvoidbeforeTest(java.util.Random random, double transportClientRatio)This method should be executed before each test to reset the cluster to its initial state.abstract Clientclient()Returns a client connected to any node in the clusterabstract voidclose()Closes the current clusterabstract voidensureEstimatedStats()Ensures that any breaker statistics are reset to 0.abstract java.lang.Iterable<Client>getClients()Returns anIterableover all clients in this test clusterabstract java.lang.StringgetClusterName()Returns the cluster nameabstract NamedWriteableRegistrygetNamedWriteableRegistry()Returns this clustersNamedWriteableRegistrythis is needed to deserialize binary content from this cluster that might include custom named writeablesabstract java.net.InetSocketAddress[]httpAddresses()Returns the http addresses of the nodes within the cluster.abstract intnumDataAndMasterNodes()Returns the number of data and master eligible nodes in the cluster.abstract intnumDataNodes()Returns the number of data nodes in the cluster.longseed()abstract intsize()Returns the number of nodes in the cluster.voidwipe(java.util.Set<java.lang.String> excludeTemplates)Wipes any data that a test can leave behind: indices, templates (except exclude templates) and repositoriesvoidwipeAllTemplates(java.util.Set<java.lang.String> exclude)Removes all templates, except the templates defined in the excludevoidwipeIndices(java.lang.String... indices)Deletes the given indices from the tests cluster.voidwipeRepositories(java.lang.String... repositories)Deletes repositories, supports wildcard notation.voidwipeTemplates(java.lang.String... templates)Deletes index templates, support wildcard notation.
-
-
-
Method Detail
-
seed
public long seed()
-
beforeTest
public void beforeTest(java.util.Random random, double transportClientRatio) throws java.io.IOException, java.lang.InterruptedExceptionThis method should be executed before each test to reset the cluster to its initial state.- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
wipe
public void wipe(java.util.Set<java.lang.String> excludeTemplates)
Wipes any data that a test can leave behind: indices, templates (except exclude templates) and repositories
-
beforeIndexDeletion
public void beforeIndexDeletion() throws java.lang.ExceptionAssertions that should run before the cluster is wiped should be called in this method- Throws:
java.lang.Exception
-
assertAfterTest
public void assertAfterTest() throws java.io.IOExceptionThis method checks all the things that need to be checked after each test- Throws:
java.io.IOException
-
afterTest
public abstract void afterTest() throws java.io.IOExceptionThis method should be executed during tear down, after each test (but after assertAfterTest)- Throws:
java.io.IOException
-
client
public abstract 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 java.net.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 java.io.IOExceptionCloses the current cluster- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
wipeIndices
public void wipeIndices(java.lang.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(java.util.Set<java.lang.String> exclude)
Removes all templates, except the templates defined in the exclude
-
wipeTemplates
public void wipeTemplates(java.lang.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(java.lang.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 java.lang.String getClusterName()
Returns the cluster name
-
getClients
public abstract java.lang.Iterable<Client> getClients()
Returns anIterableover all clients in this test cluster
-
getNamedWriteableRegistry
public abstract NamedWriteableRegistry getNamedWriteableRegistry()
Returns this clustersNamedWriteableRegistrythis is needed to deserialize binary content from this cluster that might include custom named writeables
-
-