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:
Closeable
,AutoCloseable
,Client
,ElasticsearchClient
,org.elasticsearch.core.Releasable
- Enclosing class:
- RestActionTestCase
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(java.util.function.BiFunction<org.elasticsearch.action.ActionType<R>, org.elasticsearch.action.ActionRequest, R>)
or setExecuteLocallyVerifier(java.util.function.BiFunction<org.elasticsearch.action.ActionType<?>, org.elasticsearch.action.ActionRequest, org.elasticsearch.action.ActionResponse>)
.-
Field Summary
Fields inherited from class org.elasticsearch.client.support.AbstractClient
logger, settings
Fields inherited from interface org.elasticsearch.client.Client
CLIENT_TYPE_SETTING_S
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<Request extends ActionRequest,
Response extends ActionResponse>
voiddoExecute
(ActionType<Response> action, Request request, ActionListener<Response> listener) <Request extends ActionRequest,
Response extends ActionResponse>
TaskexecuteLocally
(ActionType<Response> action, Request request, ActionListener<Response> listener) <Request extends ActionRequest,
Response extends ActionResponse>
TaskexecuteLocally
(ActionType<Response> action, Request request, TaskListener<Response> listener) void
reset()
Clears any previously set verifier functions set bysetExecuteVerifier(java.util.function.BiFunction<org.elasticsearch.action.ActionType<R>, org.elasticsearch.action.ActionRequest, R>)
and/orsetExecuteLocallyVerifier(java.util.function.BiFunction<org.elasticsearch.action.ActionType<?>, org.elasticsearch.action.ActionRequest, org.elasticsearch.action.ActionResponse>)
.void
setExecuteLocallyVerifier
(BiFunction<ActionType<?>, ActionRequest, ActionResponse> verifier) Sets the function that will be called whenexecuteLocally(ActionType, ActionRequest, TaskListener)
is called.<R extends ActionResponse>
voidsetExecuteVerifier
(BiFunction<ActionType<R>, ActionRequest, R> verifier) Sets the function that will be called whendoExecute(ActionType, ActionRequest, ActionListener)
is called.Methods inherited from class org.elasticsearch.test.client.NoOpNodeClient
close, getExecutionCount, getRemoteClusterClient, initialize
Methods inherited from class org.elasticsearch.client.node.NodeClient
getNamedWriteableRegistry
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
-
-
Method Details
-
getLocalNodeId
- Overrides:
getLocalNodeId
in classNoOpNodeClient
-
reset
public void reset()Clears any previously set verifier functions set bysetExecuteVerifier(java.util.function.BiFunction<org.elasticsearch.action.ActionType<R>, org.elasticsearch.action.ActionRequest, R>)
and/orsetExecuteLocallyVerifier(java.util.function.BiFunction<org.elasticsearch.action.ActionType<?>, org.elasticsearch.action.ActionRequest, org.elasticsearch.action.ActionResponse>)
. These functions are replaced with functions which will throw anAssertionError
if called. -
setExecuteVerifier
public <R extends ActionResponse> void setExecuteVerifier(BiFunction<ActionType<R>, ActionRequest, R> verifier) Sets the function that will be called whendoExecute(ActionType, ActionRequest, ActionListener)
is called. The given function should return a subclass ofActionResponse
that is appropriate for the action.- Parameters:
verifier
- A function which is called in place ofdoExecute(ActionType, ActionRequest, ActionListener)
-
doExecute
public <Request extends ActionRequest,Response extends ActionResponse> void doExecute(ActionType<Response> action, Request request, ActionListener<Response> listener) - Overrides:
doExecute
in classNoOpNodeClient
-
setExecuteLocallyVerifier
public void setExecuteLocallyVerifier(BiFunction<ActionType<?>, ActionRequest, ActionResponse> 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 ActionRequest,Response extends ActionResponse> Task executeLocally(ActionType<Response> action, Request request, ActionListener<Response> listener) - Overrides:
executeLocally
in classNoOpNodeClient
-
executeLocally
public <Request extends ActionRequest,Response extends ActionResponse> Task executeLocally(ActionType<Response> action, Request request, TaskListener<Response> listener) - Overrides:
executeLocally
in classNoOpNodeClient
-