use of com.linkedin.darkcluster.impl.IdenticalTrafficMultiplierDarkClusterStrategy in project rest.li by linkedin.
the class TestIdenticalTrafficMultiplierDarkClusterStrategy method testHandleRequest.
@Test(dataProvider = "getDarkClusters")
public void testHandleRequest(List<DarkClusterMetadata> darkClusterMetadataList, float expectedRandomNumber) {
String sourceClusterName = "sourceCluster";
DarkClusterDispatcher darkClusterDispatcher = new DefaultDarkClusterDispatcher(new MockClient(false));
Random random = Mockito.mock(Random.class);
Mockito.when(random.nextFloat()).thenReturn(expectedRandomNumber);
List<IdenticalTrafficMultiplierDarkClusterStrategy> strategies = darkClusterMetadataList.stream().map(darkClusterMetadata -> {
BaseDarkClusterDispatcherImpl baseDispatcher = new BaseDarkClusterDispatcherImpl(darkClusterMetadata._darkClusterName, darkClusterDispatcher, new DoNothingNotifier(), new CountingVerifierManager());
MockClusterInfoProvider mockClusterInfoProvider = new MockClusterInfoProvider();
mockClusterInfoProvider.putHttpsClusterCount(darkClusterMetadata._darkClusterName, 1);
mockClusterInfoProvider.putHttpsClusterCount(sourceClusterName, 1);
return new IdenticalTrafficMultiplierDarkClusterStrategy(sourceClusterName, darkClusterMetadata._darkClusterName, darkClusterMetadata._multiplier, baseDispatcher, new DoNothingNotifier(), mockClusterInfoProvider, random);
}).collect(Collectors.toList());
RestRequest dummyRestRequest = new RestRequestBuilder(URI.create("foo")).build();
RestRequest dummyDarkRequest = new RestRequestBuilder(URI.create("darkfoo")).build();
RequestContext dummyRequestContext = new RequestContext();
IntStream.range(0, darkClusterMetadataList.size()).forEach(index -> {
DarkClusterMetadata darkClusterMetadata = darkClusterMetadataList.get(index);
DarkClusterStrategy strategy = strategies.get(index);
boolean darkRequestSent = strategy.handleRequest(dummyRestRequest, dummyDarkRequest, dummyRequestContext);
Assert.assertEquals(darkRequestSent, darkClusterMetadata._darkRequestSent);
});
Assert.assertEquals(dummyRequestContext.getLocalAttr("identicalTrafficMultiplier.randomNumber"), expectedRandomNumber);
Mockito.verify(random).nextFloat();
}
Aggregations