Search in sources :

Example 11 with LoadBalancerStrategyTestRunnerBuilder

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.

the class TestLoadBalancerStrategy method testDifferentHighLatencyFactors.

@Test(dataProvider = "highFactor", retryAnalyzer = SingleRetry.class)
public void testDifferentHighLatencyFactors(double highFactor) {
    long unhealthyLatency = 800L;
    long healthyLatency = 400L;
    long avgLatency = (unhealthyLatency + 4 * healthyLatency) / 5;
    D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties().setRelativeLatencyHighThresholdFactor(highFactor);
    LoadBalancerStrategyTestRunner testRunner = new LoadBalancerStrategyTestRunnerBuilder(loadBalancerStrategyType.RELATIVE, DEFAULT_SERVICE_NAME, DEFAULT_NUM_HOSTS).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).setNumIntervals(3).setConstantLatency(Arrays.asList(unhealthyLatency, healthyLatency, healthyLatency, healthyLatency, healthyLatency)).setRelativeLoadBalancerStrategies(relativeStrategyProperties).build();
    testRunner.runWait();
    Map<URI, Integer> pointsMap = testRunner.getPoints();
    if (highFactor < (double) unhealthyLatency / avgLatency) {
        assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), (int) (HEALTHY_POINTS - RelativeLoadBalancerStrategyFactory.DEFAULT_DOWN_STEP * HEALTHY_POINTS * 2));
    } else {
        assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), HEALTHY_POINTS);
    }
}
Also used : LoadBalancerStrategyTestRunnerBuilder(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder) LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) URI(java.net.URI) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) Test(org.testng.annotations.Test)

Example 12 with LoadBalancerStrategyTestRunnerBuilder

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.

the class TestLoadBalancerStrategy method testOneHost.

@Test(dataProvider = "strategy")
public void testOneHost(loadBalancerStrategyType type) {
    LoadBalancerStrategyTestRunner testRunner = new LoadBalancerStrategyTestRunnerBuilder(type, // Set to corner case - only 1 host
    DEFAULT_SERVICE_NAME, 1).setConstantRequestCount(100).setNumIntervals(3).setConstantLatency(Arrays.asList(HEALTHY_HOST_CONSTANT_LATENCY)).build();
    testRunner.runWait();
    List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
    assertEquals(pointHistory.get(2).intValue(), HEALTHY_POINTS);
}
Also used : LoadBalancerStrategyTestRunnerBuilder(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder) LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) Test(org.testng.annotations.Test)

Example 13 with LoadBalancerStrategyTestRunnerBuilder

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.

the class TestLoadBalancerStrategy method testGrowingQps.

@Test(dataProvider = "strategy")
public void testGrowingQps(loadBalancerStrategyType type) {
    Map<String, String> degraderPropertiesWithMinCallCount = new HashMap<>();
    D2RelativeStrategyProperties relativePropertiesWithMinCallCount = new D2RelativeStrategyProperties();
    // Set minCallCount to be 100
    degraderPropertiesWithMinCallCount.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, "100");
    relativePropertiesWithMinCallCount.setMinCallCount(100);
    LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setDynamicRequestCount((intervalIndex) -> 10 + 50 * intervalIndex).setNumIntervals(50).setConstantLatency(Arrays.asList(UNHEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY));
    LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(new HashMap<>(), degraderPropertiesWithMinCallCount).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithMinCallCount).build();
    testRunner.runWait();
    List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
    int lowestPoints = getLowestPoints(pointHistory);
    assertEquals(pointHistory.get(3).intValue(), HEALTHY_POINTS, "The unhealthy host still has 100 points on 4th iteration because QPS was small");
    assertTrue(lowestPoints <= FULLY_DROPPED_POINTS, "The points will eventually drop");
}
Also used : LoadBalancerStrategyTestRunnerBuilder(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder) HashMap(java.util.HashMap) LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) Test(org.testng.annotations.Test)

Example 14 with LoadBalancerStrategyTestRunnerBuilder

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.

the class TestLoadBalancerStrategy method testQuarantineRecovery.

@Test(dataProvider = "strategy")
public void testQuarantineRecovery(loadBalancerStrategyType type) {
    Map<String, Object> strategyPropertiesWithQuarantineEnabled = new HashMap<>();
    D2RelativeStrategyProperties relativePropertiesWithQuarantineEnabled = new D2RelativeStrategyProperties();
    D2QuarantineProperties quarantineProperties = new D2QuarantineProperties().setQuarantineMaxPercent(DEFAULT_QUARANTINE_PERCENTAGE);
    strategyPropertiesWithQuarantineEnabled.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, String.valueOf(DEFAULT_QUARANTINE_PERCENTAGE));
    relativePropertiesWithQuarantineEnabled.setQuarantineProperties(quarantineProperties);
    LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(1000).setNumIntervals(40).setDynamicLatency(Arrays.asList(HOST_RECOVERING_TO_HEALTHY_LATENCY, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION, HEALTHY_HOST_LATENCY_CORRELATION));
    LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(strategyPropertiesWithQuarantineEnabled, new HashMap<>()).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithQuarantineEnabled).build();
    testRunner.runWait();
    List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
    assertEquals(getLowestPoints(pointHistory), QUARANTINED_POINTS);
    assertEquals(pointHistory.get(39).intValue(), HEALTHY_POINTS);
}
Also used : LoadBalancerStrategyTestRunnerBuilder(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder) D2QuarantineProperties(com.linkedin.d2.D2QuarantineProperties) HashMap(java.util.HashMap) LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) D2RelativeStrategyProperties(com.linkedin.d2.D2RelativeStrategyProperties) Test(org.testng.annotations.Test)

Example 15 with LoadBalancerStrategyTestRunnerBuilder

use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.

the class TestLoadBalancerStrategy method testOneHostBelongToMultiplePartitions.

@Test
public void testOneHostBelongToMultiplePartitions() {
    Map<Integer, PartitionData> partitionDataMapForBothPartitions = new HashMap<>();
    partitionDataMapForBothPartitions.put(0, new PartitionData(DEFAULT_WEIGHT));
    partitionDataMapForBothPartitions.put(1, new PartitionData(DEFAULT_WEIGHT));
    Map<Integer, PartitionData> partitionDataMapPartition0 = new HashMap<>();
    partitionDataMapPartition0.put(0, new PartitionData(DEFAULT_WEIGHT));
    Map<Integer, PartitionData> partitionDataMapPartition1 = new HashMap<>();
    partitionDataMapPartition1.put(1, new PartitionData(DEFAULT_WEIGHT));
    LoadBalancerStrategyTestRunner testRunner = new LoadBalancerStrategyTestRunnerBuilder(loadBalancerStrategyType.RELATIVE, DEFAULT_SERVICE_NAME, DEFAULT_NUM_HOSTS).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).addPartitionUriMap(0, Arrays.asList(0, 1, 2)).addPartitionUriMap(1, Arrays.asList(0, 3, 4)).addPartitionDataMap(0, partitionDataMapForBothPartitions).addPartitionDataMap(1, partitionDataMapPartition0).addPartitionDataMap(2, partitionDataMapPartition0).addPartitionDataMap(3, partitionDataMapPartition1).addPartitionDataMap(4, partitionDataMapPartition1).setNumIntervals(3).setConstantLatency(Arrays.asList(UNHEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, UNHEALTHY_HOST_CONSTANT_LATENCY, UNHEALTHY_HOST_CONSTANT_LATENCY)).build();
    // Send traffic to partition 0 and 1
    testRunner.runWait(Arrays.asList(0, 1));
    Map<URI, Integer> pointsMapPartition0 = testRunner.getPoints(0);
    Map<URI, Integer> pointsMapPartition1 = testRunner.getPoints(1);
    assertEquals(pointsMapPartition0.get(testRunner.getUri(0)).intValue(), (int) (HEALTHY_POINTS - RelativeLoadBalancerStrategyFactory.DEFAULT_DOWN_STEP * HEALTHY_POINTS * 2));
    assertEquals(pointsMapPartition1.get(testRunner.getUri(0)).intValue(), HEALTHY_POINTS);
}
Also used : LoadBalancerStrategyTestRunnerBuilder(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) HashMap(java.util.HashMap) LoadBalancerStrategyTestRunner(com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner) URI(java.net.URI) Test(org.testng.annotations.Test)

Aggregations

LoadBalancerStrategyTestRunnerBuilder (com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder)22 D2RelativeStrategyProperties (com.linkedin.d2.D2RelativeStrategyProperties)17 LoadBalancerStrategyTestRunner (com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner)17 Test (org.testng.annotations.Test)17 HashMap (java.util.HashMap)15 URI (java.net.URI)9 ArrayList (java.util.ArrayList)5 D2QuarantineProperties (com.linkedin.d2.D2QuarantineProperties)4 LatencyCorrelation (com.linkedin.d2.balancer.strategies.framework.LatencyCorrelation)4 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)3 HttpStatusCodeRange (com.linkedin.d2.HttpStatusCodeRange)1 HttpStatusCodeRangeArray (com.linkedin.d2.HttpStatusCodeRangeArray)1 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)1