Class SchedulerClock

java.lang.Object
java.time.Clock
com.couchbase.client.core.scheduler.SchedulerClock

public class SchedulerClock extends Clock
Clock adapter around Scheduler. That adoption gives better integration with Java 8 DateTime API.

This feature may be useful for testing purpose, especially for integration with VirtualTimeScheduler. For example:

     
         VirtualTimeScheduler scheduler = VirtualTimeScheduler.create();
         SchedulerClock clock = SchedulerClock.of(scheduler);

         ZonedDateTime beforeAdvance = ZonedDateTime.now(clock);
         scheduler.advanceTimeBy(Duration.ofSeconds(1));
         ZonedDateTime afterAdvance = ZonedDateTime.now(clock);

         Assert.assertTrue(beforeAdvance.isBefore(afterAdvance));
     
 

Since:
3.1.4
Author:
Oleh Dokuka, Peter Royal
  • Method Details

    • getZone

      @NonNull public ZoneId getZone()
      Specified by:
      getZone in class Clock
    • withZone

      @NonNull public SchedulerClock withZone(ZoneId zone)
      Specified by:
      withZone in class Clock
    • getScheduler

      @NonNull public reactor.core.scheduler.Scheduler getScheduler()
      Return wrapped Scheduler instance
      Returns:
      Scheduler instance
    • withScheduler

      @NonNull public SchedulerClock withScheduler(reactor.core.scheduler.Scheduler scheduler)
      Builder method that returns new instance of SchedulerClock which is constructed from old ZoneId and passed Scheduler instance
      Returns:
      SchedulerClock instance
    • millis

      public long millis()
      Overrides:
      millis in class Clock
    • instant

      @NonNull public Instant instant()
      Gets the current instant of the clock.

      This returns an instant representing the current instant as defined by the clock.

      Note: If scheduler does not support time in nanoseconds the returned Instant will be limited by milliseconds

      Specified by:
      instant in class Clock
      Returns:
      the current instant from this clock, not null
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Clock
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Clock
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • of

      @NonNull public static SchedulerClock of(@NonNull reactor.core.scheduler.Scheduler scheduler)
      Create instance of SchedulerClock from given Scheduler and system default ZoneId.systemDefault()
      Parameters:
      scheduler - Scheduler instance
      Returns:
      new SchedulerClock
    • of

      @NonNull public static SchedulerClock of(@NonNull reactor.core.scheduler.Scheduler scheduler, @NonNull ZoneId zoneId)
      Create instance of SchedulerClock from given Scheduler and ZoneId
      Parameters:
      scheduler - Scheduler instance
      Returns:
      new SchedulerClock