Package org.elasticsearch.test.transport
Class MockTransportService
java.lang.Object
org.elasticsearch.common.component.AbstractLifecycleComponent
org.elasticsearch.transport.TransportService
org.elasticsearch.test.transport.MockTransportService
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.elasticsearch.common.component.LifecycleComponent
,org.elasticsearch.core.Releasable
,org.elasticsearch.node.ReportingService<org.elasticsearch.transport.TransportInfo>
,org.elasticsearch.transport.TransportConnectionListener
,org.elasticsearch.transport.TransportMessageListener
public final class MockTransportService
extends org.elasticsearch.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.elasticsearch.discovery.HandshakingTransportAddressConnector, which constructs
fake DiscoveryNode instances where the publish address is one of the bound addresses).
-
Nested Class Summary
Nested classes/interfaces inherited from class org.elasticsearch.transport.TransportService
org.elasticsearch.transport.TransportService.ContextRestoreResponseHandler<T extends org.elasticsearch.transport.TransportResponse>, org.elasticsearch.transport.TransportService.HandshakeResponse
Nested classes/interfaces inherited from interface org.elasticsearch.node.ReportingService
org.elasticsearch.node.ReportingService.Info
-
Field Summary
Fields inherited from class org.elasticsearch.transport.TransportService
clusterName, connectionManager, DIRECT_RESPONSE_PROFILE, HANDSHAKE_ACTION_NAME, NOOP_TRANSPORT_INTERCEPTOR, taskManager, threadPool, transport, VALID_ACTION_PREFIXES
Fields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle
Fields inherited from interface org.elasticsearch.transport.TransportMessageListener
NOOP_LISTENER
-
Constructor Summary
ConstructorDescriptionMockTransportService
(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.transport.Transport transport, org.elasticsearch.threadpool.ThreadPool threadPool, org.elasticsearch.transport.TransportInterceptor interceptor, Function<org.elasticsearch.common.transport.BoundTransportAddress, org.elasticsearch.cluster.node.DiscoveryNode> localNodeFactory, org.elasticsearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders) Build the service.MockTransportService
(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.transport.Transport transport, org.elasticsearch.threadpool.ThreadPool threadPool, org.elasticsearch.transport.TransportInterceptor interceptor, org.elasticsearch.common.settings.ClusterSettings clusterSettings) Build the service. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addConnectBehavior
(org.elasticsearch.common.transport.TransportAddress transportAddress, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate address.boolean
addConnectBehavior
(org.elasticsearch.transport.TransportService transportService, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate service.void
addFailToSendNoConnectRule
(org.elasticsearch.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.void
addFailToSendNoConnectRule
(org.elasticsearch.common.transport.TransportAddress transportAddress, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsvoid
addFailToSendNoConnectRule
(org.elasticsearch.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.void
addFailToSendNoConnectRule
(org.elasticsearch.transport.TransportService transportService, String... blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsvoid
addFailToSendNoConnectRule
(org.elasticsearch.transport.TransportService transportService, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsboolean
addGetConnectionBehavior
(org.elasticsearch.common.transport.TransportAddress transportAddress, StubbableConnectionManager.GetConnectionBehavior behavior) Adds a get connection behavior that is used for communication with the given delegate address.boolean
Adds a get connection behavior that is the default get connection behavior.boolean
Adds a node connected behavior that is the default node connected behavior.void
addOnStopListener
(Runnable listener) <R extends org.elasticsearch.transport.TransportRequest>
voidaddRequestHandlingBehavior
(String actionName, StubbableTransport.RequestHandlingBehavior<R> handlingBehavior) Adds a new handling behavior that is used when the defined request is received.boolean
addSendBehavior
(org.elasticsearch.common.transport.TransportAddress transportAddress, StubbableTransport.SendRequestBehavior sendBehavior) Adds a new send behavior that is used for communication with the given delegate address.boolean
Adds a send behavior that is the default send behavior.boolean
addSendBehavior
(org.elasticsearch.transport.TransportService transportService, StubbableTransport.SendRequestBehavior sendBehavior) Adds a new send behavior that is used for communication with the given delegate service.void
addUnresponsiveRule
(org.elasticsearch.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.void
addUnresponsiveRule
(org.elasticsearch.common.transport.TransportAddress transportAddress, org.elasticsearch.core.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.void
addUnresponsiveRule
(org.elasticsearch.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.void
addUnresponsiveRule
(org.elasticsearch.transport.TransportService transportService, org.elasticsearch.core.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.void
Clears all the registered rules.void
Clears all the inbound rules.void
clearOutboundRules
(org.elasticsearch.common.transport.TransportAddress transportAddress) Clears the outbound rules associated with the provided delegate address.void
clearOutboundRules
(org.elasticsearch.transport.TransportService transportService) Clears the outbound rules associated with the provided delegate service.static MockTransportService
createNewService
(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.transport.Transport transport, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool, org.elasticsearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders) static MockTransportService
createNewService
(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.transport.Transport transport, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool, org.elasticsearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders, org.elasticsearch.transport.TransportInterceptor interceptor) static MockTransportService
createNewService
(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool) static MockTransportService
createNewService
(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool, org.elasticsearch.common.settings.ClusterSettings clusterSettings) protected org.elasticsearch.tasks.TaskManager
createTaskManager
(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.threadpool.ThreadPool threadPool, Set<String> taskHeaders) protected void
doClose()
protected void
doStop()
org.elasticsearch.cluster.node.DiscoveryNode
org.elasticsearch.transport.Transport
static org.elasticsearch.transport.TcpTransport
newMockTransport
(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool) void
openConnection
(org.elasticsearch.cluster.node.DiscoveryNode node, org.elasticsearch.transport.ConnectionProfile connectionProfile, org.elasticsearch.action.ActionListener<org.elasticsearch.transport.Transport.Connection> listener) Methods inherited from class org.elasticsearch.transport.TransportService
acceptIncomingRequests, addConnectionListener, addMessageListener, addressesFromString, boundAddress, connectionValidator, connectToNode, connectToNode, disconnectFromNode, doStart, getConnection, getConnectionManager, getDefaultSeedAddresses, getLocalNode, getLocalNodeConnection, getRemoteClusterService, getRequestHandler, getTaskManager, getThreadPool, handshake, handshake, info, isTransportSecure, isValidActionName, newNetworkBytesStream, nodeConnected, onConnectionClosed, onRequestReceived, onRequestSent, onResponseReceived, onResponseSent, onResponseSent, registerRequestHandler, registerRequestHandler, removeConnectionListener, removeMessageListener, sendChildRequest, sendChildRequest, sendChildRequest, sendRequest, sendRequest, sendRequest, shouldTraceAction, stats, unwrapConnection
Methods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.elasticsearch.transport.TransportConnectionListener
onConnectionOpened, onNodeConnected, onNodeDisconnected
-
Constructor Details
-
MockTransportService
public MockTransportService(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.transport.Transport transport, org.elasticsearch.threadpool.ThreadPool threadPool, org.elasticsearch.transport.TransportInterceptor interceptor, @Nullable org.elasticsearch.common.settings.ClusterSettings clusterSettings) Build the service.- Parameters:
clusterSettings
- if non null the TransportService will register with theClusterSettings
for settings updates forTransportSettings.TRACE_LOG_EXCLUDE_SETTING
andTransportSettings.TRACE_LOG_INCLUDE_SETTING
.
-
MockTransportService
public MockTransportService(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.transport.Transport transport, org.elasticsearch.threadpool.ThreadPool threadPool, org.elasticsearch.transport.TransportInterceptor interceptor, Function<org.elasticsearch.common.transport.BoundTransportAddress, org.elasticsearch.cluster.node.DiscoveryNode> localNodeFactory, @Nullable org.elasticsearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders) Build the service.- Parameters:
clusterSettings
- if non null the TransportService will register with theClusterSettings
for settings updates forTransportSettings.TRACE_LOG_EXCLUDE_SETTING
andTransportSettings.TRACE_LOG_INCLUDE_SETTING
.
-
-
Method Details
-
createNewService
public static MockTransportService createNewService(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool) -
createNewService
public static MockTransportService createNewService(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool, @Nullable org.elasticsearch.common.settings.ClusterSettings clusterSettings) -
newMockTransport
public static org.elasticsearch.transport.TcpTransport newMockTransport(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool) -
createNewService
public static MockTransportService createNewService(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.transport.Transport transport, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool, @Nullable org.elasticsearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders) -
createNewService
public static MockTransportService createNewService(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.transport.Transport transport, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool, @Nullable org.elasticsearch.common.settings.ClusterSettings clusterSettings, Set<String> taskHeaders, org.elasticsearch.transport.TransportInterceptor interceptor) -
createTaskManager
protected org.elasticsearch.tasks.TaskManager createTaskManager(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.threadpool.ThreadPool threadPool, Set<String> taskHeaders) - Overrides:
createTaskManager
in classorg.elasticsearch.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.elasticsearch.transport.TransportService transportService) Clears the outbound rules associated with the provided delegate service. -
clearOutboundRules
public void clearOutboundRules(org.elasticsearch.common.transport.TransportAddress transportAddress) Clears the outbound rules associated with the provided delegate address. -
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(org.elasticsearch.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.elasticsearch.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.elasticsearch.transport.TransportService transportService, String... blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptions -
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(org.elasticsearch.transport.TransportService transportService, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptions -
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(org.elasticsearch.common.transport.TransportAddress transportAddress, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptions -
addUnresponsiveRule
public void addUnresponsiveRule(org.elasticsearch.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.elasticsearch.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.elasticsearch.transport.TransportService transportService, org.elasticsearch.core.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.elasticsearch.common.transport.TransportAddress transportAddress, org.elasticsearch.core.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.elasticsearch.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.elasticsearch.transport.TransportService transportService, StubbableTransport.SendRequestBehavior sendBehavior) Adds a new send behavior that is used for communication with the given delegate service.- Returns:
true
if no other send behavior was registered for any of the addresses bound by delegate service.
-
addSendBehavior
public boolean addSendBehavior(org.elasticsearch.common.transport.TransportAddress transportAddress, StubbableTransport.SendRequestBehavior sendBehavior) Adds a new send behavior that is used for communication with the given delegate address.- Returns:
true
if no other send behavior was registered for this address before.
-
addSendBehavior
Adds a send behavior that is the default send behavior.- Returns:
true
if no default send behavior was registered
-
addConnectBehavior
public boolean addConnectBehavior(org.elasticsearch.transport.TransportService transportService, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate service.- Returns:
true
if no other send behavior was registered for any of the addresses bound by delegate service.
-
addConnectBehavior
public boolean addConnectBehavior(org.elasticsearch.common.transport.TransportAddress transportAddress, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate address.- Returns:
true
if no other send behavior was registered for this address before.
-
addGetConnectionBehavior
public boolean addGetConnectionBehavior(org.elasticsearch.common.transport.TransportAddress transportAddress, StubbableConnectionManager.GetConnectionBehavior behavior) Adds a get connection behavior that is used for communication with the given delegate address.- Returns:
true
if 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:
true
if no default get connection behavior was registered.
-
addNodeConnectedBehavior
Adds a node connected behavior that is the default node connected behavior.- Returns:
true
if no default node connected behavior was registered.
-
transport
-
connectionManager
-
getOriginalTransport
public org.elasticsearch.transport.Transport getOriginalTransport() -
openConnection
public void openConnection(org.elasticsearch.cluster.node.DiscoveryNode node, org.elasticsearch.transport.ConnectionProfile connectionProfile, org.elasticsearch.action.ActionListener<org.elasticsearch.transport.Transport.Connection> listener) - Overrides:
openConnection
in classorg.elasticsearch.transport.TransportService
-
addOnStopListener
-
doStop
protected void doStop()- Overrides:
doStop
in classorg.elasticsearch.transport.TransportService
-
doClose
- Overrides:
doClose
in classorg.elasticsearch.transport.TransportService
- Throws:
IOException
-
getLocalDiscoNode
public org.elasticsearch.cluster.node.DiscoveryNode getLocalDiscoNode()
-