use of com.linkedin.r2.message.rest.RestRequestBuilder in project rest.li by linkedin.
the class TestServerTimeoutAsyncEvent method testFilterThrowButShouldNotTimeout.
@Test
public void testFilterThrowButShouldNotTimeout() throws Exception {
RestRequest request = new RestRequestBuilder(getHttpUri(BUGGY_FILTER_URI)).setEntity(new byte[10240]).build();
_client.restRequest(request);
Future<RestResponse> futureResponse = _client.restRequest(request);
// if server times out, our second request would fail with TimeoutException because it's blocked by first one
try {
futureResponse.get(ASYNC_EVENT_TIMEOUT / 2, TimeUnit.MILLISECONDS);
Assert.fail("Should fail with ExecutionException");
} catch (ExecutionException ex) {
Assert.assertTrue(ex.getCause() instanceof RestException);
RestException restException = (RestException) ex.getCause();
Assert.assertTrue(restException.getResponse().getEntity().asString("UTF8").contains("Buggy filter throws."));
}
}
use of com.linkedin.r2.message.rest.RestRequestBuilder in project rest.li by linkedin.
the class TestServerTimeout method testFilterThrowButShouldNotTimeout.
@Test
public void testFilterThrowButShouldNotTimeout() throws Exception {
RestRequest request = new RestRequestBuilder(getHttpUri(BUGGY_FILTER_URI)).setEntity(new byte[10240]).build();
_client.restRequest(request);
Future<RestResponse> futureResponse = _client.restRequest(request);
// if server times out, our second request would fail with TimeoutException because it's blocked by first one
try {
futureResponse.get(SERVER_IOHANDLER_TIMEOUT / 2, TimeUnit.MILLISECONDS);
Assert.fail("Should fail with ExecutionException");
} catch (ExecutionException ex) {
Assert.assertTrue(ex.getCause() instanceof RestException);
RestException restException = (RestException) ex.getCause();
Assert.assertTrue(restException.getResponse().getEntity().asString("UTF8").contains("Buggy filter throws."));
}
}
use of com.linkedin.r2.message.rest.RestRequestBuilder in project rest.li by linkedin.
the class TestServerTimeout method testFilterNotCancelButShouldNotTimeout.
@Test
public void testFilterNotCancelButShouldNotTimeout() throws Exception {
RestRequest request = new RestRequestBuilder(getHttpUri(STREAM_EXCEPTION_FILTER_URI)).setEntity(new byte[10240]).build();
_client.restRequest(request);
Future<RestResponse> futureResponse = _client.restRequest(request);
// if server times out, our second request would fail with TimeoutException because it's blocked by first one
try {
futureResponse.get(SERVER_IOHANDLER_TIMEOUT / 2, TimeUnit.MILLISECONDS);
Assert.fail("Should fail with ExecutionException");
} catch (ExecutionException ex) {
Assert.assertTrue(ex.getCause() instanceof RestException);
RestException restException = (RestException) ex.getCause();
Assert.assertTrue(restException.getResponse().getEntity().asString("UTF8").contains("StreamException in filter."));
}
}
use of com.linkedin.r2.message.rest.RestRequestBuilder 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.message.rest.RestRequestBuilder 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));
}
Aggregations