use of com.linkedin.r2.filter.compression.ClientStreamCompressionFilter 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.compression.ClientStreamCompressionFilter in project rest.li by linkedin.
the class TestClientStreamCompressionFilter method testAcceptEncodingHeader.
@Test(dataProvider = "requestData")
public void testAcceptEncodingHeader(CompressionConfig requestCompressionConfig, CompressionOption requestCompressionOverride, boolean headerShouldBePresent, String operation) throws CompressionException, URISyntaxException, InterruptedException, ExecutionException, TimeoutException {
Executor executor = Executors.newCachedThreadPool();
ClientStreamCompressionFilter clientCompressionFilter = new ClientStreamCompressionFilter(StreamEncodingType.GZIP.getHttpName(), requestCompressionConfig, ACCEPT_COMPRESSIONS, new CompressionConfig(Integer.MAX_VALUE), Arrays.asList(ClientCompressionHelper.COMPRESS_ALL_RESPONSES_INDICATOR), executor);
// The entity should be compressible for this test.
int original = 100;
byte[] entity = new byte[original];
Arrays.fill(entity, (byte) 'A');
StreamRequest streamRequest = new StreamRequestBuilder(new URI(URI)).setMethod(RestMethod.POST).build(EntityStreams.newEntityStream(new ByteStringWriter(ByteString.copy(entity))));
int compressed = EncodingType.GZIP.getCompressor().deflate(new ByteArrayInputStream(entity)).length;
RequestContext context = new RequestContext();
if (operation != null) {
context.putLocalAttr(R2Constants.OPERATION, operation);
}
context.putLocalAttr(R2Constants.REQUEST_COMPRESSION_OVERRIDE, requestCompressionOverride);
int entityLength = headerShouldBePresent ? compressed : original;
clientCompressionFilter.onStreamRequest(streamRequest, context, Collections.<String, String>emptyMap(), new HeaderCaptureFilter(HttpConstants.ACCEPT_ENCODING, true));
}
Aggregations