public 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 and Description |
|---|---|
static interface |
InternalTestCluster.Async<T>
Simple interface that allows to wait for an async operation to finish
|
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 and Description |
|---|---|
static InternalTestCluster.RestartCallback |
EMPTY_CALLBACK |
int |
HTTP_BASE_PORT |
static int |
JVM_BASE_PORT_OFFSET
a per-JVM unique offset to be used for calculating unique port ranges.
|
static int |
PORTS_PER_CLUSTER
The number of ports in the range used for this cluster
|
static int |
PORTS_PER_JVM
The number of ports in the range used for this JVM
|
int |
TRANSPORT_BASE_PORT |
static java.lang.String |
TRANSPORT_CLIENT_PREFIX |
random, transportClientRatio| Constructor and Description |
|---|
InternalTestCluster(java.lang.String nodeMode,
long clusterSeed,
java.nio.file.Path baseDir,
boolean randomlyAddDedicatedMasters,
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 org.elasticsearch.plugins.Plugin>> mockPlugins,
java.util.function.Function<org.elasticsearch.client.Client,org.elasticsearch.client.Client> clientWrapper) |
| Modifier and Type | Method and 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() |
org.elasticsearch.client.Client |
client()
Returns a client connected to any node in the cluster
|
org.elasticsearch.client.Client |
client(java.util.function.Predicate<org.elasticsearch.common.settings.Settings> filterPredicate)
Returns a random node that applies to the given predicate.
|
org.elasticsearch.client.Client |
client(java.lang.String nodeName)
Returns a node client to a given node.
|
void |
close()
Closes the current cluster
|
void |
closeNonSharedNodes(boolean wipeData) |
static java.lang.String |
clusterName(java.lang.String prefix,
long clusterSeed) |
org.elasticsearch.cluster.service.ClusterService |
clusterService()
Returns a reference to a random node's
ClusterService |
org.elasticsearch.cluster.service.ClusterService |
clusterService(java.lang.String node)
Returns a reference to a node's
ClusterService. |
static java.lang.String |
configuredNodeMode() |
org.elasticsearch.client.Client |
coordOnlyNodeClient()
Returns a client to a coordinating only node
|
org.elasticsearch.client.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 function)
Restarts all nodes in the cluster.
|
java.lang.Iterable<org.elasticsearch.client.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.
|
org.elasticsearch.common.settings.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.
|
java.lang.String |
getNodeMode() |
java.lang.String[] |
getNodeNames() |
java.net.InetSocketAddress[] |
httpAddresses()
Returns the http addresses of the nodes within the cluster.
|
org.elasticsearch.client.Client |
masterClient()
Returns a node client to the current master node.
|
static java.util.function.Predicate<org.elasticsearch.common.settings.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.
|
org.elasticsearch.client.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.
|
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 function)
Restarts all nodes in a rolling restart fashion ie.
|
void |
setDisruptionScheme(ServiceDisruptionScheme scheme) |
int |
size()
Returns the number of nodes in the cluster.
|
org.elasticsearch.client.Client |
smartClient()
Returns a "smart" node client to a random node in the cluster
|
org.elasticsearch.client.Client |
startCoordinatingOnlyNode(org.elasticsearch.common.settings.Settings settings) |
java.lang.String |
startDataOnlyNode(org.elasticsearch.common.settings.Settings settings) |
InternalTestCluster.Async<java.lang.String> |
startDataOnlyNodeAsync() |
InternalTestCluster.Async<java.lang.String> |
startDataOnlyNodeAsync(org.elasticsearch.common.settings.Settings settings) |
InternalTestCluster.Async<java.util.List<java.lang.String>> |
startDataOnlyNodesAsync(int numNodes) |
InternalTestCluster.Async<java.util.List<java.lang.String>> |
startDataOnlyNodesAsync(int numNodes,
org.elasticsearch.common.settings.Settings settings) |
java.lang.String |
startMasterOnlyNode(org.elasticsearch.common.settings.Settings settings) |
InternalTestCluster.Async<java.lang.String> |
startMasterOnlyNodeAsync() |
InternalTestCluster.Async<java.lang.String> |
startMasterOnlyNodeAsync(org.elasticsearch.common.settings.Settings settings) |
InternalTestCluster.Async<java.util.List<java.lang.String>> |
startMasterOnlyNodesAsync(int numNodes) |
InternalTestCluster.Async<java.util.List<java.lang.String>> |
startMasterOnlyNodesAsync(int numNodes,
org.elasticsearch.common.settings.Settings settings) |
java.lang.String |
startNode()
Starts a node with default settings and returns it's name.
|
java.lang.String |
startNode(org.elasticsearch.common.settings.Settings.Builder settings)
Starts a node with the given settings builder and returns it's name.
|
java.lang.String |
startNode(org.elasticsearch.common.settings.Settings settings)
Starts a node with the given settings and returns it's name.
|
java.lang.String |
startNode(org.elasticsearch.common.settings.Settings settings,
org.elasticsearch.Version version)
Starts a node with the given settings and version and returns it's name.
|
java.lang.String |
startNode(org.elasticsearch.Version version)
Starts a node with default settings ad the specified version and returns it's name.
|
InternalTestCluster.Async<java.lang.String> |
startNodeAsync()
Starts a node in an async manner with the given settings and returns future with its name.
|
InternalTestCluster.Async<java.lang.String> |
startNodeAsync(org.elasticsearch.common.settings.Settings settings)
Starts a node in an async manner with the given settings and returns future with its name.
|
InternalTestCluster.Async<java.lang.String> |
startNodeAsync(org.elasticsearch.common.settings.Settings settings,
org.elasticsearch.Version version)
Starts a node in an async manner with the given settings and version and returns future with its name.
|
InternalTestCluster.Async<java.util.List<java.lang.String>> |
startNodesAsync(int numNodes)
Starts multiple nodes in an async manner and returns future with its name.
|
InternalTestCluster.Async<java.util.List<java.lang.String>> |
startNodesAsync(int numNodes,
org.elasticsearch.common.settings.Settings settings)
Starts multiple nodes in an async manner with the given settings and returns future with its name.
|
InternalTestCluster.Async<java.util.List<java.lang.String>> |
startNodesAsync(int numNodes,
org.elasticsearch.common.settings.Settings settings,
org.elasticsearch.Version version)
Starts multiple nodes in an async manner with the given settings and version and returns future with its name.
|
InternalTestCluster.Async<java.util.List<java.lang.String>> |
startNodesAsync(org.elasticsearch.common.settings.Settings... settings)
Starts multiple nodes (based on the number of settings provided) in an async manner, with explicit settings for each node.
|
void |
stopCurrentMasterNode()
Stops the current master node forcefully
|
boolean |
stopRandomDataNode()
Stops a random data node in the cluster.
|
void |
stopRandomNode(java.util.function.Predicate<org.elasticsearch.common.settings.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.
|
org.elasticsearch.client.Client |
transportClient()
Returns a transport client
|
seed, wipe, wipeAllTemplates, wipeIndices, wipeRepositories, wipeTemplatespublic static final int PORTS_PER_JVM
public static final int PORTS_PER_CLUSTER
public static final int JVM_BASE_PORT_OFFSET
public final int TRANSPORT_BASE_PORT
public final int HTTP_BASE_PORT
public static final java.lang.String TRANSPORT_CLIENT_PREFIX
public static final InternalTestCluster.RestartCallback EMPTY_CALLBACK
public InternalTestCluster(java.lang.String nodeMode,
long clusterSeed,
java.nio.file.Path baseDir,
boolean randomlyAddDedicatedMasters,
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 org.elasticsearch.plugins.Plugin>> mockPlugins,
java.util.function.Function<org.elasticsearch.client.Client,org.elasticsearch.client.Client> clientWrapper)
public static java.lang.String configuredNodeMode()
public java.lang.String getClusterName()
TestClustergetClusterName in class TestClusterpublic java.lang.String[] getNodeNames()
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 org.elasticsearch.client.Client client()
TestClusterclient in class TestClusterpublic org.elasticsearch.client.Client dataNodeClient()
public org.elasticsearch.client.Client masterClient()
public org.elasticsearch.client.Client nonMasterClient()
public org.elasticsearch.client.Client coordOnlyNodeClient()
public org.elasticsearch.client.Client startCoordinatingOnlyNode(org.elasticsearch.common.settings.Settings settings)
public org.elasticsearch.client.Client transportClient()
public org.elasticsearch.client.Client client(java.lang.String nodeName)
public org.elasticsearch.client.Client smartClient()
public org.elasticsearch.client.Client client(java.util.function.Predicate<org.elasticsearch.common.settings.Settings> filterPredicate)
nullpublic void close()
TestClusterclose in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class TestClusterpublic java.lang.String getNodeMode()
public void beforeTest(java.util.Random random,
double transportClientRatio)
throws java.io.IOException,
java.lang.InterruptedException
TestClusterbeforeTest in class TestClusterjava.io.IOExceptionjava.lang.InterruptedExceptionpublic void afterTest()
throws java.io.IOException
TestClusterafterTest in class TestClusterjava.io.IOExceptionpublic void beforeIndexDeletion()
TestClusterbeforeIndexDeletion in class TestClusterpublic org.elasticsearch.cluster.service.ClusterService clusterService()
ClusterServicepublic org.elasticsearch.cluster.service.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<org.elasticsearch.common.settings.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 function) throws java.lang.Exception
java.lang.Exceptionpublic void fullRestart(InternalTestCluster.RestartCallback function) 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(org.elasticsearch.Version version)
public java.lang.String startNode(org.elasticsearch.common.settings.Settings.Builder settings)
public java.lang.String startNode(org.elasticsearch.common.settings.Settings settings)
public java.lang.String startNode(org.elasticsearch.common.settings.Settings settings,
org.elasticsearch.Version version)
public InternalTestCluster.Async<java.util.List<java.lang.String>> startMasterOnlyNodesAsync(int numNodes)
public InternalTestCluster.Async<java.util.List<java.lang.String>> startMasterOnlyNodesAsync(int numNodes, org.elasticsearch.common.settings.Settings settings)
public InternalTestCluster.Async<java.util.List<java.lang.String>> startDataOnlyNodesAsync(int numNodes)
public InternalTestCluster.Async<java.util.List<java.lang.String>> startDataOnlyNodesAsync(int numNodes, org.elasticsearch.common.settings.Settings settings)
public InternalTestCluster.Async<java.lang.String> startMasterOnlyNodeAsync()
public InternalTestCluster.Async<java.lang.String> startMasterOnlyNodeAsync(org.elasticsearch.common.settings.Settings settings)
public java.lang.String startMasterOnlyNode(org.elasticsearch.common.settings.Settings settings)
public InternalTestCluster.Async<java.lang.String> startDataOnlyNodeAsync()
public InternalTestCluster.Async<java.lang.String> startDataOnlyNodeAsync(org.elasticsearch.common.settings.Settings settings)
public java.lang.String startDataOnlyNode(org.elasticsearch.common.settings.Settings settings)
public InternalTestCluster.Async<java.lang.String> startNodeAsync()
public InternalTestCluster.Async<java.lang.String> startNodeAsync(org.elasticsearch.common.settings.Settings settings)
public InternalTestCluster.Async<java.lang.String> startNodeAsync(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.Version version)
public InternalTestCluster.Async<java.util.List<java.lang.String>> startNodesAsync(int numNodes)
public InternalTestCluster.Async<java.util.List<java.lang.String>> startNodesAsync(int numNodes, org.elasticsearch.common.settings.Settings settings)
public InternalTestCluster.Async<java.util.List<java.lang.String>> startNodesAsync(int numNodes, org.elasticsearch.common.settings.Settings settings, org.elasticsearch.Version version)
public InternalTestCluster.Async<java.util.List<java.lang.String>> startNodesAsync(org.elasticsearch.common.settings.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 void setDisruptionScheme(ServiceDisruptionScheme scheme)
public void clearDisruptionScheme()
public java.lang.Iterable<org.elasticsearch.client.Client> getClients()
TestClusterIterable over all clients in this test clustergetClients in class TestClusterpublic static java.util.function.Predicate<org.elasticsearch.common.settings.Settings> nameFilter(java.lang.String... nodeName)
public org.elasticsearch.common.settings.Settings getDefaultSettings()
public void ensureEstimatedStats()
TestClusterensureEstimatedStats in class TestClusterpublic void assertAfterTest()
throws java.io.IOException
TestClusterassertAfterTest in class TestClusterjava.io.IOException