Package org.elasticsearch.test.transport
Class CapturingTransport
- java.lang.Object
-
- org.elasticsearch.test.transport.CapturingTransport
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,LifecycleComponent,Releasable,Transport
public class CapturingTransport extends java.lang.Object implements Transport
A transport class that doesn't send anything but rather captures all requests for inspection from tests
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCapturingTransport.CapturedRequest-
Nested classes/interfaces inherited from interface org.elasticsearch.transport.Transport
Transport.Connection, Transport.ResponseContext<T extends TransportResponse>, Transport.ResponseHandlers
-
-
Constructor Summary
Constructors Constructor Description CapturingTransport()
-
Method Summary
Modifier and Type Method Description voidaddLifecycleListener(LifecycleListener listener)voidaddMessageListener(TransportMessageListener listener)TransportAddress[]addressesFromString(java.lang.String address, int perAddressLimit)BoundTransportAddressboundAddress()CapturingTransport.CapturedRequest[]capturedRequests()returns all requests captured so far.java.util.Map<java.lang.String,java.util.List<CapturingTransport.CapturedRequest>>capturedRequestsByTargetNode()returns all requests captured so far, grouped by target node.voidclear()clears captured requestsvoidclose()TransportServicecreateCapturingTransportService(Settings settings, ThreadPool threadPool, TransportInterceptor interceptor, java.util.function.Function<BoundTransportAddress,DiscoveryNode> localNodeFactory, ClusterSettings clusterSettings, java.util.Set<java.lang.String> taskHeaders)CapturingTransport.CapturedRequest[]getCapturedRequestsAndClear()Returns all requests captured so far.java.util.Map<java.lang.String,java.util.List<CapturingTransport.CapturedRequest>>getCapturedRequestsByTargetNodeAndClear()Returns all requests captured so far, grouped by target node.java.util.List<java.lang.String>getLocalAddresses()RequestHandlerRegistrygetRequestHandler(java.lang.String action)Transport.ResponseHandlersgetResponseHandlers()TransportStatsgetStats()voidhandleError(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 isvoidhandleLocalError(long requestId, java.lang.Throwable t)simulate a local error for the given requestId, will be wrapped by aSendRequestTransportExceptionvoidhandleRemoteError(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.StatelifecycleState()protected booleannodeConnected(DiscoveryNode discoveryNode)protected voidonSendRequest(long requestId, java.lang.String action, TransportRequest request, DiscoveryNode node)ReleasableopenConnection(DiscoveryNode node, ConnectionProfile profile, ActionListener<Transport.Connection> listener)java.util.Map<java.lang.String,BoundTransportAddress>profileBoundAddresses()<Request extends TransportRequest>
voidregisterRequestHandler(RequestHandlerRegistry<Request> reg)voidremoveLifecycleListener(LifecycleListener listener)booleanremoveMessageListener(TransportMessageListener listener)voidstart()voidstop()-
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
getInFlightRequestBreaker
-
-
-
-
Method Detail
-
createCapturingTransportService
public TransportService createCapturingTransportService(Settings settings, ThreadPool threadPool, TransportInterceptor interceptor, java.util.function.Function<BoundTransportAddress,DiscoveryNode> localNodeFactory, @Nullable ClusterSettings clusterSettings, java.util.Set<java.lang.String> taskHeaders)
-
capturedRequests
public CapturingTransport.CapturedRequest[] capturedRequests()
returns all requests captured so far. Doesn't clear the captured request list. Seeclear()
-
getCapturedRequestsAndClear
public CapturingTransport.CapturedRequest[] getCapturedRequestsAndClear()
Returns all requests captured so far. This method does clear the captured requests list. If you do not want the captured requests list cleared, usecapturedRequests().- Returns:
- the captured requests
-
capturedRequestsByTargetNode
public java.util.Map<java.lang.String,java.util.List<CapturingTransport.CapturedRequest>> capturedRequestsByTargetNode()
returns all requests captured so far, grouped by target node. Doesn't clear the captured request list. Seeclear()
-
getCapturedRequestsByTargetNodeAndClear
public java.util.Map<java.lang.String,java.util.List<CapturingTransport.CapturedRequest>> getCapturedRequestsByTargetNodeAndClear()
Returns all requests captured so far, grouped by target node. This method does clear the captured request list. If you do not want the captured requests list cleared, usecapturedRequestsByTargetNode().- Returns:
- the captured requests grouped by target node
-
clear
public void clear()
clears captured requests
-
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 Releasable openConnection(DiscoveryNode node, ConnectionProfile profile, ActionListener<Transport.Connection> listener)
- Specified by:
openConnectionin interfaceTransport
-
onSendRequest
protected void onSendRequest(long requestId, java.lang.String action, TransportRequest request, DiscoveryNode node)
-
nodeConnected
protected boolean nodeConnected(DiscoveryNode discoveryNode)
-
getStats
public TransportStats getStats()
-
boundAddress
public BoundTransportAddress boundAddress()
- Specified by:
boundAddressin interfaceTransport
-
profileBoundAddresses
public java.util.Map<java.lang.String,BoundTransportAddress> profileBoundAddresses()
- Specified by:
profileBoundAddressesin interfaceTransport
-
addressesFromString
public TransportAddress[] addressesFromString(java.lang.String address, int perAddressLimit)
- Specified by:
addressesFromStringin interfaceTransport
-
lifecycleState
public Lifecycle.State lifecycleState()
- Specified by:
lifecycleStatein interfaceLifecycleComponent
-
addLifecycleListener
public void addLifecycleListener(LifecycleListener listener)
- Specified by:
addLifecycleListenerin interfaceLifecycleComponent
-
removeLifecycleListener
public void removeLifecycleListener(LifecycleListener listener)
- Specified by:
removeLifecycleListenerin interfaceLifecycleComponent
-
start
public void start()
- Specified by:
startin interfaceLifecycleComponent
-
stop
public void stop()
- Specified by:
stopin interfaceLifecycleComponent
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfaceReleasable
-
getLocalAddresses
public java.util.List<java.lang.String> getLocalAddresses()
- Specified by:
getLocalAddressesin interfaceTransport
-
registerRequestHandler
public <Request extends TransportRequest> void registerRequestHandler(RequestHandlerRegistry<Request> reg)
- Specified by:
registerRequestHandlerin interfaceTransport
-
getResponseHandlers
public Transport.ResponseHandlers getResponseHandlers()
- Specified by:
getResponseHandlersin interfaceTransport
-
getRequestHandler
public RequestHandlerRegistry getRequestHandler(java.lang.String action)
- Specified by:
getRequestHandlerin interfaceTransport
-
addMessageListener
public void addMessageListener(TransportMessageListener listener)
- Specified by:
addMessageListenerin interfaceTransport
-
removeMessageListener
public boolean removeMessageListener(TransportMessageListener listener)
- Specified by:
removeMessageListenerin interfaceTransport
-
-