use of com.linkedin.util.degrader.ErrorType in project rest.li by linkedin.
the class TrackerClientMockHelper method mockTrackerClients.
/**
* Mock a list of {@link TrackerClient} for testing
*
* @param numTrackerClients The number of {@link TrackerClient} to be mocked
* @param callCountList The call count that each host receives
* @param outstandingCallCountList The outstanding call count that each host receives
* @param latencyList The latency of each host
* @param outstandingLatencyList The outstanding latency of each host
* @param errorCountList The error count of each host
* @return A list of mocked {@link TrackerClient}
*/
public static List<TrackerClient> mockTrackerClients(int numTrackerClients, List<Integer> callCountList, List<Integer> outstandingCallCountList, List<Long> latencyList, List<Long> outstandingLatencyList, List<Integer> errorCountList, boolean doNotSlowStart, List<Boolean> doNotLoadBalance) {
List<TrackerClient> trackerClients = new ArrayList<>();
for (int index = 0; index < numTrackerClients; index++) {
URI uri = URI.create("URI/" + index);
TrackerClient trackerClient = Mockito.mock(TrackerClient.class);
CallTracker callTracker = Mockito.mock(CallTracker.class);
LongStats longStats = new LongStats(callCountList.get(index), latencyList.get(index), 0, 0, 0, 0, 0, 0, 0);
Map<ErrorType, Integer> errorTypeCounts = new HashMap<>();
errorTypeCounts.put(ErrorType.SERVER_ERROR, errorCountList.get(index));
CallTrackerImpl.CallTrackerStats callStats = new CallTrackerImpl.CallTrackerStats(RelativeLoadBalancerStrategyFactory.DEFAULT_UPDATE_INTERVAL_MS, 0, RelativeLoadBalancerStrategyFactory.DEFAULT_UPDATE_INTERVAL_MS, callCountList.get(index), 0, 0, errorCountList.get(index), errorCountList.get(index), 1, RelativeLoadBalancerStrategyFactory.DEFAULT_UPDATE_INTERVAL_MS - outstandingLatencyList.get(index), outstandingCallCountList.get(index), longStats, errorTypeCounts, errorTypeCounts);
Mockito.when(trackerClient.getCallTracker()).thenReturn(callTracker);
Mockito.when(callTracker.getCallStats()).thenReturn(callStats);
Mockito.when(trackerClient.getUri()).thenReturn(uri);
Mockito.when(trackerClient.getPartitionWeight(anyInt())).thenReturn(1.0);
Mockito.when(trackerClient.getSubsetWeight(anyInt())).thenReturn(1.0);
Mockito.when(trackerClient.doNotSlowStart()).thenReturn(doNotSlowStart);
Mockito.when(trackerClient.doNotLoadBalance()).thenReturn(doNotLoadBalance.get(index));
trackerClients.add(trackerClient);
}
return trackerClients;
}
Aggregations