use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class ClientSelectorTest method testGetTargetHost.
@Test
public void testGetTargetHost() {
KeyMapper.TargetHostHints.setRequestContextTargetHost(_requestContext, URI_1);
TrackerClient trackerClient = _clientSelector.getTrackerClient(_request, _requestContext, DEFAULT_RING, DEFAULT_TRACKER_CLIENT_MAP);
assertEquals(trackerClient.getUri(), URI_1);
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class ClientSelectorTest method testSubstituteClientFromRing.
@Test
public void testSubstituteClientFromRing() {
URI newUri = URI.create("new_uri");
@SuppressWarnings("unchecked") Ring<URI> ring = Mockito.mock(Ring.class);
Mockito.when(ring.get(anyInt())).thenReturn(newUri);
List<URI> ringIteratierList = Arrays.asList(newUri, URI_1, URI_2, URI_3);
Mockito.when(ring.getIterator(anyInt())).thenReturn(ringIteratierList.iterator());
TrackerClient trackerClient = _clientSelector.getTrackerClient(_request, _requestContext, ring, DEFAULT_TRACKER_CLIENT_MAP);
assertTrue(DEFAULT_TRACKER_CLIENT_MAP.containsKey(trackerClient.getUri()));
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class QuarantineManagerTest method testEnrollOneQuarantine.
@Test
public void testEnrollOneQuarantine() {
LoadBalancerQuarantine quarantine = Mockito.mock(LoadBalancerQuarantine.class);
List<TrackerClient> trackerClients = TrackerClientMockHelper.mockTrackerClients(3);
Map<TrackerClient, LoadBalancerQuarantine> existingQuarantineMap = new HashMap<>();
setup(0.5, true, true);
_quarantineManager.tryEnableQuarantine();
PartitionState state = new PartitionStateTestDataBuilder().setTrackerClientStateMap(trackerClients, Arrays.asList(StateUpdater.MIN_HEALTH_SCORE, StateUpdater.MIN_HEALTH_SCORE, QuarantineManager.INITIAL_RECOVERY_HEALTH_SCORE), Arrays.asList(TrackerClientState.HealthState.UNHEALTHY, TrackerClientState.HealthState.NEUTRAL, TrackerClientState.HealthState.UNHEALTHY), Arrays.asList(20, 20, 20)).build();
_quarantineManager.updateQuarantineState(state, state, 10000);
assertEquals(state.getQuarantineMap().size(), 1, "No exception expected");
assertTrue(state.getQuarantineMap().containsKey(trackerClients.get(0)));
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class QuarantineManagerTest method testQuarantineCheck.
@Test(dataProvider = "trueFalse")
public void testQuarantineCheck(boolean quarantineCheckResult) {
setup(0.5, false, false);
LoadBalancerQuarantine quarantine = Mockito.mock(LoadBalancerQuarantine.class);
List<TrackerClient> trackerClients = TrackerClientMockHelper.mockTrackerClients(3);
Map<TrackerClient, LoadBalancerQuarantine> existingQuarantineMap = new HashMap<>();
existingQuarantineMap.put(trackerClients.get(0), quarantine);
Mockito.when(quarantine.checkUpdateQuarantineState()).thenReturn(quarantineCheckResult);
PartitionState state = new PartitionStateTestDataBuilder().setTrackerClientStateMap(trackerClients, Arrays.asList(StateUpdater.MIN_HEALTH_SCORE, 0.6, 0.6), Arrays.asList(TrackerClientState.HealthState.NEUTRAL, TrackerClientState.HealthState.UNHEALTHY, TrackerClientState.HealthState.UNHEALTHY), Arrays.asList(20, 20, 20)).setQuarantineMap(existingQuarantineMap).build();
_quarantineManager.tryEnableQuarantine();
_quarantineManager.updateQuarantineState(state, state, DEFAULT_AVG_CLUSTER_LATENCY);
if (quarantineCheckResult) {
assertTrue(state.getQuarantineMap().isEmpty());
assertEquals(state.getRecoveryTrackerClients().size(), 1, "The quarantine should be over and the host should be put into recovery");
assertEquals(state.getTrackerClientStateMap().get(trackerClients.get(0)).getHealthScore(), QuarantineManager.INITIAL_RECOVERY_HEALTH_SCORE);
} else {
assertEquals(state.getQuarantineMap().size(), 1, "Quarantine health check failed, the host should be kept in quarantine state");
assertTrue(state.getRecoveryTrackerClients().isEmpty(), "No client should be in recovery state");
assertTrue(state.getQuarantineMap().containsKey(trackerClients.get(0)));
}
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class RelativeLoadBalancerStrategyJmxTest method mockRelativeLoadBalancerStrategyJmx.
private RelativeLoadBalancerStrategyJmx mockRelativeLoadBalancerStrategyJmx(List<TrackerClient> trackerClients) {
Map<TrackerClient, TrackerClientState> trackerClientsMap = new HashMap<>();
for (TrackerClient trackerClient : trackerClients) {
trackerClientsMap.put(trackerClient, new TrackerClientState(1, 1));
}
RelativeLoadBalancerStrategy strategy = Mockito.mock(RelativeLoadBalancerStrategy.class);
PartitionState state = Mockito.mock(PartitionState.class);
Mockito.when(state.getTrackerClientStateMap()).thenReturn(trackerClientsMap);
Mockito.when(strategy.getFirstValidPartitionId()).thenReturn(DefaultPartitionAccessor.DEFAULT_PARTITION_ID);
Mockito.when(strategy.getPartitionState(anyInt())).thenReturn(state);
return new RelativeLoadBalancerStrategyJmx(strategy);
}
Aggregations