java.lang.Object
io.github.teceli.resiliencia.test.ManualClock
All Implemented Interfaces:
Clock

public final class ManualClock extends Object implements Clock
Deterministic Clock for tests: time only moves when advanced explicitly via advance(java.time.Duration) or when a pattern sleeps, so timing-based behavior (Retry backoff, RateLimiter windows) can be asserted exactly and runs instantly. Thread-safe: patterns may read and sleep on this clock from multiple threads.
  • Method Details

    • create

      public static ManualClock create()
      A manual clock starting at a fixed, arbitrary instant.
    • startingAt

      public static ManualClock startingAt(Instant start)
      A manual clock starting at the given instant.
    • instant

      public Instant instant()
      Description copied from interface: Clock
      The current instant, as seen by this clock.
      Specified by:
      instant in interface Clock
    • sleep

      public void sleep(long millis)
      Does not block: advances the clock by the requested duration and returns immediately.
      Specified by:
      sleep in interface Clock
    • advance

      public void advance(Duration duration)
      Move the clock forward by the given duration.