use of com.linkedin.r2.message.rest.RestRequestBuilder in project rest.li by linkedin.
the class TestClientShutdown method testShutdown.
@Test
public void testShutdown() throws Exception {
TransportClientFactory clientFactory = new HttpClientFactory.Builder().build();
RestRequestBuilder builder = new RestRequestBuilder(_clientProvider.createHttpURI(_port, ECHO_URI));
byte[] content = new byte[100];
builder.setEntity(content);
Future<RestResponse> future = _client.restRequest(builder.build());
RestResponse response = future.get(30, TimeUnit.SECONDS);
Assert.assertEquals(response.getEntity().copyBytes(), content);
final FutureCallback<None> clientShutdownCallback = new FutureCallback<>();
_client.shutdown(clientShutdownCallback);
// we should catch those clients that do not shutdown properly in 5 seconds
clientShutdownCallback.get(5000, TimeUnit.MILLISECONDS);
final FutureCallback<None> factoryShutdownCallback = new FutureCallback<>();
clientFactory.shutdown(factoryShutdownCallback);
factoryShutdownCallback.get();
}
use of com.linkedin.r2.message.rest.RestRequestBuilder in project rest.li by linkedin.
the class TestDisruptor method testRestErrorDisrupt.
@Test
public void testRestErrorDisrupt() throws Exception {
final Map<String, Object> properties = new HashMap<>();
properties.put(HttpClientFactory.HTTP_REQUEST_TIMEOUT, String.valueOf(REQUEST_TIMEOUT));
final Client client = _clientProvider.createClient(FilterChains.empty(), properties);
final RequestContext requestContext = new RequestContext();
requestContext.putLocalAttr(DISRUPT_CONTEXT_KEY, DisruptContexts.error(REQUEST_LATENCY));
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean success = new AtomicBoolean(false);
client.restRequest(new RestRequestBuilder(getHttpURI()).build(), requestContext, new Callback<RestResponse>() {
@Override
public void onSuccess(RestResponse result) {
latch.countDown();
}
@Override
public void onError(Throwable e) {
success.set(e instanceof DisruptedException);
latch.countDown();
}
});
Assert.assertTrue(latch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS), "Test execution timeout");
Assert.assertTrue(success.get(), "Unexpected transport response");
}
use of com.linkedin.r2.message.rest.RestRequestBuilder in project rest.li by linkedin.
the class TestHttpClient method testClient.
@Test
public void testClient() throws Exception {
RestRequestBuilder rb = new RestRequestBuilder(getHttpUri(DISPATCHER_URI));
rb.setMethod("GET");
RestRequest request = rb.build();
Future<RestResponse> f = _client.restRequest(request);
// This will block
RestResponse response = f.get();
final ByteString entity = response.getEntity();
if (entity != null) {
System.out.println(entity.asString("UTF-8"));
} else {
System.out.println("NOTHING!");
}
assertEquals(response.getStatus(), 200);
}
use of com.linkedin.r2.message.rest.RestRequestBuilder in project rest.li by linkedin.
the class TestHttpClient method testSimpleURI.
@Test
public void testSimpleURI() throws Exception {
// Note no trailing slash; the point of the test is to ensure this URI will
// send a Request-URI of "/".
URI uri = getHttpUri(null);
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);
}
use of com.linkedin.r2.message.rest.RestRequestBuilder in project rest.li by linkedin.
the class TestServerTimeoutAsyncEvent method testServerTimeoutAfterResponding.
@Test
public void testServerTimeoutAfterResponding() throws Exception {
Future<RestResponse> futureResponse = _client.restRequest(new RestRequestBuilder(getHttpUri(TIMEOUT_AFTER_SENDING_RESPONSE_SERVER_URI)).build());
// server should timeout so get should succeed
RestResponse response = futureResponse.get(ASYNC_EVENT_TIMEOUT * 2, TimeUnit.MILLISECONDS);
Assert.assertEquals(response.getStatus(), RestStatus.OK);
Assert.assertEquals(response.getEntity().length(), RESPONSE_SIZE_WRITTEN_SO_FAR);
}
Aggregations