Package org.elasticsearch.test.rest
Class RestActionTestCase.VerifyingClient
java.lang.Object
org.elasticsearch.client.support.AbstractClient
org.elasticsearch.client.node.NodeClient
org.elasticsearch.test.client.NoOpNodeClient
org.elasticsearch.test.rest.RestActionTestCase.VerifyingClient
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,org.elasticsearch.client.Client
,org.elasticsearch.client.ElasticsearchClient
,org.elasticsearch.common.lease.Releasable
- Enclosing class:
- RestActionTestCase
public static class RestActionTestCase.VerifyingClient extends NoOpNodeClient
A mocked
NodeClient
which can be easily reconfigured to verify arbitrary verification
functions, and can be reset to allow reconfiguration partway through a test without having to construct a new object.
By default, will throw AssertionError
when any execution method is called, unless configured otherwise using
setExecuteVerifier(BiFunction)
or setExecuteLocallyVerifier(BiFunction)
.-
Field Summary
-
Constructor Summary
Constructors Constructor Description VerifyingClient(java.lang.String testName)
-
Method Summary
Modifier and Type Method Description <Request extends org.elasticsearch.action.ActionRequest, Response extends org.elasticsearch.action.ActionResponse>
voiddoExecute(org.elasticsearch.action.ActionType<Response> action, Request request, org.elasticsearch.action.ActionListener<Response> listener)
<Request extends org.elasticsearch.action.ActionRequest, Response extends org.elasticsearch.action.ActionResponse>
org.elasticsearch.tasks.TaskexecuteLocally(org.elasticsearch.action.ActionType<Response> action, Request request, org.elasticsearch.action.ActionListener<Response> listener)
<Request extends org.elasticsearch.action.ActionRequest, Response extends org.elasticsearch.action.ActionResponse>
org.elasticsearch.tasks.TaskexecuteLocally(org.elasticsearch.action.ActionType<Response> action, Request request, org.elasticsearch.tasks.TaskListener<Response> listener)
void
reset()
Clears any previously set verifier functions set bysetExecuteVerifier(BiFunction)
and/orsetExecuteLocallyVerifier(BiFunction)
.<Request extends org.elasticsearch.action.ActionRequest, Response extends org.elasticsearch.action.ActionResponse>
voidsetExecuteLocallyVerifier(java.util.function.BiFunction<org.elasticsearch.action.ActionType<Response>,Request,java.lang.Void> verifier)
Sets the function that will be called whenexecuteLocally(ActionType, ActionRequest, TaskListener)
is called.<Request extends org.elasticsearch.action.ActionRequest, Response extends org.elasticsearch.action.ActionResponse>
voidsetExecuteVerifier(java.util.function.BiFunction<org.elasticsearch.action.ActionType<Response>,Request,java.lang.Void> verifier)
Sets the function that will be called whendoExecute(ActionType, ActionRequest, ActionListener)
is called.Methods inherited from class org.elasticsearch.test.client.NoOpNodeClient
close, getLocalNodeId, getRemoteClusterClient, initialize
Methods inherited from class org.elasticsearch.client.support.AbstractClient
admin, bulk, bulk, clearScroll, clearScroll, delete, delete, execute, execute, explain, explain, fieldCaps, fieldCaps, filterWithHeader, get, get, index, index, multiGet, multiGet, multiSearch, multiSearch, multiTermVectors, multiTermVectors, prepareBulk, prepareBulk, prepareClearScroll, prepareDelete, prepareDelete, prepareExplain, prepareFieldCaps, prepareGet, prepareGet, prepareIndex, prepareIndex, prepareIndex, prepareMultiGet, prepareMultiSearch, prepareMultiTermVectors, prepareSearch, prepareSearchScroll, prepareTermVectors, prepareTermVectors, prepareUpdate, prepareUpdate, search, search, searchScroll, searchScroll, settings, termVectors, termVectors, threadPool, update, update
-
Constructor Details
-
VerifyingClient
public VerifyingClient(java.lang.String testName)
-
-
Method Details
-
reset
public void reset()Clears any previously set verifier functions set bysetExecuteVerifier(BiFunction)
and/orsetExecuteLocallyVerifier(BiFunction)
. These functions are replaced with functions which will throw anAssertionError
if called. -
setExecuteVerifier
public <Request extends org.elasticsearch.action.ActionRequest, Response extends org.elasticsearch.action.ActionResponse> void setExecuteVerifier(java.util.function.BiFunction<org.elasticsearch.action.ActionType<Response>,Request,java.lang.Void> verifier)Sets the function that will be called whendoExecute(ActionType, ActionRequest, ActionListener)
is called. The given function should return either a subclass ofActionResponse
ornull
.- Parameters:
verifier
- A function which is called in place ofdoExecute(ActionType, ActionRequest, ActionListener)
-
doExecute
public <Request extends org.elasticsearch.action.ActionRequest, Response extends org.elasticsearch.action.ActionResponse> void doExecute(org.elasticsearch.action.ActionType<Response> action, Request request, org.elasticsearch.action.ActionListener<Response> listener)- Overrides:
doExecute
in classNoOpNodeClient
-
setExecuteLocallyVerifier
public <Request extends org.elasticsearch.action.ActionRequest, Response extends org.elasticsearch.action.ActionResponse> void setExecuteLocallyVerifier(java.util.function.BiFunction<org.elasticsearch.action.ActionType<Response>,Request,java.lang.Void> verifier)Sets the function that will be called whenexecuteLocally(ActionType, ActionRequest, TaskListener)
is called. The given function should return either a subclass ofActionResponse
ornull
.- Parameters:
verifier
- A function which is called in place ofexecuteLocally(ActionType, ActionRequest, TaskListener)
-
executeLocally
public <Request extends org.elasticsearch.action.ActionRequest, Response extends org.elasticsearch.action.ActionResponse> org.elasticsearch.tasks.Task executeLocally(org.elasticsearch.action.ActionType<Response> action, Request request, org.elasticsearch.action.ActionListener<Response> listener)- Overrides:
executeLocally
in classNoOpNodeClient
-
executeLocally
public <Request extends org.elasticsearch.action.ActionRequest, Response extends org.elasticsearch.action.ActionResponse> org.elasticsearch.tasks.Task executeLocally(org.elasticsearch.action.ActionType<Response> action, Request request, org.elasticsearch.tasks.TaskListener<Response> listener)- Overrides:
executeLocally
in classNoOpNodeClient
-