Search in sources :

Example 11 with ConsistentHashAlgorithm

use of com.linkedin.d2.ConsistentHashAlgorithm in project rest.li by linkedin.

the class DegraderLoadBalancerTest method testBalancingRing.

@Test(groups = { "small", "back-end" }, dataProvider = "consistentHashAlgorithms")
public void testBalancingRing(String consistentHashAlgorithm) throws URISyntaxException {
    DegraderLoadBalancerStrategyV3 strategy = getStrategy(consistentHashAlgorithm);
    List<DegraderTrackerClient> clients = new ArrayList<>();
    URI uri1 = URI.create("http://someTestService/someTestUrl");
    URI uri2 = URI.create("http://abcxfweuoeueoueoueoukeueoueoueoueoueouo/2354");
    TestClock clock1 = new TestClock();
    TestClock clock2 = new TestClock();
    DegraderTrackerClient client1 = getClient(uri1, clock1);
    DegraderTrackerClient client2 = getClient(uri2, clock2);
    clients.add(client1);
    clients.add(client2);
    // force client2 to be disabled
    DegraderControl dcClient2Default = client2.getDegraderControl(DEFAULT_PARTITION_ID);
    dcClient2Default.setOverrideMinCallCount(1);
    dcClient2Default.setMinCallCount(1);
    dcClient2Default.setMaxDropRate(1d);
    dcClient2Default.setUpStep(0.4d);
    dcClient2Default.setHighErrorRate(0);
    CallCompletion cc = client2.getCallTracker().startCall();
    clock2.addMs(1);
    cc.endCallWithError();
    clock1.addMs(15000);
    clock2.addMs(5000);
    // now do a basic verification to verify getTrackerClient is properly weighting things
    double calls = 10000d;
    int client1Count = 0;
    int client2Count = 0;
    double tolerance = 0.05d;
    for (int i = 0; i < calls; ++i) {
        TrackerClient client = getTrackerClient(strategy, null, new RequestContext(), 1, clients);
        assertNotNull(client);
        if (client.getUri().equals(uri1)) {
            ++client1Count;
        } else {
            ++client2Count;
        }
    }
    assertTrue(Math.abs((client1Count / calls) - (100 / 160d)) < tolerance);
    assertTrue(Math.abs((client2Count / calls) - (60 / 160d)) < tolerance);
}
Also used : CallCompletion(com.linkedin.util.degrader.CallCompletion) DegraderTrackerClient(com.linkedin.d2.balancer.clients.DegraderTrackerClient) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) DegraderTrackerClient(com.linkedin.d2.balancer.clients.DegraderTrackerClient) ArrayList(java.util.ArrayList) DegraderControl(com.linkedin.util.degrader.DegraderControl) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) Test(org.testng.annotations.Test) DegraderTrackerClientTest(com.linkedin.d2.balancer.clients.DegraderTrackerClientTest)

Aggregations

Test (org.testng.annotations.Test)8 DegraderTrackerClient (com.linkedin.d2.balancer.clients.DegraderTrackerClient)6 DegraderTrackerClientTest (com.linkedin.d2.balancer.clients.DegraderTrackerClientTest)6 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)6 RequestContext (com.linkedin.r2.message.RequestContext)6 URI (java.net.URI)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 DegraderTrackerClientImpl (com.linkedin.d2.balancer.clients.DegraderTrackerClientImpl)4 D2RingProperties (com.linkedin.d2.D2RingProperties)3 StringArray (com.linkedin.data.template.StringArray)3 CallCompletion (com.linkedin.util.degrader.CallCompletion)3 DegraderControl (com.linkedin.util.degrader.DegraderControl)3 ConsistentHashAlgorithm (com.linkedin.d2.ConsistentHashAlgorithm)2 D2LoadBalancerStrategyProperties (com.linkedin.d2.D2LoadBalancerStrategyProperties)2 D2QuarantineProperties (com.linkedin.d2.D2QuarantineProperties)2 D2RelativeStrategyProperties (com.linkedin.d2.D2RelativeStrategyProperties)2 HashConfig (com.linkedin.d2.HashConfig)2 HttpMethod (com.linkedin.d2.HttpMethod)2 HttpStatusCodeRange (com.linkedin.d2.HttpStatusCodeRange)2