use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder 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");
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testMostHostWithHighLatency.
@Test
public void testMostHostWithHighLatency() {
LoadBalancerStrategyTestRunner testRunner = new LoadBalancerStrategyTestRunnerBuilder(loadBalancerStrategyType.RELATIVE, DEFAULT_SERVICE_NAME, DEFAULT_NUM_HOSTS).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).setNumIntervals(6).setConstantLatency(Arrays.asList(UNHEALTHY_HOST_CONSTANT_LATENCY, UNHEALTHY_HOST_CONSTANT_LATENCY, UNHEALTHY_HOST_CONSTANT_LATENCY, UNHEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY)).build();
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(testRunner.getUri(1)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(testRunner.getUri(2)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(testRunner.getUri(3)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(testRunner.getUri(4)).intValue(), HEALTHY_POINTS);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder 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);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder 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);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunnerBuilder in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testPartitionWeightChange.
@Test(dataProvider = "strategy")
public void testPartitionWeightChange(loadBalancerStrategyType type) {
double weight = 0.5;
Map<Integer, PartitionData> partitionDataMap = new HashMap<>();
partitionDataMap.put(LoadBalancerStrategyTestRunner.DEFAULT_PARTITION_ID, new PartitionData(weight));
LoadBalancerStrategyTestRunner testRunner = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, DEFAULT_NUM_HOSTS).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).addPartitionDataMap(0, partitionDataMap).setNumIntervals(3).setConstantLatency(Arrays.asList(HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY)).build();
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), (int) (weight * HEALTHY_POINTS));
assertEquals(pointsMap.get(testRunner.getUri(1)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(testRunner.getUri(2)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(testRunner.getUri(3)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(testRunner.getUri(4)).intValue(), HEALTHY_POINTS);
}
Aggregations