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, org.elasticsearch.common.component.LifecycleComponent, org.elasticsearch.common.lease.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 
    Modifier and Type Class Description
    static class  MockTransportService.TestPlugin  

    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

    Constructors 
    Constructor Description
    MockTransportService​(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.transport.Transport transport, org.elasticsearch.threadpool.ThreadPool threadPool, org.elasticsearch.transport.TransportInterceptor interceptor, java.util.function.Function<org.elasticsearch.common.transport.BoundTransportAddress,​org.elasticsearch.cluster.node.DiscoveryNode> localNodeFactory, org.elasticsearch.common.settings.ClusterSettings clusterSettings, java.util.Set<java.lang.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 Type Method Description
    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.
    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, java.util.Set<java.lang.String> blockedActions)
    Adds a rule that will cause matching operations to throw ConnectTransportExceptions
    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.
    void addFailToSendNoConnectRule​(org.elasticsearch.transport.TransportService transportService, java.lang.String... blockedActions)
    Adds a rule that will cause matching operations to throw ConnectTransportExceptions
    void addFailToSendNoConnectRule​(org.elasticsearch.transport.TransportService transportService, java.util.Set<java.lang.String> blockedActions)
    Adds a rule that will cause matching operations to throw ConnectTransportExceptions
    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.
    boolean addGetConnectionBehavior​(StubbableConnectionManager.GetConnectionBehavior behavior)
    Adds a get connection behavior that is the default get connection behavior.
    boolean addNodeConnectedBehavior​(StubbableConnectionManager.NodeConnectedBehavior behavior)
    Adds a node connected behavior that is the default node connected behavior.
    void addOnStopListener​(java.lang.Runnable listener)  
    <R extends org.elasticsearch.transport.TransportRequest>
    void
    addRequestHandlingBehavior​(java.lang.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 addSendBehavior​(StubbableTransport.SendRequestBehavior behavior)
    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.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.
    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.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.
    void clearAllRules()
    Clears all the registered rules.
    void clearInboundRules()
    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.
    StubbableConnectionManager connectionManager()  
    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, java.util.Set<java.lang.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, java.util.Set<java.lang.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, java.util.Set<java.lang.String> taskHeaders)  
    protected void doClose()  
    protected void doStop()  
    org.elasticsearch.cluster.node.DiscoveryNode getLocalDiscoNode()  
    org.elasticsearch.transport.Transport getOriginalTransport()  
    static MockNioTransport newMockTransport​(org.elasticsearch.common.settings.Settings settings, org.elasticsearch.Version version, org.elasticsearch.threadpool.ThreadPool threadPool)  
    org.elasticsearch.transport.Transport.Connection openConnection​(org.elasticsearch.cluster.node.DiscoveryNode node, org.elasticsearch.transport.ConnectionProfile profile)  
    StubbableTransport transport()  

    Methods inherited from class org.elasticsearch.transport.TransportService

    acceptIncomingRequests, addConnectionListener, addMessageListener, addressesFromString, boundAddress, connectionValidator, connectToNode, connectToNode, connectToNode, connectToNode, disconnectFromNode, doStart, getConnection, getConnectionManager, getDefaultSeedAddresses, getLocalNode, getRemoteClusterService, getRequestHandler, getTaskManager, getThreadPool, handshake, handshake, info, isTransportSecure, isValidActionName, nodeConnected, onConnectionClosed, onRequestReceived, onRequestSent, onResponseReceived, onResponseSent, onResponseSent, openConnection, registerRequestHandler, registerRequestHandler, removeConnectionListener, removeMessageListener, sendChildRequest, sendChildRequest, sendChildRequest, sendRequest, sendRequest, sendRequest, shouldTraceAction, stats, submitRequest, submitRequest

    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 the ClusterSettings for settings updates for TransportSettings.TRACE_LOG_EXCLUDE_SETTING and TransportSettings.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, java.util.function.Function<org.elasticsearch.common.transport.BoundTransportAddress,​org.elasticsearch.cluster.node.DiscoveryNode> localNodeFactory, @Nullable org.elasticsearch.common.settings.ClusterSettings clusterSettings, java.util.Set<java.lang.String> taskHeaders)
      Build the service.
      Parameters:
      clusterSettings - if non null the TransportService will register with the ClusterSettings for settings updates for TransportSettings.TRACE_LOG_EXCLUDE_SETTING and TransportSettings.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 MockNioTransport 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, java.util.Set<java.lang.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, java.util.Set<java.lang.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, java.util.Set<java.lang.String> taskHeaders)
      Overrides:
      createTaskManager in class org.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, java.lang.String... blockedActions)
      Adds a rule that will cause matching operations to throw ConnectTransportExceptions
    • addFailToSendNoConnectRule

      public void addFailToSendNoConnectRule​(org.elasticsearch.transport.TransportService transportService, java.util.Set<java.lang.String> blockedActions)
      Adds a rule that will cause matching operations to throw ConnectTransportExceptions
    • addFailToSendNoConnectRule

      public void addFailToSendNoConnectRule​(org.elasticsearch.common.transport.TransportAddress transportAddress, java.util.Set<java.lang.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.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.elasticsearch.common.transport.TransportAddress transportAddress, org.elasticsearch.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.elasticsearch.transport.TransportRequest> void addRequestHandlingBehavior​(java.lang.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

      public boolean addSendBehavior​(StubbableTransport.SendRequestBehavior behavior)
      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

      public boolean addGetConnectionBehavior​(StubbableConnectionManager.GetConnectionBehavior behavior)
      Adds a get connection behavior that is the default get connection behavior.
      Returns:
      true if no default get connection behavior was registered.
    • addNodeConnectedBehavior

      public boolean addNodeConnectedBehavior​(StubbableConnectionManager.NodeConnectedBehavior behavior)
      Adds a node connected behavior that is the default node connected behavior.
      Returns:
      true if no default node connected behavior was registered.
    • transport

      public StubbableTransport transport()
    • connectionManager

      public StubbableConnectionManager connectionManager()
    • getOriginalTransport

      public org.elasticsearch.transport.Transport getOriginalTransport()
    • openConnection

      public org.elasticsearch.transport.Transport.Connection openConnection​(org.elasticsearch.cluster.node.DiscoveryNode node, org.elasticsearch.transport.ConnectionProfile profile)
      Overrides:
      openConnection in class org.elasticsearch.transport.TransportService
    • addOnStopListener

      public void addOnStopListener​(java.lang.Runnable listener)
    • doStop

      protected void doStop()
      Overrides:
      doStop in class org.elasticsearch.transport.TransportService
    • doClose

      protected void doClose() throws java.io.IOException
      Overrides:
      doClose in class org.elasticsearch.transport.TransportService
      Throws:
      java.io.IOException
    • getLocalDiscoNode

      public org.elasticsearch.cluster.node.DiscoveryNode getLocalDiscoNode()