Search in sources :

Example 26 with DarkClusterConfig

use of com.linkedin.d2.DarkClusterConfig in project rest.li by linkedin.

the class DarkClustersConverterTest method testEntriesInClusterConfig.

@Test
public void testEntriesInClusterConfig() {
    DarkClusterConfigMap configMap = new DarkClusterConfigMap();
    DarkClusterStrategyNameArray multiplierStrategyTypeArray = new DarkClusterStrategyNameArray();
    multiplierStrategyTypeArray.add(DarkClusterStrategyName.RELATIVE_TRAFFIC.RELATIVE_TRAFFIC);
    D2TransportClientProperties transportClientProperties = new D2TransportClientProperties().setRequestTimeout(1000);
    DarkClusterConfig config = new DarkClusterConfig().setDarkClusterStrategyPrioritizedList(multiplierStrategyTypeArray).setTransportClientProperties(transportClientProperties);
    configMap.put(DARK_CLUSTER_KEY, config);
    DarkClusterConfigMap expectedConfigMap = new DarkClusterConfigMap();
    DarkClusterConfig expectedConfig = new DarkClusterConfig(config.data());
    expectedConfig.setMultiplier(0);
    expectedConfig.setDispatcherOutboundTargetRate(0);
    expectedConfig.setDispatcherMaxRequestsToBuffer(1);
    expectedConfig.setDispatcherBufferedRequestExpiryInSeconds(1);
    expectedConfigMap.put(DARK_CLUSTER_KEY, expectedConfig);
    DarkClusterConfigMap resultConfigMap = DarkClustersConverter.toConfig(DarkClustersConverter.toProperties(configMap));
    Assert.assertEquals(resultConfigMap, expectedConfigMap);
    // verify values are converted properly.
    DarkClusterConfig darkClusterConfig = resultConfigMap.get(DARK_CLUSTER_KEY);
    Assert.assertEquals(darkClusterConfig.getMultiplier(), DARK_CLUSTER_DEFAULT_MULTIPLIER, "unexpected multiplier");
    Assert.assertEquals(darkClusterConfig.getDarkClusterStrategyPrioritizedList().size(), 1, "there should be one strategy");
    Assert.assertEquals(darkClusterConfig.getDarkClusterStrategyPrioritizedList().get(0), DarkClusterStrategyName.RELATIVE_TRAFFIC, "expected RELATIVE_TRAFFIC strategy");
    Assert.assertTrue(darkClusterConfig.hasTransportClientProperties());
    D2TransportClientProperties returnedTransportClientProperties = darkClusterConfig.getTransportClientProperties();
    Assert.assertNotNull(returnedTransportClientProperties);
    Assert.assertTrue(returnedTransportClientProperties.hasRequestTimeout());
    Assert.assertEquals(Objects.requireNonNull(returnedTransportClientProperties.getRequestTimeout()).longValue(), 1000, "expected 1000 request Timeout");
}
Also used : DarkClusterConfigMap(com.linkedin.d2.DarkClusterConfigMap) DarkClusterStrategyNameArray(com.linkedin.d2.DarkClusterStrategyNameArray) DarkClusterConfig(com.linkedin.d2.DarkClusterConfig) D2TransportClientProperties(com.linkedin.d2.D2TransportClientProperties) Test(org.testng.annotations.Test)

Aggregations

DarkClusterConfig (com.linkedin.d2.DarkClusterConfig)23 Test (org.testng.annotations.Test)20 DarkClusterConfigMap (com.linkedin.d2.DarkClusterConfigMap)10 NoOpDarkClusterStrategy (com.linkedin.darkcluster.api.NoOpDarkClusterStrategy)10 DarkClusterStrategyNameArray (com.linkedin.d2.DarkClusterStrategyNameArray)9 DarkClusterStrategy (com.linkedin.darkcluster.api.DarkClusterStrategy)9 RelativeTrafficMultiplierDarkClusterStrategy (com.linkedin.darkcluster.impl.RelativeTrafficMultiplierDarkClusterStrategy)8 RequestContext (com.linkedin.r2.message.RequestContext)5 RestRequest (com.linkedin.r2.message.rest.RestRequest)5 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)5 Facilities (com.linkedin.d2.balancer.Facilities)4 DarkClusterManager (com.linkedin.darkcluster.api.DarkClusterManager)4 DarkClusterManagerImpl (com.linkedin.darkcluster.impl.DarkClusterManagerImpl)4 D2TransportClientProperties (com.linkedin.d2.D2TransportClientProperties)2 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)2 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)2 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)2 MockStore (com.linkedin.d2.discovery.stores.mock.MockStore)2 DarkClusterStrategyFactoryImpl (com.linkedin.darkcluster.impl.DarkClusterStrategyFactoryImpl)2 ConstantQpsRateLimiter (com.linkedin.r2.transport.http.client.ConstantQpsRateLimiter)2