Search in sources :

Example 1 with ServerRetryFilter

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

Example 2 with ServerRetryFilter

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<>());
}
Also used : RetriableRequestException(com.linkedin.r2.RetriableRequestException) ServerRetryFilter(com.linkedin.r2.filter.transport.ServerRetryFilter) NextFilter(com.linkedin.r2.filter.NextFilter) FilterChain(com.linkedin.r2.filter.FilterChain) RequestContext(com.linkedin.r2.message.RequestContext) StreamFilter(com.linkedin.r2.filter.message.stream.StreamFilter) HashMap(java.util.HashMap) Map(java.util.Map) StreamException(com.linkedin.r2.message.stream.StreamException) Test(org.testng.annotations.Test)

Example 3 with ServerRetryFilter

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

Example 4 with ServerRetryFilter

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

Aggregations

FilterChain (com.linkedin.r2.filter.FilterChain)4 NextFilter (com.linkedin.r2.filter.NextFilter)4 ServerRetryFilter (com.linkedin.r2.filter.transport.ServerRetryFilter)4 RequestContext (com.linkedin.r2.message.RequestContext)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Test (org.testng.annotations.Test)4 RetriableRequestException (com.linkedin.r2.RetriableRequestException)3 RestFilter (com.linkedin.r2.filter.message.rest.RestFilter)3 RestException (com.linkedin.r2.message.rest.RestException)2 StreamFilter (com.linkedin.r2.filter.message.stream.StreamFilter)1 StreamException (com.linkedin.r2.message.stream.StreamException)1