use of com.linkedin.d2.balancer.clients.RetryClient in project rest.li by linkedin.
the class RetryClientTest method testStreamException.
@Test
public void testStreamException() throws Exception {
SimpleLoadBalancer balancer = prepareLoadBalancer(Arrays.asList("http://test.linkedin.com/retry1", "http://test.linkedin.com/bad"), HttpClientFactory.UNLIMITED_CLIENT_REQUEST_RETRY_RATIO);
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, SystemClock.instance(), true, true);
URI uri = URI.create("d2://retryService?arg1=empty&arg2=empty");
StreamRequest streamRequest = new StreamRequestBuilder(uri).build(EntityStreams.emptyStream());
DegraderTrackerClientTest.TestCallback<StreamResponse> streamCallback = new DegraderTrackerClientTest.TestCallback<>();
RequestContext context = new RequestContext();
KeyMapper.TargetHostHints.setRequestContextTargetHost(context, URI.create("http://test.linkedin.com/bad"));
client.streamRequest(streamRequest, context, streamCallback);
assertNull(streamCallback.t);
assertNotNull(streamCallback.e);
assertTrue(streamCallback.e.getMessage().contains("exception happens"), streamCallback.e.getMessage());
}
use of com.linkedin.d2.balancer.clients.RetryClient 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);
}
use of com.linkedin.d2.balancer.clients.RetryClient in project rest.li by linkedin.
the class RetryClientTest method testRestRetryExceedsClientRetryRatio.
// Known to be flaky in CI
@Test(retryAnalyzer = SingleRetry.class)
public void testRestRetryExceedsClientRetryRatio() throws Exception {
SimpleLoadBalancer balancer = prepareLoadBalancer(Arrays.asList("http://test.linkedin.com/retry1", "http://test.linkedin.com/good"), HttpClientFactory.DEFAULT_MAX_CLIENT_REQUEST_RETRY_RATIO);
SettableClock clock = new SettableClock();
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 uri1 = URI.create("d2://retryService1?arg1=empty&arg2=empty");
RestRequest restRequest1 = new RestRequestBuilder(uri1).build();
URI uri2 = URI.create("d2://retryService2?arg1=empty&arg2=empty");
RestRequest restRequest2 = new RestRequestBuilder(uri2).build();
// This request will be retried and route to the good host
DegraderTrackerClientTest.TestCallback<RestResponse> restCallback = new DegraderTrackerClientTest.TestCallback<>();
client.restRequest(restRequest1, restCallback);
assertNull(restCallback.e);
assertNotNull(restCallback.t);
// This request will not be retried because the retry ratio is exceeded
clock.addDuration(RetryClient.DEFAULT_UPDATE_INTERVAL_MS);
restCallback = new DegraderTrackerClientTest.TestCallback<>();
client.restRequest(restRequest1, restCallback);
assertNull(restCallback.t);
assertNotNull(restCallback.e);
assertTrue(restCallback.e.getMessage().contains("Data not available"));
// If the client sends request to a different service endpoint, the retry ratio should not interfere
restCallback = new DegraderTrackerClientTest.TestCallback<>();
client.restRequest(restRequest2, restCallback);
assertNull(restCallback.e);
assertNotNull(restCallback.t);
// After 5s interval, retry counter is reset and this request will be retried again
clock.addDuration(RetryClient.DEFAULT_UPDATE_INTERVAL_MS * RetryClient.DEFAULT_AGGREGATED_INTERVAL_NUM);
restCallback = new DegraderTrackerClientTest.TestCallback<>();
client.restRequest(restRequest1, restCallback);
assertNull(restCallback.e);
assertNotNull(restCallback.t);
}
use of com.linkedin.d2.balancer.clients.RetryClient in project rest.li by linkedin.
the class RetryClientTest method testRestRetry.
@Test
public void testRestRetry() throws Exception {
SimpleLoadBalancer balancer = prepareLoadBalancer(Arrays.asList("http://test.linkedin.com/retry1", "http://test.linkedin.com/good"), HttpClientFactory.UNLIMITED_CLIENT_REQUEST_RETRY_RATIO);
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, SystemClock.instance(), true, false);
URI uri = URI.create("d2://retryService?arg1arg2");
RestRequest restRequest = new RestRequestBuilder(uri).setEntity(CONTENT).build();
DegraderTrackerClientTest.TestCallback<RestResponse> restCallback = new DegraderTrackerClientTest.TestCallback<>();
client.restRequest(restRequest, restCallback);
assertNull(restCallback.e);
assertNotNull(restCallback.t);
}
use of com.linkedin.d2.balancer.clients.RetryClient in project rest.li by linkedin.
the class RetryClientTest method testRestException.
@Test
public void testRestException() throws Exception {
SimpleLoadBalancer balancer = prepareLoadBalancer(Arrays.asList("http://test.linkedin.com/retry1", "http://test.linkedin.com/bad"), HttpClientFactory.UNLIMITED_CLIENT_REQUEST_RETRY_RATIO);
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, SystemClock.instance(), true, false);
URI uri = URI.create("d2://retryService?arg1=empty&arg2=empty");
RestRequest restRequest = new RestRequestBuilder(uri).build();
DegraderTrackerClientTest.TestCallback<RestResponse> restCallback = new DegraderTrackerClientTest.TestCallback<>();
RequestContext context = new RequestContext();
KeyMapper.TargetHostHints.setRequestContextTargetHost(context, URI.create("http://test.linkedin.com/bad"));
client.restRequest(restRequest, context, restCallback);
assertNull(restCallback.t);
assertNotNull(restCallback.e);
assertTrue(restCallback.e.getMessage().contains("exception happens"));
}
Aggregations