use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestQueryTunnel method testShouldNotQueryTunnel.
@Test
public void testShouldNotQueryTunnel() throws Exception {
String shortQuery = buildQuery(QUERY_TUNNEL_THRESHOLD - 1);
RestResponse response = getResponse(shortQuery, new RequestContext());
Assert.assertEquals(response.getStatus(), IS_NOT_TUNNELED_RESPONSE_CODE);
Assert.assertEquals(response.getEntity().copyBytes(), shortQuery.getBytes());
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestRestCompressionEcho method testResponseCompression.
@Test(dataProvider = "compressionEchoData")
public void testResponseCompression(Client client, long bytes) throws InterruptedException, TimeoutException, ExecutionException {
RestRequestBuilder builder = new RestRequestBuilder((Bootstrap.createHttpURI(PORT, ECHO_URI)));
byte[] content = new byte[(int) bytes];
for (int i = 0; i < bytes; i++) {
content[i] = (byte) (i % 256);
}
RestRequest request = builder.setEntity(content).build();
final FutureCallback<RestResponse> callback = new FutureCallback<RestResponse>();
RequestContext requestContext = new RequestContext();
// OPERATION is required to enabled response compression
requestContext.putLocalAttr(R2Constants.OPERATION, "get");
client.restRequest(request, requestContext, callback);
final RestResponse response = callback.get(60, TimeUnit.SECONDS);
Assert.assertEquals(response.getStatus(), RestStatus.OK);
Assert.assertEquals(response.getEntity().copyBytes(), content);
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class EchoHandler method handleRequest.
@Override
public void handleRequest(RestRequest request, RequestContext requestContext, final Callback<RestResponse> callback) {
RestResponseBuilder builder = new RestResponseBuilder();
callback.onSuccess(builder.setEntity(request.getEntity()).build());
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestHttpClient method testSimpleURI.
@Test(dataProvider = "configs")
public void testSimpleURI(Server server, Client client) throws Exception {
try {
server.start();
// Note no trailing slash; the point of the test is to ensure this URI will
// send a Request-URI of "/".
URI uri = URI.create("http://localhost:" + PORT);
RestRequestBuilder rb = new RestRequestBuilder(uri);
rb.setMethod("GET");
RestRequest request = rb.build();
Future<RestResponse> f = client.restRequest(request);
// This will block
RestResponse response = f.get();
assertEquals(response.getStatus(), 200);
final FutureCallback<None> callback = new FutureCallback<None>();
client.shutdown(callback);
callback.get();
} finally {
server.stop();
}
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestRAPClientCodec method testResponseDecoder.
@Test(dataProvider = "responseData")
public void testResponseDecoder(int status, String entity, HttpHeaders headers, String[] cookies) {
final EmbeddedChannel ch = new EmbeddedChannel(new RAPClientCodec());
ByteBuf content = Unpooled.copiedBuffer(entity, CHARSET);
FullHttpResponse nettyResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(status), content);
nettyResponse.headers().set(headers);
for (String cookie : cookies) {
nettyResponse.headers().add(HttpHeaderNames.SET_COOKIE, cookie);
}
ch.writeInbound(nettyResponse);
RestResponse response = (RestResponse) ch.readInbound();
Assert.assertEquals(response.getStatus(), status);
Assert.assertEquals(response.getEntity().asString(CHARSET), entity);
assertList(response.getCookies(), nettyResponse.headers().getAll(HttpConstants.RESPONSE_COOKIE_HEADER_NAME));
for (Map.Entry<String, String> header : nettyResponse.headers()) {
if (!header.getKey().equalsIgnoreCase(HttpConstants.RESPONSE_COOKIE_HEADER_NAME)) {
List<String> values = response.getHeaderValues(header.getKey());
Assert.assertNotNull(values);
Assert.assertTrue(values.contains(header.getValue()));
}
}
// make sure the incoming ByteBuf is released
Assert.assertEquals(content.refCnt(), 0);
ch.finish();
}
Aggregations