Search in sources :

Example 26 with TestClient

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

the class DegraderTrackerClientTest method testDoNotSlowStartWhenTrue.

@Test
public void testDoNotSlowStartWhenTrue() {
    Map<Integer, PartitionData> partitionDataMap = createDefaultPartitionData(1d);
    DegraderImpl.Config config = new DegraderImpl.Config();
    double initialDropRate = 0.99d;
    config.setInitialDropRate(initialDropRate);
    DegraderTrackerClient client = new DegraderTrackerClientImpl(URI.create("http://test.qa.com:1234/foo"), partitionDataMap, new TestClient(), new SettableClock(), config, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS, TrackerClientImpl.DEFAULT_ERROR_STATUS_PATTERN, true);
    DegraderControl degraderControl = client.getDegraderControl(DefaultPartitionAccessor.DEFAULT_PARTITION_ID);
    Assert.assertEquals(degraderControl.getInitialDropRate(), DegraderImpl.DEFAULT_DO_NOT_SLOW_START_INITIAL_DROP_RATE, "Initial drop rate in config should have been overridden by doNotSlowStart uri property.");
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) DegraderLoadBalancerStrategyConfig(com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyConfig) DegraderImpl(com.linkedin.util.degrader.DegraderImpl) DegraderControl(com.linkedin.util.degrader.DegraderControl) SettableClock(com.linkedin.util.clock.SettableClock) Test(org.testng.annotations.Test)

Example 27 with TestClient

use of com.linkedin.d2.balancer.clients.TestClient 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)

Example 28 with TestClient

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

the class RewriteLoadBalancerClientTestStreamRequest method testPathAppend.

@Test
public void testPathAppend() {
    URI uri = URI.create("http://test.linkedin.com:9876/test");
    String serviceName = "HistoryService";
    TestClient wrappedClient = new TestClient();
    RewriteLoadBalancerClient client = new RewriteLoadBalancerClient(serviceName, uri, wrappedClient);
    assertEquals(client.getUri(), uri);
    assertEquals(client.getServiceName(), serviceName);
    StreamRequest streamRequest;
    Map<String, String> restWireAttrs = new HashMap<>();
    TestTransportCallback<StreamResponse> restCallback = new TestTransportCallback<>();
    streamRequest = getRequest("d2://HistoryService");
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, streamRequest, restCallback, "http://test.linkedin.com:9876/test");
    streamRequest = getRequest("d2://HistoryService/");
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, streamRequest, restCallback, "http://test.linkedin.com:9876/test/");
    streamRequest = getRequest("d2://HistoryService//");
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, streamRequest, restCallback, "http://test.linkedin.com:9876/test//");
    streamRequest = getRequest("d2://HistoryService/foo");
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, streamRequest, restCallback, "http://test.linkedin.com:9876/test/foo");
    streamRequest = getRequest("d2://HistoryService/foo/");
    client.streamRequest(streamRequest, new RequestContext(), restWireAttrs, restCallback);
    checkRewrite(wrappedClient, streamRequest, restCallback, "http://test.linkedin.com:9876/test/foo/");
}
Also used : HashMap(java.util.HashMap) StreamResponse(com.linkedin.r2.message.stream.StreamResponse) TestTransportCallback(com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestTransportCallback) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) Test(org.testng.annotations.Test)

Aggregations

URI (java.net.URI)25 HashMap (java.util.HashMap)25 RequestContext (com.linkedin.r2.message.RequestContext)24 Test (org.testng.annotations.Test)23 RestRequest (com.linkedin.r2.message.rest.RestRequest)13 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)13 RestResponse (com.linkedin.r2.message.rest.RestResponse)13 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)12 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)12 TestTransportCallback (com.linkedin.d2.balancer.clients.DegraderTrackerClientTest.TestTransportCallback)10 TestClient (com.linkedin.d2.balancer.clients.TrackerClientTest.TestClient)10 TestTransportCallback (com.linkedin.d2.balancer.clients.TrackerClientTest.TestTransportCallback)10 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)7 SettableClock (com.linkedin.util.clock.SettableClock)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ByteString (com.linkedin.data.ByteString)4 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)4 Clock (com.linkedin.util.clock.Clock)4 DegraderLoadBalancerStrategyConfig (com.linkedin.d2.balancer.strategies.degrader.DegraderLoadBalancerStrategyConfig)2 DegraderControl (com.linkedin.util.degrader.DegraderControl)2