use of com.linkedin.r2.filter.message.stream.StreamFilter 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);
}
use of com.linkedin.r2.filter.message.stream.StreamFilter in project rest.li by linkedin.
the class TestRequestCompression method requestCompressionData.
@DataProvider
public Object[][] requestCompressionData() {
StreamEncodingType[] encodings = new StreamEncodingType[] { StreamEncodingType.GZIP, StreamEncodingType.DEFLATE, StreamEncodingType.SNAPPY_FRAMED, StreamEncodingType.BZIP2 };
String[] protocols = new String[] { HttpProtocolVersion.HTTP_1_1.name(), HttpProtocolVersion.HTTP_2.name() };
Object[][] args = new Object[encodings.length * protocols.length][2];
int cur = 0;
for (StreamEncodingType requestEncoding : encodings) {
for (String protocol : protocols) {
StreamFilter clientCompressionFilter = new ClientStreamCompressionFilter(requestEncoding, new CompressionConfig(THRESHOLD), null, new CompressionConfig(THRESHOLD), Arrays.asList(new String[] { "*" }), _executor);
TransportClientFactory factory = new HttpClientFactory.Builder().setFilterChain(FilterChains.createStreamChain(clientCompressionFilter)).build();
HashMap<String, String> properties = new HashMap<>();
properties.put(HttpClientFactory.HTTP_PROTOCOL_VERSION, protocol);
Client client = new TransportClientAdapter(factory.getClient(properties), true);
args[cur][0] = client;
args[cur][1] = URI.create("/" + requestEncoding.getHttpName());
cur++;
_clientFactories.add(factory);
_clients.add(client);
}
}
return args;
}
use of com.linkedin.r2.filter.message.stream.StreamFilter in project rest.li by linkedin.
the class TestServerRetryFilter method testStreamRetryFilter.
@Test
public void testStreamRetryFilter() {
String retryMessage = "this is a retry";
ServerRetryFilter retryFilter = new ServerRetryFilter();
StreamFilter captureFilter = new StreamFilter() {
@Override
public void onStreamError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<StreamRequest, StreamResponse> nextFilter) {
Assert.assertEquals(wireAttrs.get(R2Constants.RETRY_MESSAGE_ATTRIBUTE_KEY), retryMessage);
}
};
FilterChain filterChain = FilterChains.createStreamChain(captureFilter, retryFilter);
FilterUtil.fireRestError(filterChain, new StreamException(null, new RetriableRequestException(retryMessage)), new HashMap<String, String>());
}
use of com.linkedin.r2.filter.message.stream.StreamFilter in project rest.li by linkedin.
the class TestFilterChainImpl method testNullFilterInList.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNullFilterInList() {
List<RestFilter> restFilters = new ArrayList<RestFilter>();
restFilters.add(new RestCountFilter());
restFilters.add(null);
FilterChains.create(restFilters, Collections.<StreamFilter>emptyList());
}
use of com.linkedin.r2.filter.message.stream.StreamFilter in project rest.li by linkedin.
the class TestCompressionEcho method compressionEchoData.
@DataProvider
public Object[][] compressionEchoData() {
StreamEncodingType[] encodings = new StreamEncodingType[] { StreamEncodingType.GZIP, StreamEncodingType.DEFLATE, StreamEncodingType.SNAPPY_FRAMED, StreamEncodingType.BZIP2, StreamEncodingType.IDENTITY };
Object[][] args = new Object[2 * encodings.length * encodings.length][2];
int cur = 0;
for (StreamEncodingType requestEncoding : encodings) {
for (StreamEncodingType acceptEncoding : encodings) {
StreamFilter clientCompressionFilter = new ClientStreamCompressionFilter(requestEncoding, new CompressionConfig(THRESHOLD), new StreamEncodingType[] { acceptEncoding }, new CompressionConfig(THRESHOLD), Arrays.asList(new String[] { "*" }), _executor);
TransportClientFactory factory = new HttpClientFactory.Builder().setFilterChain(FilterChains.createStreamChain(clientCompressionFilter)).build();
Client client = new TransportClientAdapter(factory.getClient(getClientProperties()), true);
args[cur][0] = client;
args[cur][1] = LARGE_BYTES_NUM;
cur++;
_clientFactories.add(factory);
_clients.add(client);
}
}
// test data that won't trigger compression
for (StreamEncodingType requestEncoding : encodings) {
for (StreamEncodingType acceptEncoding : encodings) {
StreamFilter clientCompressionFilter = new ClientStreamCompressionFilter(requestEncoding, new CompressionConfig(THRESHOLD), new StreamEncodingType[] { acceptEncoding }, new CompressionConfig(THRESHOLD), Arrays.asList(new String[] { "*" }), _executor);
TransportClientFactory factory = new HttpClientFactory.Builder().setFilterChain(FilterChains.createStreamChain(clientCompressionFilter)).build();
Client client = new TransportClientAdapter(factory.getClient(getClientProperties()), true);
args[cur][0] = client;
args[cur][1] = SMALL_BYTES_NUM;
cur++;
_clientFactories.add(factory);
_clients.add(client);
}
}
return args;
}
Aggregations