use of com.linkedin.d2.balancer.properties.PartitionData in project rest.li by linkedin.
the class ZooKeeperAnnouncer method setWeight.
public void setWeight(double weight) {
Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>(1);
partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(weight));
_partitionDataMap = Collections.unmodifiableMap(partitionDataMap);
}
use of com.linkedin.d2.balancer.properties.PartitionData in project rest.li by linkedin.
the class DegraderLoadBalancerTest method getClient.
public static TrackerClient getClient(URI uri, Clock clock) {
Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>(2);
partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1));
return new TrackerClient(uri, partitionDataMap, new TestLoadBalancerClient(uri), clock, null);
}
use of com.linkedin.d2.balancer.properties.PartitionData in project rest.li by linkedin.
the class RandomLoadBalancerTest method testRoundRobinBalancer.
@Test(groups = { "small", "back-end" })
public void testRoundRobinBalancer() throws InterruptedException, URISyntaxException {
RandomLoadBalancerStrategyFactory lbFactory = new RandomLoadBalancerStrategyFactory();
RandomLoadBalancerStrategy rrLoadBalancer = lbFactory.newLoadBalancer("unused", Collections.<String, Object>emptyMap(), null);
Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>(2);
partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
TrackerClient trackerClient1 = new TrackerClient(URI.create("http://www.google.com:567/foo/bar"), partitionDataMap, null);
TrackerClient trackerClient2 = new TrackerClient(URI.create("http://www.amazon.com:567/foo/bar"), partitionDataMap, null);
List<TrackerClient> trackerClients = new ArrayList<TrackerClient>();
trackerClients.add(trackerClient1);
trackerClients.add(trackerClient2);
// test balancer with two clients, both available
for (int i = 0; i < 100; ++i) {
assertNotNull(rrLoadBalancer.getTrackerClient(null, new RequestContext(), 0, DefaultPartitionAccessor.DEFAULT_PARTITION_ID, trackerClients));
}
}
use of com.linkedin.d2.balancer.properties.PartitionData in project rest.li by linkedin.
the class DegraderLoadBalancerTest method DegraderLoadBalancerQuarantineTest.
/**
* DegraderLoadBalancerQuarantineTest
*/
@Test(groups = { "small", "back-end" })
public void DegraderLoadBalancerQuarantineTest() {
DegraderLoadBalancerStrategyConfig config = new DegraderLoadBalancerStrategyConfig(1000);
Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>(2);
TestClock clock = new TestClock();
DegraderImpl.Config degraderConfig = DegraderConfigFactory.toDegraderConfig(Collections.emptyMap());
List<TrackerClient> trackerClients = createTrackerClient(3, clock, degraderConfig);
TrackerClientUpdater trackerClientUpdater = new TrackerClientUpdater(trackerClients.get(0), DEFAULT_PARTITION_ID);
DegraderLoadBalancerQuarantine quarantine = new DegraderLoadBalancerQuarantine(trackerClientUpdater, config, "abc0");
TransportHealthCheck healthCheck = (TransportHealthCheck) quarantine.getHealthCheckClient();
RestRequest restRequest = healthCheck.getRestRequest();
Assert.assertTrue(restRequest.getURI().equals(URI.create("http://test.linkedin.com:10010/abc0")));
Assert.assertTrue(restRequest.getMethod().equals("OPTIONS"));
DegraderLoadBalancerStrategyConfig config1 = new DegraderLoadBalancerStrategyConfig(1000, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_ONLY_AT_INTERVAL, 100, null, Collections.<String, Object>emptyMap(), DegraderLoadBalancerStrategyConfig.DEFAULT_CLOCK, DegraderLoadBalancerStrategyConfig.DEFAULT_INITIAL_RECOVERY_LEVEL, DegraderLoadBalancerStrategyConfig.DEFAULT_RAMP_FACTOR, DegraderLoadBalancerStrategyConfig.DEFAULT_HIGH_WATER_MARK, DegraderLoadBalancerStrategyConfig.DEFAULT_LOW_WATER_MARK, DegraderLoadBalancerStrategyConfig.DEFAULT_GLOBAL_STEP_UP, DegraderLoadBalancerStrategyConfig.DEFAULT_GLOBAL_STEP_DOWN, DegraderLoadBalancerStrategyConfig.DEFAULT_CLUSTER_MIN_CALL_COUNT_HIGH_WATER_MARK, DegraderLoadBalancerStrategyConfig.DEFAULT_CLUSTER_MIN_CALL_COUNT_LOW_WATER_MARK, DegraderLoadBalancerStrategyConfig.DEFAULT_HASHRING_POINT_CLEANUP_RATE, null, DegraderLoadBalancerStrategyConfig.DEFAULT_NUM_PROBES, null, DegraderLoadBalancerStrategyConfig.DEFAULT_QUARANTINE_MAXPERCENT, null, null, "GET", "/test/admin", DegraderLoadBalancerStrategyConfig.DEFAULT_QUARANTINE_LATENCY);
TrackerClientUpdater updater1 = new TrackerClientUpdater(trackerClients.get(1), DEFAULT_PARTITION_ID);
quarantine = new DegraderLoadBalancerQuarantine(updater1, config1, "abc0");
healthCheck = (TransportHealthCheck) quarantine.getHealthCheckClient();
restRequest = healthCheck.getRestRequest();
Assert.assertTrue(restRequest.getURI().equals(URI.create("http://test.linkedin.com:10010/test/admin")));
Assert.assertTrue(restRequest.getMethod().equals("GET"));
DegraderLoadBalancerStrategyConfig config2 = new DegraderLoadBalancerStrategyConfig(1000, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_ONLY_AT_INTERVAL, 100, null, Collections.<String, Object>emptyMap(), DegraderLoadBalancerStrategyConfig.DEFAULT_CLOCK, DegraderLoadBalancerStrategyConfig.DEFAULT_INITIAL_RECOVERY_LEVEL, DegraderLoadBalancerStrategyConfig.DEFAULT_RAMP_FACTOR, DegraderLoadBalancerStrategyConfig.DEFAULT_HIGH_WATER_MARK, DegraderLoadBalancerStrategyConfig.DEFAULT_LOW_WATER_MARK, DegraderLoadBalancerStrategyConfig.DEFAULT_GLOBAL_STEP_UP, DegraderLoadBalancerStrategyConfig.DEFAULT_GLOBAL_STEP_DOWN, DegraderLoadBalancerStrategyConfig.DEFAULT_CLUSTER_MIN_CALL_COUNT_HIGH_WATER_MARK, DegraderLoadBalancerStrategyConfig.DEFAULT_CLUSTER_MIN_CALL_COUNT_LOW_WATER_MARK, DegraderLoadBalancerStrategyConfig.DEFAULT_HASHRING_POINT_CLEANUP_RATE, null, DegraderLoadBalancerStrategyConfig.DEFAULT_NUM_PROBES, null, DegraderLoadBalancerStrategyConfig.DEFAULT_QUARANTINE_MAXPERCENT, null, null, "OPTIONS", null, DegraderLoadBalancerStrategyConfig.DEFAULT_QUARANTINE_LATENCY);
TrackerClientUpdater updater2 = new TrackerClientUpdater(trackerClients.get(2), DEFAULT_PARTITION_ID);
quarantine = new DegraderLoadBalancerQuarantine(updater2, config2, "abc0");
healthCheck = (TransportHealthCheck) quarantine.getHealthCheckClient();
restRequest = healthCheck.getRestRequest();
Assert.assertTrue(restRequest.getURI().equals(URI.create("http://test.linkedin.com:10010/abc2")));
Assert.assertTrue(restRequest.getMethod().equals("OPTIONS"));
}
use of com.linkedin.d2.balancer.properties.PartitionData in project rest.li by linkedin.
the class DegraderLoadBalancerTest method testOneTrackerClientForPartition.
@Test(groups = { "small", "back-end" })
public void testOneTrackerClientForPartition() throws URISyntaxException {
DegraderLoadBalancerStrategyV3 strategy = getStrategy();
List<TrackerClient> clients = new ArrayList<TrackerClient>();
URI uri1 = URI.create("http://test.linkedin.com:3242/fdsaf");
Map<Integer, PartitionData> weightMap = new HashMap<Integer, PartitionData>();
weightMap.put(0, new PartitionData(1d));
TrackerClient client = new TrackerClient(uri1, weightMap, new TestLoadBalancerClient(uri1), new TestClock(), null);
clients.add(client);
// should always get the only client in the list
for (int i = 0; i < 1000; ++i) {
assertEquals(strategy.getTrackerClient(null, new RequestContext(), 0, 0, clients), client);
}
}
Aggregations