Class MockTransport

java.lang.Object
org.elasticsearch.test.transport.StubbableTransport
org.elasticsearch.test.transport.MockTransport
All Implemented Interfaces:
java.io.Closeable, java.lang.AutoCloseable, org.elasticsearch.common.component.LifecycleComponent, org.elasticsearch.common.lease.Releasable, org.elasticsearch.transport.Transport
Direct Known Subclasses:
CapturingTransport, DisruptableMockTransport

public class MockTransport
extends StubbableTransport
A basic transport implementation that allows to intercept requests that have been sent
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.elasticsearch.test.transport.StubbableTransport

    StubbableTransport.OpenConnectionBehavior, StubbableTransport.RequestHandlingBehavior<Request extends org.elasticsearch.transport.TransportRequest>, StubbableTransport.SendRequestBehavior, StubbableTransport.WrappedConnection

    Nested classes/interfaces inherited from interface org.elasticsearch.transport.Transport

    org.elasticsearch.transport.Transport.Connection, org.elasticsearch.transport.Transport.RequestHandlers, org.elasticsearch.transport.Transport.ResponseContext<T extends org.elasticsearch.transport.TransportResponse>, org.elasticsearch.transport.Transport.ResponseHandlers
  • Constructor Summary

    Constructors
    Constructor Description
    MockTransport()  
  • Method Summary

    Modifier and Type Method Description
    org.elasticsearch.transport.Transport.Connection createConnection​(org.elasticsearch.cluster.node.DiscoveryNode node)  
    org.elasticsearch.transport.TransportService createTransportService​(org.elasticsearch.common.settings.Settings settings, 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)  
    void handleError​(long requestId, org.elasticsearch.transport.TransportException e)
    simulate an error for the given requestId, unlike handleLocalError(long, Throwable) and handleRemoteError(long, Throwable), the provided exception will not be wrapped but will be delivered to the transport layer as is
    void handleLocalError​(long requestId, java.lang.Throwable t)
    simulate a local error for the given requestId, will be wrapped by a SendRequestTransportException
    void handleRemoteError​(long requestId, java.lang.Throwable t)
    simulate a remote error for the given requestId, will be wrapped by a RemoteTransportException
    <Response extends org.elasticsearch.transport.TransportResponse>
    void
    handleResponse​(long requestId, Response response)
    simulate a response for the given requestId
    protected void onSendRequest​(long requestId, java.lang.String action, org.elasticsearch.transport.TransportRequest request, org.elasticsearch.cluster.node.DiscoveryNode node)  
    void setMessageListener​(org.elasticsearch.transport.TransportMessageListener listener)  
    protected org.elasticsearch.common.io.stream.NamedWriteableRegistry writeableRegistry()  

    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.Transport

    isSecure, registerRequestHandler, setSlowLogThreshold
  • Constructor Details

    • MockTransport

      public MockTransport()
  • Method Details

    • createTransportService

      public org.elasticsearch.transport.TransportService createTransportService​(org.elasticsearch.common.settings.Settings settings, 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)
    • handleResponse

      public <Response extends org.elasticsearch.transport.TransportResponse> void handleResponse​(long requestId, Response response)
      simulate a response for the given requestId
    • handleLocalError

      public void handleLocalError​(long requestId, java.lang.Throwable t)
      simulate a local error for the given requestId, will be wrapped by a SendRequestTransportException
      Parameters:
      requestId - the id corresponding to the captured send request
      t - the failure to wrap
    • handleRemoteError

      public void handleRemoteError​(long requestId, java.lang.Throwable t)
      simulate a remote error for the given requestId, will be wrapped by a RemoteTransportException
      Parameters:
      requestId - the id corresponding to the captured send request
      t - the failure to wrap
    • handleError

      public void handleError​(long requestId, org.elasticsearch.transport.TransportException e)
      simulate an error for the given requestId, unlike handleLocalError(long, Throwable) and handleRemoteError(long, Throwable), the provided exception will not be wrapped but will be delivered to the transport layer as is
      Parameters:
      requestId - the id corresponding to the captured send request
      e - the failure
    • createConnection

      public org.elasticsearch.transport.Transport.Connection createConnection​(org.elasticsearch.cluster.node.DiscoveryNode node)
    • onSendRequest

      protected void onSendRequest​(long requestId, java.lang.String action, org.elasticsearch.transport.TransportRequest request, org.elasticsearch.cluster.node.DiscoveryNode node)
    • setMessageListener

      public void setMessageListener​(org.elasticsearch.transport.TransportMessageListener listener)
      Specified by:
      setMessageListener in interface org.elasticsearch.transport.Transport
      Overrides:
      setMessageListener in class StubbableTransport
    • writeableRegistry

      protected org.elasticsearch.common.io.stream.NamedWriteableRegistry writeableRegistry()