Class TestClock
java.lang.Object
com.loomcache.server.consensus.TestClock
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadvance(long nanos) Advance the clock by the specified amount in nanoseconds.longgetTime()Get the current time in nanoseconds.longnanoTime()Returns the current time in nanoseconds.voidsetTime(long nanos) Set the clock to an absolute time in nanoseconds.
-
Constructor Details
-
TestClock
public TestClock()
-
-
Method Details
-
nanoTime
public long nanoTime()Description copied from interface:ClockReturns the current time in nanoseconds.The absolute value is meaningless; only differences matter. This is analogous to
System.nanoTime(). -
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
-