Search in sources :

Example 6 with RestCountFilter

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

the class TestFilterChainImpl method testChainRestResponseFilters.

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

Example 7 with RestCountFilter

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

the class TestFilterChainImpl method testStreamResponseFilter.

@Test
public void testStreamResponseFilter() {
    final RestCountFilter restCountFilter = new RestCountFilter();
    final StreamCountFilter streamCountFilter = new StreamCountFilter();
    FilterChain fc = FilterChains.createRestChain(restCountFilter);
    fc = fc.addLast(streamCountFilter);
    fireStreamResponse(fc);
    assertRestCounts(0, 0, 0, restCountFilter);
    assertStreamCounts(0, 1, 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)

Example 8 with RestCountFilter

use of com.linkedin.r2.testutils.filter.RestCountFilter 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 9 with RestCountFilter

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

the class TestCapRepFilter method testRestResponse.

@Test
public void testRestResponse() throws IOException {
    Path dirPath = Files.createTempDirectory("caprep-test");
    RestCountFilter after = new RestCountFilter();
    RestCountFilter before = new RestCountFilter();
    CaptureLastCallFilter lastCallFilter = new CaptureLastCallFilter();
    FilterChain fc = FilterChains.createRestChain(lastCallFilter, before, _filter, after);
    RestRequest myRequest = new RestRequestBuilder(URI.create("/req1")).setEntity("123".getBytes()).build();
    RestResponse myResponse = new RestResponseBuilder().setStatus(201).setEntity("321".getBytes()).build();
    _filter.capture(dirPath.toString());
    RequestContext requestContext = new RequestContext();
    FilterUtil.fireRestRequest(fc, myRequest, requestContext, FilterUtil.emptyWireAttrs());
    FilterUtil.fireRestResponse(fc, myResponse, requestContext, FilterUtil.emptyWireAttrs());
    Assert.assertEquals(after.getRestReqCount(), 1);
    Assert.assertEquals(after.getRestResCount(), 1);
    Assert.assertEquals(before.getRestReqCount(), 1);
    Assert.assertEquals(before.getRestResCount(), 1);
    lastCallFilter.reset();
    _filter.passThrough();
    FilterUtil.fireRestRequest(fc, myRequest);
    Assert.assertEquals(after.getRestReqCount(), 2);
    Assert.assertEquals(after.getRestResCount(), 1);
    Assert.assertEquals(before.getRestReqCount(), 2);
    Assert.assertEquals(before.getRestResCount(), 1);
    Assert.assertNull(lastCallFilter.getLastRes());
    _filter.replay(dirPath.toString());
    FilterUtil.fireSimpleRestRequest(fc);
    Assert.assertNull(lastCallFilter.getLastRes());
    FilterUtil.fireRestRequest(fc, myRequest);
    Assert.assertEquals(lastCallFilter.getLastRes(), myResponse);
    Assert.assertEquals(after.getRestReqCount(), 3);
    Assert.assertEquals(after.getRestResCount(), 1);
    Assert.assertEquals(before.getRestReqCount(), 4);
    Assert.assertEquals(before.getRestResCount(), 2);
}
Also used : Path(java.nio.file.Path) RestRequest(com.linkedin.r2.message.rest.RestRequest) CaptureLastCallFilter(com.linkedin.r2.testutils.filter.CaptureLastCallFilter) RestResponse(com.linkedin.r2.message.rest.RestResponse) FilterChain(com.linkedin.r2.filter.FilterChain) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) RestCountFilter(com.linkedin.r2.testutils.filter.RestCountFilter) Test(org.testng.annotations.Test)

Example 10 with RestCountFilter

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

the class TestFilterChainImpl method testRestResponseFilter.

@Test
public void testRestResponseFilter() {
    final RestCountFilter restCountFilter = new RestCountFilter();
    final StreamCountFilter streamCountFilter = new StreamCountFilter();
    FilterChain fc = FilterChains.createRestChain(restCountFilter);
    fc = fc.addLast(streamCountFilter);
    fireRestResponse(fc);
    assertRestCounts(0, 1, 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

RestCountFilter (com.linkedin.r2.testutils.filter.RestCountFilter)12 Test (org.testng.annotations.Test)11 FilterChain (com.linkedin.r2.filter.FilterChain)10 StreamCountFilter (com.linkedin.r2.testutils.filter.StreamCountFilter)6 RestFilter (com.linkedin.r2.filter.message.rest.RestFilter)2 BaseRestFilter (com.linkedin.r2.filter.message.rest.BaseRestFilter)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 RestResponse (com.linkedin.r2.message.rest.RestResponse)1 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)1 CaptureLastCallFilter (com.linkedin.r2.testutils.filter.CaptureLastCallFilter)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 BeforeMethod (org.testng.annotations.BeforeMethod)1