Search in sources :

Example 46 with FilterChain

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

the class TestFilterChainImpl method testChainStreamRequestFilters.

@Test
public void testChainStreamRequestFilters() {
    final StreamCountFilter filter1 = new StreamCountFilter();
    final StreamCountFilter filter2 = new StreamCountFilter();
    final StreamCountFilter filter3 = new StreamCountFilter();
    final FilterChain fc = FilterChains.createStreamChain(filter1, filter2, filter3);
    fireStreamRequest(fc);
    assertStreamCounts(1, 0, 0, filter1);
    assertStreamCounts(1, 0, 0, filter2);
    assertStreamCounts(1, 0, 0, filter3);
}
Also used : StreamCountFilter(com.linkedin.r2.testutils.filter.StreamCountFilter) FilterChain(com.linkedin.r2.filter.FilterChain) Test(org.testng.annotations.Test)

Example 47 with FilterChain

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

the class TestFilterChainImpl method testChainRestRequestFilters.

@Test
public void testChainRestRequestFilters() {
    final RestCountFilter filter1 = new RestCountFilter();
    final RestCountFilter filter2 = new RestCountFilter();
    final RestCountFilter filter3 = new RestCountFilter();
    final FilterChain fc = FilterChains.createRestChain(filter1, filter2, filter3);
    fireRestRequest(fc);
    assertRestCounts(1, 0, 0, filter1);
    assertRestCounts(1, 0, 0, filter2);
    assertRestCounts(1, 0, 0, filter3);
}
Also used : FilterChain(com.linkedin.r2.filter.FilterChain) RestCountFilter(com.linkedin.r2.testutils.filter.RestCountFilter) Test(org.testng.annotations.Test)

Example 48 with FilterChain

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

the class TestFilterChainImpl method testChainStreamErrorFilters.

@Test
public void testChainStreamErrorFilters() {
    final StreamCountFilter filter1 = new StreamCountFilter();
    final StreamCountFilter filter2 = new StreamCountFilter();
    final StreamCountFilter filter3 = new StreamCountFilter();
    final FilterChain fc = FilterChains.createStreamChain(filter1, filter2, filter3);
    fireStreamError(fc);
    assertStreamCounts(0, 0, 1, filter1);
    assertStreamCounts(0, 0, 1, filter2);
    assertStreamCounts(0, 0, 1, filter3);
}
Also used : StreamCountFilter(com.linkedin.r2.testutils.filter.StreamCountFilter) FilterChain(com.linkedin.r2.filter.FilterChain) Test(org.testng.annotations.Test)

Example 49 with FilterChain

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

the class TestFilterChainImpl method testFilterOrderTwoChains.

@Test
public void testFilterOrderTwoChains() {
    AtomicInteger count = new AtomicInteger(0);
    CheckOrderFilter filter1 = new CheckOrderFilter(count);
    CheckOrderFilter filter2 = new CheckOrderFilter(count);
    List<RestFilter> restFilters = new ArrayList<RestFilter>();
    restFilters.add(filter1);
    restFilters.add(filter2);
    List<StreamFilter> streamFilters = new ArrayList<StreamFilter>();
    streamFilters.add(filter1);
    streamFilters.add(filter2);
    final FilterChain fc = FilterChains.create(restFilters, streamFilters);
    fireRestRequest(fc);
    Assert.assertEquals(filter1.getOrder(), 1);
    Assert.assertEquals(filter2.getOrder(), 2);
    fireRestResponse(fc);
    Assert.assertEquals(filter1.getOrder(), 4);
    Assert.assertEquals(filter2.getOrder(), 3);
    fireRestError(fc);
    Assert.assertEquals(filter1.getOrder(), 6);
    Assert.assertEquals(filter2.getOrder(), 5);
    count.set(0);
    fireStreamRequest(fc);
    Assert.assertEquals(filter1.getOrder(), 1);
    Assert.assertEquals(filter2.getOrder(), 2);
    fireStreamResponse(fc);
    Assert.assertEquals(filter1.getOrder(), 4);
    Assert.assertEquals(filter2.getOrder(), 3);
    fireStreamError(fc);
    Assert.assertEquals(filter1.getOrder(), 6);
    Assert.assertEquals(filter2.getOrder(), 5);
}
Also used : RestFilter(com.linkedin.r2.filter.message.rest.RestFilter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FilterChain(com.linkedin.r2.filter.FilterChain) ArrayList(java.util.ArrayList) StreamFilter(com.linkedin.r2.filter.message.stream.StreamFilter) Test(org.testng.annotations.Test)

Example 50 with FilterChain

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

the class TestFilterChainImpl method testRestRequestFilter.

@Test
public void testRestRequestFilter() {
    final RestCountFilter restCountFilter = new RestCountFilter();
    final StreamCountFilter streamCountFilter = new StreamCountFilter();
    FilterChain fc = FilterChains.createRestChain(restCountFilter);
    fc = fc.addLast(streamCountFilter);
    fireRestRequest(fc);
    assertRestCounts(1, 0, 0, restCountFilter);
    assertStreamCounts(0, 0, 0, streamCountFilter);
}
Also used : StreamCountFilter(com.linkedin.r2.testutils.filter.StreamCountFilter) FilterChain(com.linkedin.r2.filter.FilterChain) RestCountFilter(com.linkedin.r2.testutils.filter.RestCountFilter) Test(org.testng.annotations.Test)

Aggregations

FilterChain (com.linkedin.r2.filter.FilterChain)45 Test (org.testng.annotations.Test)38 RequestContext (com.linkedin.r2.message.RequestContext)28 RestRequest (com.linkedin.r2.message.rest.RestRequest)20 RestResponse (com.linkedin.r2.message.rest.RestResponse)17 RestFilter (com.linkedin.r2.filter.message.rest.RestFilter)15 HashMap (java.util.HashMap)12 ByteString (com.linkedin.data.ByteString)11 Map (java.util.Map)11 RestException (com.linkedin.r2.message.rest.RestException)10 RestCountFilter (com.linkedin.r2.testutils.filter.RestCountFilter)10 StreamCountFilter (com.linkedin.r2.testutils.filter.StreamCountFilter)10 NextFilter (com.linkedin.r2.filter.NextFilter)9 Callback (com.linkedin.common.callback.Callback)8 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)8 FullEntityReader (com.linkedin.r2.message.stream.entitystream.FullEntityReader)8 CaptureLastCallFilter (com.linkedin.r2.testutils.filter.CaptureLastCallFilter)7 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)6 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)5 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)5