use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestServerTimeoutAsyncEvent method testFilterNotCancelButShouldNotTimeout.
@Test
public void testFilterNotCancelButShouldNotTimeout() throws Exception {
RestRequest request = new RestRequestBuilder(Bootstrap.createHttpURI(PORT, 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(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("StreamException in filter."));
}
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestStreamEcho method testDelayedEcho.
@Test
public void testDelayedEcho() throws Exception {
for (Client client : clients()) {
RestRequest restRequest = new RestRequestBuilder(Bootstrap.createHttpURI(PORT, DELAYED_ECHO_URI)).setEntity("wei ni hao ma?".getBytes()).build();
RestResponse response = client.restRequest(restRequest).get();
Assert.assertEquals(response.getEntity().asString(Charset.defaultCharset()), "wei ni hao ma?");
}
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestQueryTunnel method getResponse.
private RestResponse getResponse(String query, RequestContext requestContext) throws Exception {
URI uri = URI.create("http://localhost:" + _port + "/checkQuery?" + query);
RestRequestBuilder builder = new RestRequestBuilder(uri);
return _client.restRequest(builder.build(), requestContext).get(5000, TimeUnit.MILLISECONDS);
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestQueryTunnel method setUp.
@BeforeClass
protected void setUp() throws Exception {
Map<String, String> clientProperties = new HashMap<String, String>();
clientProperties.put(HttpClientFactory.HTTP_QUERY_POST_THRESHOLD, String.valueOf(QUERY_TUNNEL_THRESHOLD));
clientProperties.put(HttpClientFactory.HTTP_PROTOCOL_VERSION, _httpProtocolVersion);
_clientFactory = new HttpClientFactory();
final TransportClient transportClient = _clientFactory.getClient(clientProperties);
_client = new TransportClientAdapter(transportClient, _clientROS);
final RestRequestHandler restHandler = new CheckQueryTunnelHandler();
final StreamRequestHandler streamHandler = new StreamRequestHandlerAdapter(restHandler);
TransportDispatcher dispatcher = new TransportDispatcher() {
@Override
public void handleRestRequest(RestRequest req, Map<String, String> wireAttrs, RequestContext requestContext, TransportCallback<RestResponse> callback) {
restHandler.handleRequest(req, requestContext, new TransportCallbackAdapter<RestResponse>(callback));
}
@Override
public void handleStreamRequest(StreamRequest req, Map<String, String> wireAttrs, RequestContext requestContext, TransportCallback<StreamResponse> callback) {
streamHandler.handleRequest(req, requestContext, new TransportCallbackAdapter<StreamResponse>(callback));
}
};
_server = new HttpServerFactory(_servletType).createH2cServer(_port, dispatcher, _serverROS);
_server.start();
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestQueryTunnel method testShouldQueryTunnel.
@Test
public void testShouldQueryTunnel() throws Exception {
String longQuery = buildQuery(QUERY_TUNNEL_THRESHOLD);
RestResponse response = getResponse(longQuery, new RequestContext());
Assert.assertEquals(response.getStatus(), IS_TUNNELED_RESPONSE_CODE);
Assert.assertEquals(response.getEntity().copyBytes(), longQuery.getBytes());
}
Aggregations