Search in sources :

Example 6 with DisruptedException

use of com.linkedin.r2.disruptor.DisruptedException in project rest.li by linkedin.

the class TestDisruptor method testRestErrorDisrupt.

@Test
public void testRestErrorDisrupt() throws Exception {
    final Map<String, String> properties = new HashMap<>();
    properties.put(HttpClientFactory.HTTP_REQUEST_TIMEOUT, String.valueOf(REQUEST_TIMEOUT));
    final TransportClientFactory factory = new HttpClientFactory.Builder().build();
    final TransportClient client = factory.getClient(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(new URI(REQUEST_URI)).build(), requestContext, new HashMap<>(), response -> {
        success.set(response.hasError() && response.getError() instanceof DisruptedException);
        latch.countDown();
    });
    Assert.assertTrue(latch.await(TEST_TIMEOUT, TimeUnit.MILLISECONDS), "Test execution timeout");
    Assert.assertTrue(success.get(), "Unexpected transport response");
}
Also used : TransportClient(com.linkedin.r2.transport.common.bridge.client.TransportClient) HashMap(java.util.HashMap) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DisruptedException(com.linkedin.r2.disruptor.DisruptedException) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) TransportClientFactory(com.linkedin.r2.transport.common.TransportClientFactory) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) Test(org.testng.annotations.Test)

Aggregations

RequestContext (com.linkedin.r2.message.RequestContext)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Test (org.testng.annotations.Test)6 DisruptedException (com.linkedin.r2.disruptor.DisruptedException)4 URI (java.net.URI)4 HashMap (java.util.HashMap)4 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)3 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)3 NextFilter (com.linkedin.r2.filter.NextFilter)2 RestResponse (com.linkedin.r2.message.rest.RestResponse)2 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)2 Client (com.linkedin.r2.transport.common.Client)2 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)2 TransportClient (com.linkedin.r2.transport.common.bridge.client.TransportClient)2 HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)2 Map (java.util.Map)2 AbstractServiceTest (test.r2.integ.clientserver.providers.AbstractServiceTest)2 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)1