Search in sources :

Example 11 with com.linkedin.d2.loadBalancerStrategyType

use of com.linkedin.d2.loadBalancerStrategyType 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 12 with com.linkedin.d2.loadBalancerStrategyType

use of com.linkedin.d2.loadBalancerStrategyType 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 13 with com.linkedin.d2.loadBalancerStrategyType

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

the class TestLoadBalancerStrategy method testSlowStart.

@Test(dataProvider = "strategy", retryAnalyzer = SingleRetry.class)
public void testSlowStart(loadBalancerStrategyType type) {
    Map<String, String> degraderPropertiesWithSlowStart = new HashMap<>();
    D2RelativeStrategyProperties relativePropertiesWithSlowStart = new D2RelativeStrategyProperties();
    degraderPropertiesWithSlowStart.put(PropertyKeys.DEGRADER_SLOW_START_THRESHOLD, "0.2");
    relativePropertiesWithSlowStart.setSlowStartThreshold(0.2);
    LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(60).setNumIntervals(50).setDegraderStrategies(new HashMap<>(), degraderPropertiesWithSlowStart).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(new HashMap<>(), degraderPropertiesWithSlowStart).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithSlowStart).build();
    testRunner.runWait();
    List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
    assertTrue(hasPointsInHistory(pointHistory, Arrays.asList(2, 4, 8, 16)), "Slow start should double the health score when it is below threshold");
}
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 com.linkedin.d2.loadBalancerStrategyType

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

the class TestLoadBalancerStrategy method testRaceCondition.

@Test(dataProvider = "raceConditionScenario")
public void testRaceCondition(loadBalancerStrategyType type, int numTrackerClients) {
    Map<String, String> degraderProperties = new HashMap<>();
    degraderProperties.put(PropertyKeys.DEGRADER_INITIAL_DROP_RATE, "0.99");
    degraderProperties.put(PropertyKeys.DEGRADER_SLOW_START_THRESHOLD, "0.16");
    D2RelativeStrategyProperties relativeProperties = new D2RelativeStrategyProperties().setSlowStartThreshold(0.16).setInitialHealthScore(0.01);
    LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 10).setConstantRequestCount(30).setNumIntervals(50).setConstantLatency(Arrays.asList(HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_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<>(), degraderProperties).build() : builder.setRelativeLoadBalancerStrategies(relativeProperties).build();
    testRunner.runWaitInconsistentTrackerClients(numTrackerClients);
    assertEquals(testRunner.getPoints().size(), 10);
    assertEquals(testRunner.getPoints().get(testRunner.getUri(0)).intValue(), 100);
}
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 15 with com.linkedin.d2.loadBalancerStrategyType

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

the class TestLoadBalancerStrategy method testStayQuarantined.

@Test(dataProvider = "strategy")
public void testStayQuarantined(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(10).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(strategyPropertiesWithQuarantineEnabled, new HashMap<>()).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithQuarantineEnabled).build();
    testRunner.runWait();
    List<Integer> pointHistory = testRunner.getPointHistory().get(testRunner.getUri(0));
    assertEquals(pointHistory.get(9).intValue(), QUARANTINED_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)

Aggregations

Test (org.testng.annotations.Test)15 HashMap (java.util.HashMap)14 LoadBalancerStrategyTestRunner (com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner)13 LoadBalancerStrategyTestRunnerBuilder (com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder)13 D2RelativeStrategyProperties (com.linkedin.d2.D2RelativeStrategyProperties)11 URI (java.net.URI)6 D2QuarantineProperties (com.linkedin.d2.D2QuarantineProperties)4 D2ClusterPartitionConfiguration (com.linkedin.d2.D2ClusterPartitionConfiguration)2 RangedPartitionProperties (com.linkedin.d2.RangedPartitionProperties)2 HashBasedPartitionProperties (com.linkedin.d2.balancer.properties.HashBasedPartitionProperties)2 NullPartitionProperties (com.linkedin.d2.balancer.properties.NullPartitionProperties)2 PartitionProperties (com.linkedin.d2.balancer.properties.PartitionProperties)2 RangeBasedPartitionProperties (com.linkedin.d2.balancer.properties.RangeBasedPartitionProperties)2 ArrayList (java.util.ArrayList)2 DarkClusterStrategyNameArray (com.linkedin.d2.DarkClusterStrategyNameArray)1 HttpStatusCodeRange (com.linkedin.d2.HttpStatusCodeRange)1 HttpStatusCodeRangeArray (com.linkedin.d2.HttpStatusCodeRangeArray)1 LoadBalancerState (com.linkedin.d2.balancer.LoadBalancerState)1 ServiceUnavailableException (com.linkedin.d2.balancer.ServiceUnavailableException)1 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)1