Class MockExecutor

java.lang.Object
com.google.jenkins.plugins.util.Executor
com.google.jenkins.plugins.util.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:
  • Nested Class Summary

    Nested classes/interfaces inherited from class com.google.jenkins.plugins.util.Executor

    Executor.Default
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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
    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
    Did we see all of the expected requests?
    boolean
    Did we see any unexpected requests?
    void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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;
      Overrides:
      sleep in class Executor
    • execute

      public <T> T execute(RequestCallable<T> request) throws IOException, ExecutorException
      Executes the request, returning a response of the appropriate type.
      Specified by:
      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
    • 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?