Class DefaultMockTicker

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.locks.ReentrantLock lock  
      private java.util.concurrent.atomic.AtomicLong nanoTime  
      private java.util.concurrent.locks.Condition sleeperCondition  
      private java.util.Set<java.lang.Thread> sleepers  
      private java.util.concurrent.locks.Condition tickCondition  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void advance​(long amount, java.util.concurrent.TimeUnit unit)
      Advances the current Ticker.nanoTime() by the given amount of time.
      void awaitSleepingThread​(java.lang.Thread thread)
      Wait for the given thread to enter the sleep(long, TimeUnit) method, and block.
      long nanoTime()
      The time elapsed since initialization of this class in nanoseconds.
      void sleep​(long delay, java.util.concurrent.TimeUnit unit)
      Waits until the given amount of time goes by.
      • Methods inherited from class java.lang.Object

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

      • lock

        private final java.util.concurrent.locks.ReentrantLock lock
      • tickCondition

        private final java.util.concurrent.locks.Condition tickCondition
      • sleeperCondition

        private final java.util.concurrent.locks.Condition sleeperCondition
      • nanoTime

        private final java.util.concurrent.atomic.AtomicLong nanoTime
      • sleepers

        private final java.util.Set<java.lang.Thread> sleepers
    • Constructor Detail

      • DefaultMockTicker

        DefaultMockTicker()
    • Method Detail

      • nanoTime

        public long nanoTime()
        Description copied from interface: Ticker
        The time elapsed since initialization of this class in nanoseconds. This may return a negative number just like System.nanoTime().
        Specified by:
        nanoTime in interface Ticker
      • sleep

        public void sleep​(long delay,
                          java.util.concurrent.TimeUnit unit)
                   throws java.lang.InterruptedException
        Description copied from interface: Ticker
        Waits until the given amount of time goes by.
        Specified by:
        sleep in interface Ticker
        Parameters:
        delay - the amount of delay.
        unit - the TimeUnit of delay.
        Throws:
        java.lang.InterruptedException
        See Also:
        Thread.sleep(long)
      • awaitSleepingThread

        public void awaitSleepingThread​(java.lang.Thread thread)
                                 throws java.lang.InterruptedException
        Wait for the given thread to enter the sleep(long, TimeUnit) method, and block.
        Throws:
        java.lang.InterruptedException
      • advance

        public void advance​(long amount,
                            java.util.concurrent.TimeUnit unit)
        Description copied from interface: MockTicker
        Advances the current Ticker.nanoTime() by the given amount of time.
        Specified by:
        advance in interface MockTicker
        Parameters:
        amount - the amount of time to advance this ticker by.
        unit - the TimeUnit of amount.