use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerPerformanceSimulation method testHostRecoveringToHealthy.
@Test(dataProvider = "relativeLatencyLowThresholdFactor")
public void testHostRecoveringToHealthy(double relativeLatencyLowThresholdFactor, int numHosts) {
LoadBalancerStrategyTestRunner testRunner = buildDefaultRunnerWithRecoveringBadHost(numHosts, HOST_BECOMING_HEALTHY_LATENCY, relativeLatencyLowThresholdFactor);
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
assertEquals(pointsMap.get(testRunner.getUri(0)).intValue(), HEALTHY_POINTS);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testAllHostsBelongToMultiplePartitions.
@Test
public void testAllHostsBelongToMultiplePartitions() {
Map<Integer, PartitionData> partitionDataMapForBothPartitions = new HashMap<>();
partitionDataMapForBothPartitions.put(0, new PartitionData(DEFAULT_WEIGHT));
partitionDataMapForBothPartitions.put(1, new PartitionData(DEFAULT_WEIGHT));
LoadBalancerStrategyTestRunner testRunner = new LoadBalancerStrategyTestRunnerBuilder(loadBalancerStrategyType.RELATIVE, DEFAULT_SERVICE_NAME, 3).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).addPartitionUriMap(0, Arrays.asList(0, 1, 2)).addPartitionUriMap(1, Arrays.asList(0, 1, 2)).addPartitionDataMap(0, partitionDataMapForBothPartitions).addPartitionDataMap(1, partitionDataMapForBothPartitions).addPartitionDataMap(2, partitionDataMapForBothPartitions).setNumIntervals(3).setConstantLatency(Arrays.asList(UNHEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_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(pointsMapPartition0.get(testRunner.getUri(1)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMapPartition0.get(testRunner.getUri(2)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMapPartition1.get(testRunner.getUri(0)).intValue(), (int) (HEALTHY_POINTS - RelativeLoadBalancerStrategyFactory.DEFAULT_DOWN_STEP * HEALTHY_POINTS * 2));
assertEquals(pointsMapPartition1.get(testRunner.getUri(1)).intValue(), HEALTHY_POINTS);
assertEquals(pointsMapPartition1.get(testRunner.getUri(2)).intValue(), HEALTHY_POINTS);
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testFastRecovery.
@Test(dataProvider = "strategy")
public void testFastRecovery(loadBalancerStrategyType type) {
Map<String, Object> strategyPropertiesWithQuarantineEnabled = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithQuarantineEnabled = new D2RelativeStrategyProperties();
strategyPropertiesWithQuarantineEnabled.put(PropertyKeys.HTTP_LB_QUARANTINE_MAX_PERCENT, String.valueOf(DEFAULT_QUARANTINE_PERCENTAGE));
strategyPropertiesWithQuarantineEnabled.put(PropertyKeys.HTTP_LB_RING_RAMP_FACTOR, "2.0");
relativePropertiesWithQuarantineEnabled.setQuarantineProperties(new D2QuarantineProperties().setQuarantineMaxPercent(DEFAULT_QUARANTINE_PERCENTAGE));
relativePropertiesWithQuarantineEnabled.setEnableFastRecovery(true);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(100).setNumIntervals(30).setDegraderStrategies(strategyPropertiesWithQuarantineEnabled, new HashMap<>()).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));
assertTrue(hasPointsInHistory(pointHistory, Arrays.asList(2)), "Fast recovery should recover the points from 1 to 2 initially");
}
use of com.linkedin.d2.balancer.strategies.framework.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testErrorStatusMatch.
@Test(dataProvider = "strategy")
public void testErrorStatusMatch(loadBalancerStrategyType type) {
Map<String, Object> strategyPropertiesWithErrorFilter = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithErrorFilter = new D2RelativeStrategyProperties();
// Only 503 is counted as error
strategyPropertiesWithErrorFilter.put(PropertyKeys.HTTP_LB_ERROR_STATUS_REGEX, "(503)");
relativePropertiesWithErrorFilter.setErrorStatusFilter(new HttpStatusCodeRangeArray(Arrays.asList(new HttpStatusCodeRange().setLowerBound(503).setUpperBound(503))));
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, DEFAULT_NUM_HOSTS).setConstantRequestCount(DEFAULT_REQUESTS_PER_INTERVAL).setNumIntervals(6).setConstantLatency(Arrays.asList(HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY, HEALTHY_HOST_CONSTANT_LATENCY)).setConstantErrorCount(Arrays.asList(UNHEALTHY_ERROR_COUNT, HEALTHY_ERROR_COUNT, HEALTHY_ERROR_COUNT, HEALTHY_ERROR_COUNT, HEALTHY_ERROR_COUNT));
LoadBalancerStrategyTestRunner testRunner = type == loadBalancerStrategyType.DEGRADER ? builder.setDegraderStrategies(strategyPropertiesWithErrorFilter, new HashMap<>()).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithErrorFilter).build();
testRunner.runWait();
Map<URI, Integer> pointsMap = testRunner.getPoints();
// Event with the error 500, the host is not marked as unhealthy
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.LoadBalancerStrategyTestRunner in project rest.li by linkedin.
the class TestLoadBalancerStrategy method testLowQps.
@Test(dataProvider = "strategy")
public void testLowQps(loadBalancerStrategyType type) {
Map<String, String> degraderPropertiesWithMinCallCount = new HashMap<>();
D2RelativeStrategyProperties relativePropertiesWithMinCallCount = new D2RelativeStrategyProperties();
// Set minCallCount to be 20
degraderPropertiesWithMinCallCount.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, "20");
relativePropertiesWithMinCallCount.setMinCallCount(20);
LoadBalancerStrategyTestRunnerBuilder builder = new LoadBalancerStrategyTestRunnerBuilder(type, DEFAULT_SERVICE_NAME, 5).setConstantRequestCount(10).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(new HashMap<>(), degraderPropertiesWithMinCallCount).build() : builder.setRelativeLoadBalancerStrategies(relativePropertiesWithMinCallCount).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);
}
Aggregations