Package spock.lang
Annotation Type Retry
@Beta @Retention(RUNTIME) @Target({TYPE,METHOD}) public @interface Retry
Retries the given feature if an exception occurs during execution.
Retries can be applied to feature methods and spec classes. Applying it to
a spec class has the same effect as applying it to each feature method that
isn't already annotated with @Retry.
A @Retry annotation that is declared on a spec class is applied to
all features in all subclasses as well, unless a subclass declares its own
annotation. If so, the retries defined in the subclass are applied to all
feature methods declared in the subclass as well as inherited ones.
- Since:
- 1.2
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRetry.Mode -
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description Class<? extends Closure>conditionCondition that is evaluated to decide whether the feature should be retried.intcountThe number of retries.intdelayDelay between retries in millis, 0 to disable.Class<? extends Throwable>[]exceptionsConfigures which types of Exceptions should be retried.Retry.ModemodeRetry mode, controls what is retried.
-
Element Details
-
exceptions
Configures which types of Exceptions should be retried. Subclasses are included if their parent class is listed.- Returns:
- array of Exception classes to retry.
- Default:
- {java.lang.Exception.class, java.lang.AssertionError.class}
-
condition
Condition that is evaluated to decide whether the feature should be retried. The configured closure is called with a delegate of typeRetryConditionContextwhich provides access to the current exception andSpecificationinstance. The feature is retried if the exception class passes the type check and the specified condition holds true. If no condition is specified, only the type check is performed.- Returns:
- predicate that must hold for the feature to be retried.
- Default:
- groovy.lang.Closure.class
-
count
int countThe number of retries.- Returns:
- number of retries.
- Default:
- 3
-
delay
int delayDelay between retries in millis, 0 to disable.- Returns:
- number of millis to wait.
- Default:
- 0
-
mode
Retry.Mode modeRetry mode, controls what is retried.- Returns:
- retry mode
- Default:
- ITERATION
-