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 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 int |
DEFAULT_HIGH_NUM_MASTER_NODES |
static int |
DEFAULT_LOW_NUM_MASTER_NODES |
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(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 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() |
void |
clearDisruptionScheme(boolean ensureHealthyCluster) |
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 . |
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 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<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[] |
getNodeNames() |
java.util.Collection<java.lang.Class<? extends org.elasticsearch.plugins.Plugin>> |
getPlugins() |
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.
|
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.
|
org.elasticsearch.client.Client |
smartClient()
Returns a "smart" node client to a random node in the cluster
|
java.lang.String |
startCoordinatingOnlyNode(org.elasticsearch.common.settings.Settings settings) |
java.lang.String |
startDataOnlyNode() |
java.lang.String |
startDataOnlyNode(org.elasticsearch.common.settings.Settings settings) |
java.util.List<java.lang.String> |
startDataOnlyNodes(int numNodes) |
java.util.List<java.lang.String> |
startDataOnlyNodes(int numNodes,
org.elasticsearch.common.settings.Settings settings) |
java.lang.String |
startMasterOnlyNode() |
java.lang.String |
startMasterOnlyNode(org.elasticsearch.common.settings.Settings settings) |
java.util.List<java.lang.String> |
startMasterOnlyNodes(int numNodes) |
java.util.List<java.lang.String> |
startMasterOnlyNodes(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.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,
org.elasticsearch.common.settings.Settings settings)
Starts multiple nodes with the given settings and returns their names
|
java.util.List<java.lang.String> |
startNodes(org.elasticsearch.common.settings.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<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
|
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
|
seed, wipe, wipeAllTemplates, wipeIndices, wipeRepositories, wipeTemplates
public 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 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 org.elasticsearch.plugins.Plugin>> mockPlugins, java.util.function.Function<org.elasticsearch.client.Client,org.elasticsearch.client.Client> clientWrapper)
public java.lang.String getClusterName()
TestCluster
getClusterName
in class TestCluster
public 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 org.elasticsearch.plugins.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.IOException
public java.lang.String nodePrefix()
public org.elasticsearch.client.Client client()
TestCluster
client
in class TestCluster
public org.elasticsearch.client.Client dataNodeClient()
public org.elasticsearch.client.Client masterClient()
public org.elasticsearch.client.Client nonMasterClient()
public org.elasticsearch.client.Client coordOnlyNodeClient()
public java.lang.String 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)
null
public void close()
TestCluster
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class TestCluster
public void beforeTest(java.util.Random random, double transportClientRatio) throws java.io.IOException, java.lang.InterruptedException
TestCluster
beforeTest
in class TestCluster
java.io.IOException
java.lang.InterruptedException
public void validateClusterFormed()
public void validateClusterFormed(java.lang.String viaNode)
public void afterTest() throws java.io.IOException
TestCluster
afterTest
in class TestCluster
java.io.IOException
public void beforeIndexDeletion() throws java.lang.Exception
TestCluster
beforeIndexDeletion
in class TestCluster
java.lang.Exception
public org.elasticsearch.cluster.service.ClusterService clusterService()
ClusterService
public 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()
TestCluster
size
in class TestCluster
public java.net.InetSocketAddress[] httpAddresses()
TestCluster
httpAddresses
in class TestCluster
public boolean stopRandomDataNode() throws java.io.IOException
java.io.IOException
public void stopRandomNode(java.util.function.Predicate<org.elasticsearch.common.settings.Settings> filter) throws java.io.IOException
java.io.IOException
public void stopCurrentMasterNode() throws java.io.IOException
java.io.IOException
public void stopRandomNonMasterNode() throws java.io.IOException
java.io.IOException
public void restartRandomNode() throws java.lang.Exception
java.lang.Exception
public void restartRandomNode(InternalTestCluster.RestartCallback callback) throws java.lang.Exception
java.lang.Exception
public void restartRandomDataNode() throws java.lang.Exception
java.lang.Exception
public void restartRandomDataNode(InternalTestCluster.RestartCallback callback) throws java.lang.Exception
java.lang.Exception
public void restartNode(java.lang.String nodeName, InternalTestCluster.RestartCallback callback) throws java.lang.Exception
java.lang.Exception
public void fullRestart() throws java.lang.Exception
java.lang.Exception
public void rollingRestart() throws java.lang.Exception
java.lang.Exception
public void rollingRestart(InternalTestCluster.RestartCallback callback) throws java.lang.Exception
java.lang.Exception
public void fullRestart(InternalTestCluster.RestartCallback callback) throws java.lang.Exception
java.lang.Exception
public 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.common.settings.Settings.Builder settings)
public java.lang.String startNode(org.elasticsearch.common.settings.Settings settings)
public java.util.List<java.lang.String> startNodes(int numOfNodes)
public java.util.List<java.lang.String> startNodes(int numOfNodes, org.elasticsearch.common.settings.Settings settings)
public java.util.List<java.lang.String> startNodes(org.elasticsearch.common.settings.Settings... settings)
public java.util.List<java.lang.String> startMasterOnlyNodes(int numNodes)
public java.util.List<java.lang.String> startMasterOnlyNodes(int numNodes, org.elasticsearch.common.settings.Settings settings)
public java.util.List<java.lang.String> startDataOnlyNodes(int numNodes)
public java.util.List<java.lang.String> startDataOnlyNodes(int numNodes, org.elasticsearch.common.settings.Settings settings)
public java.lang.String startMasterOnlyNode()
public java.lang.String startMasterOnlyNode(org.elasticsearch.common.settings.Settings settings)
public java.lang.String startDataOnlyNode()
public java.lang.String startDataOnlyNode(org.elasticsearch.common.settings.Settings settings)
public void closeNonSharedNodes(boolean wipeData) throws java.io.IOException
java.io.IOException
public int numDataNodes()
TestCluster
numDataNodes
in class TestCluster
public int numDataAndMasterNodes()
TestCluster
numDataAndMasterNodes
in class TestCluster
public int numMasterNodes()
public void setDisruptionScheme(ServiceDisruptionScheme scheme)
public void clearDisruptionScheme()
public void clearDisruptionScheme(boolean ensureHealthyCluster)
public java.lang.Iterable<org.elasticsearch.client.Client> getClients()
TestCluster
Iterable
over all clients in this test clustergetClients
in class TestCluster
public 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()
TestCluster
ensureEstimatedStats
in class TestCluster
public void assertAfterTest() throws java.io.IOException
TestCluster
assertAfterTest
in class TestCluster
java.io.IOException