Search in sources :

Example 1 with CallTrackerImpl

use of com.linkedin.util.degrader.CallTrackerImpl in project rest.li by linkedin.

the class ConsistentHashRingBenchmark method createCallTrackerMap.

private static Map<URI, CallTracker> createCallTrackerMap(URI mostWantedHost, int load) {
    Map<URI, CallTracker> callTrackerMap = new HashMap<>();
    CallTracker callTracker = new CallTrackerImpl(5000L);
    IntStream.range(0, load).forEach(e -> callTracker.startCall());
    callTrackerMap.put(mostWantedHost, callTracker);
    return callTrackerMap;
}
Also used : HashMap(java.util.HashMap) CallTrackerImpl(com.linkedin.util.degrader.CallTrackerImpl) URI(java.net.URI) CallTracker(com.linkedin.util.degrader.CallTracker)

Example 2 with CallTrackerImpl

use of com.linkedin.util.degrader.CallTrackerImpl in project rest.li by linkedin.

the class BoundedLoadConsistentHashTest method createCallTrackerMap.

private Map<URI, CallTracker> createCallTrackerMap(Map<URI, Integer> loadMap) {
    Map<URI, CallTracker> callTrackerMap = new HashMap<>();
    for (Map.Entry<URI, Integer> entry : loadMap.entrySet()) {
        CallTracker callTracker = new CallTrackerImpl(5000L);
        IntStream.range(0, entry.getValue()).forEach(e -> callTracker.startCall());
        callTrackerMap.put(entry.getKey(), callTracker);
    }
    return callTrackerMap;
}
Also used : HashMap(java.util.HashMap) CallTrackerImpl(com.linkedin.util.degrader.CallTrackerImpl) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) CallTracker(com.linkedin.util.degrader.CallTracker)

Example 3 with CallTrackerImpl

use of com.linkedin.util.degrader.CallTrackerImpl in project rest.li by linkedin.

the class TrackerClientMockHelper method mockTrackerClients.

/**
 * Mock a list of {@link TrackerClient} without call stats
 *
 * @param numTrackerClients The number of hosts to be mocked
 * @return A list of mocked {@link TrackerClient}
 */
public static List<TrackerClient> mockTrackerClients(int numTrackerClients) {
    List<TrackerClient> trackerClients = new ArrayList<>();
    for (int index = 0; index < numTrackerClients; index++) {
        URI uri = URI.create("URI/" + index);
        TrackerClient trackerClient = Mockito.mock(TrackerClient.class);
        Mockito.when(trackerClient.getCallTracker()).thenReturn(new CallTrackerImpl(RelativeLoadBalancerStrategyFactory.DEFAULT_UPDATE_INTERVAL_MS));
        Mockito.when(trackerClient.getUri()).thenReturn(uri);
        Mockito.when(trackerClient.getPartitionWeight(anyInt())).thenReturn(1.0);
        Mockito.when(trackerClient.getSubsetWeight(anyInt())).thenReturn(1.0);
        trackerClients.add(trackerClient);
    }
    return trackerClients;
}
Also used : TrackerClient(com.linkedin.d2.balancer.clients.TrackerClient) CallTrackerImpl(com.linkedin.util.degrader.CallTrackerImpl) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 4 with CallTrackerImpl

use of com.linkedin.util.degrader.CallTrackerImpl in project rest.li by linkedin.

the class ConsistentHashRingSimulator method initState.

private ConsistentHashRingState initState(RingFactory<String> ringFactory, Map<String, Integer> pointsMap) {
    Map<String, CallTracker> callTrackerMap = new ConcurrentHashMap<>();
    Map<String, List<Integer>> latencyMap = new ConcurrentHashMap<>();
    for (String server : pointsMap.keySet()) {
        CallTracker callTracker = new CallTrackerImpl(5000L);
        callTrackerMap.put(server, callTracker);
        latencyMap.put(server, new ArrayList<>());
    }
    Ring<String> ring = ringFactory.createRing(pointsMap, callTrackerMap);
    return new ConsistentHashRingState(ring, callTrackerMap, latencyMap);
}
Also used : CallTrackerImpl(com.linkedin.util.degrader.CallTrackerImpl) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CallTracker(com.linkedin.util.degrader.CallTracker)

Aggregations

CallTrackerImpl (com.linkedin.util.degrader.CallTrackerImpl)4 CallTracker (com.linkedin.util.degrader.CallTracker)3 URI (java.net.URI)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TrackerClient (com.linkedin.d2.balancer.clients.TrackerClient)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1