use of com.linkedin.r2.RetriableRequestException in project rest.li by linkedin.
the class ChannelPoolLifecycle method create.
@Override
public void create(final Callback<Channel> channelCallback) {
final long start = System.currentTimeMillis();
_bootstrap.connect(_remoteAddress).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
if (channelFuture.isSuccess()) {
synchronized (_createTimeTracker) {
_createTimeTracker.addValue(System.currentTimeMillis() - start);
}
Channel c = channelFuture.channel();
if (_tcpNoDelay) {
c.config().setOption(ChannelOption.TCP_NODELAY, true);
}
_channelGroup.add(c);
channelCallback.onSuccess(c);
} else {
Throwable cause = channelFuture.cause();
if (cause instanceof ConnectException) {
channelCallback.onError(new RetriableRequestException(cause));
} else {
channelCallback.onError(HttpNettyStreamClient.toException(cause));
}
}
}
});
}
use of com.linkedin.r2.RetriableRequestException in project rest.li by linkedin.
the class RetryTrackerClient method handleRequest.
private <REQ extends Request, RESP extends Response> void handleRequest(REQ request, Map<String, String> wireAttrs, TransportCallback<RESP> callback, Consumer<REQ> requestConsumer, Supplier<RESP> responseSupplier) {
// Process request
requestConsumer.accept(request);
// Prepare response
TransportResponse<RESP> response;
if (_uri.toString().startsWith("http://test.linkedin.com/retry")) {
RetriableRequestException ex = new RetriableRequestException("Data not available");
response = TransportResponseImpl.error(ex);
} else if (_uri.toString().equals("http://test.linkedin.com/bad")) {
response = TransportResponseImpl.error(RestException.forError(404, "exception happens"), wireAttrs);
} else {
response = TransportResponseImpl.success(responseSupplier.get(), wireAttrs);
}
callback.onResponse(response);
}
use of com.linkedin.r2.RetriableRequestException in project rest.li by linkedin.
the class ClientRetryFilter method processError.
private <REQ extends Request, RES extends Response> void processError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<REQ, RES> nextFilter) {
String retryAttr = wireAttrs.get(R2Constants.RETRY_MESSAGE_ATTRIBUTE_KEY);
if (retryAttr != null) {
if (ex instanceof RestException) {
ex = new RestException(((RestException) ex).getResponse(), new RetriableRequestException(retryAttr, ex.getCause()));
} else if (ex instanceof StreamException) {
ex = new StreamException(((StreamException) ex).getResponse(), new RetriableRequestException(retryAttr, ex.getCause()));
} else {
ex = new RetriableRequestException(retryAttr, ex);
}
}
nextFilter.onError(ex, requestContext, wireAttrs);
}
use of com.linkedin.r2.RetriableRequestException in project rest.li by linkedin.
the class TestClientRetryFilter method testRetryFilter.
@Test
public void testRetryFilter() {
String retryMessage = "this is a retry";
ClientRetryFilter clientRetryFilter = new ClientRetryFilter();
RestFilter captureFilter = new RestFilter() {
@Override
public void onRestError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) {
Assert.assertTrue(ex instanceof RetriableRequestException);
Assert.assertEquals(retryMessage, ex.getMessage());
}
};
Map<String, String> wireAttributes = new HashMap<>();
wireAttributes.put(R2Constants.RETRY_MESSAGE_ATTRIBUTE_KEY, retryMessage);
FilterChain filterChain = FilterChains.createRestChain(captureFilter, clientRetryFilter);
FilterUtil.fireRestError(filterChain, new RemoteInvocationException("exception"), wireAttributes);
}
use of com.linkedin.r2.RetriableRequestException in project rest.li by linkedin.
the class TestClientRetryFilter method testClientSideRetriableException.
@Test
public void testClientSideRetriableException() {
ClientRetryFilter clientRetryFilter = new ClientRetryFilter();
RestFilter captureFilter = new RestFilter() {
@Override
public void onRestError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) {
Assert.assertTrue(ex instanceof RetriableRequestException);
Assert.assertFalse(((RetriableRequestException) ex).getDoNotRetryOverride());
}
};
FilterChain filterChain = FilterChains.createRestChain(captureFilter, clientRetryFilter);
FilterUtil.fireRestError(filterChain, new RetriableRequestException("exception"), new HashMap<>());
}
Aggregations