Search in sources :

Example 1 with StreamCountFilter

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

the class TestFilterChainImpl method testChainStreamResponseFilters.

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

Example 2 with StreamCountFilter

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

the class TestCapRepFilter method testStreamResponse.

@Test
public void testStreamResponse() throws IOException {
    Path dirPath = Files.createTempDirectory("caprep-test");
    StreamCountFilter after = new StreamCountFilter();
    StreamCountFilter before = new StreamCountFilter();
    CaptureLastCallFilter lastCallFilter = new CaptureLastCallFilter();
    FilterChain fc = FilterChains.createStreamChain(StreamFilterAdapters.adaptRestFilter(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.fireStreamRequest(fc, Messages.toStreamRequest(myRequest), requestContext, FilterUtil.emptyWireAttrs());
    FilterUtil.fireStreamResponse(fc, Messages.toStreamResponse(myResponse), requestContext, FilterUtil.emptyWireAttrs());
    Assert.assertEquals(after.getStreamReqCount(), 1);
    Assert.assertEquals(after.getStreamResCount(), 1);
    Assert.assertEquals(before.getStreamReqCount(), 1);
    Assert.assertEquals(before.getStreamResCount(), 1);
    lastCallFilter.reset();
    _filter.passThrough();
    FilterUtil.fireStreamRequest(fc, Messages.toStreamRequest(myRequest));
    Assert.assertEquals(after.getStreamReqCount(), 2);
    Assert.assertEquals(after.getStreamResCount(), 1);
    Assert.assertEquals(before.getStreamReqCount(), 2);
    Assert.assertEquals(before.getStreamResCount(), 1);
    Assert.assertNull(lastCallFilter.getLastRes());
    _filter.replay(dirPath.toString());
    FilterUtil.fireSimpleStreamRequest(fc);
    Assert.assertNull(lastCallFilter.getLastRes());
    FilterUtil.fireStreamRequest(fc, Messages.toStreamRequest(myRequest), new RequestContext(), FilterUtil.emptyWireAttrs());
    Assert.assertEquals(lastCallFilter.getLastRes(), myResponse);
    Assert.assertEquals(after.getStreamReqCount(), 3);
    Assert.assertEquals(after.getStreamResCount(), 1);
    Assert.assertEquals(before.getStreamReqCount(), 4);
    Assert.assertEquals(before.getStreamResCount(), 2);
}
Also used : Path(java.nio.file.Path) StreamCountFilter(com.linkedin.r2.testutils.filter.StreamCountFilter) 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) Test(org.testng.annotations.Test)

Example 3 with StreamCountFilter

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

the class TestFilterChainImpl method testStreamErrorFilter.

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

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

the class TestFilterChainImpl method testStreamRequestFilter.

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

Example 5 with StreamCountFilter

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

the class StreamFilterTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    _filter = new StreamFilter() {
    };
    _beforeFilter = new StreamCountFilter();
    _afterFilter = new StreamCountFilter();
    _fc = FilterChains.createStreamChain(_beforeFilter, _filter, _afterFilter);
}
Also used : StreamCountFilter(com.linkedin.r2.testutils.filter.StreamCountFilter) StreamFilter(com.linkedin.r2.filter.message.stream.StreamFilter) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

StreamCountFilter (com.linkedin.r2.testutils.filter.StreamCountFilter)11 FilterChain (com.linkedin.r2.filter.FilterChain)10 Test (org.testng.annotations.Test)10 RestCountFilter (com.linkedin.r2.testutils.filter.RestCountFilter)6 StreamFilter (com.linkedin.r2.filter.message.stream.StreamFilter)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 BeforeMethod (org.testng.annotations.BeforeMethod)1