Class B2ClockSim


  • public class B2ClockSim
    extends B2Clock
    B2ClockSim provides a simple simulation of a clock, for use in tests.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void advanceBoth​(java.time.Duration delta)
      Shifts the current time by the given duration.
      void advanceNow​(java.time.Duration delta)
      Shifts the current wall clock time by the given duration.
      long monotonicMillis()  
      void resetBoth​(java.time.LocalDateTime desiredNow)
      This is intended to be run between tests to reset the clock to an initial state, as if the simulator has just be constructed.
      long wallClockMillis()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • wallClockMillis

        public long wallClockMillis()
        Specified by:
        wallClockMillis in class B2Clock
        Returns:
        the number of milliseconds since the unix epoch. may be negative if now is before the epoch. the values returned by this represent wall clock time and might not be monotonic if the system clock is changed. time might sometimes flow at a variable speed or even backwards if the clock is being adjusted.
      • monotonicMillis

        public long monotonicMillis()
        Specified by:
        monotonicMillis in class B2Clock
        Returns:
        a monotonically increasing number of milliseconds. note that it has no relationship to wall clock time and will differ between different runs of the JVM. It is monotonically increasing! AND it won't wrap during any single run of a JVM. (unless the JVM runs for hundreds of of years! (2^63 nanos) / (10^9 nanos/sec) / (86400 secs/day) / (365 days/year) ~= 292 years)
      • advanceBoth

        public void advanceBoth​(java.time.Duration delta)
        Shifts the current time by the given duration. The wallClock and monotonic times will go forward by the same amount.
        Parameters:
        delta - the amount of time to shift both clocks by. must be non-negative to avoid making the monotonic clock go backwards!
      • advanceNow

        public void advanceNow​(java.time.Duration delta)
        Shifts the current wall clock time by the given duration. Only nowMillis will be adjusted. Use this when you want to shift time backwards, since you're not allowed to call advanceBoth() with negative value.
        Parameters:
        delta - the time to advance the wall clock by
      • resetBoth

        public void resetBoth​(java.time.LocalDateTime desiredNow)
        This is intended to be run between tests to reset the clock to an initial state, as if the simulator has just be constructed.
        Parameters:
        desiredNow - the desired wall clock time.