Class MockTransportService
java.lang.Object
org.opensearch.common.lifecycle.AbstractLifecycleComponent
org.opensearch.transport.TransportService
org.opensearch.test.transport.MockTransportService
- All Implemented Interfaces:
Closeable,AutoCloseable,org.opensearch.common.lease.Releasable,org.opensearch.common.lifecycle.LifecycleComponent,org.opensearch.core.service.ReportingService<org.opensearch.transport.TransportInfo>,org.opensearch.transport.TransportConnectionListener,org.opensearch.transport.TransportMessageListener
public final class MockTransportService
extends org.opensearch.transport.TransportService
A mock delegate service that allows to simulate different network topology failures.
Internally it maps TransportAddress objects to rules that inject failures.
Adding rules for a node is done by adding rules for all bound addresses of a node
(and the publish address, if different).
Matching requests to rules is based on the delegate address associated with the
discovery node of the request, namely by DiscoveryNode.getAddress().
This address is usually the publish address of the node but can also be a different one
(for example, @see org.opensearch.discovery.HandshakingTransportAddressConnector, which constructs
fake DiscoveryNode instances where the publish address is one of the bound addresses).
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.opensearch.transport.TransportService
org.opensearch.transport.TransportService.ContextRestoreResponseHandler<T extends org.opensearch.core.transport.TransportResponse>, org.opensearch.transport.TransportService.HandshakeResponseNested classes/interfaces inherited from interface org.opensearch.core.service.ReportingService
org.opensearch.core.service.ReportingService.Info -
Field Summary
Fields inherited from class org.opensearch.transport.TransportService
clusterName, connectionManager, DIRECT_RESPONSE_PROFILE, HANDSHAKE_ACTION_NAME, interceptor, localNodeFactory, NOOP_TRANSPORT_INTERCEPTOR, responseHandlers, taskManager, threadPool, tracer, transport, VALID_ACTION_PREFIXESFields inherited from class org.opensearch.common.lifecycle.AbstractLifecycleComponent
lifecycleFields inherited from interface org.opensearch.transport.TransportMessageListener
NOOP_LISTENER -
Constructor Summary
ConstructorsConstructorDescriptionMockTransportService(org.opensearch.common.settings.Settings settings, org.opensearch.transport.Transport transport, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.transport.TransportInterceptor interceptor, Function<org.opensearch.core.common.transport.BoundTransportAddress, org.opensearch.cluster.node.DiscoveryNode> localNodeFactory, org.opensearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders, org.opensearch.telemetry.tracing.Tracer tracer) Build the service.MockTransportService(org.opensearch.common.settings.Settings settings, org.opensearch.transport.Transport transport, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.transport.TransportInterceptor interceptor, org.opensearch.common.settings.ClusterSettings clusterSettings, org.opensearch.telemetry.tracing.Tracer tracer) Build the service.MockTransportService(org.opensearch.common.settings.Settings settings, org.opensearch.transport.Transport transport, org.opensearch.transport.Transport streamTransport, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.transport.TransportInterceptor interceptor, Function<org.opensearch.core.common.transport.BoundTransportAddress, org.opensearch.cluster.node.DiscoveryNode> localNodeFactory, org.opensearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders, org.opensearch.telemetry.tracing.Tracer tracer) -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddConnectBehavior(org.opensearch.core.common.transport.TransportAddress transportAddress, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate address.booleanaddConnectBehavior(org.opensearch.transport.TransportService transportService, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate service.voidaddFailToSendNoConnectRule(org.opensearch.core.common.transport.TransportAddress transportAddress) Adds a rule that will cause every send request to fail, and each new connect since the rule is added to fail as well.voidaddFailToSendNoConnectRule(org.opensearch.core.common.transport.TransportAddress transportAddress, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsvoidaddFailToSendNoConnectRule(org.opensearch.transport.TransportService transportService) Adds a rule that will cause every send request to fail, and each new connect since the rule is added to fail as well.voidaddFailToSendNoConnectRule(org.opensearch.transport.TransportService transportService, String... blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsvoidaddFailToSendNoConnectRule(org.opensearch.transport.TransportService transportService, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsbooleanaddGetConnectionBehavior(org.opensearch.core.common.transport.TransportAddress transportAddress, StubbableConnectionManager.GetConnectionBehavior behavior) Adds a get connection behavior that is used for communication with the given delegate address.booleanAdds a get connection behavior that is the default get connection behavior.booleanAdds a node connected behavior that is the default node connected behavior.voidaddOnStopListener(Runnable listener) <R extends org.opensearch.transport.TransportRequest>
voidaddRequestHandlingBehavior(String actionName, StubbableTransport.RequestHandlingBehavior<R> handlingBehavior) Adds a new handling behavior that is used when the defined request is received.booleanaddSendBehavior(org.opensearch.core.common.transport.TransportAddress transportAddress, StubbableTransport.SendRequestBehavior sendBehavior) Adds a new send behavior that is used for communication with the given delegate address.booleanAdds a send behavior that is the default send behavior.booleanaddSendBehavior(org.opensearch.transport.TransportService transportService, StubbableTransport.SendRequestBehavior sendBehavior) Adds a new send behavior that is used for communication with the given delegate service.voidaddUnresponsiveRule(org.opensearch.core.common.transport.TransportAddress transportAddress) Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added.voidaddUnresponsiveRule(org.opensearch.core.common.transport.TransportAddress transportAddress, org.opensearch.common.unit.TimeValue duration) Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added.voidaddUnresponsiveRule(org.opensearch.transport.TransportService transportService) Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added.voidaddUnresponsiveRule(org.opensearch.transport.TransportService transportService, org.opensearch.common.unit.TimeValue duration) Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added.voidClears all the registered rules.voidClears all the inbound rules.voidclearOutboundRules(org.opensearch.core.common.transport.TransportAddress transportAddress) Clears the outbound rules associated with the provided delegate address.voidclearOutboundRules(org.opensearch.transport.TransportService transportService) Clears the outbound rules associated with the provided delegate service.static MockTransportServicecreateNewService(org.opensearch.common.settings.Settings settings, org.opensearch.transport.Transport transport, org.opensearch.Version version, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders, org.opensearch.telemetry.tracing.Tracer tracer) static MockTransportServicecreateNewService(org.opensearch.common.settings.Settings settings, org.opensearch.transport.Transport transport, org.opensearch.Version version, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders, org.opensearch.transport.TransportInterceptor interceptor, org.opensearch.telemetry.tracing.Tracer tracer) static MockTransportServicecreateNewService(org.opensearch.common.settings.Settings settings, org.opensearch.Version version, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.common.settings.ClusterSettings clusterSettings, org.opensearch.telemetry.tracing.Tracer tracer) static MockTransportServicecreateNewService(org.opensearch.common.settings.Settings settings, org.opensearch.Version version, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.telemetry.tracing.Tracer tracer) protected org.opensearch.tasks.TaskManagercreateTaskManager(org.opensearch.common.settings.Settings settings, org.opensearch.common.settings.ClusterSettings clusterSettings, org.opensearch.threadpool.ThreadPool threadPool, Set<String> taskHeaders) protected voiddoClose()protected voiddoStop()org.opensearch.cluster.node.DiscoveryNodeorg.opensearch.transport.Transportstatic MockNioTransportnewMockTransport(org.opensearch.common.settings.Settings settings, org.opensearch.Version version, org.opensearch.threadpool.ThreadPool threadPool) org.opensearch.transport.Transport.ConnectionopenConnection(org.opensearch.cluster.node.DiscoveryNode node, org.opensearch.transport.ConnectionProfile profile) Methods inherited from class org.opensearch.transport.TransportService
acceptIncomingRequests, addConnectionListener, addMessageListener, addressesFromString, boundAddress, clearPendingDisconnections, connectionValidator, connectionValidatorForExtensionConnectingToNode, connectToExtensionNode, connectToExtensionNode, connectToExtensionNode, connectToExtensionNode, connectToNode, connectToNode, connectToNode, connectToNode, connectToNodeAsExtension, connectToNodeAsExtension, connectToNodeAsExtension, disconnectFromNode, doStart, ensureClassloaded, extensionConnectionValidator, getConnection, getConnectionManager, getDefaultSeedAddresses, getLocalNode, getRemoteClusterService, getRequestHandler, getTaskManager, getThreadPool, handshake, handshake, info, isLocalNode, isTransportSecure, isValidActionName, nodeConnected, onConnectionClosed, onRequestReceived, onRequestSent, onResponseReceived, onResponseSent, onResponseSent, openConnection, registerRequestHandler, registerRequestHandler, registerRequestHandler, removeConnectionListener, removeMessageListener, sendChildRequest, sendChildRequest, sendChildRequest, sendLocalRequest, sendRequest, sendRequest, sendRequest, sendRequestAsync, setPendingDisconnection, shouldTraceAction, stats, submitRequest, submitRequest, validateActionNameMethods inherited from class org.opensearch.common.lifecycle.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opensearch.transport.TransportConnectionListener
onConnectionOpened, onNodeConnected, onNodeDisconnectedMethods inherited from interface org.opensearch.transport.TransportMessageListener
onStreamResponseSent
-
Constructor Details
-
MockTransportService
public MockTransportService(org.opensearch.common.settings.Settings settings, org.opensearch.transport.Transport transport, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.transport.TransportInterceptor interceptor, @Nullable org.opensearch.common.settings.ClusterSettings clusterSettings, org.opensearch.telemetry.tracing.Tracer tracer) Build the service.- Parameters:
clusterSettings- if non null the TransportService will register with theClusterSettingsfor settings updates forTransportSettings.TRACE_LOG_EXCLUDE_SETTINGandTransportSettings.TRACE_LOG_INCLUDE_SETTING.
-
MockTransportService
public MockTransportService(org.opensearch.common.settings.Settings settings, org.opensearch.transport.Transport transport, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.transport.TransportInterceptor interceptor, Function<org.opensearch.core.common.transport.BoundTransportAddress, org.opensearch.cluster.node.DiscoveryNode> localNodeFactory, @Nullable org.opensearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders, org.opensearch.telemetry.tracing.Tracer tracer) Build the service.- Parameters:
clusterSettings- if non null the TransportService will register with theClusterSettingsfor settings updates forTransportSettings.TRACE_LOG_EXCLUDE_SETTINGandTransportSettings.TRACE_LOG_INCLUDE_SETTING.
-
MockTransportService
public MockTransportService(org.opensearch.common.settings.Settings settings, org.opensearch.transport.Transport transport, @Nullable org.opensearch.transport.Transport streamTransport, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.transport.TransportInterceptor interceptor, Function<org.opensearch.core.common.transport.BoundTransportAddress, org.opensearch.cluster.node.DiscoveryNode> localNodeFactory, @Nullable org.opensearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders, org.opensearch.telemetry.tracing.Tracer tracer)
-
-
Method Details
-
createNewService
public static MockTransportService createNewService(org.opensearch.common.settings.Settings settings, org.opensearch.Version version, org.opensearch.threadpool.ThreadPool threadPool, org.opensearch.telemetry.tracing.Tracer tracer) -
createNewService
public static MockTransportService createNewService(org.opensearch.common.settings.Settings settings, org.opensearch.Version version, org.opensearch.threadpool.ThreadPool threadPool, @Nullable org.opensearch.common.settings.ClusterSettings clusterSettings, org.opensearch.telemetry.tracing.Tracer tracer) -
newMockTransport
public static MockNioTransport newMockTransport(org.opensearch.common.settings.Settings settings, org.opensearch.Version version, org.opensearch.threadpool.ThreadPool threadPool) -
createNewService
public static MockTransportService createNewService(org.opensearch.common.settings.Settings settings, org.opensearch.transport.Transport transport, org.opensearch.Version version, org.opensearch.threadpool.ThreadPool threadPool, @Nullable org.opensearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders, org.opensearch.telemetry.tracing.Tracer tracer) -
createNewService
public static MockTransportService createNewService(org.opensearch.common.settings.Settings settings, org.opensearch.transport.Transport transport, org.opensearch.Version version, org.opensearch.threadpool.ThreadPool threadPool, @Nullable org.opensearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders, org.opensearch.transport.TransportInterceptor interceptor, org.opensearch.telemetry.tracing.Tracer tracer) -
createTaskManager
protected org.opensearch.tasks.TaskManager createTaskManager(org.opensearch.common.settings.Settings settings, org.opensearch.common.settings.ClusterSettings clusterSettings, org.opensearch.threadpool.ThreadPool threadPool, Set<String> taskHeaders) - Overrides:
createTaskManagerin classorg.opensearch.transport.TransportService
-
clearAllRules
public void clearAllRules()Clears all the registered rules. -
clearInboundRules
public void clearInboundRules()Clears all the inbound rules. -
clearOutboundRules
public void clearOutboundRules(org.opensearch.transport.TransportService transportService) Clears the outbound rules associated with the provided delegate service. -
clearOutboundRules
public void clearOutboundRules(org.opensearch.core.common.transport.TransportAddress transportAddress) Clears the outbound rules associated with the provided delegate address. -
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(org.opensearch.transport.TransportService transportService) Adds a rule that will cause every send request to fail, and each new connect since the rule is added to fail as well. -
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(org.opensearch.core.common.transport.TransportAddress transportAddress) Adds a rule that will cause every send request to fail, and each new connect since the rule is added to fail as well. -
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(org.opensearch.transport.TransportService transportService, String... blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptions -
addFailToSendNoConnectRule
-
addFailToSendNoConnectRule
-
addUnresponsiveRule
public void addUnresponsiveRule(org.opensearch.transport.TransportService transportService) Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added. -
addUnresponsiveRule
public void addUnresponsiveRule(org.opensearch.core.common.transport.TransportAddress transportAddress) Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added. -
addUnresponsiveRule
public void addUnresponsiveRule(org.opensearch.transport.TransportService transportService, org.opensearch.common.unit.TimeValue duration) Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added.- Parameters:
duration- the amount of time to delay sending and connecting.
-
addUnresponsiveRule
public void addUnresponsiveRule(org.opensearch.core.common.transport.TransportAddress transportAddress, org.opensearch.common.unit.TimeValue duration) Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added.- Parameters:
duration- the amount of time to delay sending and connecting.
-
addRequestHandlingBehavior
public <R extends org.opensearch.transport.TransportRequest> void addRequestHandlingBehavior(String actionName, StubbableTransport.RequestHandlingBehavior<R> handlingBehavior) Adds a new handling behavior that is used when the defined request is received. -
addSendBehavior
public boolean addSendBehavior(org.opensearch.transport.TransportService transportService, StubbableTransport.SendRequestBehavior sendBehavior) Adds a new send behavior that is used for communication with the given delegate service.- Returns:
trueif no other send behavior was registered for any of the addresses bound by delegate service.
-
addSendBehavior
public boolean addSendBehavior(org.opensearch.core.common.transport.TransportAddress transportAddress, StubbableTransport.SendRequestBehavior sendBehavior) Adds a new send behavior that is used for communication with the given delegate address.- Returns:
trueif no other send behavior was registered for this address before.
-
addSendBehavior
Adds a send behavior that is the default send behavior.- Returns:
trueif no default send behavior was registered
-
addConnectBehavior
public boolean addConnectBehavior(org.opensearch.transport.TransportService transportService, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate service.- Returns:
trueif no other send behavior was registered for any of the addresses bound by delegate service.
-
addConnectBehavior
public boolean addConnectBehavior(org.opensearch.core.common.transport.TransportAddress transportAddress, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate address.- Returns:
trueif no other send behavior was registered for this address before.
-
addGetConnectionBehavior
public boolean addGetConnectionBehavior(org.opensearch.core.common.transport.TransportAddress transportAddress, StubbableConnectionManager.GetConnectionBehavior behavior) Adds a get connection behavior that is used for communication with the given delegate address.- Returns:
trueif no other get connection behavior was registered for this address before.
-
addGetConnectionBehavior
Adds a get connection behavior that is the default get connection behavior.- Returns:
trueif no default get connection behavior was registered.
-
addNodeConnectedBehavior
Adds a node connected behavior that is the default node connected behavior.- Returns:
trueif no default node connected behavior was registered.
-
transport
-
connectionManager
-
getOriginalTransport
public org.opensearch.transport.Transport getOriginalTransport() -
openConnection
public org.opensearch.transport.Transport.Connection openConnection(org.opensearch.cluster.node.DiscoveryNode node, org.opensearch.transport.ConnectionProfile profile) - Overrides:
openConnectionin classorg.opensearch.transport.TransportService
-
addOnStopListener
-
doStop
protected void doStop()- Overrides:
doStopin classorg.opensearch.transport.TransportService
-
doClose
- Overrides:
doClosein classorg.opensearch.transport.TransportService- Throws:
IOException
-
getLocalDiscoNode
public org.opensearch.cluster.node.DiscoveryNode getLocalDiscoNode()
-