Class TestClock

java.lang.Object
io.opentelemetry.sdk.testing.time.TestClock
All Implemented Interfaces:
io.opentelemetry.sdk.common.Clock

@ThreadSafe public final class TestClock extends Object implements io.opentelemetry.sdk.common.Clock
A mutable Clock that allows the time to be set for testing.
  • Method Details

    • create

      public static TestClock create()
      Creates a clock initialized to a constant non-zero time.
      Returns:
      a clock initialized to a constant non-zero time.
    • create

      public static TestClock create(Instant instant)
      Creates a clock with the given time.
    • setTime

      public void setTime(Instant instant)
      Sets the current time.
    • advance

      public void advance(Duration duration)
      Advances the time and mutates this instance.
    • advance

      public void advance(long duration, TimeUnit unit)
      Advances the time and mutates this instance.
    • now

      public long now()
      Specified by:
      now in interface io.opentelemetry.sdk.common.Clock
    • nanoTime

      public long nanoTime()
      Specified by:
      nanoTime in interface io.opentelemetry.sdk.common.Clock