Package com.google.jenkins.plugins.util
Class MockExecutor
java.lang.Object
com.google.jenkins.plugins.util.Executor
com.google.jenkins.plugins.util.MockExecutor
This is an implementation of
Executor
that can be injected to inject a set of canned
responses to requests including:
- A pre-determined object
- Throwing an
IOException
orExecutorException
- Passing through a part of the request as the response
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.jenkins.plugins.util.Executor
Executor.Default
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<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>>
voidpassThruWhen
(Class<C> requestType) When the next request matches the givenrequestType
pass through the request'sgetJsonContent()
cast to the expected response type.<T,
S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, C extends S>
voidpassThruWhen
(Class<C> requestType, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestType
and the provided userPredicate
pass through the request'sgetJsonContent()
cast to the expected response type.boolean
sawAll()
Did we see all of the expected requests?boolean
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>>
voidthrowWhen
(Class<C> requestType, ExecutorException exception) When the next request matches the givenrequestType
throwexception
instead of responding.<T,
S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, C extends S>
voidthrowWhen
(Class<C> requestType, ExecutorException exception, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestType
and the provided userPredicate
throwexception
instead of responding.<T,
C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>>
voidthrowWhen
(Class<C> requestType, IOException exception) When the next request matches the givenrequestType
throwexception
instead of responding.<T,
S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, C extends S>
voidthrowWhen
(Class<C> requestType, IOException exception, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestType
and the provided userPredicate
throwexception
instead of responding.<T,
C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>>
voidWhen the next request matches the givenrequestType
returnresponse
as the response.<T,
S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, C extends S>
voidWhen the next request matches the givenrequestType
and the provided userPredicate
returnresponse
as the response.
-
Constructor Details
-
MockExecutor
public MockExecutor()
-
-
Method Details
-
sleep
public 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; -
execute
Executes the request, returning a response of the appropriate type.- Specified by:
execute
in classExecutor
- Type Parameters:
T
- The type of the expected response- Parameters:
request
- The request we are issuing- Returns:
- a Json object of the given type
- Throws:
IOException
- if anything goes wrongExecutorException
-
execute
public <T> T execute(com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T> request) throws IOException, ExecutorException Executes the request, returning a response of the appropriate type.- Overrides:
execute
in classExecutor
- Type Parameters:
T
- The type of the expected response- Parameters:
request
- The request we are issuing- Returns:
- a Json object of the given type
- Throws:
IOException
- if anything goes wrongExecutorException
-
when
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, void whenC extends S> (Class<C> requestType, T response, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestType
and the provided userPredicate
returnresponse
as the response. -
when
public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void when(Class<C> requestType, T response) When the next request matches the givenrequestType
returnresponse
as the response. -
throwWhen
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, void throwWhenC extends S> (Class<C> requestType, IOException exception, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestType
and the provided userPredicate
throwexception
instead of responding. -
throwWhen
public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void throwWhen(Class<C> requestType, IOException exception) When the next request matches the givenrequestType
throwexception
instead of responding. -
throwWhen
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, void throwWhenC extends S> (Class<C> requestType, ExecutorException exception, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestType
and the provided userPredicate
throwexception
instead of responding. -
throwWhen
public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void throwWhen(Class<C> requestType, ExecutorException exception) When the next request matches the givenrequestType
throwexception
instead of responding. -
passThruWhen
public <T,S extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>, void passThruWhenC extends S> (Class<C> requestType, com.google.common.base.Predicate<S> predicate) When the next request matches the givenrequestType
and the provided userPredicate
pass through the request'sgetJsonContent()
cast to the expected response type. -
passThruWhen
public <T,C extends com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest<T>> void passThruWhen(Class<C> requestType) When the next request matches the givenrequestType
pass through the request'sgetJsonContent()
cast to the expected response type. -
sawAll
public boolean sawAll()Did we see all of the expected requests? -
sawUnexpected
public boolean sawUnexpected()Did we see any unexpected requests?
-