Search in sources :

Example 1 with StatelessBackOffPolicy

use of org.springframework.retry.backoff.StatelessBackOffPolicy in project spring-retry by spring-projects.

the class RetryTemplateTests method testBackOffInterrupted.

@Test
public void testBackOffInterrupted() throws Throwable {
    RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setBackOffPolicy(new StatelessBackOffPolicy() {

        @Override
        protected void doBackOff() throws BackOffInterruptedException {
            throw new BackOffInterruptedException("foo");
        }
    });
    try {
        retryTemplate.execute(new RetryCallback<Object, Exception>() {

            @Override
            public Object doWithRetry(RetryContext context) throws Exception {
                throw new RuntimeException("Bad!");
            }
        });
        fail("Expected RuntimeException");
    } catch (BackOffInterruptedException e) {
        assertEquals("foo", e.getMessage());
    }
}
Also used : StatelessBackOffPolicy(org.springframework.retry.backoff.StatelessBackOffPolicy) RetryContext(org.springframework.retry.RetryContext) BackOffInterruptedException(org.springframework.retry.backoff.BackOffInterruptedException) TerminatedRetryException(org.springframework.retry.TerminatedRetryException) BackOffInterruptedException(org.springframework.retry.backoff.BackOffInterruptedException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 RetryContext (org.springframework.retry.RetryContext)1 TerminatedRetryException (org.springframework.retry.TerminatedRetryException)1 BackOffInterruptedException (org.springframework.retry.backoff.BackOffInterruptedException)1 StatelessBackOffPolicy (org.springframework.retry.backoff.StatelessBackOffPolicy)1