@Beta @GwtCompatible public class FakeTicker extends Ticker
The ticker can be configured so that the time is incremented whenever read()
is called:
see setAutoIncrementStep(long, java.util.concurrent.TimeUnit)
.
This class is thread-safe.
Modifier and Type | Field and Description |
---|---|
private long |
autoIncrementStepNanos |
private java.util.concurrent.atomic.AtomicLong |
nanos |
Constructor and Description |
---|
FakeTicker() |
Modifier and Type | Method and Description |
---|---|
FakeTicker |
advance(java.time.Duration duration)
Advances the ticker value by
duration . |
FakeTicker |
advance(long nanoseconds)
Advances the ticker value by
nanoseconds . |
FakeTicker |
advance(long time,
java.util.concurrent.TimeUnit timeUnit)
Advances the ticker value by
time in timeUnit . |
long |
read()
Returns the number of nanoseconds elapsed since this ticker's fixed point of reference.
|
FakeTicker |
setAutoIncrementStep(java.time.Duration autoIncrementStep)
Sets the increment applied to the ticker whenever it is queried.
|
FakeTicker |
setAutoIncrementStep(long autoIncrementStep,
java.util.concurrent.TimeUnit timeUnit)
Sets the increment applied to the ticker whenever it is queried.
|
systemTicker
private final java.util.concurrent.atomic.AtomicLong nanos
private volatile long autoIncrementStepNanos
public FakeTicker advance(long time, java.util.concurrent.TimeUnit timeUnit)
time
in timeUnit
.public FakeTicker advance(long nanoseconds)
nanoseconds
.@GwtIncompatible public FakeTicker advance(java.time.Duration duration)
duration
.public FakeTicker setAutoIncrementStep(long autoIncrementStep, java.util.concurrent.TimeUnit timeUnit)
The default behavior is to auto increment by zero. i.e: The ticker is left unchanged when queried.
@GwtIncompatible public FakeTicker setAutoIncrementStep(java.time.Duration autoIncrementStep)
The default behavior is to auto increment by zero. i.e: The ticker is left unchanged when queried.