use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class StateUpdaterTest method testInitializePartition.
@Test(dataProvider = "partitionId")
public void testInitializePartition(int partitionId) {
setup(new D2RelativeStrategyProperties(), new ConcurrentHashMap<>());
List<TrackerClient> trackerClients = TrackerClientMockHelper.mockTrackerClients(2, Arrays.asList(20, 20), Arrays.asList(10, 10), Arrays.asList(200L, 500L), Arrays.asList(100L, 200L), Arrays.asList(0, 0));
assertTrue(_stateUpdater.getPointsMap(partitionId).isEmpty(), "There should be no state before initialization");
_stateUpdater.updateState(new HashSet<>(trackerClients), partitionId, DEFAULT_CLUSTER_GENERATION_ID, false);
assertEquals(_stateUpdater.getPointsMap(partitionId).get(trackerClients.get(0).getUri()).intValue(), HEALTHY_POINTS);
assertEquals(_stateUpdater.getPointsMap(partitionId).get(trackerClients.get(1).getUri()).intValue(), HEALTHY_POINTS);
assertEquals(_stateUpdater.getFirstValidPartitionId(), partitionId);
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class StateUpdaterTest method testHealthScoreDrop.
@Test(dataProvider = "trackerClients")
public void testHealthScoreDrop(List<TrackerClient> trackerClients, double highLatencyFactor, double highErrorRate, boolean expectToDropHealthScore) {
PartitionState state = new PartitionStateTestDataBuilder().setClusterGenerationId(DEFAULT_CLUSTER_GENERATION_ID).setTrackerClientStateMap(trackerClients, Arrays.asList(StateUpdater.MAX_HEALTH_SCORE, StateUpdater.MAX_HEALTH_SCORE, StateUpdater.MAX_HEALTH_SCORE), Arrays.asList(TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY), Arrays.asList(30, 30, 30)).build();
ConcurrentMap<Integer, PartitionState> partitionLoadBalancerStateMap = new ConcurrentHashMap<>();
partitionLoadBalancerStateMap.put(DEFAULT_PARTITION_ID, state);
setup(new D2RelativeStrategyProperties().setRelativeLatencyHighThresholdFactor(highLatencyFactor).setHighErrorRate(highErrorRate), partitionLoadBalancerStateMap);
_stateUpdater.updateState();
Map<URI, Integer> pointsMap = _stateUpdater.getPointsMap(DEFAULT_PARTITION_ID);
if (!expectToDropHealthScore) {
assertEquals(pointsMap.get(trackerClients.get(0).getUri()).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(trackerClients.get(1).getUri()).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(trackerClients.get(2).getUri()).intValue(), HEALTHY_POINTS);
} else {
assertEquals(pointsMap.get(trackerClients.get(0).getUri()).intValue(), (int) (HEALTHY_POINTS - RelativeLoadBalancerStrategyFactory.DEFAULT_DOWN_STEP * RelativeLoadBalancerStrategyFactory.DEFAULT_POINTS_PER_WEIGHT));
assertEquals(pointsMap.get(trackerClients.get(1).getUri()).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(trackerClients.get(2).getUri()).intValue(), HEALTHY_POINTS);
}
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class StateUpdaterTest method testClusterUrisChange.
@Test
public void testClusterUrisChange() {
List<TrackerClient> trackerClients = TrackerClientMockHelper.mockTrackerClients(3, Arrays.asList(20, 20, 20), Arrays.asList(10, 10, 10), Arrays.asList(200L, 220L, 1000L), Arrays.asList(100L, 110L, 500L), Arrays.asList(0, 0, 0));
PartitionState state = new PartitionStateTestDataBuilder().setClusterGenerationId(DEFAULT_CLUSTER_GENERATION_ID).setTrackerClientStateMap(trackerClients, Arrays.asList(StateUpdater.MAX_HEALTH_SCORE, StateUpdater.MAX_HEALTH_SCORE, StateUpdater.MAX_HEALTH_SCORE), Arrays.asList(TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY), Arrays.asList(30, 30, 30)).build();
ConcurrentMap<Integer, PartitionState> partitionLoadBalancerStateMap = new ConcurrentHashMap<>();
partitionLoadBalancerStateMap.put(DEFAULT_PARTITION_ID, state);
setup(new D2RelativeStrategyProperties(), partitionLoadBalancerStateMap);
// New tracker clients set only contains 2 out of 3 tracker clients from the old state
Set<TrackerClient> newTrackerClientSet = new HashSet<>();
newTrackerClientSet.add(trackerClients.get(0));
newTrackerClientSet.add(trackerClients.get(1));
_stateUpdater.updateStateForPartition(newTrackerClientSet, DEFAULT_PARTITION_ID, state, 1L, false);
Map<URI, Integer> pointsMap = _stateUpdater.getPointsMap(DEFAULT_PARTITION_ID);
assertEquals(pointsMap.size(), 2, "There should only be 2 uris after cluster id change");
assertEquals(pointsMap.get(trackerClients.get(0).getUri()).intValue(), HEALTHY_POINTS);
assertEquals(pointsMap.get(trackerClients.get(1).getUri()).intValue(), HEALTHY_POINTS);
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class LoadBalancerStrategyTestRunnerBuilder method buildRelativeStrategy.
private LoadBalancerStrategyTestRunner buildRelativeStrategy() {
if (_serviceProperties == null) {
setRelativeLoadBalancerStrategies(new D2RelativeStrategyProperties());
}
_strategy = new RelativeLoadBalancerStrategyFactory(_clockedExecutor, null, new ArrayList<>(), null, _clockedExecutor).newLoadBalancer(_serviceProperties);
_transportClients = _uris.stream().map(uri -> new MockTransportClient(_clockedExecutor, _latencyManager, _errorCountManager, uri, INTERVAL_IN_MILLIS, _currentErrorCountMap, _lastRequestCountMap, _callCountMap, _latencySumMap)).collect(Collectors.toList());
Map<URI, TrackerClient> trackerClientMap = _transportClients.stream().map(transportClient -> {
// If partition map is not specified, by default we only support one partition
Map<Integer, PartitionData> partitionDataMap = _partitionDataMap.getOrDefault(transportClient.getUri(), DEFAULT_PARTITION_DATA_MAP);
return new TrackerClientImpl(transportClient.getUri(), partitionDataMap, transportClient, _clockedExecutor, INTERVAL_IN_MILLIS, (status) -> status >= 500 && status <= 599);
}).collect(Collectors.toMap(TrackerClient::getUri, trackerClient -> trackerClient));
return buildInternal(trackerClientMap);
}
use of com.linkedin.d2.D2RelativeStrategyProperties in project rest.li by linkedin.
the class StateUpdaterTest method testUpdateTrackerClientWithDoNotLoadBalance.
@Test
public void testUpdateTrackerClientWithDoNotLoadBalance() {
final boolean doNotLoadBalance = true;
List<TrackerClient> trackerClients = TrackerClientMockHelper.mockTrackerClients(3, Arrays.asList(20, 1, 20), Arrays.asList(0, 0, 0), Arrays.asList(1000L, 5000L, 100000L), Arrays.asList(0L, 0L, 0L), Arrays.asList(0, 0, 10), Arrays.asList(false, false, doNotLoadBalance));
PartitionState state = new PartitionStateTestDataBuilder().setClusterGenerationId(DEFAULT_CLUSTER_GENERATION_ID).setTrackerClientStateMap(trackerClients, Arrays.asList(1.0, 1.0, 1.0), Arrays.asList(TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY, TrackerClientState.HealthState.HEALTHY), Arrays.asList(30, 30, 30)).build();
ConcurrentMap<Integer, PartitionState> partitionLoadBalancerStateMap = new ConcurrentHashMap<>();
partitionLoadBalancerStateMap.put(DEFAULT_PARTITION_ID, state);
setup(new D2RelativeStrategyProperties(), partitionLoadBalancerStateMap);
_stateUpdater.updateState();
Map<URI, Integer> pointsMap = _stateUpdater.getPointsMap(DEFAULT_PARTITION_ID);
assertEquals(pointsMap.get(trackerClients.get(0).getUri()).intValue(), HEALTHY_POINTS, "Healthy client should not have health score reduced.");
assertEquals(pointsMap.get(trackerClients.get(1).getUri()).intValue(), (int) (HEALTHY_POINTS - RelativeLoadBalancerStrategyFactory.DEFAULT_DOWN_STEP * RelativeLoadBalancerStrategyFactory.DEFAULT_POINTS_PER_WEIGHT), "This should be considered unhealthy because its latency exceeds the threshold " + "(the client with load balancing disabled should not affect the average latency calculation).");
assertEquals(pointsMap.get(trackerClients.get(2).getUri()).intValue(), HEALTHY_POINTS, "The client with load balancing disabled " + "should not have health score reduced.");
}
Aggregations