use of com.linkedin.d2.balancer.simple.LoadBalancerSimulator in project rest.li by linkedin.
the class SimpleLoadBalancerDelayTest method loadBalancerQuarantineReQuarantineTest.
/**
* Client is quarantined again after evicted, with longer backoff time
* @throws Exception
*/
@Test(groups = { "small", "back-end" })
public void loadBalancerQuarantineReQuarantineTest() throws Exception {
String uri1 = "test.qa1.com:1234";
String uri2 = "test.qa2.com:2345";
List<String> uris = Arrays.asList(uri1, uri2);
// Construct the delay patterns: for each URI there is a list of delays for each interval
Map<String, List<Long>> delayMaps = new HashMap<>();
delayMaps.put("test.qa1.com:1234", Arrays.asList(80l, 3000l, 3000l, 3000l, 3000l, 3000l, 90l, 3150l, 3100l, 3800l, 3150l, 90l, 80l, 90l, 60l, 65l, 80l, 20l));
delayMaps.put("test.qa2.com:2345", Arrays.asList(90l, 90l, 60l, 90l, 50l, 80l, 60l, 90l, 90l, 90l, 60l, 90l, 60l, 65l, 180l, 90l, 120l, 60l));
LoadBalancerSimulator.TimedValueGenerator<String, Long> delayGenerator = new DelayValueGenerator<>(delayMaps, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
// Construct the QPS generator
LoadBalancerSimulator.QPSGenerator qpsGenerator = new ConstantQPSGenerator(1000);
// Create the simulator
LoadBalancerSimulator loadBalancerSimulator = LoadBalancerSimulationBuilder.build("cluster-1", "foo", uris, lbStrategyPropertiesWithQuarantine(), null, null, delayGenerator, qpsGenerator);
URI expectedUri1 = LoadBalancerSimulationBuilder.getExpectedUri("test.qa1.com:1234", "foo");
// Start the simulation
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
printStates(loadBalancerSimulator);
// the points for uri1 should be 100
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2), 100);
// wait for 2 intervals due to call dropping involved
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
// the points for uri1 should be 60
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 60);
// continue the simulation
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
// the points for uri1 should be 0 as it is now in quarantine
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 0);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2), 100);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 0);
// Evicted from quarantine finally. The point number should be none zero
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1) > 0);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
// uri1 should be quarantined again
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 0);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 3);
printStates(loadBalancerSimulator);
// uri1 should be evicted again
assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1) > 0);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 4);
printStates(loadBalancerSimulator);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
_log.info(loadBalancerSimulator.getClockedExecutor().toString());
// Done. Shutdown the simulation
loadBalancerSimulator.shutdown();
}
use of com.linkedin.d2.balancer.simple.LoadBalancerSimulator in project rest.li by linkedin.
the class SimpleLoadBalancerDelayTest method testLoadBalancerWithFastRecoveryAndSlowstartWithDegrading.
@Test(groups = { "small", "back-end" })
public void testLoadBalancerWithFastRecoveryAndSlowstartWithDegrading() throws Exception {
// Generate service, cluster and uri properties for d2
URI uri1 = URI.create("http://test.qa1.com:1234");
URI uri2 = URI.create("http://test.qa2.com:2345");
String clusterName = "cluster-2";
Map<Integer, PartitionData> partitionData = new HashMap<>(1);
partitionData.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
Map<URI, Map<Integer, PartitionData>> uriData = new HashMap<>(1);
uriData.put(uri1, partitionData);
ClusterProperties clusterProperties = new ClusterProperties(clusterName);
List<String> prioritizedSchemes = Collections.singletonList("http");
// set initial drop rate and slow start threshold
Map<String, String> degraderProperties = DegraderLoadBalancerTest.degraderDefaultConfig();
degraderProperties.put(PropertyKeys.DEGRADER_INITIAL_DROP_RATE, "0.99");
degraderProperties.put(PropertyKeys.DEGRADER_SLOW_START_THRESHOLD, "0.1");
degraderProperties.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, "1");
degraderProperties.put(PropertyKeys.DEGRADER_DOWN_STEP, "0.3");
// constant delay generator
Map<String, List<Long>> delayMaps = new HashMap<>();
delayMaps.put("test.qa1.com:1234", Arrays.asList(80L, 80L, 60L, 80L, 50L, 80L, 80L, 80L, 60L, 80L, 60L, 80L, 80L, 80L, 60L, 80L, 50L, 60L, 80L, 60L, 80L, 80L, 80L, 60L, 80L, 60L, 80L, 80L, 60L, 80L, 50L, 80L, 80L, 80L, 60L, 80L, 60L, 80L, 80L, 60L, 80L, 50L, 80L, 80L, 80L, 60L, 80L, 60L));
delayMaps.put("test.qa2.com:2345", Arrays.asList(80L, 80L, 60L, 80L, 50L, 80L, 80L, 80L, 60L, 80L, 60L, 80L, 80L, 80L, 60L, 80L, 50L, 60L, 80L, 60L, 80L, 80L, 3080L, 3060L, 89L, 60L, 3080L, 3080L, 3000L, 3000L, 3000L, 3000L, 3080L, 4060L, 3080L, 4080L, 4060L, 80L, 80L, 60L, 60L, 60L));
LoadBalancerSimulator.TimedValueGenerator<String, Long> delayGenerator = new DelayValueGenerator<>(delayMaps, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
LoadBalancerSimulator.QPSGenerator qpsGenerator = new QPSValueGenerator(Arrays.asList(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1000, 1000, 1000));
Map<String, Object> transportClientProperties = Collections.singletonMap("DelayGenerator", delayGenerator);
ServiceProperties serviceProperties = new ServiceProperties("foo", clusterName, "/foo", Arrays.asList("degraderV3"), lbStrategyPropertiesWithSlowstart(), transportClientProperties, degraderProperties, prioritizedSchemes, null);
UriProperties uriProperties = new UriProperties(clusterName, uriData);
// pass all the info to the simulator
LoadBalancerSimulator loadBalancerSimulator = new LoadBalancerSimulator(serviceProperties, clusterProperties, uriProperties, delayGenerator, qpsGenerator, null);
// Start the simulation: wait for uri to its full points
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 5);
assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1) >= 4);
// _log.info("Points is " + loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1));
printStates(loadBalancerSimulator);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 5);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
printStates(loadBalancerSimulator);
// Adding uri2
uriData.put(uri2, partitionData);
uriProperties = new UriProperties(clusterName, uriData);
loadBalancerSimulator.updateUriProperties(uriProperties);
// no traffic to uri2, even though the points are increasing
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 10);
assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2) >= 8);
printStates(loadBalancerSimulator);
// Got traffic, computedDrapRate recovered.
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
// degrading again with high latency: kicked out from recoveryMap
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2) < 32);
printStates(loadBalancerSimulator);
}
use of com.linkedin.d2.balancer.simple.LoadBalancerSimulator in project rest.li by linkedin.
the class SimpleLoadBalancerDelayTest method testLoadBalancerWithFastRecoveryAndSlowstart.
@Test(groups = { "small", "back-end" })
public void testLoadBalancerWithFastRecoveryAndSlowstart() throws Exception {
// Generate service, cluster and uri properties for d2
URI uri1 = URI.create("http://test.qa1.com:1234");
URI uri2 = URI.create("http://test.qa2.com:2345");
String clusterName = "cluster-2";
Map<Integer, PartitionData> partitionData = new HashMap<>(1);
partitionData.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
Map<URI, Map<Integer, PartitionData>> uriData = new HashMap<>(1);
uriData.put(uri1, partitionData);
ClusterProperties clusterProperties = new ClusterProperties(clusterName);
List<String> prioritizedSchemes = Collections.singletonList("http");
// set initial drop rate and slow start threshold
Map<String, String> degraderProperties = DegraderLoadBalancerTest.degraderDefaultConfig();
degraderProperties.put(PropertyKeys.DEGRADER_INITIAL_DROP_RATE, "0.99");
degraderProperties.put(PropertyKeys.DEGRADER_SLOW_START_THRESHOLD, "0.1");
degraderProperties.put(PropertyKeys.DEGRADER_MIN_CALL_COUNT, "1");
degraderProperties.put(PropertyKeys.DEGRADER_DOWN_STEP, "0.3");
// constant delay generator
LoadBalancerSimulator.TimedValueGenerator<String, Long> delayGenerator = (uri, time, unit) -> 100l;
LoadBalancerSimulator.QPSGenerator qpsGenerator = new QPSValueGenerator(Arrays.asList(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20, 1, 1, 1, 1, 1, 1, 1, 1, 10));
Map<String, Object> transportClientProperties = Collections.singletonMap("DelayGenerator", delayGenerator);
ServiceProperties serviceProperties = new ServiceProperties("foo", clusterName, "/foo", Arrays.asList("degraderV3"), lbStrategyPropertiesWithSlowstart(), transportClientProperties, degraderProperties, prioritizedSchemes, null);
UriProperties uriProperties = new UriProperties(clusterName, uriData);
// pass all the info to the simulator
LoadBalancerSimulator loadBalancerSimulator = new LoadBalancerSimulator(serviceProperties, clusterProperties, uriProperties, delayGenerator, qpsGenerator, null);
// Start the simulation: wait for uri to its full points
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 5);
assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1) >= 4);
// _log.info("Points is " + loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1));
printStates(loadBalancerSimulator);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 5);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
printStates(loadBalancerSimulator);
// Adding uri2
uriData.put(uri2, partitionData);
uriProperties = new UriProperties(clusterName, uriData);
loadBalancerSimulator.updateUriProperties(uriProperties);
// no traffic to uri2, even though the points are increasing
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 10);
assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2) >= 4);
printStates(loadBalancerSimulator);
// only one possible recovery, points increasing by recoveryMap
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 8);
assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2) >= 64);
printStates(loadBalancerSimulator);
// fully recovered
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 6);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2), 100);
printStates(loadBalancerSimulator);
}
use of com.linkedin.d2.balancer.simple.LoadBalancerSimulator in project rest.li by linkedin.
the class SimpleLoadBalancerDelayTest method loadBalancerQuarantineMixTest.
/**
* When quarantine is full, the rest of the clients should degrading just as no quarantine presents
* @throws Exception
*/
@Test(groups = { "small", "back-end" })
public void loadBalancerQuarantineMixTest() throws Exception {
String uri1 = "test.qa1.com:1234";
String uri2 = "test.qa2.com:2345";
String uri3 = "test.qa3.com:6789";
List<String> uris = Arrays.asList(uri1, uri2, uri3);
// Construct the delay patterns: for each URI there is a list of delays for each interval
Map<String, List<Long>> delayMaps = new HashMap<>();
delayMaps.put("test.qa1.com:1234", Arrays.asList(80l, 3000l, 3000l, 3000l, 3000l, 3090l, 3075l, 90l, 80l, 75l, 90l, 80l, 20l, 60l, 85l, 60l));
delayMaps.put("test.qa2.com:2345", Arrays.asList(90l, 90l, 75l, 90l, 50l, 80l, 90l, 90l, 75l, 90l, 75l, 90l, 50l, 60l, 20l, 80l, 60l, 20l));
delayMaps.put("test.qa3.com:6789", Arrays.asList(80l, 3000l, 3000l, 3000l, 3000l, 90l, 75l, 90l, 80l, 75l, 90l, 80l, 800l, 50l, 60l, 85l, 50l));
LoadBalancerSimulator.TimedValueGenerator<String, Long> delayGenerator = new DelayValueGenerator<>(delayMaps, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
// Construct the QPS generator
LoadBalancerSimulator.QPSGenerator qpsGenerator = new ConstantQPSGenerator(1000);
// Create the simulator
LoadBalancerSimulator loadBalancerSimulator = LoadBalancerSimulationBuilder.build("cluster-1", "foo", uris, lbStrategyPropertiesWithQuarantine(), null, null, delayGenerator, qpsGenerator);
URI expectedUri1 = LoadBalancerSimulationBuilder.getExpectedUri("test.qa1.com:1234", "foo");
// Start the simulation
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
printStates(loadBalancerSimulator);
// the points for uri1 should be 100
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2), 100);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri3), 100);
// wait for 2 intervals due to call dropping involved
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
// the points for uri1/uri3 should be 60
// Also if the loadbalancing strategy changed, the numbers could be lower
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 60);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri3), 60);
// continue the simulation
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
// the points for uri3 should be 0 as it is now in quarantine, uri1 should not be 0
assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1) > 0);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri3), 0);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
// uri1 points in minimal (1)
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 1);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
// uri 3 evicted, uri 1 in quarantine
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 0);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri3), 1);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 8);
printStates(loadBalancerSimulator);
// uri1/uri3 should fully recovered by now
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri3), 100);
_log.info(loadBalancerSimulator.getClockedExecutor().toString());
// Done. Shutdown the simulation
loadBalancerSimulator.shutdown();
}
use of com.linkedin.d2.balancer.simple.LoadBalancerSimulator in project rest.li by linkedin.
the class SimpleLoadBalancerDelayTest method loadBalancerQuarantineMaxNumTest.
/**
* Quarantine with CAP: no more client can be added when CAP reached
* @throws Exception
*/
@Test(groups = { "small", "back-end" })
public void loadBalancerQuarantineMaxNumTest() throws Exception {
String uri1 = "test.qa1.com:1234";
String uri2 = "test.qa2.com:2345";
String uri3 = "test.qa3.com:6789";
List<String> uris = Arrays.asList(uri1, uri2, uri3);
// Construct the delay patterns: for each URI there is a list of delays for each interval
Map<String, List<Long>> delayMaps = new HashMap<>();
delayMaps.put("test.qa1.com:1234", Arrays.asList(80l, 3000l, 3000l, 3000l, 3000l, 90l, 75l, 90l, 80l, 75l, 90l, 80l));
delayMaps.put("test.qa2.com:2345", Arrays.asList(90l, 90l, 75l, 90l, 50l, 80l, 90l, 90l, 75l, 90l, 75l, 90l));
delayMaps.put("test.qa3.com:6789", Arrays.asList(80l, 3000l, 3000l, 3000l, 3000l, 90l, 75l, 90l, 80l, 75l, 90l, 80l));
LoadBalancerSimulator.TimedValueGenerator<String, Long> delayGenerator = new DelayValueGenerator<>(delayMaps, DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
// Construct the QPS generator
LoadBalancerSimulator.QPSGenerator qpsGenerator = new ConstantQPSGenerator(1000);
// Create the simulator
LoadBalancerSimulator loadBalancerSimulator = LoadBalancerSimulationBuilder.build("cluster-1", "foo", uris, lbStrategyPropertiesWithQuarantine(), null, null, delayGenerator, qpsGenerator);
URI expectedUri1 = LoadBalancerSimulationBuilder.getExpectedUri("test.qa1.com:1234", "foo");
// Start the simulation
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS);
printStates(loadBalancerSimulator);
// the points for uri1 should be 100
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2), 100);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri3), 100);
// wait for 2 intervals due to call dropping involved
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
// the points for uri1/uri3 should be 60
// Also if the loadbalancing strategy changed, the numbers could be lower
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 60);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri3), 60);
// continue the simulation
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
// the points for uri3 should be 0 as it is now in quarantine, uri1 should not be 0
assertTrue(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1) > 0);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri3), 0);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 2);
printStates(loadBalancerSimulator);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri3), 0);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri2), 100);
loadBalancerSimulator.runWait(DegraderLoadBalancerStrategyConfig.DEFAULT_UPDATE_INTERVAL_MS * 9);
printStates(loadBalancerSimulator);
// uri1/uri3 should fully recovered by now
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri1), 100);
assertEquals(loadBalancerSimulator.getPoint("foo", DefaultPartitionAccessor.DEFAULT_PARTITION_ID, uri3), 100);
// the points for uri3 should be around 60, recovering
_log.info(loadBalancerSimulator.getClockedExecutor().toString());
// Done. Shutdown the simulation
loadBalancerSimulator.shutdown();
}
Aggregations