public class MockExecutor extends Executor
Executor
that can be injected to inject a set of canned
responses to requests including:
IOException
or ExecutorException
Executor.Default
Constructor and Description |
---|
MockExecutor() |
Modifier and Type | Method and Description |
---|---|
<T> T |
execute(com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T> request)
Executes the request, returning a response of the appropriate type.
|
<T> T |
execute(RequestCallable<T> request)
Executes the request, returning a response of the appropriate type.
|
<T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> |
passThruWhen(Class<C> requestType)
When the next request matches the given
requestType pass through the request's getJsonContent() cast to the expected response type. |
<T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> |
passThruWhen(Class<C> requestType,
com.google.common.base.Predicate<S> predicate)
When the next request matches the given
requestType and the provided user Predicate pass through the request's getJsonContent() cast to the expected response
type. |
boolean |
sawAll()
Did we see all of the expected requests?
|
boolean |
sawUnexpected()
Did we see any unexpected requests?
|
void |
sleep()
Surface this as a canonical means by which to sleep, so that clients can layer their own retry
logic on top of the executor using the same sleep facility;
|
<T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> |
throwWhen(Class<C> requestType,
ExecutorException exception)
When the next request matches the given
requestType throw exception instead of
responding. |
<T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> |
throwWhen(Class<C> requestType,
ExecutorException exception,
com.google.common.base.Predicate<S> predicate)
When the next request matches the given
requestType and the provided user Predicate throw exception instead of responding. |
<T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> |
throwWhen(Class<C> requestType,
IOException exception)
When the next request matches the given
requestType throw exception instead of
responding. |
<T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> |
throwWhen(Class<C> requestType,
IOException exception,
com.google.common.base.Predicate<S> predicate)
When the next request matches the given
requestType and the provided user Predicate throw exception instead of responding. |
<T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> |
when(Class<C> requestType,
T response)
When the next request matches the given
requestType return response as the
response. |
<T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> |
when(Class<C> requestType,
T response,
com.google.common.base.Predicate<S> predicate)
When the next request matches the given
requestType and the provided user Predicate return response as the response. |
public void sleep()
public <T> T execute(RequestCallable<T> request) throws IOException, ExecutorException
execute
in class Executor
T
- The type of the expected responserequest
- The request we are issuingIOException
- if anything goes wrongExecutorException
public <T> T execute(com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T> request) throws IOException, ExecutorException
execute
in class Executor
T
- The type of the expected responserequest
- The request we are issuingIOException
- if anything goes wrongExecutorException
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> void when(Class<C> requestType, T response, com.google.common.base.Predicate<S> predicate)
requestType
and the provided user Predicate
return response
as the response.public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void when(Class<C> requestType, T response)
requestType
return response
as the
response.public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> void throwWhen(Class<C> requestType, IOException exception, com.google.common.base.Predicate<S> predicate)
requestType
and the provided user Predicate
throw exception
instead of responding.public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void throwWhen(Class<C> requestType, IOException exception)
requestType
throw exception
instead of
responding.public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> void throwWhen(Class<C> requestType, ExecutorException exception, com.google.common.base.Predicate<S> predicate)
requestType
and the provided user Predicate
throw exception
instead of responding.public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void throwWhen(Class<C> requestType, ExecutorException exception)
requestType
throw exception
instead of
responding.public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>,C extends S> void passThruWhen(Class<C> requestType, com.google.common.base.Predicate<S> predicate)
requestType
and the provided user Predicate
pass through the request's getJsonContent()
cast to the expected response
type.public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void passThruWhen(Class<C> requestType)
requestType
pass through the request's getJsonContent()
cast to the expected response type.public boolean sawAll()
public boolean sawUnexpected()
Copyright © 2016–2021. All rights reserved.