use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy 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);
}
use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy in project rest.li by linkedin.
the class SimpleLoadBalancerStateTest method testServiceStrategyListWithRelativeStrategy.
@Test
public void testServiceStrategyListWithRelativeStrategy() {
reset();
LinkedList<String> strategyList = new LinkedList<>();
URI uri = URI.create("http://cluster-1/test");
List<String> schemes = new ArrayList<>();
Map<URI, Double> weights = new HashMap<>();
weights.put(uri, 1d);
schemes.add("http");
_state.listenToService("service-1", new NullStateListenerCallback());
_state.listenToCluster("cluster-1", new NullStateListenerCallback());
strategyList.add(RelativeLoadBalancerStrategy.RELATIVE_LOAD_BALANCER_STRATEGY_NAME);
strategyList.add(DegraderLoadBalancerStrategyV3.DEGRADER_STRATEGY_NAME);
_serviceRegistry.put("service-1", new ServiceProperties("service-1", "cluster-1", "/test", strategyList, Collections.<String, Object>emptyMap(), null, null, schemes, null));
_clusterRegistry.put("cluster-1", new ClusterProperties("cluster-1"));
LoadBalancerStrategy strategy = _state.getStrategy("service-1", "http");
assertNotNull(strategy);
assertTrue(strategy instanceof RelativeLoadBalancerStrategy);
}
use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy in project rest.li by linkedin.
the class RelativeLoadBalancerStrategyFactory method newLoadBalancer.
@Override
public RelativeLoadBalancerStrategy newLoadBalancer(ServiceProperties serviceProperties) {
D2RelativeStrategyProperties relativeStrategyProperties = RelativeStrategyPropertiesConverter.toProperties(serviceProperties.getRelativeStrategyProperties());
relativeStrategyProperties = putDefaultValues(relativeStrategyProperties);
return new RelativeLoadBalancerStrategy(getRelativeStateUpdater(relativeStrategyProperties, serviceProperties.getServiceName(), serviceProperties.getClusterName(), serviceProperties.getPath()), getClientSelector(relativeStrategyProperties));
}
use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy in project rest.li by linkedin.
the class LoadBalancerStrategyBenchmark method buildRelativeLoadBalancerStrategy.
private static RelativeLoadBalancerStrategy buildRelativeLoadBalancerStrategy() {
D2RelativeStrategyProperties relativeStrategyProperties = new D2RelativeStrategyProperties();
ServiceProperties serviceProperties = new ServiceProperties(DUMMY_SERVICE_NAME, DEFAULT_CLUSTER_NAME, DEFAULT_PATH, DEFAULT_STRATEGY_LIST, null, null, null, null, null, null, null, RelativeStrategyPropertiesConverter.toMap(relativeStrategyProperties));
return new RelativeLoadBalancerStrategyFactory(EXECUTOR_SERVICE, null, new ArrayList<>(), null, SystemClock.instance()).newLoadBalancer(serviceProperties);
}
use of com.linkedin.d2.balancer.strategies.relative.RelativeLoadBalancerStrategy in project rest.li by linkedin.
the class RelativeLoadBalancerStrategyJmxTest method testNoValidPartitionData.
@Test
public void testNoValidPartitionData() {
RelativeLoadBalancerStrategy strategy = Mockito.mock(RelativeLoadBalancerStrategy.class);
Mockito.when(strategy.getFirstValidPartitionId()).thenReturn(DefaultPartitionAccessor.DEFAULT_PARTITION_ID);
Mockito.when(strategy.getPartitionState(anyInt())).thenReturn(null);
RelativeLoadBalancerStrategyJmx jmx = new RelativeLoadBalancerStrategyJmx(strategy);
assertEquals(jmx.getLatencyStandardDeviation(), 0.0);
assertEquals(jmx.getLatencyMeanAbsoluteDeviation(), 0.0);
assertEquals(jmx.getAboveAverageLatencyStandardDeviation(), 0.0);
assertEquals(jmx.getMaxLatencyRelativeFactor(), 0.0);
assertEquals(jmx.getNthPercentileLatencyRelativeFactor(0.95), 0.0);
assertEquals(jmx.getTotalPointsInHashRing(), 0);
assertEquals(jmx.getUnhealthyHostsCount(), 0);
assertEquals(jmx.getQuarantineHostsCount(), 0);
}
Aggregations