Class TestClock

java.lang.Object
com.loomcache.server.consensus.TestClock
All Implemented Interfaces:
Clock

public class TestClock extends Object implements Clock
Test clock with manual time advancement for deterministic testing.

Allows tests to control the passage of time without depending on wall-clock timing. Start time is 0; advance with advance(long).

  • Constructor Details

    • TestClock

      public TestClock()
  • Method Details

    • nanoTime

      public long nanoTime()
      Description copied from interface: Clock
      Returns the current time in nanoseconds.

      The absolute value is meaningless; only differences matter. This is analogous to System.nanoTime().

      Specified by:
      nanoTime in interface Clock
      Returns:
      nanoseconds since an arbitrary reference point
    • advance

      public void advance(long nanos)
      Advance the clock by the specified amount in nanoseconds.
      Parameters:
      nanos - nanoseconds to advance
    • setTime

      public void setTime(long nanos)
      Set the clock to an absolute time in nanoseconds.
      Parameters:
      nanos - absolute time
    • getTime

      public long getTime()
      Get the current time in nanoseconds.
      Returns:
      current time