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 ClassesNested classes/interfaces inherited from class org.elasticsearch.transport.TransportService
TransportService.ContextRestoreResponseHandler<T extends TransportResponse>, TransportService.HandshakeResponseNested 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, ENABLE_STACK_OVERFLOW_AVOIDANCE, HANDSHAKE_ACTION_NAME, NOOP_TRANSPORT_INTERCEPTOR, taskManager, threadPool, transport, VALID_ACTION_PREFIXESFields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycleFields inherited from interface org.elasticsearch.transport.TransportMessageListener
NOOP_LISTENER -
Constructor Summary
ConstructorsConstructorDescriptionMockTransportService(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 TypeMethodDescriptionbooleanaddConnectBehavior(TransportAddress transportAddress, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate address.booleanaddConnectBehavior(TransportService transportService, StubbableTransport.OpenConnectionBehavior connectBehavior) Adds a new connect behavior that is used for creating connections with the given delegate service.voidaddFailToSendNoConnectRule(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(TransportAddress transportAddress, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsvoidaddFailToSendNoConnectRule(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(TransportService transportService, String... blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsvoidaddFailToSendNoConnectRule(TransportService transportService, Set<String> blockedActions) Adds a rule that will cause matching operations to throw ConnectTransportExceptionsbooleanaddGetConnectionBehavior(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.voidaddMessageListener(TransportMessageListener listener) booleanAdds a node connected behavior that is the default node connected behavior.voidaddOnStopListener(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.booleanaddSendBehavior(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(TransportService transportService, StubbableTransport.SendRequestBehavior sendBehavior) Adds a new send behavior that is used for communication with the given delegate service.voidaddUnresponsiveRule(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(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.voidaddUnresponsiveRule(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(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.voidClears all the registered rules.voidClears all the inbound rules.voidclearOutboundRules(TransportAddress transportAddress) Clears the outbound rules associated with the provided delegate address.voidclearOutboundRules(TransportService transportService) Clears the outbound rules associated with the provided delegate service.static MockTransportServicecreateNewService(Settings settings, VersionInformation version, TransportVersion transportVersion, ThreadPool threadPool) static MockTransportServicecreateNewService(Settings settings, VersionInformation version, TransportVersion transportVersion, ThreadPool threadPool, ClusterSettings clusterSettings) static MockTransportServicecreateNewService(Settings settings, Transport transport, VersionInformation version, ThreadPool threadPool, ClusterSettings clusterSettings, Set<String> taskHeaders) static MockTransportServicecreateNewService(Settings settings, Transport transport, VersionInformation version, ThreadPool threadPool, ClusterSettings clusterSettings, Set<String> taskHeaders, TransportInterceptor interceptor) static TaskManagercreateTaskManager(Settings settings, ThreadPool threadPool, Set<String> taskHeaders, Tracer tracer) protected voiddoClose()protected voiddoStop()static MockTransportServicegetInstance(String nodeName) static TcpTransportnewMockTransport(Settings settings, TransportVersion version, ThreadPool threadPool) static TcpTransportnewMockTransport(Settings settings, TransportVersion version, ThreadPool threadPool, NamedWriteableRegistry namedWriteableRegistry) voidonConnectionClosed(Transport.Connection connection) voidonRequestReceived(long requestId, String action) voidonRequestSent(DiscoveryNode node, long requestId, String action, TransportRequest request, TransportRequestOptions options) voidonResponseReceived(long requestId, Transport.ResponseContext holder) voidonResponseSent(long requestId, String action) voidonResponseSent(long requestId, String action, Exception e) voidopenConnection(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) voidvoidMethods inherited from class org.elasticsearch.transport.TransportService
acceptIncomingRequests, addConnectionListener, addressesFromString, boundAddress, boundRemoteAccessAddress, connectionValidator, connectToNode, connectToNode, disconnectFromNode, doStart, getConnection, getConnectionManager, getDefaultSeedAddresses, getLocalNode, getLocalNodeConnection, getRemoteClusterService, getRequestHandler, getTaskManager, getThreadPool, handleInternalSendException, handshake, handshake, info, isDirectResponseChannel, isTransportSecure, isValidActionName, newNetworkBytesStream, nodeConnected, registerRequestHandler, registerRequestHandler, removeConnectionListener, sendChildRequest, sendChildRequest, sendChildRequest, sendRequest, sendRequest, sendRequest, shouldTraceAction, stats, unwrapConnectionMethods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 theClusterSettingsfor settings updates forTransportSettings.TRACE_LOG_EXCLUDE_SETTINGandTransportSettings.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 theClusterSettingsfor settings updates forTransportSettings.TRACE_LOG_EXCLUDE_SETTINGandTransportSettings.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
-
createTaskManager
public static TaskManager createTaskManager(Settings settings, ThreadPool threadPool, Set<String> taskHeaders, Tracer tracer) -
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:
trueif 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:
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(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(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(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
-
openConnection
public void openConnection(DiscoveryNode node, ConnectionProfile connectionProfile, ActionListener<Transport.Connection> listener) - Overrides:
openConnectionin classTransportService
-
setOnConnectionClosedCallback
-
onConnectionClosed
- Specified by:
onConnectionClosedin interfaceTransportConnectionListener- Overrides:
onConnectionClosedin classTransportService
-
addOnStopListener
-
doStop
protected void doStop()- Overrides:
doStopin classTransportService
-
doClose
- Overrides:
doClosein classTransportService- Throws:
IOException
-
onRequestReceived
- Specified by:
onRequestReceivedin interfaceTransportMessageListener- Overrides:
onRequestReceivedin classTransportService
-
onRequestSent
public void onRequestSent(DiscoveryNode node, long requestId, String action, TransportRequest request, TransportRequestOptions options) - Specified by:
onRequestSentin interfaceTransportMessageListener- Overrides:
onRequestSentin classTransportService
-
onResponseReceived
- Specified by:
onResponseReceivedin interfaceTransportMessageListener- Overrides:
onResponseReceivedin classTransportService
-
onResponseSent
- Specified by:
onResponseSentin interfaceTransportMessageListener- Overrides:
onResponseSentin classTransportService
-
onResponseSent
- Specified by:
onResponseSentin interfaceTransportMessageListener- Overrides:
onResponseSentin classTransportService
-
addMessageListener
-
removeMessageListener
-