Package org.springframework.retry

Examples of org.springframework.retry.RetryPolicy


   * Delegate to the policy currently activated in the context.
   *
   * @see org.springframework.retry.RetryPolicy#canRetry(org.springframework.retry.RetryContext)
   */
  public boolean canRetry(RetryContext context) {
    RetryPolicy policy = (RetryPolicy) context;
    return policy.canRetry(context);
  }
View Full Code Here


   * Delegate to the policy currently activated in the context.
   *
   * @see org.springframework.retry.RetryPolicy#close(org.springframework.retry.RetryContext)
   */
  public void close(RetryContext context) {
    RetryPolicy policy = (RetryPolicy) context;
    policy.close(context);
  }
View Full Code Here

   *
   * @see org.springframework.retry.RetryPolicy#registerThrowable(org.springframework.retry.RetryContext,
   * Throwable)
   */
  public void registerThrowable(RetryContext context, Throwable throwable) {
    RetryPolicy policy = (RetryPolicy) context;
    policy.registerThrowable(context, throwable);
    ((RetryContextSupport) context).registerThrowable(throwable);
  }
View Full Code Here

   */
  protected <T, E extends Throwable> T doExecute(RetryCallback<T, E> retryCallback,
      RecoveryCallback<T> recoveryCallback, RetryState state) throws E,
      ExhaustedRetryException {

    RetryPolicy retryPolicy = this.retryPolicy;
    BackOffPolicy backOffPolicy = this.backOffPolicy;

    // Allow the retry policy to initialise itself...
    RetryContext context = open(retryPolicy, state);
    if (logger.isTraceEnabled()) {
View Full Code Here

   * Test method for
   * {@link org.springframework.batch.core.step.item.SimpleRetryExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)} .
   */
  public void testRethrowWhenRetryExhausted() throws Throwable {

    RetryPolicy retryPolicy = new NeverRetryPolicy();
    RuntimeException ex = new RuntimeException("foo");

    SimpleRetryExceptionHandler handler = getHandlerAfterRetry(retryPolicy, ex, Collections
        .<Class<? extends Throwable>> singleton(Error.class));

View Full Code Here

   * Test method for
   * {@link org.springframework.batch.core.step.item.SimpleRetryExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)} .
   */
  public void testNoRethrowWhenRetryNotExhausted() throws Throwable {

    RetryPolicy retryPolicy = new AlwaysRetryPolicy();
    RuntimeException ex = new RuntimeException("foo");

    SimpleRetryExceptionHandler handler = getHandlerAfterRetry(retryPolicy, ex, Collections
        .<Class<? extends Throwable>> singleton(Error.class));

View Full Code Here

   * Test method for
   * {@link org.springframework.batch.core.step.item.SimpleRetryExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)} .
   */
  public void testRethrowWhenFatal() throws Throwable {

    RetryPolicy retryPolicy = new AlwaysRetryPolicy();
    RuntimeException ex = new RuntimeException("foo");

    SimpleRetryExceptionHandler handler = getHandlerAfterRetry(retryPolicy, ex, Collections
        .<Class<? extends Throwable>> singleton(RuntimeException.class));

View Full Code Here

  /**
   * @return fully configured retry template for item processing phase.
   */
  protected BatchRetryTemplate createRetryOperations() {

    RetryPolicy retryPolicy = this.retryPolicy;
    SimpleRetryPolicy simpleRetryPolicy = null;

    Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, Boolean>(
        retryableExceptionClasses);
    map.put(ForceRollbackForWriteSkipException.class, true);
    simpleRetryPolicy = new SimpleRetryPolicy(retryLimit, map);

    if (retryPolicy == null) {
      Assert.state(!(retryableExceptionClasses.isEmpty() && retryLimit > 0),
          "If a retry limit is provided then retryable exceptions must also be specified");
      retryPolicy = simpleRetryPolicy;
    }
    else if ((!retryableExceptionClasses.isEmpty() && retryLimit > 0)) {
      CompositeRetryPolicy compositeRetryPolicy = new CompositeRetryPolicy();
      compositeRetryPolicy.setPolicies(new RetryPolicy[] { retryPolicy, simpleRetryPolicy });
      retryPolicy = compositeRetryPolicy;
    }

    RetryPolicy retryPolicyWrapper = getFatalExceptionAwareProxy(retryPolicy);

    BatchRetryTemplate batchRetryTemplate = new BatchRetryTemplate();
    if (backOffPolicy != null) {
      batchRetryTemplate.setBackOffPolicy(backOffPolicy);
    }
View Full Code Here

    assertEquals(input, list.get(0));
  }

  @Test
  public void testExhaustedClearsHistoryAfterLastAttempt() throws Throwable {
    RetryPolicy retryPolicy = new SimpleRetryPolicy(1, Collections
        .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true));
    retryTemplate.setRetryPolicy(retryPolicy);

    final String input = "foo";
    RetryState state = new DefaultRetryState(input);
    RetryCallback<String, Exception> callback = new RetryCallback<String, Exception>() {
      public String doWithRetry(RetryContext context) throws Exception {
        throw new RuntimeException("Barf!");
      }
    };

    try {
      retryTemplate.execute(callback, state);
      fail("Expected ExhaustedRetryException");
    }
    catch (RuntimeException e) {
      assertEquals("Barf!", e.getMessage());
    }

    try {
      retryTemplate.execute(callback, state);
      fail("Expected ExhaustedRetryException");
    }
    catch (ExhaustedRetryException e) {
      // expected
    }

    RetryContext context = retryTemplate.open(retryPolicy, state);
    // True after exhausted - the history is reset...
    assertTrue(retryPolicy.canRetry(context));
  }
View Full Code Here

  }

  @Test
  public void testKeyGeneratorNotConsistentAfterFailure() throws Throwable {

    RetryPolicy retryPolicy = new SimpleRetryPolicy(3, Collections
        .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true));
    retryTemplate.setRetryPolicy(retryPolicy);
    final StringHolder item = new StringHolder("bar");
    RetryState state = new DefaultRetryState(item);
View Full Code Here

TOP

Related Classes of org.springframework.retry.RetryPolicy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.