Search in sources :

Example 1 with DarkRequestHeaderGenerator

use of com.linkedin.darkcluster.api.DarkRequestHeaderGenerator in project rest.li by linkedin.

the class TestDarkClusterManager method testWithDarkHeaders.

@Test
public void testWithDarkHeaders() {
    MockClusterInfoProvider clusterInfoProvider = new MockClusterInfoProvider();
    Facilities facilities = new MockFacilities(clusterInfoProvider);
    // This configuration will choose the RelativeTrafficMultiplierDarkClusterStrategy
    DarkClusterConfig darkClusterConfig = createRelativeTrafficMultiplierConfig(1.0f);
    clusterInfoProvider.addDarkClusterConfig(SOURCE_CLUSTER_NAME, DARK_CLUSTER_NAME, darkClusterConfig);
    DarkClusterStrategyFactory mockStrategyFactory = Mockito.mock(DarkClusterStrategyFactory.class);
    DarkClusterStrategy mockDarkStrategy = Mockito.mock(DarkClusterStrategy.class);
    DarkRequestHeaderGenerator darkRequestHeaderGenerator = Mockito.mock(DarkRequestHeaderGenerator.class);
    Mockito.when(mockStrategyFactory.get(DARK_CLUSTER_NAME)).thenReturn(mockDarkStrategy);
    Mockito.when(darkRequestHeaderGenerator.get(DARK_CLUSTER_NAME)).thenReturn(Optional.of(new DarkRequestHeaderGenerator.HeaderNameValuePair("header", "value")));
    RestRequest restRequest = new RestRequestBuilder(URI.create("/abc")).setMethod(METHOD_SAFE).build();
    RestRequest darkRequest = new RestRequestBuilder(URI.create("d2://" + DARK_CLUSTER_NAME + "/abc")).setMethod(METHOD_SAFE).setHeader("header", "value").build();
    RequestContext requestContext = new RequestContext();
    Mockito.when(mockDarkStrategy.handleRequest(restRequest, darkRequest, new RequestContext(requestContext))).thenReturn(true);
    DarkClusterManager darkClusterManager = new DarkClusterManagerImpl(SOURCE_CLUSTER_NAME, facilities, mockStrategyFactory, null, null, new DoNothingNotifier(), null, Collections.singletonList(darkRequestHeaderGenerator));
    boolean status = darkClusterManager.handleDarkRequest(restRequest, requestContext);
    Assert.assertTrue(status);
}
Also used : DarkClusterStrategyFactory(com.linkedin.darkcluster.api.DarkClusterStrategyFactory) DarkClusterStrategy(com.linkedin.darkcluster.api.DarkClusterStrategy) NoOpDarkClusterStrategy(com.linkedin.darkcluster.api.NoOpDarkClusterStrategy) Facilities(com.linkedin.d2.balancer.Facilities) DarkRequestHeaderGenerator(com.linkedin.darkcluster.api.DarkRequestHeaderGenerator) RestRequest(com.linkedin.r2.message.rest.RestRequest) 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 DarkClusterStrategy (com.linkedin.darkcluster.api.DarkClusterStrategy)1 DarkClusterStrategyFactory (com.linkedin.darkcluster.api.DarkClusterStrategyFactory)1 DarkRequestHeaderGenerator (com.linkedin.darkcluster.api.DarkRequestHeaderGenerator)1 NoOpDarkClusterStrategy (com.linkedin.darkcluster.api.NoOpDarkClusterStrategy)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