use of com.linkedin.d2.balancer.util.KeyMapperProvider in project rest.li by linkedin.
the class DynamicClientTest method testClient.
@Test(groups = { "small", "back-end" }, dataProvider = "restOverStreamSwitch")
@SuppressWarnings("deprecation")
public void testClient(boolean restOverStream) throws URISyntaxException {
LoadBalancerMock balancer = new LoadBalancerMock(false);
DirectoryProvider dirProvider = new DirectoryProviderMock();
KeyMapperProvider keyMapperProvider = new KeyMapperProviderMock();
ClientFactoryProvider clientFactoryProvider = Mockito.mock(ClientFactoryProvider.class);
Facilities facilities = new DelegatingFacilities(dirProvider, keyMapperProvider, clientFactoryProvider);
DynamicClient client = new DynamicClient(balancer, facilities, restOverStream);
URI uri = URI.create("d2://test");
RestRequest restRequest = new RestRequestBuilder(uri).build();
TestCallback<RestResponse> restCallback = new TestCallback<>();
client.restRequest(restRequest, restCallback);
assertNull(restCallback.e);
assertNotNull(restCallback.t);
Facilities myFacilities = client.getFacilities();
assertNotNull(facilities, "facilities should not be null");
}
use of com.linkedin.d2.balancer.util.KeyMapperProvider in project rest.li by linkedin.
the class RequestTimeoutClientTest method testRequestTimeoutAllowed.
/**
* Check that the timeout are the expected ones
*/
@Test(groups = { "small" }, dataProvider = "allCombinations3x")
@SuppressWarnings("deprecation")
public void testRequestTimeoutAllowed(boolean isHigherThanDefault, boolean ignoreTimeoutIfHigher, int expectedTimeout) throws Exception {
LoadBalancerSimulator.ClockedExecutor clockedExecutor = new LoadBalancerSimulator.ClockedExecutor();
LoadBalancerMock balancer = new LoadBalancerMock(false, true, clockedExecutor);
DirectoryProvider dirProvider = new DirectoryProviderMock();
KeyMapperProvider keyMapperProvider = new KeyMapperProviderMock();
ClientFactoryProvider clientFactoryProvider = Mockito.mock(ClientFactoryProvider.class);
Facilities facilities = new DelegatingFacilities(dirProvider, keyMapperProvider, clientFactoryProvider);
D2Client client = new DynamicClient(balancer, facilities, true);
URI uri = URI.create("d2://test");
RestRequest restRequest = new RestRequestBuilder(uri).build();
client = new RequestTimeoutClient(client, balancer, clockedExecutor);
RequestContext requestContext = new RequestContext();
int requestTimeout = isHigherThanDefault ? DEFAULT_REQUEST_TIMEOUT + 100 : DEFAULT_REQUEST_TIMEOUT - 100;
DegraderTrackerClientTest.TestCallback<RestResponse> restCallback = new DegraderTrackerClientTest.TestCallback<>();
requestContext.putLocalAttr(R2Constants.REQUEST_TIMEOUT, requestTimeout);
if (ignoreTimeoutIfHigher) {
requestContext.putLocalAttr(R2Constants.REQUEST_TIMEOUT_IGNORE_IF_HIGHER_THAN_DEFAULT, ignoreTimeoutIfHigher);
}
client.restRequest(restRequest, requestContext, restCallback);
clockedExecutor.run(expectedTimeout - 10).get();
Assert.assertFalse(checkTimeoutFired(restCallback));
checkRequestTimeoutOrViewSet(requestContext);
clockedExecutor.run(expectedTimeout + 10).get();
Assert.assertTrue(checkTimeoutFired(restCallback));
checkRequestTimeoutOrViewSet(requestContext);
}
Aggregations