Package org.springframework.retry.policy

Examples of org.springframework.retry.policy.SimpleRetryPolicy


    // Something that won't be thrown by JUnit...
    callback.setExceptionToThrow(new IllegalArgumentException());
    callback.setAttemptsBeforeSuccess(Integer.MAX_VALUE);
    RetryTemplate retryTemplate = new RetryTemplate();
    int retryAttempts = 2;
    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(retryAttempts,
        Collections.<Class<? extends Throwable>, Boolean> singletonMap(
            Exception.class, true)));
    try {
      retryTemplate.execute(callback);
      fail("Expected IllegalArgumentException");
View Full Code Here


    int attempts = 3;
    callback.setAttemptsBeforeSuccess(attempts);
    callback.setExceptionToThrow(new IllegalArgumentException());

    RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(attempts,
        Collections.<Class<? extends Throwable>, Boolean> singletonMap(
            Exception.class, true)));
    retryTemplate.execute(callback);
    assertEquals(attempts, callback.attempts);
  }
View Full Code Here

    int attempts = 3;
    callback.setAttemptsBeforeSuccess(attempts);
    callback.setExceptionToThrow(new IllegalArgumentException());

    RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(attempts,
        Collections.<Class<? extends Throwable>, Boolean> singletonMap(
            Exception.class, true)));
    BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(
        Collections
            .<Class<? extends Throwable>> singleton(IllegalArgumentException.class),
View Full Code Here

  }

  @Test
  public void testSetExceptions() throws Throwable {
    RetryTemplate template = new RetryTemplate();
    SimpleRetryPolicy policy = new SimpleRetryPolicy(3,
        Collections.<Class<? extends Throwable>, Boolean> singletonMap(
            RuntimeException.class, true));
    template.setRetryPolicy(policy);

    int attempts = 3;
View Full Code Here

      MockRetryCallback callback = new MockRetryCallback();
      MockBackOffStrategy backOff = new MockBackOffStrategy();
      callback.setAttemptsBeforeSuccess(x);
      RetryTemplate retryTemplate = new RetryTemplate();
      retryTemplate.setBackOffPolicy(backOff);
      retryTemplate.setRetryPolicy(new SimpleRetryPolicy(x, Collections
          .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class,
              true)));
      retryTemplate.execute(callback);
      assertEquals(x, callback.attempts);
      assertEquals(1, backOff.startCalls);
View Full Code Here

   */
  @Test
  public void testNoBackOffForRethrownException() throws Throwable {

    RetryTemplate tested = new RetryTemplate();
    tested.setRetryPolicy(new SimpleRetryPolicy(1,
        Collections.<Class<? extends Throwable>, Boolean> singletonMap(
            Exception.class, true)));

    BackOffPolicy bop = createStrictMock(BackOffPolicy.class);
    BackOffContext backOffContext = new BackOffContext() {
View Full Code Here

    assertFalse(retryPolicy.canRetry(context));
  }

  @Test
  public void testRecover() throws Throwable {
    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1, Collections
        .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
    final String input = "foo";
    RetryState state = new DefaultRetryState(input);
    RetryCallback<String, Exception> callback = new RetryCallback<String, Exception>() {
      public String doWithRetry(RetryContext context) throws Exception {
View Full Code Here

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

  @Test
  public void testSwitchToStatelessForNoRollback() throws Throwable {
    retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1, Collections
        .<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true)));
    // Roll back for these:
    BinaryExceptionClassifier classifier = new BinaryExceptionClassifier(Collections
        .<Class<? extends Throwable>> singleton(DataAccessException.class));
    // ...but not these:
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.policy.SimpleRetryPolicy

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.