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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations