use of com.linkedin.r2.filter.message.stream.StreamFilter in project rest.li by linkedin.
the class TestRequestCompression method noCompressionData.
@DataProvider
public Object[][] noCompressionData() {
StreamEncodingType[] encodings = new StreamEncodingType[] { StreamEncodingType.GZIP, StreamEncodingType.DEFLATE, StreamEncodingType.SNAPPY_FRAMED, StreamEncodingType.BZIP2, StreamEncodingType.IDENTITY };
String[] protocols = new String[] { HttpProtocolVersion.HTTP_1_1.name(), HttpProtocolVersion.HTTP_2.name() };
Object[][] args = new Object[encodings.length * protocols.length][1];
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(Collections.<String, String>emptyMap()), 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 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);
}
Aggregations