Class EventualCondition
java.lang.Object
de.hybris.platform.integrationservices.util.EventualCondition
A test condition that is evaluated repeatedly during a reasonable period of time. It's intended to assert asynchronous changes.
Default evaluation period is 10 seconds and the condition is evaluated approximately every 500 milliseconds.
-
Method Summary
Modifier and TypeMethodDescriptionstatic EventualConditionCreates evaluation condition with default evaluation period and interval.voidEvaluates the conditions represented by the code body.static voidpause(long timeout) Pauses current thread execution for at least the specified timeout period.voidEvaluates whether the code body does not throw exceptions within the duration used by this condition.voidWaits for the specified condition to turntruewithin the specified time frame.Specifies duration period for the following eventual condition.
-
Method Details
-
eventualCondition
Creates evaluation condition with default evaluation period and interval.- Returns:
- a condition that is evaluated about every 500 milliseconds within 10 seconds period.
-
within
Specifies duration period for the following eventual condition.- Parameters:
duration- duration to applie for the eventual conditions. Default value, if not specified, is 10 seconds.- Returns:
- an
EventualConditionwith the duration specified.
-
expect
Evaluates the conditions represented by the code body. For example, let's say we have a class Job that changes its state asynchronously. In this case this method can be used like this:Job job = new Job // start the job job.start(); // assert the asynchronous condition that the job eventually finishes. eventualCondition().expect(() -> assertEquals("finished", job.getState());In other words, this method waits withing the time period used by this condition until thebodystops throwing exceptions. As soon, as the body did not throw an exception on its subsequent execution, the method returns. If the time period has been exceeded and the body still keeps throwing the exception, that exception will be propagated.- Parameters:
body- a code to evaluate. It should throw an exception when the condition is not met.
-
retains
Evaluates whether the code body does not throw exceptions within the duration used by this condition. For example, let's say we have a class Job that changes its state asynchronously and we want to verify that it remains in the RUNNING state for a certain period of time. In this case this method can be used like this:Job job = new Job // start the job job.start(); // assert the asynchronous condition that the job eventually finishes. eventualCondition().within(Duration.ofSeconds(3)).retains(() -> assertEquals("running", job.getState());If we useexpect(Runnable)method here, then the condition will pass on first evaluation and we immediately leave the method without waiting to check that the condition still passes at the end of the desired time frame.- Parameters:
body- a code to evaluate. It should throw an exception when the condition is not met.
-
waitFor
Waits for the specified condition to turntruewithin the specified time frame. For example, let's say we have a class Job that changes its state asynchronously and we want to wait until the job finishes. This method can be used like this to achieve this scenario:Job job = new Job // start the job job.start(); // assert the asynchronous condition that the job eventually finishes. eventualCondition().within(Duration.ofSeconds(3)).waitFor(() -> job.getState() == CronJobStatus.FINISHED);- Parameters:
condition- a condition to wait for- See Also:
-
pause
public static void pause(long timeout) Pauses current thread execution for at least the specified timeout period. The thread may be paused for longer. The only condition when the thread won't be paused for the timeout period, is if it is interrupted.- Parameters:
timeout- number of milliseconds to sleep.- See Also:
-