Search in sources :

Example 1 with TestCallback

use of com.linkedin.d2.balancer.clients.TrackerClientTest.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 {
    TestLoadBalancer balancer = new TestLoadBalancer(false);
    DirectoryProvider dirProvider = new TestDirectoryProvider();
    KeyMapperProvider keyMapperProvider = new TestKeyMapperProvider();
    ClientFactoryProvider clientFactoryProvider = new TestClientFactoryProvider();
    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<RestResponse>();
    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.TrackerClientTest.TestCallback) URI(java.net.URI) Facilities(com.linkedin.d2.balancer.Facilities) DelegatingFacilities(com.linkedin.d2.balancer.util.DelegatingFacilities) RestRequest(com.linkedin.r2.message.rest.RestRequest) DirectoryProvider(com.linkedin.d2.balancer.util.DirectoryProvider) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) DelegatingFacilities(com.linkedin.d2.balancer.util.DelegatingFacilities) Test(org.testng.annotations.Test)

Example 2 with TestCallback

use of com.linkedin.d2.balancer.clients.TrackerClientTest.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 {
    TestLoadBalancer balancer = new TestLoadBalancer(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<RestResponse>();
    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 : 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.TrackerClientTest.TestCallback) URI(java.net.URI) Facilities(com.linkedin.d2.balancer.Facilities) 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.TrackerClientTest.TestCallback)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 ClientFactoryProvider (com.linkedin.d2.balancer.util.ClientFactoryProvider)1 DirectoryProvider (com.linkedin.d2.balancer.util.DirectoryProvider)1 KeyMapperProvider (com.linkedin.d2.balancer.util.KeyMapperProvider)1