Search in sources :

Example 1 with TestCallback

use of com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestCallback in project rest.li by linkedin.

the class DynamicClientTest method testUnavailable.

@Test(groups = { "small", "back-end" }, dataProvider = "restOverStreamSwitch")
public void testUnavailable(boolean restOverStream) throws URISyntaxException {
    LoadBalancerMock balancer = new LoadBalancerMock(true);
    DynamicClient client = new DynamicClient(balancer, null, restOverStream);
    URI uri = URI.create("d2://test");
    RestRequest restRequest = new RestRequestBuilder(uri).build();
    TestCallback<RestResponse> restCallback = new TestCallback<>();
    client.restRequest(restRequest, restCallback);
    assertNotNull(restCallback.e);
    assertTrue(restCallback.e instanceof ServiceUnavailableException);
    assertNull(restCallback.t);
    Facilities facilities = client.getFacilities();
    assertNull(facilities, "facilities should be null");
}
Also used : LoadBalancerMock(com.linkedin.d2.balancer.clients.stub.LoadBalancerMock) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestResponse(com.linkedin.r2.message.rest.RestResponse) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) ServiceUnavailableException(com.linkedin.d2.balancer.ServiceUnavailableException) TestCallback(com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestCallback) URI(java.net.URI) Facilities(com.linkedin.d2.balancer.Facilities) DelegatingFacilities(com.linkedin.d2.balancer.util.DelegatingFacilities) Test(org.testng.annotations.Test)

Example 2 with TestCallback

use of com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestCallback 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");
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) KeyMapperProvider(com.linkedin.d2.balancer.util.KeyMapperProvider) ClientFactoryProvider(com.linkedin.d2.balancer.util.ClientFactoryProvider) TestCallback(com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestCallback) URI(java.net.URI) Facilities(com.linkedin.d2.balancer.Facilities) DelegatingFacilities(com.linkedin.d2.balancer.util.DelegatingFacilities) LoadBalancerMock(com.linkedin.d2.balancer.clients.stub.LoadBalancerMock) DirectoryProviderMock(com.linkedin.d2.balancer.clients.stub.DirectoryProviderMock) RestRequest(com.linkedin.r2.message.rest.RestRequest) DirectoryProvider(com.linkedin.d2.balancer.util.DirectoryProvider) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) KeyMapperProviderMock(com.linkedin.d2.balancer.clients.stub.KeyMapperProviderMock) DelegatingFacilities(com.linkedin.d2.balancer.util.DelegatingFacilities) Test(org.testng.annotations.Test)

Aggregations

Facilities (com.linkedin.d2.balancer.Facilities)2 TestCallback (com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestCallback)2 LoadBalancerMock (com.linkedin.d2.balancer.clients.stub.LoadBalancerMock)2 DelegatingFacilities (com.linkedin.d2.balancer.util.DelegatingFacilities)2 RestRequest (com.linkedin.r2.message.rest.RestRequest)2 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)2 RestResponse (com.linkedin.r2.message.rest.RestResponse)2 URI (java.net.URI)2 Test (org.testng.annotations.Test)2 ServiceUnavailableException (com.linkedin.d2.balancer.ServiceUnavailableException)1 DirectoryProviderMock (com.linkedin.d2.balancer.clients.stub.DirectoryProviderMock)1 KeyMapperProviderMock (com.linkedin.d2.balancer.clients.stub.KeyMapperProviderMock)1 ClientFactoryProvider (com.linkedin.d2.balancer.util.ClientFactoryProvider)1 DirectoryProvider (com.linkedin.d2.balancer.util.DirectoryProvider)1 KeyMapperProvider (com.linkedin.d2.balancer.util.KeyMapperProvider)1