@ThreadSafe public class TestClock extends Object implements Clock
Clock that allows the time to be set for testing.| Modifier and Type | Method and Description |
|---|---|
void |
advanceMillis(long millis)
Advances the time by millis and mutates this instance.
|
void |
advanceNanos(long nanos)
Advances the time by nanos and mutates this instance.
|
static TestClock |
create()
Creates a clock initialized to a constant non-zero time.
|
static TestClock |
create(long epochNanos)
Creates a clock with the given time.
|
long |
nanoTime()
Returns a time measurement with nanosecond precision that can only be used to calculate elapsed
time.
|
long |
now()
Obtains the current epoch timestamp in nanos from this clock.
|
void |
setTime(long epochNanos)
Sets the time.
|
public static TestClock create()
public static TestClock create(long epochNanos)
epochNanos - the initial time in nanos since epoch.TestClock with the given time.public void setTime(long epochNanos)
epochNanos - the new time.public void advanceMillis(long millis)
millis - the increase in time.public void advanceNanos(long nanos)
nanos - the increase in time.public long now()
Clockpublic long nanoTime()
Clock