public class AssertWithBackoff extends Object
| Modifier and Type | Class and Description |
|---|---|
class |
AssertWithBackoff.EqualsCheck<T> |
| Constructor and Description |
|---|
AssertWithBackoff() |
| Modifier and Type | Method and Description |
|---|---|
<T> void |
assertEquals(com.google.common.base.Function<Void,T> actual,
T expected,
String message)
A convenience method for
assertTrue(Predicate, String) to keep checking until a
certain value until it becomes equal to an expected value. |
static void |
assertTrue(com.google.common.base.Predicate<Void> condition,
long assertTimeoutMs,
String message,
org.slf4j.Logger log,
double backoffFactor,
long maxSleepMs)
Performs a check for a condition with a back-off.
|
void |
assertTrue(com.google.common.base.Predicate<Void> condition,
String message)
Performs a check for a condition with a back-off.
|
AssertWithBackoff |
backoffFactor(double backoffFactor)
Set the number to multiple the sleep after condition failure
|
static long |
computeRetrySleep(long currentSleepMs,
double backoffFactor,
long maxSleepMs,
long endTimeMs)
Computes a new sleep for a retry of a condition check.
|
static AssertWithBackoff |
create()
Creates a new instance
|
double |
getBackoffFactor()
The number to multiple the sleep after condition failure
|
org.slf4j.Logger |
getLogger()
The logger to use for logging waiting, results, etc.
|
long |
getMaxSleepMs()
The max time to sleep between condition failures
|
long |
getTimeoutMs()
the max time in milliseconds to wait for the condition to become true
|
AssertWithBackoff |
logger(org.slf4j.Logger log)
Set the logger to use for logging waiting, results, etc.
|
AssertWithBackoff |
maxSleepMs(long maxSleepMs)
Set the max time to sleep between condition failures
|
AssertWithBackoff |
timeoutMs(long assertTimeoutMs)
Set the max time in milliseconds to wait for the condition to become true
|
public static AssertWithBackoff create()
public AssertWithBackoff timeoutMs(long assertTimeoutMs)
public long getTimeoutMs()
public AssertWithBackoff maxSleepMs(long maxSleepMs)
public long getMaxSleepMs()
public AssertWithBackoff backoffFactor(double backoffFactor)
public double getBackoffFactor()
public AssertWithBackoff logger(org.slf4j.Logger log)
public org.slf4j.Logger getLogger()
public void assertTrue(com.google.common.base.Predicate<Void> condition, String message) throws TimeoutException, InterruptedException
condition - the condition to wait forassertTimeoutMs - the max time in milliseconds to wait for the condition to become truemessage - a message to print while waiting for the conditionlog - a logger to use for logging waiting, resultsTimeoutException - if the condition did not become true in the specified time budgetInterruptedExceptionpublic <T> void assertEquals(com.google.common.base.Function<Void,T> actual, T expected, String message) throws TimeoutException, InterruptedException
assertTrue(Predicate, String) to keep checking until a
certain value until it becomes equal to an expected value.actual - a function that checks the actual valueexpected - the expected valuemessage - a debugging messageTimeoutExceptionInterruptedExceptionpublic static void assertTrue(com.google.common.base.Predicate<Void> condition, long assertTimeoutMs, String message, org.slf4j.Logger log, double backoffFactor, long maxSleepMs) throws TimeoutException, InterruptedException
condition - the condition to wait forassertTimeoutMs - the max time in milliseconds to wait for the condition to become truemessage - the message to print while waiting for the conditionlog - the logger to use for logging waiting, resultsbackoffFactor - the number to multiple the sleep after condition failure;maxSleepMs - the max time to sleep between condition failures; default isTimeoutException - if the condition did not become true in the specified time budgetInterrupedException - if the assert gets interrupted while waiting for the condition to
become true.InterruptedExceptionpublic static long computeRetrySleep(long currentSleepMs,
double backoffFactor,
long maxSleepMs,
long endTimeMs)
currentSleepMs - the last sleep duration in millisecondsbackoffFactor - the factor to multiple currentSleepMsmaxSleepMs - the maximum allowed sleep in millisecondsendTimeMs - the end time based on timeout for the condition to become true