Package io.opencensus.testing.common
Class TestClock
java.lang.Object
io.opencensus.common.Clock
io.opencensus.testing.common.TestClock
A
Clock
that allows the time to be set for testing.- Since:
- 0.5
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
advanceTime
(Duration duration) Advances the time by a duration.static TestClock
create()
Creates a clock initialized to a constant non-zero time.static TestClock
Creates a clock with the given time.private static long
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
Sets the time.private static Timestamp
validateNanos
(Timestamp time)
-
Field Details
-
NUM_NANOS_PER_SECOND
private static final int NUM_NANOS_PER_SECOND- See Also:
-
currentTime
-
-
Constructor Details
-
TestClock
private TestClock()
-
-
Method Details
-
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
Creates a clock with the given time.- Parameters:
time
- the initial time.- Returns:
- a new
TestClock
with the given time. - Since:
- 0.5
-
setTime
Sets the time.- Parameters:
time
- the new time.- Since:
- 0.5
-
advanceTime
Advances the time by a duration.- Parameters:
duration
- the increase in time.- Since:
- 0.5
-
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. -
validateNanos
-
getNanos
-