Class Timer


  • public class Timer
    extends Object
    Delays thread execution for specified time or unless stop conditions are satisfied according to the actual Timer.ResolutionLogic. This class is not thread-safe.

    Setting the sleep interval to the value less than 15 ms is questionable since some operating systems do not provide such precision. Moreover such values may impact test performance.

    In case of no stop conditions are specified (not recommended), the timer logic corresponds to the regular Thread.sleep(long) execution.

    • Constructor Detail

      • Timer

        public Timer()
        Create new timer with default delay, sleep interval and stop conditions resolution logic.
    • Method Detail

      • setDelay

        public Timer setDelay​(long delay)
        Set the delay value. The value is automatically adjusted according to the Configuration#getTestTimeoutFactor() so that it's possible to configure timeouts according to the testing runtime performance and throughput.
        Parameters:
        delay - The delay in milliseconds
        Returns:
        self
      • setDelay

        public Timer setDelay​(long delay,
                              TimeUnit timeUnit)
        Set the delay value. The value is automatically adjusted according to the Configuration#getTestTimeoutFactor() so that it's possible to configure timeouts according to the testing runtime performance and throughput.
        Parameters:
        delay -
        timeUnit -
        Returns:
        self
      • setSleepInterval

        public Timer setSleepInterval​(long sleepInterval)
        Set new sleep interval value.
        Parameters:
        sleepInterval -
        Returns:
        self
      • setResolutionLogic

        public Timer setResolutionLogic​(Timer.ResolutionLogic resolutionLogic)
        Set new resolution logic.
        Parameters:
        resolutionLogic -
        Returns:
        self
      • addStopCondition

        public Timer addStopCondition​(Timer.StopCondition condition)
        Add new stop condition.
        Parameters:
        condition -
        Returns:
        self
      • addStopCondition

        public Timer addStopCondition​(Timer.StopCondition condition,
                                      boolean clear)
        Add new stop condition.
        Parameters:
        condition -
        clear - Clear stop conditions and reset stopConditionsSatisfiedBeforeTimeout
        Returns:
        self
      • reset

        public void reset()
        Reset to default values.
      • clearStopConditions

        public void clearStopConditions()
        Clear stop conditions and reset stopConditionsSatisfiedBeforeTimeout.
      • isStopConditionsSatisfiedBeforeTimeout

        public boolean isStopConditionsSatisfiedBeforeTimeout()
        Returns:
        true if stop conditions are satisfied according to actual resolutionLogic before timeout occurs, false otherwise
      • getDelay

        public long getDelay()
        Returns:
        the current delay in ms
      • getSleepInterval

        public long getSleepInterval()
        Returns:
        the current sleep interval in ms
      • startNew

        public static Timer startNew​(long delay,
                                     long sleepInterval)
                              throws InterruptedException
        Start a new timer with specified delay and sleep interval.
        Parameters:
        delay -
        Returns:
        finished timer
        Throws:
        InterruptedException