use of com.linkedin.r2.filter.message.rest.RestFilter in project rest.li by linkedin.
the class TestStreamFilterAdapters method testRequestFilterAdapterCallsOnResponse.
@Test
public void testRequestFilterAdapterCallsOnResponse() {
FilterChain fc = adaptAndCreateFilterChain(new RestFilter() {
@Override
public void onRestRequest(RestRequest req, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) {
nextFilter.onResponse(simpleRestResponse(req.getEntity().asString("UTF8")), requestContext, wireAttrs);
}
});
fc.onStreamRequest(simpleStreamRequest("12345"), FilterUtil.emptyRequestContext(), FilterUtil.emptyWireAttrs());
StreamResponse capturedReq = _beforeFilter.getResponse();
capturedReq.getEntityStream().setReader(new FullEntityReader(new Callback<ByteString>() {
@Override
public void onError(Throwable e) {
Assert.fail("shouldn't have error");
}
@Override
public void onSuccess(ByteString result) {
Assert.assertEquals(result.asString("UTF8"), "12345");
}
}));
}
use of com.linkedin.r2.filter.message.rest.RestFilter 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);
}
use of com.linkedin.r2.filter.message.rest.RestFilter 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<String, String>());
}
use of com.linkedin.r2.filter.message.rest.RestFilter in project rest.li by linkedin.
the class TestReplaceableFilter method testSetAndGet.
@Test
public void testSetAndGet() {
final ReplaceableFilter filter = getFilter();
final RestFilter newFilter = new PassThroughFilter();
Assert.assertTrue(!filter.getFilter().equals(newFilter));
filter.setFilter(newFilter);
Assert.assertEquals(newFilter, filter.getFilter());
}
Aggregations