use of cn.taketoday.retry.ExhaustedRetryException in project today-framework by TAKETODAY.
the class StatefulRetryOperationsInterceptorTests method testRetryExceptionAfterTooManyAttemptsWithNoRecovery.
@Test
public void testRetryExceptionAfterTooManyAttemptsWithNoRecovery() throws Exception {
((Advised) service).addAdvice(interceptor);
interceptor.setRetryOperations(retryTemplate);
retryTemplate.setRetryPolicy(new NeverRetryPolicy());
try {
service.service("foo");
fail("Expected Exception.");
} catch (Exception e) {
String message = e.getMessage();
assertTrue("Wrong message: " + message, message.startsWith("Not enough calls"));
}
assertEquals(1, count);
try {
service.service("foo");
fail("Expected ExhaustedRetryException");
} catch (ExhaustedRetryException e) {
// expected
String message = e.getMessage();
assertTrue("Wrong message: " + message, message.startsWith("Retry exhausted"));
}
assertEquals(1, count);
}
use of cn.taketoday.retry.ExhaustedRetryException in project today-framework by TAKETODAY.
the class StatefulRecoveryRetryTests method testExhaustedClearsHistoryAfterLastAttempt.
@Test
public void testExhaustedClearsHistoryAfterLastAttempt() throws Throwable {
RetryPolicy retryPolicy = new SimpleRetryPolicy(1);
this.retryTemplate.setRetryPolicy(retryPolicy);
final String input = "foo";
RetryState state = new DefaultRetryState(input);
RetryCallback<String, Exception> callback = new RetryCallback<String, Exception>() {
@Override
public String doWithRetry(RetryContext context) throws Exception {
throw new RuntimeException("Barf!");
}
};
try {
this.retryTemplate.execute(callback, state);
fail("Expected ExhaustedRetryException");
} catch (RuntimeException e) {
assertEquals("Barf!", e.getMessage());
}
try {
this.retryTemplate.execute(callback, state);
fail("Expected ExhaustedRetryException");
} catch (ExhaustedRetryException e) {
// expected
}
RetryContext context = this.retryTemplate.open(retryPolicy, state);
// True after exhausted - the history is reset...
assertTrue(retryPolicy.canRetry(context));
}
use of cn.taketoday.retry.ExhaustedRetryException in project today-infrastructure by TAKETODAY.
the class CircuitBreakerStatisticsTests method testFailedRecoveryCountsAsAbort.
@Test
public void testFailedRecoveryCountsAsAbort() throws Throwable {
this.retryTemplate.setRetryPolicy(new CircuitBreakerRetryPolicy(new NeverRetryPolicy()));
this.recovery = new RecoveryCallback<Object>() {
@Override
public Object recover(RetryContext context) throws Exception {
throw new ExhaustedRetryException("Planned exhausted");
}
};
try {
this.retryTemplate.execute(this.callback, this.recovery, this.state);
fail("Expected ExhaustedRetryException");
} catch (ExhaustedRetryException e) {
// Fine
}
MutableRetryStatistics stats = (MutableRetryStatistics) repository.findOne("test");
assertEquals(1, stats.getStartedCount());
assertEquals(1, stats.getAbortCount());
assertEquals(0, stats.getRecoveryCount());
}
use of cn.taketoday.retry.ExhaustedRetryException in project today-infrastructure by TAKETODAY.
the class StatefulRetryIntegrationTests method testExternalRetryWithFailAndNoRetry.
@Test
public void testExternalRetryWithFailAndNoRetry() throws Throwable {
MockRetryCallback callback = new MockRetryCallback();
RetryState retryState = new DefaultRetryState("foo");
RetryTemplate retryTemplate = new RetryTemplate();
MapRetryContextCache cache = new MapRetryContextCache();
retryTemplate.setRetryContextCache(cache);
retryTemplate.setRetryPolicy(new SimpleRetryPolicy(1));
assertFalse(cache.containsKey("foo"));
try {
retryTemplate.execute(callback, retryState);
// The first failed attempt we expect to retry...
fail("Expected RuntimeException");
} catch (RuntimeException e) {
assertEquals(null, e.getMessage());
}
assertTrue(cache.containsKey("foo"));
try {
retryTemplate.execute(callback, retryState);
// We don't get a second attempt...
fail("Expected ExhaustedRetryException");
} catch (ExhaustedRetryException e) {
// This is now the "exhausted" message:
assertNotNull(e.getMessage());
}
assertFalse(cache.containsKey("foo"));
// Callback is called once: the recovery path should be called in
// handleRetryExhausted (so not in this test)...
assertEquals(1, callback.attempts);
}
use of cn.taketoday.retry.ExhaustedRetryException in project today-infrastructure by TAKETODAY.
the class StatefulRecoveryRetryTests method testExhaustedClearsHistoryAfterLastAttempt.
@Test
public void testExhaustedClearsHistoryAfterLastAttempt() throws Throwable {
RetryPolicy retryPolicy = new SimpleRetryPolicy(1);
this.retryTemplate.setRetryPolicy(retryPolicy);
final String input = "foo";
RetryState state = new DefaultRetryState(input);
RetryCallback<String, Exception> callback = new RetryCallback<String, Exception>() {
@Override
public String doWithRetry(RetryContext context) throws Exception {
throw new RuntimeException("Barf!");
}
};
try {
this.retryTemplate.execute(callback, state);
fail("Expected ExhaustedRetryException");
} catch (RuntimeException e) {
assertEquals("Barf!", e.getMessage());
}
try {
this.retryTemplate.execute(callback, state);
fail("Expected ExhaustedRetryException");
} catch (ExhaustedRetryException e) {
// expected
}
RetryContext context = this.retryTemplate.open(retryPolicy, state);
// True after exhausted - the history is reset...
assertTrue(retryPolicy.canRetry(context));
}
Aggregations