use of com.linkedin.darkcluster.api.DarkGateKeeper in project rest.li by linkedin.
the class TestDarkClusterManager method testDarkGateKeeper.
@Test
public void testDarkGateKeeper() {
DarkGateKeeper darkGateKeeper = new DarkGateKeeper() {
@Override
public boolean shouldDispatchToDark(RestRequest request, RequestContext requestContext, String darkClusterName) {
return darkClusterName.equals(DARK_CLUSTER_NAME);
}
};
MockClusterInfoProvider clusterInfoProvider = new MockClusterInfoProvider();
Facilities facilities = new MockFacilities(clusterInfoProvider);
MockStrategyFactory strategyFactory = new MockStrategyFactory();
DarkClusterManager darkClusterManager = new DarkClusterManagerImpl(SOURCE_CLUSTER_NAME, facilities, strategyFactory, null, null, new DoNothingNotifier(), darkGateKeeper);
strategyFactory.start();
// This configuration will choose the RelativeTrafficMultiplierDarkClusterStrategy
DarkClusterConfig darkClusterConfig = createRelativeTrafficMultiplierConfig(1.0f);
clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME2, darkClusterConfig);
RestRequest restRequest1 = new RestRequestBuilder(URI.create("/white")).setMethod(METHOD_SAFE).build();
boolean whiteStatus = darkClusterManager.handleDarkRequest(restRequest1, new RequestContext());
RestRequest restRequest2 = new RestRequestBuilder(URI.create("/black")).setMethod(METHOD_SAFE).build();
boolean blackStatus = darkClusterManager.handleDarkRequest(restRequest2, new RequestContext());
Assert.assertFalse(whiteStatus, "white uri requests not as expected");
Assert.assertFalse(blackStatus, "black uri requests not as expected");
Assert.assertEquals(strategyFactory.strategyGetOrCreateCount, 0, "unexpected strategy GetOrCreateCount");
clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig);
boolean whiteStatus1 = darkClusterManager.handleDarkRequest(restRequest1, new RequestContext());
boolean blackStatus1 = darkClusterManager.handleDarkRequest(restRequest2, new RequestContext());
Assert.assertTrue(whiteStatus1, "white uri requests not as expected");
Assert.assertTrue(blackStatus1, "black uri requests not as expected");
Assert.assertEquals(strategyFactory.strategyGetOrCreateCount, 2, "unexpected strategy GetOrCreateCount");
}
Aggregations