Search in sources :

Example 1 with ClientRetryFilter

use of com.linkedin.r2.filter.transport.ClientRetryFilter 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);
}
Also used : RetriableRequestException(com.linkedin.r2.RetriableRequestException) RestFilter(com.linkedin.r2.filter.message.rest.RestFilter) HashMap(java.util.HashMap) NextFilter(com.linkedin.r2.filter.NextFilter) FilterChain(com.linkedin.r2.filter.FilterChain) ClientRetryFilter(com.linkedin.r2.filter.transport.ClientRetryFilter) RequestContext(com.linkedin.r2.message.RequestContext) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 2 with ClientRetryFilter

use of com.linkedin.r2.filter.transport.ClientRetryFilter in project rest.li by linkedin.

the class TestClientRetryFilter method testNoWireAttribute.

@Test
public void testNoWireAttribute() {
    ClientRetryFilter clientRetryFilter = new ClientRetryFilter();
    RemoteInvocationException exception = new RemoteInvocationException("exception");
    RestFilter captureFilter = new RestFilter() {

        @Override
        public void onRestError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) {
            Assert.assertEquals(exception, ex);
        }
    };
    FilterChain filterChain = FilterChains.createRestChain(captureFilter, clientRetryFilter);
    FilterUtil.fireRestError(filterChain, exception, new HashMap<>());
}
Also used : RestFilter(com.linkedin.r2.filter.message.rest.RestFilter) NextFilter(com.linkedin.r2.filter.NextFilter) FilterChain(com.linkedin.r2.filter.FilterChain) ClientRetryFilter(com.linkedin.r2.filter.transport.ClientRetryFilter) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) RequestContext(com.linkedin.r2.message.RequestContext) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)2 FilterChain (com.linkedin.r2.filter.FilterChain)2 NextFilter (com.linkedin.r2.filter.NextFilter)2 RestFilter (com.linkedin.r2.filter.message.rest.RestFilter)2 ClientRetryFilter (com.linkedin.r2.filter.transport.ClientRetryFilter)2 RequestContext (com.linkedin.r2.message.RequestContext)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.testng.annotations.Test)2 RetriableRequestException (com.linkedin.r2.RetriableRequestException)1