Search in sources :

Example 16 with ClockedExecutor

use of com.linkedin.test.util.ClockedExecutor in project rest.li by linkedin.

the class RetryClientTest method testRestRetryUnlimitedClientRetryRatio.

@Test
public void testRestRetryUnlimitedClientRetryRatio() throws Exception {
    SimpleLoadBalancer balancer = prepareLoadBalancer(Arrays.asList("http://test.linkedin.com/retry1", "http://test.linkedin.com/good"), HttpClientFactory.UNLIMITED_CLIENT_REQUEST_RETRY_RATIO);
    ClockedExecutor clock = new ClockedExecutor();
    DynamicClient dynamicClient = new DynamicClient(balancer, null);
    RetryClient client = new RetryClient(dynamicClient, balancer, D2ClientConfig.DEFAULT_RETRY_LIMIT, RetryClient.DEFAULT_UPDATE_INTERVAL_MS, RetryClient.DEFAULT_AGGREGATED_INTERVAL_NUM, clock, true, false);
    URI uri = URI.create("d2://retryService?arg1=empty&arg2=empty");
    RestRequest restRequest = new RestRequestBuilder(uri).build();
    clock.scheduleWithFixedDelay(() -> {
        DegraderTrackerClientTest.TestCallback<RestResponse> restCallback = new DegraderTrackerClientTest.TestCallback<>();
        client.restRequest(restRequest, restCallback);
        // This request will be retried and route to the good host
        assertNull(restCallback.e);
        assertNotNull(restCallback.t);
    }, 0, 100, TimeUnit.MILLISECONDS);
    clock.runFor(RetryClient.DEFAULT_UPDATE_INTERVAL_MS * 2);
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) SimpleLoadBalancer(com.linkedin.d2.balancer.simple.SimpleLoadBalancer) RestResponse(com.linkedin.r2.message.rest.RestResponse) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) ClockedExecutor(com.linkedin.test.util.ClockedExecutor) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

ClockedExecutor (com.linkedin.test.util.ClockedExecutor)16 Test (org.testng.annotations.Test)14 None (com.linkedin.common.util.None)12 ArrayList (java.util.ArrayList)9 ConstantQpsRateLimiter (com.linkedin.r2.transport.http.client.ConstantQpsRateLimiter)7 FutureCallback (com.linkedin.common.callback.FutureCallback)6 AsyncRateLimiter (com.linkedin.r2.transport.http.client.AsyncRateLimiter)3 ExecutionException (java.util.concurrent.ExecutionException)3 LongTracking (com.linkedin.common.stats.LongTracking)2 DarkClusterDispatcher (com.linkedin.darkcluster.api.DarkClusterDispatcher)2 DefaultDarkClusterDispatcher (com.linkedin.darkcluster.impl.DefaultDarkClusterDispatcher)2 RestRequest (com.linkedin.r2.message.rest.RestRequest)2 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)2 AsyncPoolImpl (com.linkedin.r2.transport.http.client.AsyncPoolImpl)2 ExponentialBackOffRateLimiter (com.linkedin.r2.transport.http.client.ExponentialBackOffRateLimiter)2 ObjectCreationTimeoutException (com.linkedin.r2.transport.http.client.ObjectCreationTimeoutException)2 PoolStats (com.linkedin.r2.transport.http.client.PoolStats)2 SmoothRateLimiter (com.linkedin.r2.transport.http.client.SmoothRateLimiter)2 TimeoutException (java.util.concurrent.TimeoutException)2 DarkClusterConfig (com.linkedin.d2.DarkClusterConfig)1