Interface MockTicker

  • All Superinterfaces:
    Ticker

    public interface MockTicker
    extends Ticker
    A fake Ticker that allows the caller control the flow of time. This can be useful when you test time-sensitive logic without waiting for too long or introducing flakiness due to non-deterministic nature of system clock.
    • Method Detail

      • initialNanoTime

        default long initialNanoTime()
        Description copied from interface: Ticker
        The initial value used for delay and computations based upon a monotonic time source.
        Specified by:
        initialNanoTime in interface Ticker
        Returns:
        initial value used for delay and computations based upon a monotonic time source.
      • advance

        void advance​(long amount,
                     java.util.concurrent.TimeUnit unit)
        Advances the current Ticker.nanoTime() by the given amount of time.
        Parameters:
        amount - the amount of time to advance this ticker by.
        unit - the TimeUnit of amount.
      • advanceMillis

        default void advanceMillis​(long amountMillis)
        Advances the current Ticker.nanoTime() by the given amount of time.
        Parameters:
        amountMillis - the number of milliseconds to advance this ticker by.