Package org.elasticsearch.test
Class InternalTestCluster
java.lang.Object
org.elasticsearch.test.TestCluster
org.elasticsearch.test.InternalTestCluster
InternalTestCluster manages a set of JVM private nodes and allows convenient access to them.
The cluster supports randomized configuration such that nodes started in the cluster will
automatically load asserting services tracking resources like file handles or open searchers.
The Cluster is bound to a test lifecycle where tests must call beforeTest(java.util.Random) 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceTemporarily adds node paths based entitlements based on a node'ssettingsandconfigPathuntil the returned handle is closed.static classAn abstract class that is called duringrollingRestart(InternalTestCluster.RestartCallback)and / orfullRestart(InternalTestCluster.RestartCallback)to execute actions at certain stages of the restart. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault value of bootstrapMasterNodeIndex, indicating that bootstrapping should happen automatically.static final intSentinel value of bootstrapMasterNodeIndex, indicating that bootstrapMasterNodeIndex was set explicitly and has been used.static final intstatic final intstatic final InternalTestCluster.RestartCallbackFields inherited from class org.elasticsearch.test.TestCluster
random -
Constructor Summary
ConstructorsConstructorDescriptionInternalTestCluster(long clusterSeed, Path baseDir, boolean randomlyAddDedicatedMasters, boolean autoManageMasterNodes, int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes, String nodePrefix, Collection<Class<? extends Plugin>> mockPlugins, Function<Client, Client> clientWrapper, boolean forbidPrivateIndexSettings, boolean forceSingleDataPath, boolean autoManageVotingExclusions, InternalTestCluster.EntitledNodePathsProvider entitledNodePathsProvider) InternalTestCluster(long clusterSeed, Path baseDir, boolean randomlyAddDedicatedMasters, boolean autoManageMasterNodes, int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes, String nodePrefix, Collection<Class<? extends Plugin>> mockPlugins, Function<Client, Client> clientWrapper, InternalTestCluster.EntitledNodePathsProvider entitledNodePathsProvider) -
Method Summary
Modifier and TypeMethodDescriptionvoidThis method should be executed during tear down, after each test (but after assertAfterTest)voidThis method checks all the things that need to be checked after each testvoidAsserts that the document history in Lucene index is consistent with Translog's on every index shard of the cluster.voidvoidvoidvoidAsserts that all shards with the same shardId should have document Ids.voidvoidvoidAssertions that should run before the cluster is wiped should be called in this methodvoidbeforeTest(Random random) This method should be executed before each test to reset the cluster to its initial state.voidvoidclearDisruptionScheme(boolean ensureHealthyCluster) client()Returns a client connected to any node in the clusterReturns a node client to a given node.voidclose()Closes the current clustervoidcloseNonSharedNodes(boolean wipeData) static StringclusterName(String prefix, long clusterSeed) Returns a reference to a random node'sClusterServiceclusterService(String node) Returns a reference to a node'sClusterService.Returns a client to a coordinating only nodeReturns a node client to a data node in the cluster.dataPathSettings(String node) voidensureAtLeastNumDataNodes(int n) Ensures that at leastndata nodes are present in the cluster.voidensureAtMostNumDataNodes(int n) Ensures that at mostnare up and running.voidEnsures that any breaker statistics are reset to 0.voidRestarts all nodes in the cluster.voidRestarts all nodes in the cluster.<T> TgetAnyMasterNodeInstance(Class<T> clazz) Return the instance of the given class >T< from any of the master-eligible nodes (not necessarily the elected master).Returns anIterableover all clients in this test clusterReturns the cluster name<T> TgetCurrentMasterNodeInstance(Class<T> clazz) Return the instance of the given class >T< from the elected master node.<T> TgetDataNodeInstance(Class<T> clazz) <T> Iterable<T> getDataNodeInstances(Class<T> clazz) Returns an Iterable to all instances for the given class >T< across all data nodes in the cluster.<T> Iterable<T> getDataOrMasterNodeInstances(Class<T> clazz) Returns an Iterable to all instances for the given class >T< across all data and master nodes in the cluster.<T> TgetInstance(Class<T> clazz) Returns a reference to a random nodes instances of the given class >T<<T> TgetInstance(Class<T> clazz, String nodeName) <T> TgetInstance(Class<T> clazz, DiscoveryNodeRole role) <T> Iterable<T> getInstances(Class<T> clazz) Returns an Iterable to all instances for the given class >T< across all nodes in the cluster.Returns the name of the current master node in the cluster.getMasterName(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.Returns this clustersNamedWriteableRegistrythis is needed to deserialize binary content from this cluster that might include custom named writeablesString[]getNodeNameThat(Predicate<Settings> predicate) Collection<Class<? extends Plugin>> Returns the http addresses of the nodes within the cluster.Returns a node client to the current master node.nodesInclude(String index) Returns a set of nodes that have at least one shard of the given index.Returns a node client to random node but not the master.intReturns the number of data and master eligible nodes in the cluster.intReturns the number of data nodes in the cluster.intvoidrestartNode(String nodeName) Restarts a node.voidrestartNode(String nodeName, InternalTestCluster.RestartCallback callback) Restarts a node and calls the callback during restart.voidRestarts a random data node in the clustervoidRestarts a random data node in the cluster and calls the callback during restart.voidRestarts all nodes in a rolling restart fashion ie.voidsetBootstrapMasterNodeIndex(int bootstrapMasterNodeIndex) SetsbootstrapMasterNodeIndexto the given value, seebootstrapMasterNodeWithSpecifiedIndex(List)for the description of how this field is used.voidintsize()Returns the number of nodes in the cluster.Returns a "smart" node client to a random node in the clusterstartCoordinatingOnlyNode(Settings settings) startDataOnlyNode(Settings settings) startDataOnlyNodes(int numNodes) startDataOnlyNodes(int numNodes, Settings settings) startMasterOnlyNode(Settings settings) startMasterOnlyNodes(int numNodes) startMasterOnlyNodes(int numNodes, Settings settings) Starts a node with default settings and returns its name.Starts a node with the given settings and returns its name.startNode(Settings.Builder settings) Starts a node with the given settings builder and returns its name.startNodes(int numOfNodes) Starts multiple nodes with default settings and returns their namesstartNodes(int numOfNodes, Settings settings) Starts multiple nodes with the given settings and returns their namesstartNodes(Settings... extraSettings) Starts multiple nodes with the given settings and returns their namesvoidStops the current master node forcefullybooleanStops a specific node in the cluster.booleanStops a random data node in the cluster.voidStops any of the current nodes but not the master node.voidensure a cluster is formed with all published nodes.voidMethods inherited from class org.elasticsearch.test.TestCluster
seed, wipe, wipeIndices, wipeTemplates
-
Field Details
-
DEFAULT_LOW_NUM_MASTER_NODES
public static final int DEFAULT_LOW_NUM_MASTER_NODES- See Also:
-
DEFAULT_HIGH_NUM_MASTER_NODES
public static final int DEFAULT_HIGH_NUM_MASTER_NODES- See Also:
-
BOOTSTRAP_MASTER_NODE_INDEX_AUTO
public static final int BOOTSTRAP_MASTER_NODE_INDEX_AUTODefault value of bootstrapMasterNodeIndex, indicating that bootstrapping should happen automatically.- See Also:
-
BOOTSTRAP_MASTER_NODE_INDEX_DONE
public static final int BOOTSTRAP_MASTER_NODE_INDEX_DONESentinel value of bootstrapMasterNodeIndex, indicating that bootstrapMasterNodeIndex was set explicitly and has been used.- See Also:
-
EMPTY_CALLBACK
-
-
Constructor Details
-
InternalTestCluster
public InternalTestCluster(long clusterSeed, Path baseDir, boolean randomlyAddDedicatedMasters, boolean autoManageMasterNodes, int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes, String nodePrefix, Collection<Class<? extends Plugin>> mockPlugins, Function<Client, Client> clientWrapper, InternalTestCluster.EntitledNodePathsProvider entitledNodePathsProvider) -
InternalTestCluster
public InternalTestCluster(long clusterSeed, Path baseDir, boolean randomlyAddDedicatedMasters, boolean autoManageMasterNodes, int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes, String nodePrefix, Collection<Class<? extends Plugin>> mockPlugins, Function<Client, Client> clientWrapper, boolean forbidPrivateIndexSettings, boolean forceSingleDataPath, boolean autoManageVotingExclusions, InternalTestCluster.EntitledNodePathsProvider entitledNodePathsProvider)
-
-
Method Details
-
setBootstrapMasterNodeIndex
public void setBootstrapMasterNodeIndex(int bootstrapMasterNodeIndex) SetsbootstrapMasterNodeIndexto the given value, seebootstrapMasterNodeWithSpecifiedIndex(List)for the description of how this field is used. It's only possible to changebootstrapMasterNodeIndexvalue if autoManageMasterNodes is false. -
getClusterName
Description copied from class:TestClusterReturns the cluster name- Specified by:
getClusterNamein classTestCluster
-
getNodeNames
-
getPlugins
-
clusterName
-
ensureAtLeastNumDataNodes
public void ensureAtLeastNumDataNodes(int n) Ensures that at leastndata nodes are present in the cluster. if more nodes thannare present this method will not stop any of the running nodes. -
ensureAtMostNumDataNodes
Ensures that at mostnare up and running. If less nodes thatnare running this method will not start any additional nodes.- Throws:
IOException
-
client
Description copied from class:TestClusterReturns a client connected to any node in the cluster- Specified by:
clientin classTestCluster
-
dataNodeClient
Returns a node client to a data node in the cluster. Note: use this with care tests should not rely on a certain nodes client. -
masterClient
Returns a node client to the current master node. Note: use this with care tests should not rely on a certain nodes client. -
nonMasterClient
Returns a node client to random node but not the master. This method will fail if no non-master client is available. -
coordOnlyNodeClient
Returns a client to a coordinating only node -
startCoordinatingOnlyNode
-
client
Returns a node client to a given node. -
smartClient
Returns a "smart" node client to a random node in the cluster -
close
Description copied from class:TestClusterCloses the current cluster- Specified by:
closein classTestCluster- Throws:
IOException
-
beforeTest
Description copied from class:TestClusterThis method should be executed before each test to reset the cluster to its initial state.- Overrides:
beforeTestin classTestCluster- Throws:
IOExceptionInterruptedException
-
validateClusterFormed
public void validateClusterFormed()ensure a cluster is formed with all published nodes. -
afterTest
public void afterTest()Description copied from class:TestClusterThis method should be executed during tear down, after each test (but after assertAfterTest)- Specified by:
afterTestin classTestCluster
-
beforeIndexDeletion
Description copied from class:TestClusterAssertions that should run before the cluster is wiped should be called in this method- Overrides:
beforeIndexDeletionin classTestCluster- Throws:
Exception
-
assertConsistentHistoryBetweenTranslogAndLuceneIndex
Asserts that the document history in Lucene index is consistent with Translog's on every index shard of the cluster. This assertion might be expensive, thus we prefer not to execute on every test but only interesting tests.- Throws:
IOException
-
assertMergeExecutorIsDone
- Throws:
Exception
-
assertNoInFlightDocsInEngine
- Throws:
Exception
-
assertSeqNos
- Throws:
Exception
-
assertSameDocIdsOnShards
Asserts that all shards with the same shardId should have document Ids.- Throws:
Exception
-
wipePendingDataDirectories
public void wipePendingDataDirectories() -
clusterService
Returns a reference to a random node'sClusterService -
clusterService
Returns a reference to a node'sClusterService. If the given node is null, a random node will be selected. -
getInstances
Returns an Iterable to all instances for the given class >T< across all nodes in the cluster. -
getDataNodeInstances
Returns an Iterable to all instances for the given class >T< across all data nodes in the cluster. -
getCurrentMasterNodeInstance
Return the instance of the given class >T< from the elected master node. See alsogetAnyMasterNodeInstance(java.lang.Class<T>). -
getDataOrMasterNodeInstances
Returns an Iterable to all instances for the given class >T< across all data and master nodes in the cluster. -
getInstance
- Returns:
- the instance of the given class from the node with provided
nodeName
-
getInstance
- Returns:
- the instance of the given class from a random node with provided
role
-
getDataNodeInstance
-
getAnyMasterNodeInstance
Return the instance of the given class >T< from any of the master-eligible nodes (not necessarily the elected master). See alsogetCurrentMasterNodeInstance(java.lang.Class<T>). -
getInstance
Returns a reference to a random nodes instances of the given class >T< -
dataPathSettings
-
size
public int size()Description copied from class:TestClusterReturns the number of nodes in the cluster.- Specified by:
sizein classTestCluster
-
httpAddresses
Description copied from class:TestClusterReturns the http addresses of the nodes within the cluster. Can be used to run REST tests against the test cluster.- Specified by:
httpAddressesin classTestCluster
-
stopRandomDataNode
Stops a random data node in the cluster. Returns true if a node was found to stop, false otherwise.- Throws:
IOException
-
stopNode
Stops a specific node in the cluster. Returns true if the node was found to stop, false otherwise.- Throws:
IOException
-
stopCurrentMasterNode
Stops the current master node forcefully- Throws:
IOException
-
stopRandomNonMasterNode
Stops any of the current nodes but not the master node.- Throws:
IOException
-
configPaths
-
restartRandomDataNode
Restarts a random data node in the cluster- Throws:
Exception
-
restartRandomDataNode
Restarts a random data node in the cluster and calls the callback during restart.- Throws:
Exception
-
restartNode
Restarts a node.- Throws:
Exception
-
restartNode
public void restartNode(String nodeName, InternalTestCluster.RestartCallback callback) throws Exception Restarts a node and calls the callback during restart.- Throws:
Exception
-
fullRestart
Restarts all nodes in the cluster. It first stops all nodes and then restarts all the nodes again.- Throws:
Exception
-
rollingRestart
Restarts all nodes in a rolling restart fashion ie. only restarts on node a time.- Throws:
Exception
-
fullRestart
Restarts all nodes in the cluster. It first stops all nodes and then restarts all the nodes again.- Throws:
Exception
-
getMasterName
Returns the name of the current master node in the cluster. -
getMasterName
Returns the name of the current master node in the cluster and executes the request via the node specified in the viaNode parameter. If viaNode isn't specified a random node will be picked to the send the request to. -
getNonMasterNodeName
-
getRandomNodeName
- Returns:
- the name of a random node in a cluster
-
getNodeNameThat
- Returns:
- the name of a random node in a cluster that match the
predicate
-
nodesInclude
Returns a set of nodes that have at least one shard of the given index. -
startNode
Starts a node with default settings and returns its name. -
startNode
Starts a node with the given settings builder and returns its name. -
startNode
Starts a node with the given settings and returns its name. -
startNodes
Starts multiple nodes with default settings and returns their names -
startNodes
Starts multiple nodes with the given settings and returns their names -
startNodes
Starts multiple nodes with the given settings and returns their names -
startMasterOnlyNodes
-
startMasterOnlyNodes
-
startDataOnlyNodes
-
startDataOnlyNodes
-
startMasterOnlyNode
-
startMasterOnlyNode
-
startDataOnlyNode
-
startDataOnlyNode
-
numDataNodes
public int numDataNodes()Description copied from class:TestClusterReturns the number of data nodes in the cluster.- Specified by:
numDataNodesin classTestCluster
-
numDataAndMasterNodes
public int numDataAndMasterNodes()Description copied from class:TestClusterReturns the number of data and master eligible nodes in the cluster.- Specified by:
numDataAndMasterNodesin classTestCluster
-
numMasterNodes
public int numMasterNodes() -
masterEligibleNodeNames
-
setDisruptionScheme
-
clearDisruptionScheme
public void clearDisruptionScheme() -
clearDisruptionScheme
public void clearDisruptionScheme(boolean ensureHealthyCluster) -
getClients
Description copied from class:TestClusterReturns anIterableover all clients in this test cluster- Specified by:
getClientsin classTestCluster
-
getNamedWriteableRegistry
Description copied from class:TestClusterReturns this clustersNamedWriteableRegistrythis is needed to deserialize binary content from this cluster that might include custom named writeables- Specified by:
getNamedWriteableRegistryin classTestCluster
-
getDefaultSettings
-
ensureEstimatedStats
public void ensureEstimatedStats()Description copied from class:TestClusterEnsures 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.- Specified by:
ensureEstimatedStatsin classTestCluster
-
assertAfterTest
Description copied from class:TestClusterThis method checks all the things that need to be checked after each test- Overrides:
assertAfterTestin classTestCluster- Throws:
Exception
-
assertRequestsFinished
public void assertRequestsFinished() -
awaitIndexShardCloseAsyncTasks
public void awaitIndexShardCloseAsyncTasks()
-