Package io.opencensus.testing.common
Class TestClock
- java.lang.Object
-
- io.opencensus.common.Clock
-
- io.opencensus.testing.common.TestClock
-
-
Field Summary
Fields Modifier and Type Field Description private Timestamp
currentTime
private static int
NUM_NANOS_PER_SECOND
-
Constructor Summary
Constructors Modifier Constructor Description private
TestClock()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
advanceTime(Duration duration)
Advances the time by a duration.static TestClock
create()
Creates a clock initialized to a constant non-zero time.static TestClock
create(Timestamp time)
Creates a clock with the given time.private static long
getNanos(Timestamp time)
Timestamp
now()
Obtains the current instant from this clock.long
nowNanos()
Returns a time measurement with nanosecond precision that can only be used to calculate elapsed time.void
setTime(Timestamp time)
Sets the time.private static Timestamp
validateNanos(Timestamp time)
-
-
-
Field Detail
-
NUM_NANOS_PER_SECOND
private static final int NUM_NANOS_PER_SECOND
- See Also:
- Constant Field Values
-
currentTime
private Timestamp currentTime
-
-
Method Detail
-
create
public static TestClock create()
Creates a clock initialized to a constant non-zero time.Timestamp.create(0, 0)
is not a good default, because it represents an invalid time.- Returns:
- a clock initialized to a constant non-zero time.
- Since:
- 0.5
-
create
public static TestClock create(Timestamp time)
Creates a clock with the given time.- Parameters:
time
- the initial time.- Returns:
- a new
TestClock
with the given time. - Since:
- 0.5
-
setTime
public void setTime(Timestamp time)
Sets the time.- Parameters:
time
- the new time.- Since:
- 0.5
-
advanceTime
public void advanceTime(Duration duration)
Advances the time by a duration.- Parameters:
duration
- the increase in time.- Since:
- 0.5
-
now
public Timestamp now()
Description copied from class:Clock
Obtains the current instant from this clock.
-
nowNanos
public long nowNanos()
Description copied from class:Clock
Returns a time measurement with nanosecond precision that can only be used to calculate elapsed time.
-
getNanos
private static long getNanos(Timestamp time)
-
-