use of com.linkedin.d2.backuprequests.ConstantResponseTimeDistribution in project rest.li by linkedin.
the class TestBackupRequestsClient method testStatsConsumerLatencyUpdate.
// @Test - Disabled due to flakiness. See SI-3077 to track and resolve this.
public void testStatsConsumerLatencyUpdate() throws Exception {
AtomicReference<ServiceProperties> serviceProperties = new AtomicReference<>();
TestBackupRequestsStrategyStatsConsumer statsConsumer = new TestBackupRequestsStrategyStatsConsumer();
serviceProperties.set(createServiceProperties(null));
BackupRequestsClient client = createClient(serviceProperties::get, statsConsumer, new ConstantResponseTimeDistribution(1, TimeUnit.NANOSECONDS), false);
URI uri = URI.create("d2://testService");
RestRequest restRequest = new RestRequestBuilder(uri).setEntity(CONTENT).build();
RequestContext requestContext = new RequestContext();
requestContext.putLocalAttr(R2Constants.OPERATION, "get");
Future<RestResponse> response = client.restRequest(restRequest, requestContext);
assertEquals(response.get().getStatus(), 200);
List<StatsConsumerEvent> events = statsConsumer.getEvents();
assertEquals(events.size(), 0);
for (int i = 0; i < Short.MAX_VALUE * 4; i++) {
requestContext = new RequestContext();
requestContext.putLocalAttr(R2Constants.OPERATION, "get");
response = client.restRequest(restRequest, requestContext);
assertEquals(response.get().getStatus(), 200);
}
assertEquals(statsConsumer.getLatencyWithBackup().size(), 0);
assertEquals(statsConsumer.getLatencyWithoutBackup().size(), 0);
serviceProperties.set(createServiceProperties(Arrays.asList(createBackupRequestsConfiguration(5, "get"))));
while (statsConsumer.getLatencyWithoutBackup().size() < 1) {
requestContext = new RequestContext();
requestContext.putLocalAttr(R2Constants.OPERATION, "get");
response = client.restRequest(restRequest, requestContext);
assertEquals(response.get().getStatus(), 200);
}
assertEquals(statsConsumer.getLatencyWithoutBackup().size(), 1);
assertEquals(statsConsumer.getLatencyWithBackup().size(), 1);
// allowing 1% imprecision
long expected = statsConsumer.getLatencyWithoutBackup().get(0).getTotalCount();
long actual = statsConsumer.getLatencyWithBackup().get(0).getTotalCount();
assertTrue(actual > expected * .99 && actual < expected * 1.01, "Expected: " + expected + "+-" + (expected * .01) + ", but actual: " + actual);
}
use of com.linkedin.d2.backuprequests.ConstantResponseTimeDistribution in project rest.li by linkedin.
the class TestBackupRequestsClient method testD2ServiceUnavailable.
@Test(dataProvider = "isD2Async")
public void testD2ServiceUnavailable(boolean isD2Async) throws Exception {
LoadBalancer loadBalancer = new TestLoadBalancer(new ConstantResponseTimeDistribution(1, TimeUnit.NANOSECONDS), null, new ServiceUnavailableException("", ""));
TestBackupRequestsStrategyStatsConsumer statsConsumer = new TestBackupRequestsStrategyStatsConsumer();
BackupRequestsClient client = createClient(statsConsumer, loadBalancer, isD2Async);
URI uri = URI.create("d2://testService");
RestRequest restRequest = new RestRequestBuilder(uri).setEntity(CONTENT).build();
RequestContext requestContext = new RequestContext();
requestContext.putLocalAttr(R2Constants.OPERATION, "get");
Future<RestResponse> response = client.restRequest(restRequest, requestContext);
assertEquals(response.get().getStatus(), 200, "If D2 call fails, we should fallback to request without backup");
List<StatsConsumerEvent> events = statsConsumer.getEvents();
assertEquals(events.size(), 0);
}
Aggregations