Search in sources :

Example 1 with ErrorType

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LongStats(com.linkedin.common.stats.LongStats) URI(java.net.URI) TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) ErrorType(com.linkedin.util.degrader.ErrorType) CallTrackerImpl(com.linkedin.util.degrader.CallTrackerImpl) CallTracker(com.linkedin.util.degrader.CallTracker)

Aggregations

LongStats (com.linkedin.common.stats.LongStats)1 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)1 CallTracker (com.linkedin.util.degrader.CallTracker)1 CallTrackerImpl (com.linkedin.util.degrader.CallTrackerImpl)1 ErrorType (com.linkedin.util.degrader.ErrorType)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1