java.io.Closeable, java.lang.AutoCloseablepublic final class InternalTestCluster extends TestCluster
The Cluster is bound to a test lifecycle where tests must call beforeTest(java.util.Random, double) and
afterTest() to initialize and reset the cluster in order to be more reproducible. The term "more" relates
to the async nature of Elasticsearch in combination with randomized testing. Once Threads and asynchronous calls
are involved reproducibility is very limited. This class should only be used through ESIntegTestCase.
| Modifier and Type | Class | Description |
|---|---|---|
static class |
InternalTestCluster.RestartCallback |
An abstract class that is called during
rollingRestart(InternalTestCluster.RestartCallback)
and / or fullRestart(InternalTestCluster.RestartCallback) to execute actions at certain
stages of the restart. |
| Modifier and Type | Field | Description |
|---|---|---|
static int |
DEFAULT_HIGH_NUM_MASTER_NODES |
|
static int |
DEFAULT_LOW_NUM_MASTER_NODES |
|
static InternalTestCluster.RestartCallback |
EMPTY_CALLBACK |
|
static java.lang.String |
TRANSPORT_CLIENT_PREFIX |
random, transportClientRatio| Constructor | Description |
|---|---|
InternalTestCluster(long clusterSeed,
java.nio.file.Path baseDir,
boolean randomlyAddDedicatedMasters,
boolean autoManageMinMasterNodes,
int minNumDataNodes,
int maxNumDataNodes,
java.lang.String clusterName,
NodeConfigurationSource nodeConfigurationSource,
int numClientNodes,
boolean enableHttpPipelining,
java.lang.String nodePrefix,
java.util.Collection<java.lang.Class<? extends Plugin>> mockPlugins,
java.util.function.Function<Client,Client> clientWrapper) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
afterTest() |
This method should be executed during tear down, after each test (but after assertAfterTest)
|
void |
assertAfterTest() |
This method checks all the things that need to be checked after each test
|
void |
beforeIndexDeletion() |
Assertions that should run before the cluster is wiped should be called in this method
|
void |
beforeTest(java.util.Random random,
double transportClientRatio) |
This method should be executed before each test to reset the cluster to its initial state.
|
void |
clearDisruptionScheme() |
|
void |
clearDisruptionScheme(boolean ensureHealthyCluster) |
|
Client |
client() |
Returns a client connected to any node in the cluster
|
Client |
client(java.lang.String nodeName) |
Returns a node client to a given node.
|
Client |
client(java.util.function.Predicate<Settings> filterPredicate) |
Returns a random node that applies to the given predicate.
|
void |
close() |
Closes the current cluster
|
void |
closeNonSharedNodes(boolean wipeData) |
|
static java.lang.String |
clusterName(java.lang.String prefix,
long clusterSeed) |
|
ClusterService |
clusterService() |
Returns a reference to a random node's
ClusterService |
ClusterService |
clusterService(java.lang.String node) |
Returns a reference to a node's
ClusterService. |
Client |
coordOnlyNodeClient() |
Returns a client to a coordinating only node
|
Client |
dataNodeClient() |
Returns a node client to a data node in the cluster.
|
void |
ensureAtLeastNumDataNodes(int n) |
Ensures that at least
n data nodes are present in the cluster. |
void |
ensureAtMostNumDataNodes(int n) |
Ensures that at most
n are up and running. |
void |
ensureEstimatedStats() |
Ensures that any breaker statistics are reset to 0.
|
void |
fullRestart() |
Restarts all nodes in the cluster.
|
void |
fullRestart(InternalTestCluster.RestartCallback callback) |
Restarts all nodes in the cluster.
|
boolean |
getAutoManageMinMasterNode() |
returns true if the
ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING setting is auto managed by this cluster |
java.lang.Iterable<Client> |
getClients() |
Returns an
Iterable over all clients in this test cluster |
java.lang.String |
getClusterName() |
Returns the cluster name
|
<T> T |
getDataNodeInstance(java.lang.Class<T> clazz) |
|
<T> java.lang.Iterable<T> |
getDataNodeInstances(java.lang.Class<T> clazz) |
Returns an Iterable to all instances for the given class >T< across all data nodes in the cluster.
|
<T> java.lang.Iterable<T> |
getDataOrMasterNodeInstances(java.lang.Class<T> clazz) |
Returns an Iterable to all instances for the given class >T< across all data and master nodes
in the cluster.
|
Settings |
getDefaultSettings() |
|
<T> T |
getInstance(java.lang.Class<T> clazz) |
Returns a reference to a random nodes instances of the given class >T<
|
<T> T |
getInstance(java.lang.Class<T> clazz,
java.lang.String node) |
Returns a reference to the given nodes instances of the given class >T<
|
<T> java.lang.Iterable<T> |
getInstances(java.lang.Class<T> clazz) |
Returns an Iterable to all instances for the given class >T< across all nodes in the cluster.
|
java.lang.String |
getMasterName() |
Returns the name of the current master node in the cluster.
|
java.lang.String |
getMasterName(java.lang.String viaNode) |
Returns the name of the current master node in the cluster and executes the request via the node specified
in the viaNode parameter.
|
NamedWriteableRegistry |
getNamedWriteableRegistry() |
Returns this clusters
NamedWriteableRegistry this is needed to
deserialize binary content from this cluster that might include custom named writeables |
java.lang.String[] |
getNodeNames() |
|
java.util.Collection<java.lang.Class<? extends Plugin>> |
getPlugins() |
|
java.net.InetSocketAddress[] |
httpAddresses() |
Returns the http addresses of the nodes within the cluster.
|
Client |
masterClient() |
Returns a node client to the current master node.
|
static java.util.function.Predicate<Settings> |
nameFilter(java.lang.String... nodeName) |
Returns a predicate that only accepts settings of nodes with one of the given names.
|
java.lang.String |
nodePrefix() |
Returns the common node name prefix for this test cluster.
|
java.util.Set<java.lang.String> |
nodesInclude(java.lang.String index) |
Returns a set of nodes that have at least one shard of the given index.
|
Client |
nonMasterClient() |
Returns a node client to random node but not the master.
|
int |
numDataAndMasterNodes() |
Returns the number of data and master eligible nodes in the cluster.
|
int |
numDataNodes() |
Returns the number of data nodes in the cluster.
|
int |
numMasterNodes() |
|
void |
restartNode(java.lang.String nodeName,
InternalTestCluster.RestartCallback callback) |
Restarts a node and calls the callback during restart.
|
void |
restartRandomDataNode() |
Restarts a random data node in the cluster
|
void |
restartRandomDataNode(InternalTestCluster.RestartCallback callback) |
Restarts a random data node in the cluster and calls the callback during restart.
|
void |
restartRandomNode() |
Restarts a random node in the cluster
|
void |
restartRandomNode(InternalTestCluster.RestartCallback callback) |
Restarts a random node in the cluster and calls the callback during restart.
|
void |
rollingRestart() |
Restarts all nodes in a rolling restart fashion ie.
|
void |
rollingRestart(InternalTestCluster.RestartCallback callback) |
Restarts all nodes in a rolling restart fashion ie.
|
void |
setDisruptionScheme(ServiceDisruptionScheme scheme) |
|
int |
size() |
Returns the number of nodes in the cluster.
|
Client |
smartClient() |
Returns a "smart" node client to a random node in the cluster
|
java.lang.String |
startCoordinatingOnlyNode(Settings settings) |
|
java.lang.String |
startDataOnlyNode() |
|
java.lang.String |
startDataOnlyNode(Settings settings) |
|
java.util.List<java.lang.String> |
startDataOnlyNodes(int numNodes) |
|
java.util.List<java.lang.String> |
startDataOnlyNodes(int numNodes,
Settings settings) |
|
java.lang.String |
startMasterOnlyNode() |
|
java.lang.String |
startMasterOnlyNode(Settings settings) |
|
java.util.List<java.lang.String> |
startMasterOnlyNodes(int numNodes) |
|
java.util.List<java.lang.String> |
startMasterOnlyNodes(int numNodes,
Settings settings) |
|
java.lang.String |
startNode() |
Starts a node with default settings and returns it's name.
|
java.lang.String |
startNode(Settings settings) |
Starts a node with the given settings and returns it's name.
|
java.lang.String |
startNode(Settings.Builder settings) |
Starts a node with the given settings builder and returns it's name.
|
java.util.List<java.lang.String> |
startNodes(int numOfNodes) |
Starts multiple nodes with default settings and returns their names
|
java.util.List<java.lang.String> |
startNodes(int numOfNodes,
Settings settings) |
Starts multiple nodes with the given settings and returns their names
|
java.util.List<java.lang.String> |
startNodes(Settings... settings) |
Starts multiple nodes with the given settings and returns their names
|
void |
stopCurrentMasterNode() |
Stops the current master node forcefully
|
boolean |
stopRandomDataNode() |
Stops a random data node in the cluster.
|
void |
stopRandomNode(java.util.function.Predicate<Settings> filter) |
Stops a random node in the cluster that applies to the given filter or non if the non of the nodes applies to the
filter.
|
void |
stopRandomNonMasterNode() |
Stops any of the current nodes but not the master node.
|
Client |
transportClient() |
Returns a transport client
|
void |
validateClusterFormed() |
ensure a cluster is formed with all published nodes.
|
void |
validateClusterFormed(java.lang.String viaNode) |
ensure a cluster is formed with all published nodes, but do so by using the client of the specified node
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitseed, wipe, wipeAllTemplates, wipeIndices, wipeRepositories, wipeTemplatespublic static final int DEFAULT_LOW_NUM_MASTER_NODES
public static final int DEFAULT_HIGH_NUM_MASTER_NODES
public static final java.lang.String TRANSPORT_CLIENT_PREFIX
public static final InternalTestCluster.RestartCallback EMPTY_CALLBACK
public InternalTestCluster(long clusterSeed,
java.nio.file.Path baseDir,
boolean randomlyAddDedicatedMasters,
boolean autoManageMinMasterNodes,
int minNumDataNodes,
int maxNumDataNodes,
java.lang.String clusterName,
NodeConfigurationSource nodeConfigurationSource,
int numClientNodes,
boolean enableHttpPipelining,
java.lang.String nodePrefix,
java.util.Collection<java.lang.Class<? extends Plugin>> mockPlugins,
java.util.function.Function<Client,Client> clientWrapper)
public java.lang.String getClusterName()
TestClustergetClusterName in class TestClusterpublic boolean getAutoManageMinMasterNode()
ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING setting is auto managed by this clusterpublic java.lang.String[] getNodeNames()
public java.util.Collection<java.lang.Class<? extends Plugin>> getPlugins()
public static java.lang.String clusterName(java.lang.String prefix,
long clusterSeed)
public void ensureAtLeastNumDataNodes(int n)
n data nodes are present in the cluster.
if more nodes than n are present this method will not
stop any of the running nodes.public void ensureAtMostNumDataNodes(int n)
throws java.io.IOException
n are up and running.
If less nodes that n are running this method
will not start any additional nodes.java.io.IOExceptionpublic java.lang.String nodePrefix()
public Client client()
TestClusterclient in class TestClusterpublic Client dataNodeClient()
public Client masterClient()
public Client nonMasterClient()
public Client coordOnlyNodeClient()
public java.lang.String startCoordinatingOnlyNode(Settings settings)
public Client transportClient()
public Client client(java.lang.String nodeName)
public Client smartClient()
public Client client(java.util.function.Predicate<Settings> filterPredicate)
nullpublic void close()
TestClusterclose in interface java.lang.AutoCloseableclose in interface java.io.Closeableclose in class TestClusterpublic void beforeTest(java.util.Random random,
double transportClientRatio)
throws java.io.IOException,
java.lang.InterruptedException
TestClusterbeforeTest in class TestClusterjava.io.IOExceptionjava.lang.InterruptedExceptionpublic void validateClusterFormed()
public void validateClusterFormed(java.lang.String viaNode)
public void afterTest()
throws java.io.IOException
TestClusterafterTest in class TestClusterjava.io.IOExceptionpublic void beforeIndexDeletion()
throws java.lang.Exception
TestClusterbeforeIndexDeletion in class TestClusterjava.lang.Exceptionpublic ClusterService clusterService()
ClusterServicepublic ClusterService clusterService(@Nullable java.lang.String node)
ClusterService. If the given node is null, a random node will be selected.public <T> java.lang.Iterable<T> getInstances(java.lang.Class<T> clazz)
public <T> java.lang.Iterable<T> getDataNodeInstances(java.lang.Class<T> clazz)
public <T> java.lang.Iterable<T> getDataOrMasterNodeInstances(java.lang.Class<T> clazz)
public <T> T getInstance(java.lang.Class<T> clazz,
java.lang.String node)
public <T> T getDataNodeInstance(java.lang.Class<T> clazz)
public <T> T getInstance(java.lang.Class<T> clazz)
public int size()
TestClustersize in class TestClusterpublic java.net.InetSocketAddress[] httpAddresses()
TestClusterhttpAddresses in class TestClusterpublic boolean stopRandomDataNode()
throws java.io.IOException
java.io.IOExceptionpublic void stopRandomNode(java.util.function.Predicate<Settings> filter) throws java.io.IOException
java.io.IOExceptionpublic void stopCurrentMasterNode()
throws java.io.IOException
java.io.IOExceptionpublic void stopRandomNonMasterNode()
throws java.io.IOException
java.io.IOExceptionpublic void restartRandomNode()
throws java.lang.Exception
java.lang.Exceptionpublic void restartRandomNode(InternalTestCluster.RestartCallback callback) throws java.lang.Exception
java.lang.Exceptionpublic void restartRandomDataNode()
throws java.lang.Exception
java.lang.Exceptionpublic void restartRandomDataNode(InternalTestCluster.RestartCallback callback) throws java.lang.Exception
java.lang.Exceptionpublic void restartNode(java.lang.String nodeName,
InternalTestCluster.RestartCallback callback)
throws java.lang.Exception
java.lang.Exceptionpublic void fullRestart()
throws java.lang.Exception
java.lang.Exceptionpublic void rollingRestart()
throws java.lang.Exception
java.lang.Exceptionpublic void rollingRestart(InternalTestCluster.RestartCallback callback) throws java.lang.Exception
java.lang.Exceptionpublic void fullRestart(InternalTestCluster.RestartCallback callback) throws java.lang.Exception
java.lang.Exceptionpublic java.lang.String getMasterName()
public java.lang.String getMasterName(@Nullable java.lang.String viaNode)
public java.util.Set<java.lang.String> nodesInclude(java.lang.String index)
public java.lang.String startNode()
public java.lang.String startNode(Settings.Builder settings)
public java.lang.String startNode(Settings settings)
public java.util.List<java.lang.String> startNodes(int numOfNodes)
public java.util.List<java.lang.String> startNodes(int numOfNodes,
Settings settings)
public java.util.List<java.lang.String> startNodes(Settings... settings)
public java.util.List<java.lang.String> startMasterOnlyNodes(int numNodes)
public java.util.List<java.lang.String> startMasterOnlyNodes(int numNodes,
Settings settings)
public java.util.List<java.lang.String> startDataOnlyNodes(int numNodes)
public java.util.List<java.lang.String> startDataOnlyNodes(int numNodes,
Settings settings)
public java.lang.String startMasterOnlyNode()
public java.lang.String startMasterOnlyNode(Settings settings)
public java.lang.String startDataOnlyNode()
public java.lang.String startDataOnlyNode(Settings settings)
public void closeNonSharedNodes(boolean wipeData)
throws java.io.IOException
java.io.IOExceptionpublic int numDataNodes()
TestClusternumDataNodes in class TestClusterpublic int numDataAndMasterNodes()
TestClusternumDataAndMasterNodes in class TestClusterpublic int numMasterNodes()
public void setDisruptionScheme(ServiceDisruptionScheme scheme)
public void clearDisruptionScheme()
public void clearDisruptionScheme(boolean ensureHealthyCluster)
public java.lang.Iterable<Client> getClients()
TestClusterIterable over all clients in this test clustergetClients in class TestClusterpublic NamedWriteableRegistry getNamedWriteableRegistry()
TestClusterNamedWriteableRegistry this is needed to
deserialize binary content from this cluster that might include custom named writeablesgetNamedWriteableRegistry in class TestClusterpublic static java.util.function.Predicate<Settings> nameFilter(java.lang.String... nodeName)
public Settings getDefaultSettings()
public void ensureEstimatedStats()
TestClusterensureEstimatedStats in class TestClusterpublic void assertAfterTest()
throws java.io.IOException
TestClusterassertAfterTest in class TestClusterjava.io.IOException