Class MockBackOff

java.lang.Object
com.google.api.client.testing.util.MockBackOff
All Implemented Interfaces:
BackOff

@Beta public class MockBackOff extends Object implements BackOff
Beta
Mock for BackOff that always returns a fixed number.

Implementation is not thread-safe.

Since:
1.15
  • Field Details

    • backOffMillis

      private long backOffMillis
      Fixed back-off milliseconds.
    • maxTries

      private int maxTries
      Maximum number of tries before returning BackOff.STOP.
    • numTries

      private int numTries
      Number of tries so far.
  • Constructor Details

    • MockBackOff

      public MockBackOff()
  • Method Details

    • reset

      public void reset() throws IOException
      Description copied from interface: BackOff
      Reset to initial state.
      Specified by:
      reset in interface BackOff
      Throws:
      IOException
    • nextBackOffMillis

      public long nextBackOffMillis() throws IOException
      Description copied from interface: BackOff
      Gets the number of milliseconds to wait before retrying the operation or BackOff.STOP to indicate that no retries should be made.

      Example usage:

         long backOffMillis = backoff.nextBackOffMillis();
         if (backOffMillis == Backoff.STOP) {
           // do not retry operation
         } else {
           // sleep for backOffMillis milliseconds and retry operation
         }
       
      Specified by:
      nextBackOffMillis in interface BackOff
      Throws:
      IOException
    • setBackOffMillis

      public MockBackOff setBackOffMillis(long backOffMillis)
      Sets the fixed back-off milliseconds (defaults to 0).

      Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

    • setMaxTries

      public MockBackOff setMaxTries(int maxTries)
      Sets the maximum number of tries before returning BackOff.STOP (defaults to 10).

      Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

    • getMaxTries

      public final int getMaxTries()
      Returns the maximum number of tries before returning BackOff.STOP.
    • getNumberOfTries

      public final int getNumberOfTries()
      Returns the number of tries so far.