use of com.linkedin.util.clock.SettableClock 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.util.clock.SettableClock in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testBadTrackerClients.
@Test(groups = { "small", "back-end" })
public void testBadTrackerClients() throws URISyntaxException {
DegraderLoadBalancerStrategyV3 strategy = getStrategy();
// test null twice (first time will have no state)
for (int i = 0; i < 2; ++i) {
assertNull(getTrackerClient(strategy, null, new RequestContext(), 0, null));
}
strategy = getStrategy();
// test empty twice (first time will have no state)
for (int i = 0; i < 2; ++i) {
assertNull(getTrackerClient(strategy, null, new RequestContext(), 0, new ArrayList<>()));
}
// test same cluster generation id but different client lists
strategy = getStrategy();
List<DegraderTrackerClient> clients1 = new ArrayList<>();
SettableClock clock1 = new SettableClock();
SettableClock clock2 = new SettableClock();
List<DegraderTrackerClient> clients2 = new ArrayList<>();
SettableClock clock3 = new SettableClock();
SettableClock clock4 = new SettableClock();
clients1.add(getClient(URI.create("http://test.linkedin.com:3242/fdsaf"), clock1));
clients1.add(getClient(URI.create("http://test.linkedin.com:3243/fdsaf"), clock2));
clients2.add(getClient(URI.create("http://asdbasdf.com:3242/fdsaf"), clock3));
clients2.add(getClient(URI.create("ftp://example.com:21/what"), clock4));
// same cluster generation id but different tracker clients
assertNotNull(getTrackerClient(strategy, null, new RequestContext(), 0, clients2));
assertNull(getTrackerClient(strategy, null, new RequestContext(), 0, clients1));
// now trigger an update by cluster generation id
assertNotNull(getTrackerClient(strategy, null, new RequestContext(), 1, clients1));
assertNull(getTrackerClient(strategy, null, new RequestContext(), 1, clients2));
}
Aggregations