Search in sources :

Example 1 with StatelessBackOffPolicy

use of cn.taketoday.retry.backoff.StatelessBackOffPolicy in project today-infrastructure by TAKETODAY.

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(cn.taketoday.retry.backoff.StatelessBackOffPolicy) RetryContext(cn.taketoday.retry.RetryContext) BackOffInterruptedException(cn.taketoday.retry.backoff.BackOffInterruptedException) TerminatedRetryException(cn.taketoday.retry.TerminatedRetryException) BackOffInterruptedException(cn.taketoday.retry.backoff.BackOffInterruptedException) Test(org.junit.Test)

Example 2 with StatelessBackOffPolicy

use of cn.taketoday.retry.backoff.StatelessBackOffPolicy in project today-framework by TAKETODAY.

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(cn.taketoday.retry.backoff.StatelessBackOffPolicy) RetryContext(cn.taketoday.retry.RetryContext) BackOffInterruptedException(cn.taketoday.retry.backoff.BackOffInterruptedException) TerminatedRetryException(cn.taketoday.retry.TerminatedRetryException) BackOffInterruptedException(cn.taketoday.retry.backoff.BackOffInterruptedException) Test(org.junit.Test)

Aggregations

RetryContext (cn.taketoday.retry.RetryContext)2 TerminatedRetryException (cn.taketoday.retry.TerminatedRetryException)2 BackOffInterruptedException (cn.taketoday.retry.backoff.BackOffInterruptedException)2 StatelessBackOffPolicy (cn.taketoday.retry.backoff.StatelessBackOffPolicy)2 Test (org.junit.Test)2