Class MockExecutor


  • public class MockExecutor
    extends Executor
    This is an implementation of Executor that can be injected to inject a set of canned responses to requests including:
    • Constructor Summary

      Constructors 
      Constructor Description
      MockExecutor()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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>>
      void
      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>
      void
      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>>
      void
      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>
      void
      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>>
      void
      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>
      void
      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>>
      void
      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>
      void
      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.
      • Methods inherited from class com.google.jenkins.plugins.util.Executor

        sleep
    • Constructor Detail

      • MockExecutor

        public MockExecutor()
    • Method Detail

      • 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;
        Overrides:
        sleep in class Executor
      • 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 class Executor
        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 wrong
        ExecutorException
      • when

        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)
        When the next request matches the given requestType and the provided user Predicate return response 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 given requestType return response as the response.
      • throwWhen

        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)
        When the next request matches the given requestType and the provided user Predicate throw exception 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 given requestType throw exception instead of responding.
      • throwWhen

        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)
        When the next request matches the given requestType and the provided user Predicate throw exception 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 given requestType throw exception instead of responding.
      • passThruWhen

        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)
        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.
      • 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 given requestType pass through the request's getJsonContent() 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?