Class InternalTestCluster
java.lang.Object
org.opensearch.test.TestCluster
org.opensearch.test.InternalTestCluster
- All Implemented Interfaces:
Closeable,AutoCloseable
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 OpenSearch in combination with randomized testing. Once Threads and asynchronous calls
are involved reproducibility is very limited. This class should only be used through OpenSearchIntegTestCase.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic 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 intstatic final intstatic final InternalTestCluster.RestartCallbackFields inherited from class org.opensearch.test.TestCluster
random -
Constructor Summary
ConstructorsConstructorDescriptionInternalTestCluster(long clusterSeed, Path baseDir, boolean randomlyAddDedicatedClusterManagers, boolean autoManageClusterManagerNodes, int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes, String nodePrefix, Collection<Class<? extends org.opensearch.plugins.Plugin>> mockPlugins, Function<org.opensearch.transport.client.Client, org.opensearch.transport.client.Client> clientWrapper) InternalTestCluster(long clusterSeed, Path baseDir, boolean randomlyAddDedicatedClusterManagers, boolean autoManageClusterManagerNodes, int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes, String nodePrefix, Collection<Class<? extends org.opensearch.plugins.Plugin>> mockPlugins, Function<org.opensearch.transport.client.Client, org.opensearch.transport.client.Client> clientWrapper, boolean forbidPrivateIndexSettings) -
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.voidvoidvoidAsserts that all shards with the same shardId should have document Ids.voidvoidAssertions 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) org.opensearch.transport.client.Clientclient()Returns a client connected to any node in the clusterorg.opensearch.transport.client.ClientReturns a node client to a given node.voidclose()Closes the current clustervoidcloseNonSharedNodes(boolean wipeData) org.opensearch.transport.client.ClientReturns a node client to the current cluster-manager node.static StringclusterName(String prefix, long clusterSeed) org.opensearch.cluster.service.ClusterServiceReturns a reference to a random node'sClusterServiceorg.opensearch.cluster.service.ClusterServiceclusterService(String node) Returns a reference to a node'sClusterService.org.opensearch.transport.client.ClientReturns a client to a coordinating only nodeorg.opensearch.transport.client.ClientReturns a node client to a data node in the cluster.org.opensearch.common.settings.SettingsdataPathSettings(String node) voidensureAtLeastNumDataNodes(int n) Ensures that at leastndata nodes are present in the cluster.voidEnsures that at leastndata-warm nodes are present in the cluster.voidensureAtLeastNumWarmNodes(int n) Ensures that at leastnwarm 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.Iterable<org.opensearch.transport.client.Client> Returns anIterableover all clients in this test clusterReturns the name of the current cluster-manager node in the cluster.getClusterManagerName(String viaNode) Returns the name of the current cluster-manager node in the cluster and executes the request via the node specified in the viaNode parameter.Returns the name of all the cluster managers in the cluster<T> TgetClusterManagerNodeInstance(Class<T> clazz) Returns the cluster name<T> TgetCurrentClusterManagerNodeInstance(Class<T> clazz) <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> getDataOrClusterManagerNodeInstances(Class<T> clazz) Returns an Iterable to all instances for the given class >T< across all data and cluster-manager nodes in the cluster.org.opensearch.common.settings.Settings<T> TgetInstance(Class<T> clazz) Returns a reference to a random nodes instances of the given class >T<<T> TgetInstance(Class<T> clazz, String node) Returns a reference to the given nodes instances of the given class >T<<T> Iterable<T> getInstances(Class<T> clazz) Returns an Iterable to all instances for the given class >T< across all nodes in the cluster.org.opensearch.core.common.io.stream.NamedWriteableRegistryReturns this clustersNamedWriteableRegistrythis is needed to deserialize binary content from this cluster that might include custom named writeablesString[]Collection<Class<? extends org.opensearch.plugins.Plugin>> Returns the http addresses of the nodes within the cluster.static Predicate<org.opensearch.common.settings.Settings> nameFilter(String... nodeNames) Returns a predicate that only accepts settings of nodes with one of the given names.nodesInclude(String index) Returns a set of nodes that have at least one shard of the given index.org.opensearch.transport.client.ClientReturns a node client to random node but not the cluster-manager.intintReturns the number of data and cluster-manager eligible nodes in the cluster.intReturns the number of data nodes in the cluster.intintvoidReplace all nodes by stopping all current node and starting new node.voidrestartNode(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.voidsetBootstrapClusterManagerNodeIndex(int bootstrapClusterManagerNodeIndex) SetsbootstrapClusterManagerNodeIndexto the given value, seebootstrapClusterManagerNodeWithSpecifiedIndex(List)for the description of how this field is used.voidintsize()Returns the number of nodes in the cluster.org.opensearch.transport.client.ClientReturns a "smart" node client to a random node in the clusterstartClusterManagerOnlyNode(org.opensearch.common.settings.Settings settings) startClusterManagerOnlyNodes(int numNodes) startClusterManagerOnlyNodes(int numNodes, org.opensearch.common.settings.Settings settings) startCoordinatingOnlyNode(org.opensearch.common.settings.Settings settings) startDataAndWarmNodes(int numNodes) startDataAndWarmNodes(int numNodes, org.opensearch.common.settings.Settings settings) startDataOnlyNode(org.opensearch.common.settings.Settings settings) startDataOnlyNodes(int numNodes) startDataOnlyNodes(int numNodes, org.opensearch.common.settings.Settings settings) startDataOnlyNodes(int numNodes, org.opensearch.common.settings.Settings settings, Boolean ignoreNodeJoin) Starts a node with default settings and returns its name.startNode(org.opensearch.common.settings.Settings settings) Starts a node with the given settings and returns its name.startNode(org.opensearch.common.settings.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, org.opensearch.common.settings.Settings settings) Starts multiple nodes with the given settings and returns their namesstartNodes(int numOfNodes, org.opensearch.common.settings.Settings settings, Boolean waitForNodeJoin) Starts multiple nodes with the given settings and returns their namesstartNodes(Boolean waitForNodeJoin, org.opensearch.common.settings.Settings... extraSettings) Starts multiple nodes with the given settings and returns their namesstartNodes(org.opensearch.common.settings.Settings... extraSettings) Starts multiple nodes with the given settings and returns their namesstartSearchOnlyNode(org.opensearch.common.settings.Settings settings) startSearchOnlyNodes(int numNodes) startSearchOnlyNodes(int numNodes, org.opensearch.common.settings.Settings settings) startWarmOnlyNodes(int numNodes) startWarmOnlyNodes(int numNodes, org.opensearch.common.settings.Settings settings) voidStops all running nodes in clustervoidStops the current cluster-manager node forcefully.booleanStops a random data node in the cluster.voidstopRandomNode(Predicate<org.opensearch.common.settings.Settings> filter) Stops a random node in the cluster that applies to the given filter.voidStops any of the current nodes but not the cluster-manager node.booleanStops a random warm node in the cluster.voidensure a cluster is formed with all published nodes.voidMethods inherited from class org.opensearch.test.TestCluster
seed, wipe, wipeAllDataStreams, wipeAllTemplates, wipeIndices, wipeRepositories, wipeTemplates
-
Field Details
-
DEFAULT_LOW_NUM_CLUSTER_MANAGER_NODES
public static final int DEFAULT_LOW_NUM_CLUSTER_MANAGER_NODES- See Also:
-
DEFAULT_HIGH_NUM_CLUSTER_MANAGER_NODES
public static final int DEFAULT_HIGH_NUM_CLUSTER_MANAGER_NODES- See Also:
-
EMPTY_CALLBACK
-
-
Constructor Details
-
InternalTestCluster
public InternalTestCluster(long clusterSeed, Path baseDir, boolean randomlyAddDedicatedClusterManagers, boolean autoManageClusterManagerNodes, int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes, String nodePrefix, Collection<Class<? extends org.opensearch.plugins.Plugin>> mockPlugins, Function<org.opensearch.transport.client.Client, org.opensearch.transport.client.Client> clientWrapper) -
InternalTestCluster
public InternalTestCluster(long clusterSeed, Path baseDir, boolean randomlyAddDedicatedClusterManagers, boolean autoManageClusterManagerNodes, int minNumDataNodes, int maxNumDataNodes, String clusterName, NodeConfigurationSource nodeConfigurationSource, int numClientNodes, String nodePrefix, Collection<Class<? extends org.opensearch.plugins.Plugin>> mockPlugins, Function<org.opensearch.transport.client.Client, org.opensearch.transport.client.Client> clientWrapper, boolean forbidPrivateIndexSettings)
-
-
Method Details
-
setBootstrapClusterManagerNodeIndex
public void setBootstrapClusterManagerNodeIndex(int bootstrapClusterManagerNodeIndex) SetsbootstrapClusterManagerNodeIndexto the given value, seebootstrapClusterManagerNodeWithSpecifiedIndex(List)for the description of how this field is used. It's only possible to changebootstrapClusterManagerNodeIndexvalue if autoManageClusterManagerNodes 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. -
ensureAtLeastNumWarmNodes
public void ensureAtLeastNumWarmNodes(int n) Ensures that at leastnwarm nodes are present in the cluster. if more nodes thannare present this method will not stop any of the running nodes. -
ensureAtLeastNumWarmAndDataNodes
public void ensureAtLeastNumWarmAndDataNodes(int n) Ensures that at leastndata-warm 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
public org.opensearch.transport.client.Client client()Description copied from class:TestClusterReturns a client connected to any node in the cluster- Specified by:
clientin classTestCluster
-
dataNodeClient
public org.opensearch.transport.client.Client 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. -
clusterManagerClient
public org.opensearch.transport.client.Client clusterManagerClient()Returns a node client to the current cluster-manager node. Note: use this with care tests should not rely on a certain nodes client. -
nonClusterManagerClient
public org.opensearch.transport.client.Client nonClusterManagerClient()Returns a node client to random node but not the cluster-manager. This method will fail if no non-cluster-manager client is available. -
coordOnlyNodeClient
public org.opensearch.transport.client.Client coordOnlyNodeClient()Returns a client to a coordinating only node -
startCoordinatingOnlyNode
-
client
Returns a node client to a given node. -
smartClient
public org.opensearch.transport.client.Client 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 interfaceAutoCloseable- Specified by:
closein interfaceCloseable- 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
-
assertNoInFlightDocsInEngine
-
assertSeqNos
-
assertSameDocIdsOnShards
-
wipePendingDataDirectories
public void wipePendingDataDirectories() -
clusterService
public org.opensearch.cluster.service.ClusterService 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
-
getDataNodeInstances
-
getCurrentClusterManagerNodeInstance
-
getDataOrClusterManagerNodeInstances
-
getInstance
-
getDataNodeInstance
-
getClusterManagerNodeInstance
-
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
-
stopRandomWarmNode
Stops a random warm node in the cluster. Returns true if a node was found to stop, false otherwise.- Throws:
IOException
-
stopRandomDataNode
Stops a random data node in the cluster. Returns true if a node was found to stop, false otherwise.- Throws:
IOException
-
stopRandomNode
public void stopRandomNode(Predicate<org.opensearch.common.settings.Settings> filter) throws IOException Stops a random node in the cluster that applies to the given filter. Does nothing if none of the nodes match the filter.- Throws:
IOException
-
stopCurrentClusterManagerNode
Stops the current cluster-manager node forcefully.- Throws:
IOException
-
stopRandomNodeNotCurrentClusterManager
Stops any of the current nodes but not the cluster-manager node.- Throws:
IOException
-
stopAllNodes
public void stopAllNodes()Stops all running nodes in cluster -
resetCluster
public void resetCluster()Replace all nodes by stopping all current node and starting new node. Used for remote store test cases, where remote state is restored. -
restartRandomDataNode
-
restartRandomDataNode
Restarts a random data node in the cluster and calls the callback during restart.- Throws:
Exception
-
restartNode
-
restartNode
public void restartNode(String nodeName, InternalTestCluster.RestartCallback callback) throws Exception Restarts a node and calls the callback during restart.- Throws:
Exception
-
fullRestart
-
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
-
getClusterManagerNames
-
getClusterManagerName
Returns the name of the current cluster-manager node in the cluster. -
getClusterManagerName
-
getDataNodeNames
-
nodesInclude
-
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
-
startNodes
-
startNodes
-
startNodes
-
startNodes
-
startClusterManagerOnlyNodes
-
startClusterManagerOnlyNodes
-
startDataAndWarmNodes
-
startDataAndWarmNodes
-
startSearchOnlyNodes
-
startSearchOnlyNodes
-
startSearchOnlyNode
-
startSearchOnlyNode
-
startDataOnlyNodes
-
startDataOnlyNodes
-
startDataOnlyNodes
-
startWarmOnlyNodes
-
startWarmOnlyNodes
-
startClusterManagerOnlyNode
-
startClusterManagerOnlyNode
-
startDataOnlyNode
-
startDataOnlyNode
-
numDataNodes
public int numDataNodes()Description copied from class:TestClusterReturns the number of data nodes in the cluster.- Specified by:
numDataNodesin classTestCluster
-
numWarmNodes
public int numWarmNodes() -
numWarmAndDataNodes
public int numWarmAndDataNodes() -
numDataAndClusterManagerNodes
public int numDataAndClusterManagerNodes()Description copied from class:TestClusterReturns the number of data and cluster-manager eligible nodes in the cluster.- Specified by:
numDataAndClusterManagerNodesin classTestCluster
-
numClusterManagerNodes
public int numClusterManagerNodes() -
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
public org.opensearch.core.common.io.stream.NamedWriteableRegistry 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
-
nameFilter
-
getDefaultSettings
public org.opensearch.common.settings.Settings 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()
-