use of com.linkedin.r2.filter.transport.ServerRetryFilter in project rest.li by linkedin.
the class TestServerRetryFilter method testRetryFilter.
@Test
public void testRetryFilter() {
String retryMessage = "this is a retry";
ServerRetryFilter retryFilter = new ServerRetryFilter();
RestFilter captureFilter = new RestFilter() {
@Override
public void onRestError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) {
Assert.assertEquals(wireAttrs.get(R2Constants.RETRY_MESSAGE_ATTRIBUTE_KEY), retryMessage);
}
};
FilterChain filterChain = FilterChains.createRestChain(captureFilter, retryFilter);
FilterUtil.fireRestError(filterChain, new RestException(null, new RetriableRequestException(retryMessage)), new HashMap<>());
}
use of com.linkedin.r2.filter.transport.ServerRetryFilter in project rest.li by linkedin.
the class TestServerRetryFilter method testStreamRetryFilter.
@Test
public void testStreamRetryFilter() {
String retryMessage = "this is a retry";
ServerRetryFilter retryFilter = new ServerRetryFilter();
StreamFilter captureFilter = new StreamFilter() {
@Override
public void onStreamError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<StreamRequest, StreamResponse> nextFilter) {
Assert.assertEquals(wireAttrs.get(R2Constants.RETRY_MESSAGE_ATTRIBUTE_KEY), retryMessage);
}
};
FilterChain filterChain = FilterChains.createStreamChain(captureFilter, retryFilter);
FilterUtil.fireRestError(filterChain, new StreamException(null, new RetriableRequestException(retryMessage)), new HashMap<>());
}
use of com.linkedin.r2.filter.transport.ServerRetryFilter in project rest.li by linkedin.
the class TestServerRetryFilter method testNestedException.
@Test
public void testNestedException() {
String retryMessage = "this is a retry";
ServerRetryFilter retryFilter = new ServerRetryFilter();
RestFilter captureFilter = new RestFilter() {
@Override
public void onRestError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) {
Assert.assertEquals(wireAttrs.get(R2Constants.RETRY_MESSAGE_ATTRIBUTE_KEY), retryMessage);
}
};
FilterChain filterChain = FilterChains.createRestChain(captureFilter, retryFilter);
Throwable nestedException = new RetriableRequestException(retryMessage);
for (int i = 0; i < 5; i++) {
nestedException = new RuntimeException(nestedException);
}
FilterUtil.fireRestError(filterChain, new RestException(null, nestedException), new HashMap<>());
}
use of com.linkedin.r2.filter.transport.ServerRetryFilter in project rest.li by linkedin.
the class TestServerRetryFilter method testNotRetriableException.
@Test
public void testNotRetriableException() {
ServerRetryFilter retryFilter = new ServerRetryFilter();
RestFilter captureFilter = new RestFilter() {
@Override
public void onRestError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) {
Assert.assertNull(wireAttrs.get(R2Constants.RETRY_MESSAGE_ATTRIBUTE_KEY));
}
};
FilterChain filterChain = FilterChains.createRestChain(captureFilter, retryFilter);
FilterUtil.fireRestError(filterChain, new RuntimeException(new RuntimeException()), new HashMap<>());
}
Aggregations