Search in sources :

Example 1 with Facilities

use of com.linkedin.d2.balancer.Facilities in project rest.li by linkedin.

the class ZKFSTest method testClientFactoryProvider.

@Test
public void testClientFactoryProvider() throws Exception {
    startServer();
    try {
        ZKFSLoadBalancer balancer = getBalancer();
        FutureCallback<None> callback = new FutureCallback<None>();
        balancer.start(callback);
        callback.get(30, TimeUnit.SECONDS);
        Facilities facilities = balancer.getFacilities();
        TransportClientFactory factory = facilities.getClientFactory("http");
        Assert.assertNotNull(factory);
        Assert.assertTrue(factory instanceof HttpClientFactory);
    } finally {
        stopServer();
    }
}
Also used : None(com.linkedin.common.util.None) TransportClientFactory(com.linkedin.r2.transport.common.TransportClientFactory) HttpClientFactory(com.linkedin.r2.transport.http.client.HttpClientFactory) FutureCallback(com.linkedin.common.callback.FutureCallback) Facilities(com.linkedin.d2.balancer.Facilities) Test(org.testng.annotations.Test)

Example 2 with Facilities

use of com.linkedin.d2.balancer.Facilities 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 3 with Facilities

use of com.linkedin.d2.balancer.Facilities 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)3 Test (org.testng.annotations.Test)3 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 FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1 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 TransportClientFactory (com.linkedin.r2.transport.common.TransportClientFactory)1 HttpClientFactory (com.linkedin.r2.transport.http.client.HttpClientFactory)1