Package org.elasticsearch.test.transport
Class MockTransport
- java.lang.Object
-
- org.elasticsearch.test.transport.MockTransport
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,LifecycleComponent
,Releasable
,Transport
- Direct Known Subclasses:
CapturingTransport
,DisruptableMockTransport
public class MockTransport extends java.lang.Object implements Transport, LifecycleComponent
A basic transport implementation that allows to intercept requests that have been sent
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.elasticsearch.transport.Transport
Transport.Connection, Transport.ResponseContext<T extends TransportResponse>, Transport.ResponseHandlers
-
-
Constructor Summary
Constructors Constructor Description MockTransport()
-
Method Summary
Modifier and Type Method Description void
addLifecycleListener(LifecycleListener listener)
TransportAddress[]
addressesFromString(java.lang.String address)
BoundTransportAddress
boundAddress()
void
close()
Transport.Connection
createConnection(DiscoveryNode node)
TransportService
createTransportService(Settings settings, ThreadPool threadPool, TransportInterceptor interceptor, java.util.function.Function<BoundTransportAddress,DiscoveryNode> localNodeFactory, ClusterSettings clusterSettings, java.util.Set<java.lang.String> taskHeaders)
java.util.List<java.lang.String>
getDefaultSeedAddresses()
RequestHandlerRegistry<TransportRequest>
getRequestHandler(java.lang.String action)
Transport.ResponseHandlers
getResponseHandlers()
TransportStats
getStats()
void
handleError(long requestId, TransportException e)
simulate an error for the given requestId, unlikehandleLocalError(long, Throwable)
andhandleRemoteError(long, Throwable)
, the provided exception will not be wrapped but will be delivered to the transport layer as isvoid
handleLocalError(long requestId, java.lang.Throwable t)
simulate a local error for the given requestId, will be wrapped by aSendRequestTransportException
void
handleRemoteError(long requestId, java.lang.Throwable t)
simulate a remote error for the given requestId, will be wrapped by aRemoteTransportException
<Response extends TransportResponse>
voidhandleResponse(long requestId, Response response)
simulate a response for the given requestIdLifecycle.State
lifecycleState()
protected void
onSendRequest(long requestId, java.lang.String action, TransportRequest request, DiscoveryNode node)
void
openConnection(DiscoveryNode node, ConnectionProfile profile, ActionListener<Transport.Connection> listener)
java.util.Map<java.lang.String,BoundTransportAddress>
profileBoundAddresses()
<Request extends TransportRequest>
voidregisterRequestHandler(RequestHandlerRegistry<Request> reg)
void
removeLifecycleListener(LifecycleListener listener)
void
setMessageListener(TransportMessageListener listener)
void
start()
void
stop()
protected NamedWriteableRegistry
writeableRegistry()
-
-
-
Method Detail
-
createTransportService
public TransportService createTransportService(Settings settings, ThreadPool threadPool, TransportInterceptor interceptor, java.util.function.Function<BoundTransportAddress,DiscoveryNode> localNodeFactory, @Nullable ClusterSettings clusterSettings, java.util.Set<java.lang.String> taskHeaders)
-
handleResponse
public <Response extends 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 aSendRequestTransportException
- Parameters:
requestId
- the id corresponding to the captured send requestt
- 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 aRemoteTransportException
- Parameters:
requestId
- the id corresponding to the captured send requestt
- the failure to wrap
-
handleError
public void handleError(long requestId, TransportException e)
simulate an error for the given requestId, unlikehandleLocalError(long, Throwable)
andhandleRemoteError(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 requeste
- the failure
-
openConnection
public void openConnection(DiscoveryNode node, ConnectionProfile profile, ActionListener<Transport.Connection> listener)
- Specified by:
openConnection
in interfaceTransport
-
createConnection
public Transport.Connection createConnection(DiscoveryNode node)
-
onSendRequest
protected void onSendRequest(long requestId, java.lang.String action, TransportRequest request, DiscoveryNode node)
-
getStats
public TransportStats getStats()
-
boundAddress
public BoundTransportAddress boundAddress()
- Specified by:
boundAddress
in interfaceTransport
-
profileBoundAddresses
public java.util.Map<java.lang.String,BoundTransportAddress> profileBoundAddresses()
- Specified by:
profileBoundAddresses
in interfaceTransport
-
addressesFromString
public TransportAddress[] addressesFromString(java.lang.String address)
- Specified by:
addressesFromString
in interfaceTransport
-
lifecycleState
public Lifecycle.State lifecycleState()
- Specified by:
lifecycleState
in interfaceLifecycleComponent
-
addLifecycleListener
public void addLifecycleListener(LifecycleListener listener)
- Specified by:
addLifecycleListener
in interfaceLifecycleComponent
-
removeLifecycleListener
public void removeLifecycleListener(LifecycleListener listener)
- Specified by:
removeLifecycleListener
in interfaceLifecycleComponent
-
start
public void start()
- Specified by:
start
in interfaceLifecycleComponent
-
stop
public void stop()
- Specified by:
stop
in interfaceLifecycleComponent
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceReleasable
-
getDefaultSeedAddresses
public java.util.List<java.lang.String> getDefaultSeedAddresses()
- Specified by:
getDefaultSeedAddresses
in interfaceTransport
-
registerRequestHandler
public <Request extends TransportRequest> void registerRequestHandler(RequestHandlerRegistry<Request> reg)
- Specified by:
registerRequestHandler
in interfaceTransport
-
getResponseHandlers
public Transport.ResponseHandlers getResponseHandlers()
- Specified by:
getResponseHandlers
in interfaceTransport
-
getRequestHandler
public RequestHandlerRegistry<TransportRequest> getRequestHandler(java.lang.String action)
- Specified by:
getRequestHandler
in interfaceTransport
-
setMessageListener
public void setMessageListener(TransportMessageListener listener)
- Specified by:
setMessageListener
in interfaceTransport
-
writeableRegistry
protected NamedWriteableRegistry writeableRegistry()
-
-