use of cn.taketoday.retry.policy.NeverRetryPolicy in project today-infrastructure by TAKETODAY.
the class RetryOperationsInterceptorTests method testRetryExceptionAfterTooManyAttempts.
@Test
public void testRetryExceptionAfterTooManyAttempts() throws Exception {
((Advised) this.service).addAdvice(this.interceptor);
RetryTemplate template = new RetryTemplate();
template.setRetryPolicy(new NeverRetryPolicy());
this.interceptor.setRetryOperations(template);
try {
this.service.service();
fail("Expected Exception.");
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Not enough calls"));
}
assertEquals(1, count);
}
use of cn.taketoday.retry.policy.NeverRetryPolicy in project today-infrastructure 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.policy.NeverRetryPolicy in project today-infrastructure by TAKETODAY.
the class StatefulRetryOperationsInterceptorTests method testTransformerRecoveryAfterTooManyAttempts.
@Test
public void testTransformerRecoveryAfterTooManyAttempts() throws Exception {
((Advised) transformer).addAdvice(interceptor);
interceptor.setRetryOperations(retryTemplate);
retryTemplate.setRetryPolicy(new NeverRetryPolicy());
try {
transformer.transform("foo");
fail("Expected Exception.");
} catch (Exception e) {
String message = e.getMessage();
assertTrue("Wrong message: " + message, message.startsWith("Not enough calls"));
}
assertEquals(1, count);
interceptor.setRecoverer((MethodInvocationRecoverer<Collection<String>>) (data, cause) -> {
count++;
return Collections.singleton((String) data[0]);
});
Collection<String> result = transformer.transform("foo");
assertEquals(2, count);
assertEquals(1, result.size());
}
use of cn.taketoday.retry.policy.NeverRetryPolicy in project today-infrastructure by TAKETODAY.
the class RetryTemplateTests method testRethrowError.
@Test
public void testRethrowError() throws Throwable {
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setRetryPolicy(new NeverRetryPolicy());
try {
retryTemplate.execute(new RetryCallback<Object, Exception>() {
@Override
public Object doWithRetry(RetryContext context) throws Exception {
throw new Error("Realllly bad!");
}
});
fail("Expected Error");
} catch (Error e) {
assertEquals("Realllly bad!", e.getMessage());
}
}
use of cn.taketoday.retry.policy.NeverRetryPolicy in project today-infrastructure by TAKETODAY.
the class RetryTemplateTests method testFailedPolicy.
@SuppressWarnings("serial")
@Test
public void testFailedPolicy() throws Throwable {
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setRetryPolicy(new NeverRetryPolicy() {
@Override
public void registerThrowable(RetryContext context, Throwable throwable) {
throw new RuntimeException("Planned");
}
});
try {
retryTemplate.execute(new RetryCallback<Object, Exception>() {
@Override
public Object doWithRetry(RetryContext context) throws Exception {
throw new RuntimeException("Realllly bad!");
}
});
fail("Expected Error");
} catch (TerminatedRetryException e) {
assertEquals("Planned", e.getCause().getMessage());
}
}
Aggregations