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
,LifecycleComponent
,org.elasticsearch.core.Releasable
,ReportingService<TransportInfo>
,TransportConnectionListener
,TransportMessageListener
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
TransportService.ContextRestoreResponseHandler<T extends TransportResponse>, TransportService.HandshakeResponse
Nested classes/interfaces inherited from interface org.elasticsearch.node.ReportingService
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
(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, ClusterSettings clusterSettings) MockTransportService
(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, ClusterSettings clusterSettings, Set<String> taskHeaders) Build the service.MockTransportService
(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor, ClusterSettings clusterSettings) Build the service. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addConnectBehavior
(TransportAddress transportAddress, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate address.boolean
addConnectBehavior
(TransportService transportService, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate service.void
addFailToSendNoConnectRule
(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
(TransportAddress transportAddress, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsvoid
addFailToSendNoConnectRule
(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
(TransportService transportService, String... blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsvoid
addFailToSendNoConnectRule
(TransportService transportService, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsboolean
addGetConnectionBehavior
(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 TransportRequest>
voidaddRequestHandlingBehavior
(String actionName, StubbableTransport.RequestHandlingBehavior<R> handlingBehavior) Adds a new handling behavior that is used when the defined request is received.boolean
addSendBehavior
(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
(TransportService transportService, StubbableTransport.SendRequestBehavior sendBehavior) Adds a new send behavior that is used for communication with the given delegate service.void
addUnresponsiveRule
(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
(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
(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
(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
(TransportAddress transportAddress) Clears the outbound rules associated with the provided delegate address.void
clearOutboundRules
(TransportService transportService) Clears the outbound rules associated with the provided delegate service.static MockTransportService
createNewService
(Settings settings, VersionInformation version, TransportVersion transportVersion, ThreadPool threadPool) static MockTransportService
createNewService
(Settings settings, VersionInformation version, TransportVersion transportVersion, ThreadPool threadPool, ClusterSettings clusterSettings) static MockTransportService
createNewService
(Settings settings, Transport transport, VersionInformation version, ThreadPool threadPool, ClusterSettings clusterSettings, Set<String> taskHeaders) static MockTransportService
createNewService
(Settings settings, Transport transport, VersionInformation version, ThreadPool threadPool, ClusterSettings clusterSettings, Set<String> taskHeaders, TransportInterceptor interceptor) protected void
doClose()
protected void
doStop()
static MockTransportService
getInstance
(String nodeName) static TcpTransport
newMockTransport
(Settings settings, TransportVersion version, ThreadPool threadPool) static TcpTransport
newMockTransport
(Settings settings, TransportVersion version, ThreadPool threadPool, NamedWriteableRegistry namedWriteableRegistry) void
openConnection
(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) Methods inherited from class org.elasticsearch.transport.TransportService
acceptIncomingRequests, addConnectionListener, addMessageListener, addressesFromString, boundAddress, boundRemoteAccessAddress, connectionValidator, connectToNode, connectToNode, disconnectFromNode, doStart, getConnection, getConnectionManager, getDefaultSeedAddresses, getLocalNode, getLocalNodeConnection, getRemoteClusterService, getRequestHandler, getTaskManager, getThreadPool, handleInternalSendException, 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, 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(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor, @Nullable 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(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, @Nullable 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
.
-
MockTransportService
public MockTransportService(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor, Function<BoundTransportAddress, DiscoveryNode> localNodeFactory, @Nullable ClusterSettings clusterSettings)
-
-
Method Details
-
createNewService
public static MockTransportService createNewService(Settings settings, VersionInformation version, TransportVersion transportVersion, ThreadPool threadPool) -
createNewService
public static MockTransportService createNewService(Settings settings, VersionInformation version, TransportVersion transportVersion, ThreadPool threadPool, @Nullable ClusterSettings clusterSettings) -
newMockTransport
public static TcpTransport newMockTransport(Settings settings, TransportVersion version, ThreadPool threadPool) -
newMockTransport
public static TcpTransport newMockTransport(Settings settings, TransportVersion version, ThreadPool threadPool, NamedWriteableRegistry namedWriteableRegistry) -
createNewService
public static MockTransportService createNewService(Settings settings, Transport transport, VersionInformation version, ThreadPool threadPool, @Nullable ClusterSettings clusterSettings, Set<String> taskHeaders) -
createNewService
public static MockTransportService createNewService(Settings settings, Transport transport, VersionInformation version, ThreadPool threadPool, @Nullable ClusterSettings clusterSettings, Set<String> taskHeaders, TransportInterceptor interceptor) -
getInstance
-
clearAllRules
public void clearAllRules()Clears all the registered rules. -
clearInboundRules
public void clearInboundRules()Clears all the inbound rules. -
clearOutboundRules
Clears the outbound rules associated with the provided delegate service. -
clearOutboundRules
Clears the outbound rules associated with the provided delegate address. -
addFailToSendNoConnectRule
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
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
Adds a rule that will cause matching operations to throw ConnectTransportExceptions -
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(TransportService transportService, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptions -
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(TransportAddress transportAddress, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptions -
addUnresponsiveRule
Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added. -
addUnresponsiveRule
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(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(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 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(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(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(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(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(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
-
openConnection
public void openConnection(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) - Overrides:
openConnection
in classTransportService
-
addOnStopListener
-
doStop
protected void doStop()- Overrides:
doStop
in classTransportService
-
doClose
- Overrides:
doClose
in classTransportService
- Throws:
IOException
-
getLocalDiscoNode
-