use of com.linkedin.darkcluster.impl.RelativeTrafficMultiplierDarkClusterStrategy in project rest.li by linkedin.
the class TestDarkClusterStrategyFactory method testRemoveDarkClusters.
@Test
public void testRemoveDarkClusters() {
DarkClusterConfig darkClusterConfig1 = createRelativeTrafficMultiplierConfig(0.5f);
DarkClusterConfig darkClusterConfig2 = createRelativeTrafficMultiplierConfig(0.1f);
_clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig1);
_clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME2, darkClusterConfig2);
// now trigger a refresh on the source cluster.
_clusterInfoProvider.notifyListenersClusterAdded(SOURCE_CLUSTER_NAME);
DarkClusterStrategy strategy = _strategyFactory.get(DARK_CLUSTER_NAME);
Assert.assertTrue(strategy instanceof RelativeTrafficMultiplierDarkClusterStrategy);
Assert.assertEquals(((RelativeTrafficMultiplierDarkClusterStrategy) strategy).getMultiplier(), 0.5f, "expected 0.5f multiplier");
DarkClusterStrategy strategy2 = _strategyFactory.get(DARK_CLUSTER_NAME2);
Assert.assertTrue(strategy2 instanceof RelativeTrafficMultiplierDarkClusterStrategy);
Assert.assertEquals(((RelativeTrafficMultiplierDarkClusterStrategy) strategy2).getMultiplier(), 0.1f, "expected 0.1f multiplier");
// update the clusterInfoProvider, and refresh the strategyMap
_clusterInfoProvider.removeDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME2);
_clusterInfoProvider.notifyListenersClusterAdded(SOURCE_CLUSTER_NAME);
DarkClusterStrategy strategy3 = _strategyFactory.get(DARK_CLUSTER_NAME);
Assert.assertTrue(strategy3 instanceof RelativeTrafficMultiplierDarkClusterStrategy);
// there should be no strategy entry for DARK_CLUSTER_NAME2, so it should return the NO_OP strategy
DarkClusterStrategy strategy4 = _strategyFactory.get(DARK_CLUSTER_NAME2);
Assert.assertSame(strategy4, NO_OP_DARK_CLUSTER_STRATEGY);
}
use of com.linkedin.darkcluster.impl.RelativeTrafficMultiplierDarkClusterStrategy in project rest.li by linkedin.
the class TestDarkClusterStrategyFactory method testUpdateStrategyDarkClusterChange.
@Test
public void testUpdateStrategyDarkClusterChange() {
DarkClusterConfig darkClusterConfig1 = createRelativeTrafficMultiplierConfig(0.5f);
DarkClusterConfig darkClusterConfig2 = createRelativeTrafficMultiplierConfig(0.1f);
_clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig1);
_clusterInfoProvider.notifyListenersClusterAdded(SOURCE_CLUSTER_NAME);
DarkClusterStrategy strategy = _strategyFactory.get(DARK_CLUSTER_NAME);
Assert.assertTrue(strategy instanceof RelativeTrafficMultiplierDarkClusterStrategy);
Assert.assertEquals(((RelativeTrafficMultiplierDarkClusterStrategy) strategy).getMultiplier(), 0.5f, "expected 0.5f multiplier");
// update the strategy.
_clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig2);
// now trigger a refresh on the dark cluster. Note that darkClusterConfig1 is ignored since there should already be an entry for this
// dark cluster, and we should get the strategy associated with darkClusterConfig2 back.
_clusterInfoProvider.notifyListenersClusterAdded(SOURCE_CLUSTER_NAME);
DarkClusterStrategy strategy3 = _strategyFactory.get(DARK_CLUSTER_NAME);
Assert.assertTrue(strategy3 instanceof RelativeTrafficMultiplierDarkClusterStrategy);
Assert.assertEquals(((RelativeTrafficMultiplierDarkClusterStrategy) strategy3).getMultiplier(), 0.1f, "expected 0.1f multiplier");
// if someone has a handle to old strategies, those should still be usable.
RestRequest dummyRestRequest = new RestRequestBuilder(URI.create("foo")).build();
strategy.handleRequest(dummyRestRequest, dummyRestRequest, new RequestContext());
}
use of com.linkedin.darkcluster.impl.RelativeTrafficMultiplierDarkClusterStrategy in project rest.li by linkedin.
the class TestDarkClusterStrategyFactory method testStrategyFallThru.
@Test
public void testStrategyFallThru() {
DarkClusterConfig darkClusterConfig1 = createRelativeTrafficMultiplierConfig(0.5f);
DarkClusterStrategyNameArray darkClusterStrategyList = new DarkClusterStrategyNameArray();
darkClusterStrategyList.addAll(Arrays.asList(CONSTANT_QPS, RELATIVE_TRAFFIC));
darkClusterConfig1.setDarkClusterStrategyPrioritizedList(darkClusterStrategyList);
_clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig1);
_clusterInfoProvider.notifyListenersClusterAdded(SOURCE_CLUSTER_NAME);
DarkClusterStrategy strategy = _strategyFactory.get(DARK_CLUSTER_NAME);
// test that we didn't find a strategy corresponding to Constant QPS and fell through to Relative traffic
Assert.assertTrue(strategy instanceof RelativeTrafficMultiplierDarkClusterStrategy);
Assert.assertEquals(((RelativeTrafficMultiplierDarkClusterStrategy) strategy).getMultiplier(), 0.5f, "expected 0.5f multiplier");
}
use of com.linkedin.darkcluster.impl.RelativeTrafficMultiplierDarkClusterStrategy in project rest.li by linkedin.
the class TestDarkClusterStrategyFactory method testStrategyPopulatedWithoutExplicitUpdate.
@Test
public void testStrategyPopulatedWithoutExplicitUpdate() {
DarkClusterStrategy strategy = _strategyFactory.get(PREEXISTING_DARK_CLUSTER_NAME);
Assert.assertTrue(strategy instanceof RelativeTrafficMultiplierDarkClusterStrategy);
Assert.assertEquals(((RelativeTrafficMultiplierDarkClusterStrategy) strategy).getMultiplier(), 0.5f, "expected 0.5f multiplier");
}
use of com.linkedin.darkcluster.impl.RelativeTrafficMultiplierDarkClusterStrategy in project rest.li by linkedin.
the class TestDarkClusterStrategyFactory method testChangingStrategiesAfterStoppingListener.
@Test
public void testChangingStrategiesAfterStoppingListener() {
DarkClusterConfig darkClusterConfig1 = createRelativeTrafficMultiplierConfig(0.5f);
DarkClusterConfig darkClusterConfig2 = createRelativeTrafficMultiplierConfig(0.1f);
_clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig1);
_clusterInfoProvider.notifyListenersClusterAdded(SOURCE_CLUSTER_NAME);
DarkClusterStrategy strategy = _strategyFactory.get(DARK_CLUSTER_NAME);
Assert.assertTrue(strategy instanceof RelativeTrafficMultiplierDarkClusterStrategy);
Assert.assertEquals(((RelativeTrafficMultiplierDarkClusterStrategy) strategy).getMultiplier(), 0.5f, "expected 0.5f multiplier");
_strategyFactory.shutdown();
// update the strategy.
_clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig2);
_clusterInfoProvider.notifyListenersClusterAdded(SOURCE_CLUSTER_NAME);
// Nothing should have been changed, since we shutdown down the listener
DarkClusterStrategy strategy2 = _strategyFactory.get(DARK_CLUSTER_NAME);
Assert.assertTrue(strategy2 instanceof RelativeTrafficMultiplierDarkClusterStrategy);
Assert.assertEquals(((RelativeTrafficMultiplierDarkClusterStrategy) strategy2).getMultiplier(), 0.5f, "expected 0.5f multiplier");
}
Aggregations