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 class  Retry.Mode  
  • Optional Element Summary

    Optional Elements
    Modifier and Type Optional Element Description
    Class<? extends Closure> condition
    Condition that is evaluated to decide whether the feature should be retried.
    int count
    The number of retries.
    int delay
    Delay between retries in millis, 0 to disable.
    Class<? extends Throwable>[] exceptions
    Configures which types of Exceptions should be retried.
    Retry.Mode mode
    Retry mode, controls what is retried.
  • Element Details

    • exceptions

      Class<? extends Throwable>[] 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

      Class<? extends Closure> condition
      Condition that is evaluated to decide whether the feature should be retried. The configured closure is called with a delegate of type RetryConditionContext which provides access to the current exception and Specification instance. 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 count
      The number of retries.
      Returns:
      number of retries.
      Default:
      3
    • delay

      int delay
      Delay between retries in millis, 0 to disable.
      Returns:
      number of millis to wait.
      Default:
      0
    • mode

      Retry mode, controls what is retried.
      Returns:
      retry mode
      Default:
      ITERATION