Search in sources :

Example 1 with DarkGateKeeper

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");
}
Also used : Facilities(com.linkedin.d2.balancer.Facilities) RestRequest(com.linkedin.r2.message.rest.RestRequest) DarkGateKeeper(com.linkedin.darkcluster.api.DarkGateKeeper) DarkClusterConfig(com.linkedin.d2.DarkClusterConfig) DarkClusterManagerImpl(com.linkedin.darkcluster.impl.DarkClusterManagerImpl) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) DarkClusterManager(com.linkedin.darkcluster.api.DarkClusterManager) Test(org.testng.annotations.Test)

Aggregations

DarkClusterConfig (com.linkedin.d2.DarkClusterConfig)1 Facilities (com.linkedin.d2.balancer.Facilities)1 DarkClusterManager (com.linkedin.darkcluster.api.DarkClusterManager)1 DarkGateKeeper (com.linkedin.darkcluster.api.DarkGateKeeper)1 DarkClusterManagerImpl (com.linkedin.darkcluster.impl.DarkClusterManagerImpl)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 Test (org.testng.annotations.Test)1