public class Timer extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
Timer.ResolutionLogic |
static interface |
Timer.StopCondition |
Constructor and Description |
---|
Timer()
Create new timer with default delay, sleep interval and stop conditions resolution logic.
|
Modifier and Type | Method and Description |
---|---|
Timer |
addStopCondition(Timer.StopCondition condition)
Add new stop condition.
|
Timer |
addStopCondition(Timer.StopCondition condition,
boolean clear)
Add new stop condition.
|
void |
clearStopConditions()
Clear stop conditions and reset
stopConditionsSatisfiedBeforeTimeout . |
long |
getDelay() |
long |
getSleepInterval() |
boolean |
isStopConditionsSatisfiedBeforeTimeout() |
void |
reset()
Reset to default values.
|
Timer |
setDelay(long delay)
Set the delay value.
|
Timer |
setDelay(long delay,
TimeUnit timeUnit)
Set the delay value.
|
Timer |
setResolutionLogic(Timer.ResolutionLogic resolutionLogic)
Set new resolution logic.
|
Timer |
setSleepInterval(long sleepInterval)
Set new sleep interval value.
|
Timer |
start()
Start the timer.
|
static Timer |
startNew(long delay)
Start a new timer with specified delay.
|
static Timer |
startNew(long delay,
long sleepInterval)
Start a new timer with specified delay and sleep interval.
|
public Timer()
public Timer setDelay(long delay)
Configuration#getTestTimeoutFactor()
so that it's possible to configure
timeouts according to the testing runtime performance and throughput.delay
- The delay in millisecondspublic Timer setDelay(long delay, TimeUnit timeUnit)
Configuration#getTestTimeoutFactor()
so that it's possible to configure
timeouts according to the testing runtime performance and throughput.delay
- timeUnit
- public Timer setSleepInterval(long sleepInterval)
sleepInterval
- public Timer setResolutionLogic(Timer.ResolutionLogic resolutionLogic)
resolutionLogic
- public Timer addStopCondition(Timer.StopCondition condition)
condition
- public Timer addStopCondition(Timer.StopCondition condition, boolean clear)
condition
- clear
- Clear stop conditions and reset stopConditionsSatisfiedBeforeTimeout
public Timer start() throws InterruptedException
InterruptedException
public void reset()
public void clearStopConditions()
stopConditionsSatisfiedBeforeTimeout
.public boolean isStopConditionsSatisfiedBeforeTimeout()
true
if stop conditions are satisfied according to actual resolutionLogic
before timeout occurs, false
otherwisepublic long getDelay()
public long getSleepInterval()
public static Timer startNew(long delay) throws InterruptedException
delay
- InterruptedException
public static Timer startNew(long delay, long sleepInterval) throws InterruptedException
delay
- InterruptedException
Copyright © 2021. All rights reserved.