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:
java.io.Closeable,java.lang.AutoCloseable,LifecycleComponent,Releasable,TransportConnectionListener,TransportMessageListener
public final class MockTransportService extends 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.zen.ping.unicast.UnicastZenPing, which constructs fake DiscoveryNode instances where the publish address is one of the bound addresses).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMockTransportService.TestPluginstatic classMockTransportService.Tracer-
Nested classes/interfaces inherited from class org.elasticsearch.transport.TransportService
TransportService.ContextRestoreResponseHandler<T extends TransportResponse>, TransportService.HandshakeResponse
-
-
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
-
-
Constructor Summary
Constructors Constructor Description MockTransportService(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor, java.util.function.Function<BoundTransportAddress,DiscoveryNode> localNodeFactory, ClusterSettings clusterSettings, java.util.Set<java.lang.String> taskHeaders)Build the service.MockTransportService(Settings settings, Transport transport, ThreadPool threadPool, TransportInterceptor interceptor, ClusterSettings clusterSettings)Build the service.
-
Method Summary
Modifier and Type Method Description booleanaddConnectBehavior(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, java.lang.String... blockedActions)Adds a rule that will cause matching operations to throw ConnectTransportExceptionsvoidaddFailToSendNoConnectRule(TransportAddress transportAddress, java.util.Set<java.lang.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, java.lang.String... blockedActions)Adds a rule that will cause matching operations to throw ConnectTransportExceptionsvoidaddFailToSendNoConnectRule(TransportService transportService, java.util.Set<java.lang.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.booleanaddGetConnectionBehavior(StubbableConnectionManager.GetConnectionBehavior behavior)Adds a get connection behavior that is the default get connection behavior.booleanaddGetConnectionBehavior(TransportService transportService, StubbableConnectionManager.GetConnectionBehavior behavior)Adds a new get connection behavior that is used for communication with the given delegate service.booleanaddNodeConnectedBehavior(TransportAddress transportAddress, StubbableConnectionManager.NodeConnectedBehavior behavior)Adds a node connected behavior that is used for the given delegate address.booleanaddNodeConnectedBehavior(StubbableConnectionManager.NodeConnectedBehavior behavior)Adds a node connected behavior that is the default node connected behavior.booleanaddNodeConnectedBehavior(TransportService transportService, StubbableConnectionManager.NodeConnectedBehavior behavior)Adds a node connected behavior that is used for the given delegate service.booleanaddSendBehavior(TransportAddress transportAddress, StubbableTransport.SendRequestBehavior sendBehavior)Adds a new send behavior that is used for communication with the given delegate address.booleanaddSendBehavior(StubbableTransport.SendRequestBehavior behavior)Adds 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.voidaddTracer(MockTransportService.Tracer tracer)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, 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, 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.voidclearAllRules()Clears all the registered rules.voidclearRule(TransportAddress transportAddress)Clears the rule associated with the provided delegate address.voidclearRule(TransportService transportService)Clears the rule associated with the provided delegate service.voidclearTracers()StubbableConnectionManagerconnectionManager()static MockTransportServicecreateNewService(Settings settings, Transport transport, Version version, ThreadPool threadPool, ClusterSettings clusterSettings, java.util.Set<java.lang.String> taskHeaders)static MockTransportServicecreateNewService(Settings settings, Version version, ThreadPool threadPool, ClusterSettings clusterSettings)protected TaskManagercreateTaskManager(Settings settings, ThreadPool threadPool, java.util.Set<java.lang.String> taskHeaders)protected voiddoClose()static TransportAddress[]extractTransportAddresses(TransportService transportService)DiscoveryNodegetLocalDiscoNode()TransportgetOriginalTransport()static MockTcpTransportnewMockTransport(Settings settings, Version version, ThreadPool threadPool)Transport.ConnectionopenConnection(DiscoveryNode node, ConnectionProfile profile)booleanremoveTracer(MockTransportService.Tracer tracer)protected booleantraceEnabled()protected voidtraceReceivedRequest(long requestId, java.lang.String action)protected voidtraceReceivedResponse(long requestId, DiscoveryNode sourceNode, java.lang.String action)protected voidtraceRequestSent(DiscoveryNode node, long requestId, java.lang.String action, TransportRequestOptions options)protected voidtraceResponseSent(long requestId, java.lang.String action)protected voidtraceResponseSent(long requestId, java.lang.String action, java.lang.Exception e)StubbableTransporttransport()-
Methods inherited from class org.elasticsearch.transport.TransportService
acceptIncomingRequests, addConnectionListener, addressesFromString, boundAddress, connectionValidator, connectToNode, connectToNode, disconnectFromNode, doStart, doStop, getConnection, getConnectionManager, getLocalAddresses, getLocalNode, getRemoteClusterService, getRequestHandler, getTaskManager, getThreadPool, handshake, handshake, info, isValidActionName, nodeConnected, onConnectionClosed, onRequestReceived, onRequestSent, onResponseReceived, onResponseSent, onResponseSent, registerRequestHandler, registerRequestHandler, registerRequestHandler, registerRequestHandler, removeConnectionListener, sendChildRequest, sendChildRequest, sendChildRequest, sendRequest, sendRequest, sendRequest, stats, submitRequest, submitRequest, traceUnresolvedResponse
-
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 Detail
-
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, java.util.function.Function<BoundTransportAddress,DiscoveryNode> localNodeFactory, @Nullable ClusterSettings clusterSettings, java.util.Set<java.lang.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.
-
-
Method Detail
-
createNewService
public static MockTransportService createNewService(Settings settings, Version version, ThreadPool threadPool, @Nullable ClusterSettings clusterSettings)
-
newMockTransport
public static MockTcpTransport newMockTransport(Settings settings, Version version, ThreadPool threadPool)
-
createNewService
public static MockTransportService createNewService(Settings settings, Transport transport, Version version, ThreadPool threadPool, @Nullable ClusterSettings clusterSettings, java.util.Set<java.lang.String> taskHeaders)
-
extractTransportAddresses
public static TransportAddress[] extractTransportAddresses(TransportService transportService)
-
createTaskManager
protected TaskManager createTaskManager(Settings settings, ThreadPool threadPool, java.util.Set<java.lang.String> taskHeaders)
- Overrides:
createTaskManagerin classTransportService
-
clearAllRules
public void clearAllRules()
Clears all the registered rules.
-
clearRule
public void clearRule(TransportService transportService)
Clears the rule associated with the provided delegate service.
-
clearRule
public void clearRule(TransportAddress transportAddress)
Clears the rule associated with the provided delegate address.
-
addFailToSendNoConnectRule
public void 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.
-
addFailToSendNoConnectRule
public 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.
-
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(TransportService transportService, java.lang.String... blockedActions)
Adds a rule that will cause matching operations to throw ConnectTransportExceptions
-
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(TransportAddress transportAddress, java.lang.String... blockedActions)
Adds a rule that will cause matching operations to throw ConnectTransportExceptions
-
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(TransportService transportService, java.util.Set<java.lang.String> blockedActions)
Adds a rule that will cause matching operations to throw ConnectTransportExceptions
-
addFailToSendNoConnectRule
public void addFailToSendNoConnectRule(TransportAddress transportAddress, java.util.Set<java.lang.String> blockedActions)
Adds a rule that will cause matching operations to throw ConnectTransportExceptions
-
addUnresponsiveRule
public 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.
-
addUnresponsiveRule
public 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.
-
addUnresponsiveRule
public void addUnresponsiveRule(TransportService transportService, 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, 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.
-
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
public boolean addSendBehavior(StubbableTransport.SendRequestBehavior behavior)
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(TransportService transportService, StubbableConnectionManager.GetConnectionBehavior behavior)
Adds a new get connection behavior that is used for communication with the given delegate service.- Returns:
trueif no other get connection behavior was registered for any of the addresses bound by delegate service.
-
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
public boolean addGetConnectionBehavior(StubbableConnectionManager.GetConnectionBehavior behavior)
Adds a get connection behavior that is the default get connection behavior.- Returns:
trueif no default get connection behavior was registered.
-
addNodeConnectedBehavior
public boolean addNodeConnectedBehavior(TransportService transportService, StubbableConnectionManager.NodeConnectedBehavior behavior)
Adds a node connected behavior that is used for the given delegate service.- Returns:
trueif no other node connected behavior was registered for any of the addresses bound by delegate service.
-
addNodeConnectedBehavior
public boolean addNodeConnectedBehavior(TransportAddress transportAddress, StubbableConnectionManager.NodeConnectedBehavior behavior)
Adds a node connected behavior that is used for the given delegate address.- Returns:
trueif no other node connected behavior was registered for this address before.
-
addNodeConnectedBehavior
public boolean addNodeConnectedBehavior(StubbableConnectionManager.NodeConnectedBehavior behavior)
Adds a node connected behavior that is the default node connected behavior.- Returns:
trueif no default node connected behavior was registered.
-
transport
public StubbableTransport transport()
-
connectionManager
public StubbableConnectionManager connectionManager()
-
addTracer
public void addTracer(MockTransportService.Tracer tracer)
-
removeTracer
public boolean removeTracer(MockTransportService.Tracer tracer)
-
clearTracers
public void clearTracers()
-
traceEnabled
protected boolean traceEnabled()
- Overrides:
traceEnabledin classTransportService
-
traceReceivedRequest
protected void traceReceivedRequest(long requestId, java.lang.String action)- Overrides:
traceReceivedRequestin classTransportService
-
traceResponseSent
protected void traceResponseSent(long requestId, java.lang.String action)- Overrides:
traceResponseSentin classTransportService
-
traceResponseSent
protected void traceResponseSent(long requestId, java.lang.String action, java.lang.Exception e)- Overrides:
traceResponseSentin classTransportService
-
traceReceivedResponse
protected void traceReceivedResponse(long requestId, DiscoveryNode sourceNode, java.lang.String action)- Overrides:
traceReceivedResponsein classTransportService
-
traceRequestSent
protected void traceRequestSent(DiscoveryNode node, long requestId, java.lang.String action, TransportRequestOptions options)
- Overrides:
traceRequestSentin classTransportService
-
getOriginalTransport
public Transport getOriginalTransport()
-
openConnection
public Transport.Connection openConnection(DiscoveryNode node, ConnectionProfile profile) throws java.io.IOException
- Overrides:
openConnectionin classTransportService- Throws:
java.io.IOException
-
doClose
protected void doClose() throws java.io.IOException- Overrides:
doClosein classTransportService- Throws:
java.io.IOException
-
getLocalDiscoNode
public DiscoveryNode getLocalDiscoNode()
-
-