use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class StateUpdaterTest method testClusterGenerationIdChange.
// Known to be flaky in CI
@Test(retryAnalyzer = ThreeRetries.class)
public void testClusterGenerationIdChange() throws InterruptedException {
PartitionState state = new PartitionStateTestDataBuilder().setClusterGenerationId(DEFAULT_CLUSTER_GENERATION_ID).build();
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));
ConcurrentMap<Integer, PartitionState> partitionLoadBalancerStateMap = new ConcurrentHashMap<>();
partitionLoadBalancerStateMap.put(DEFAULT_PARTITION_ID, state);
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
D2RelativeStrategyProperties relativeStrategyProperties = RelativeLoadBalancerStrategyFactory.putDefaultValues(new D2RelativeStrategyProperties());
_stateUpdater = new StateUpdater(relativeStrategyProperties, _quarantineManager, executorService, partitionLoadBalancerStateMap, Collections.emptyList(), SERVICE_NAME);
// update will be scheduled twice, once from interval update, once from cluster change
CountDownLatch countDownLatch = new CountDownLatch(2);
Mockito.doAnswer(new ExecutionCountDown<>(countDownLatch)).when(_quarantineManager).updateQuarantineState(any(), any(), anyLong());
// Cluster generation id changed from 0 to 1
_stateUpdater.updateState(new HashSet<>(trackerClients), DEFAULT_PARTITION_ID, 1, false);
if (!countDownLatch.await(5, TimeUnit.SECONDS)) {
fail("cluster update failed to finish within 5 seconds");
}
assertEquals(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).size(), 2);
executorService.shutdown();
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class StateUpdaterTest method testForceUpdate.
// Known to be flaky in CI
@Test(retryAnalyzer = ThreeRetries.class)
public void testForceUpdate() throws InterruptedException {
PartitionState state = new PartitionStateTestDataBuilder().setClusterGenerationId(DEFAULT_CLUSTER_GENERATION_ID).build();
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));
ConcurrentMap<Integer, PartitionState> partitionLoadBalancerStateMap = new ConcurrentHashMap<>();
partitionLoadBalancerStateMap.put(DEFAULT_PARTITION_ID, state);
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
D2RelativeStrategyProperties relativeStrategyProperties = RelativeLoadBalancerStrategyFactory.putDefaultValues(new D2RelativeStrategyProperties());
_stateUpdater = new StateUpdater(relativeStrategyProperties, _quarantineManager, executorService, partitionLoadBalancerStateMap, Collections.emptyList(), SERVICE_NAME);
// update will be scheduled three times, once from interval update, once from cluster change, once from force update
CountDownLatch countDownLatch = new CountDownLatch(3);
Mockito.doAnswer(new ExecutionCountDown<>(countDownLatch)).when(_quarantineManager).updateQuarantineState(any(), any(), anyLong());
// Cluster generation id changed from 0 to 1
_stateUpdater.updateState(new HashSet<>(trackerClients), DEFAULT_PARTITION_ID, 1, false);
_stateUpdater.updateState(new HashSet<>(trackerClients), DEFAULT_PARTITION_ID, 1, true);
if (!countDownLatch.await(5, TimeUnit.SECONDS)) {
fail("cluster update failed to finish within 5 seconds");
}
assertEquals(_stateUpdater.getPointsMap(DEFAULT_PARTITION_ID).size(), 2);
executorService.shutdown();
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class ClientSelectorTest method testGetTargetHostNotFound.
@Test
public void testGetTargetHostNotFound() {
URI newUri = URI.create("new_uri");
KeyMapper.TargetHostHints.setRequestContextTargetHost(_requestContext, newUri);
TrackerClient trackerClient = _clientSelector.getTrackerClient(_request, _requestContext, DEFAULT_RING, DEFAULT_TRACKER_CLIENT_MAP);
assertEquals(trackerClient, null);
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class ClientSelectorTest method testAllClientsExcluded.
@Test
public void testAllClientsExcluded() {
LoadBalancerStrategy.ExcludedHostHints.addRequestContextExcludedHost(_requestContext, URI_1);
LoadBalancerStrategy.ExcludedHostHints.addRequestContextExcludedHost(_requestContext, URI_2);
LoadBalancerStrategy.ExcludedHostHints.addRequestContextExcludedHost(_requestContext, URI_3);
TrackerClient trackerClient = _clientSelector.getTrackerClient(_request, _requestContext, DEFAULT_RING, DEFAULT_TRACKER_CLIENT_MAP);
assertEquals(trackerClient, null);
}
use of com.linkedin.d2.balancer.clients.TrackerClient in project rest.li by linkedin.
the class ClientSelectorTest method testRingAndHostInconsistency.
@Test
public void testRingAndHostInconsistency() {
URI newUri = URI.create("new_uri");
TrackerClient newTrackerClient = Mockito.mock(TrackerClient.class);
Mockito.when(newTrackerClient.getUri()).thenReturn(newUri);
Map<URI, TrackerClient> newTrackerClientMap = new HashMap<>();
newTrackerClientMap.put(newUri, newTrackerClient);
TrackerClient trackerClient = _clientSelector.getTrackerClient(_request, _requestContext, DEFAULT_RING, newTrackerClientMap);
assertEquals(trackerClient, newTrackerClient, "The host should be picked from the tracker client list passed from the request because the ring is completely out of date");
}
Aggregations