use of com.linkedin.r2.filter.CompressionConfig in project rest.li by linkedin.
the class TestClientStreamCompressionFilter method provideRequestData.
@DataProvider(name = "requestData")
private Object[][] provideRequestData() {
CompressionConfig smallThresholdConfig = new CompressionConfig(1);
CompressionConfig largeThresholdConfig = new CompressionConfig(10000);
return new Object[][] { { new CompressionConfig(Integer.MAX_VALUE), CompressionOption.FORCE_OFF, false, "" }, { new CompressionConfig(Integer.MAX_VALUE), CompressionOption.FORCE_ON, true, "" }, { new CompressionConfig(Integer.MAX_VALUE), null, false, "" }, { new CompressionConfig(0), CompressionOption.FORCE_OFF, false, "" }, { new CompressionConfig(0), CompressionOption.FORCE_ON, true, "" }, { new CompressionConfig(0), null, true, "" }, { smallThresholdConfig, CompressionOption.FORCE_OFF, false, "" }, { smallThresholdConfig, CompressionOption.FORCE_ON, true, "" }, { smallThresholdConfig, null, true, "" }, { largeThresholdConfig, CompressionOption.FORCE_OFF, false, "" }, { largeThresholdConfig, CompressionOption.FORCE_ON, true, "" }, { largeThresholdConfig, null, false, "" }, // The same tests, but with null instead of an empty string
{ new CompressionConfig(Integer.MAX_VALUE), CompressionOption.FORCE_OFF, false, null }, { new CompressionConfig(Integer.MAX_VALUE), CompressionOption.FORCE_ON, true, null }, { new CompressionConfig(Integer.MAX_VALUE), null, false, null }, { new CompressionConfig(0), CompressionOption.FORCE_OFF, false, null }, { new CompressionConfig(0), CompressionOption.FORCE_ON, true, null }, { new CompressionConfig(0), null, true, null }, { smallThresholdConfig, CompressionOption.FORCE_OFF, false, null }, { smallThresholdConfig, CompressionOption.FORCE_ON, true, null }, { smallThresholdConfig, null, true, null }, { largeThresholdConfig, CompressionOption.FORCE_OFF, false, null }, { largeThresholdConfig, CompressionOption.FORCE_ON, true, null }, { largeThresholdConfig, null, false, null } };
}
use of com.linkedin.r2.filter.CompressionConfig in project rest.li by linkedin.
the class TestClientCompressionFilter method testResponseCompressionRules.
@Test(dataProvider = "responseCompressionData")
public void testResponseCompressionRules(CompressionConfig responseCompressionConfig, CompressionOption responseCompressionOverride, String expectedAcceptEncoding, String expectedCompressionThreshold, String operation) throws CompressionException, URISyntaxException {
ClientCompressionFilter clientCompressionFilter = new ClientCompressionFilter(EncodingType.SNAPPY.getHttpName(), new CompressionConfig(Integer.MAX_VALUE), ACCEPT_COMPRESSIONS, responseCompressionConfig, Arrays.asList(ClientCompressionHelper.COMPRESS_ALL_RESPONSES_INDICATOR));
RestRequest restRequest = new RestRequestBuilder(new URI(URI)).build();
RequestContext context = new RequestContext();
if (operation != null) {
context.putLocalAttr(R2Constants.OPERATION, operation);
}
context.putLocalAttr(R2Constants.RESPONSE_COMPRESSION_OVERRIDE, responseCompressionOverride);
clientCompressionFilter.onRestRequest(restRequest, context, Collections.<String, String>emptyMap(), new HeaderCaptureFilter(HttpConstants.ACCEPT_ENCODING, expectedAcceptEncoding));
clientCompressionFilter.onRestRequest(restRequest, context, Collections.<String, String>emptyMap(), new HeaderCaptureFilter(HttpConstants.HEADER_RESPONSE_COMPRESSION_THRESHOLD, expectedCompressionThreshold));
}
use of com.linkedin.r2.filter.CompressionConfig in project rest.li by linkedin.
the class TestClientCompressionFilter method testRequestCompressionRules.
@Test(dataProvider = "requestCompressionData")
public void testRequestCompressionRules(CompressionConfig requestCompressionConfig, CompressionOption requestCompressionOverride, boolean headerShouldBePresent) throws CompressionException, URISyntaxException {
ClientCompressionFilter clientCompressionFilter = new ClientCompressionFilter(EncodingType.SNAPPY.getHttpName(), requestCompressionConfig, ACCEPT_COMPRESSIONS, new CompressionConfig(Integer.MAX_VALUE), Collections.<String>emptyList());
// The entity should be compressible for this test.
int original = 100;
byte[] entity = new byte[original];
Arrays.fill(entity, (byte) 'A');
RestRequest restRequest = new RestRequestBuilder(new URI(URI)).setMethod(RestMethod.POST).setEntity(entity).build();
int compressed = EncodingType.SNAPPY.getCompressor().deflate(new ByteArrayInputStream(entity)).length;
RequestContext context = new RequestContext();
context.putLocalAttr(R2Constants.REQUEST_COMPRESSION_OVERRIDE, requestCompressionOverride);
int entityLength = headerShouldBePresent ? compressed : original;
String expectedContentEncoding = headerShouldBePresent ? EncodingType.SNAPPY.getHttpName() : null;
clientCompressionFilter.onRestRequest(restRequest, context, Collections.<String, String>emptyMap(), new HeaderCaptureFilter(HttpConstants.CONTENT_ENCODING, expectedContentEncoding, entityLength));
}
use of com.linkedin.r2.filter.CompressionConfig in project rest.li by linkedin.
the class RestLiIntegrationTest method init.
public void init(List<? extends Filter> filters) throws IOException {
final FilterChain fc = FilterChains.empty().addLastRest(new ServerCompressionFilter(RestLiIntTestServer.supportedCompression, new CompressionConfig(0))).addLastRest(new SimpleLoggingFilter());
init(filters, fc, false);
}
use of com.linkedin.r2.filter.CompressionConfig in project rest.li by linkedin.
the class TestRequestCompression method requestData.
@DataProvider(name = "requestData")
private Object[][] requestData() {
int tiny = 10;
int small = 100;
int large = 1000;
int huge = 10000;
CompressionConfig tinyThresholdConfig = new CompressionConfig(tiny);
CompressionConfig hugeThresholdConfig = new CompressionConfig(huge);
String encodings = "unsupportedEncoding, x-snappy-framed, snappy, gzip";
RestliRequestOptions forceOnOption = new RestliRequestOptionsBuilder().setProtocolVersionOption(ProtocolVersionOption.USE_LATEST_IF_AVAILABLE).setRequestCompressionOverride(CompressionOption.FORCE_ON).build();
RestliRequestOptions forceOffOption = new RestliRequestOptionsBuilder().setProtocolVersionOption(ProtocolVersionOption.USE_LATEST_IF_AVAILABLE).setRequestCompressionOverride(CompressionOption.FORCE_OFF).build();
return new Object[][] { // Compression depending on request size
{ null, encodings, RestliRequestOptions.DEFAULT_OPTIONS, large, EXPECT_COMPRESSION }, { null, encodings, RestliRequestOptions.DEFAULT_OPTIONS, small, EXPECT_NO_COMPRESSION }, // Override the default threshold and cause even small requests to be compressed
{ tinyThresholdConfig, encodings, RestliRequestOptions.DEFAULT_OPTIONS, large, EXPECT_COMPRESSION }, { tinyThresholdConfig, encodings, RestliRequestOptions.DEFAULT_OPTIONS, small, EXPECT_COMPRESSION }, // Override the default threshold and causes even large requests to be NOT compressed.
{ hugeThresholdConfig, encodings, RestliRequestOptions.DEFAULT_OPTIONS, large, EXPECT_NO_COMPRESSION }, { hugeThresholdConfig, encodings, RestliRequestOptions.DEFAULT_OPTIONS, small, EXPECT_NO_COMPRESSION }, // Force on/off using RestliRequestOptions
{ null, encodings, forceOnOption, large, EXPECT_COMPRESSION }, { null, encodings, forceOnOption, small, EXPECT_COMPRESSION }, { hugeThresholdConfig, encodings, forceOnOption, small, EXPECT_COMPRESSION }, { null, encodings, forceOffOption, large, EXPECT_NO_COMPRESSION }, { null, encodings, forceOffOption, small, EXPECT_NO_COMPRESSION }, { tinyThresholdConfig, encodings, forceOffOption, large, EXPECT_NO_COMPRESSION }, // Force on/off using RequestCompressionConfig
{ new CompressionConfig(0), encodings, RestliRequestOptions.DEFAULT_OPTIONS, large, EXPECT_COMPRESSION }, { new CompressionConfig(0), encodings, RestliRequestOptions.DEFAULT_OPTIONS, small, EXPECT_COMPRESSION }, { new CompressionConfig(Integer.MAX_VALUE), encodings, RestliRequestOptions.DEFAULT_OPTIONS, large, EXPECT_NO_COMPRESSION }, { new CompressionConfig(Integer.MAX_VALUE), encodings, RestliRequestOptions.DEFAULT_OPTIONS, small, EXPECT_NO_COMPRESSION }, // RestliRequestOptions takes precedence over RequestCompressionConfig
{ new CompressionConfig(0), encodings, forceOffOption, large, EXPECT_NO_COMPRESSION }, { new CompressionConfig(Integer.MAX_VALUE), encodings, forceOnOption, small, EXPECT_COMPRESSION }, // Can't compress if no encodings are available
{ null, "unsupportedEncoding", RestliRequestOptions.DEFAULT_OPTIONS, large, EXPECT_NO_COMPRESSION }, { null, "", RestliRequestOptions.DEFAULT_OPTIONS, large, EXPECT_NO_COMPRESSION }, { new CompressionConfig(0), "unsupportedEncoding", RestliRequestOptions.DEFAULT_OPTIONS, large, EXPECT_NO_COMPRESSION }, { null, "", forceOnOption, large, EXPECT_NO_COMPRESSION } };
}
Aggregations