use of org.springframework.retry.RetryContext in project dhis2-core by dhis2.
the class MetadataRetryContextTest method testShouldSetRetryContextCorrectly.
@Test
public void testShouldSetRetryContextCorrectly() throws Exception {
RetryContext newMock = mock(RetryContext.class);
metadataRetryContext.setRetryContext(newMock);
assertEquals(newMock, metadataRetryContext.getRetryContext());
}
use of org.springframework.retry.RetryContext in project spring-integration by spring-projects.
the class AdvisedMessageHandlerTests method errorMessageSendingRecovererTestsNoThrowable.
@Test
public void errorMessageSendingRecovererTestsNoThrowable() {
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
throw new RuntimeException("fooException");
}
};
QueueChannel errors = new QueueChannel();
RequestHandlerRetryAdvice advice = new RequestHandlerRetryAdvice();
ErrorMessageSendingRecoverer recoverer = new ErrorMessageSendingRecoverer(errors);
advice.setRecoveryCallback(recoverer);
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setRetryPolicy(new SimpleRetryPolicy() {
static final long serialVersionUID = -1;
@Override
public boolean canRetry(RetryContext context) {
return false;
}
});
advice.setRetryTemplate(retryTemplate);
advice.setBeanFactory(mock(BeanFactory.class));
advice.afterPropertiesSet();
List<Advice> adviceChain = new ArrayList<Advice>();
adviceChain.add(advice);
handler.setAdviceChain(adviceChain);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
Message<String> message = new GenericMessage<String>("Hello, world!");
handler.handleMessage(message);
Message<?> error = errors.receive(10000);
assertNotNull(error);
assertTrue(error.getPayload() instanceof ErrorMessageSendingRecoverer.RetryExceptionNotAvailableException);
assertNotNull(((MessagingException) error.getPayload()).getFailedMessage());
assertSame(message, ((MessagingException) error.getPayload()).getFailedMessage());
}
use of org.springframework.retry.RetryContext in project spring-cloud-netflix by spring-cloud.
the class RetryableOkHttpLoadBalancingClient method execute.
@Override
public OkHttpRibbonResponse execute(final OkHttpRibbonRequest ribbonRequest, final IClientConfig configOverride) throws Exception {
final LoadBalancedRetryPolicy retryPolicy = loadBalancedRetryFactory.createRetryPolicy(this.getClientName(), this);
RetryCallback<OkHttpRibbonResponse, Exception> retryCallback = new RetryCallback<OkHttpRibbonResponse, Exception>() {
@Override
public OkHttpRibbonResponse doWithRetry(RetryContext context) throws Exception {
// on retries the policy will choose the server and set it in the context
// extract the server and update the request being made
OkHttpRibbonRequest newRequest = ribbonRequest;
if (context instanceof LoadBalancedRetryContext) {
ServiceInstance service = ((LoadBalancedRetryContext) context).getServiceInstance();
validateServiceInstance(service);
// Reconstruct the request URI using the host and port set in the retry context
newRequest = newRequest.withNewUri(new URI(service.getUri().getScheme(), newRequest.getURI().getUserInfo(), service.getHost(), service.getPort(), newRequest.getURI().getPath(), newRequest.getURI().getQuery(), newRequest.getURI().getFragment()));
}
if (isSecure(configOverride)) {
final URI secureUri = UriComponentsBuilder.fromUri(newRequest.getUri()).scheme("https").build().toUri();
newRequest = newRequest.withNewUri(secureUri);
}
OkHttpClient httpClient = getOkHttpClient(configOverride, secure);
final Request request = newRequest.toRequest();
Response response = httpClient.newCall(request).execute();
if (retryPolicy.retryableStatusCode(response.code())) {
ResponseBody responseBody = response.peekBody(Integer.MAX_VALUE);
response.close();
throw new OkHttpStatusCodeException(RetryableOkHttpLoadBalancingClient.this.clientName, response, responseBody, newRequest.getURI());
}
return new OkHttpRibbonResponse(response, newRequest.getUri());
}
};
return this.executeWithRetry(ribbonRequest, retryPolicy, retryCallback, new LoadBalancedRecoveryCallback<OkHttpRibbonResponse, Response>() {
@Override
protected OkHttpRibbonResponse createResponse(Response response, URI uri) {
return new OkHttpRibbonResponse(response, uri);
}
});
}
use of org.springframework.retry.RetryContext in project molgenis by molgenis.
the class ConnectionRetryConfigTest method testRetryPolicyInterrupted.
@Test
public void testRetryPolicyInterrupted() {
RetryContext context = retryPolicy.open(null);
retryPolicy.registerThrowable(context, new InterruptedException("Going down"));
assertFalse(retryPolicy.canRetry(context));
}
use of org.springframework.retry.RetryContext in project molgenis by molgenis.
the class ConnectionRetryConfigTest method testRetryPolicyMolgenisDataException.
@Test
public void testRetryPolicyMolgenisDataException() {
RetryContext context = retryPolicy.open(null);
retryPolicy.registerThrowable(context, new MolgenisDataException("Failed to connect"));
assertTrue(retryPolicy.canRetry(context));
}
Aggregations