use of com.linkedin.d2.DarkClusterConfigMap in project rest.li by linkedin.
the class DarkClustersConverter method toProperties.
@SuppressWarnings("unchecked")
public static Map<String, Object> toProperties(DarkClusterConfigMap config) {
if (config == null) {
return Collections.emptyMap();
} else {
Map<String, Object> darkProps = new HashMap<>();
for (Map.Entry<String, DarkClusterConfig> entry : config.entrySet()) {
String darkClusterName = entry.getKey();
DarkClusterConfig darkClusterConfig = entry.getValue();
Map<String, Object> prop = new HashMap<>();
if (darkClusterConfig.hasMultiplier()) {
prop.put(PropertyKeys.DARK_CLUSTER_MULTIPLIER, darkClusterConfig.getMultiplier().toString());
}
if (darkClusterConfig.hasDispatcherOutboundTargetRate()) {
prop.put(PropertyKeys.DARK_CLUSTER_OUTBOUND_TARGET_RATE, darkClusterConfig.getDispatcherOutboundTargetRate().toString());
}
if (darkClusterConfig.hasDispatcherMaxRequestsToBuffer()) {
prop.put(PropertyKeys.DARK_CLUSTER_MAX_REQUESTS_TO_BUFFER, darkClusterConfig.getDispatcherMaxRequestsToBuffer().toString());
}
if (darkClusterConfig.hasDispatcherBufferedRequestExpiryInSeconds()) {
prop.put(PropertyKeys.DARK_CLUSTER_BUFFERED_REQUEST_EXPIRY_IN_SECONDS, darkClusterConfig.getDispatcherBufferedRequestExpiryInSeconds().toString());
}
if (darkClusterConfig.hasDarkClusterStrategyPrioritizedList()) {
DarkClusterStrategyNameArray strategyNameArray = darkClusterConfig.getDarkClusterStrategyPrioritizedList();
List<String> strategyList = new ArrayList<>();
for (DarkClusterStrategyName type : strategyNameArray) {
strategyList.add(type.toString());
}
prop.put(PropertyKeys.DARK_CLUSTER_STRATEGY_LIST, strategyList);
}
if (darkClusterConfig.hasTransportClientProperties()) {
prop.put(PropertyKeys.DARK_CLUSTER_TRANSPORT_CLIENT_PROPERTIES, TransportClientPropertiesConverter.toProperties(darkClusterConfig.getTransportClientProperties()));
}
darkProps.put(darkClusterName, prop);
}
return darkProps;
}
}
use of com.linkedin.d2.DarkClusterConfigMap in project rest.li by linkedin.
the class DarkClustersConverterTest method testDarkClustersConverter.
@Test(dataProvider = "provideKeys")
public void testDarkClustersConverter(boolean successExpected, DarkClusterConfig darkClusterConfig) {
DarkClusterConfigMap configMap = new DarkClusterConfigMap();
configMap.put(DARK_CLUSTER_KEY, darkClusterConfig);
try {
Assert.assertEquals(DarkClustersConverter.toConfig(DarkClustersConverter.toProperties(configMap)), configMap);
} catch (Exception | AssertionError e) {
if (successExpected) {
Assert.fail("expected success for conversion of: " + darkClusterConfig, e);
}
}
}
use of com.linkedin.d2.DarkClusterConfigMap in project rest.li by linkedin.
the class DarkClustersConverterTest method testMultipleStrategies.
@Test
public void testMultipleStrategies() {
DarkClusterConfigMap configMap = new DarkClusterConfigMap();
DarkClusterStrategyNameArray darkClusterStrategyNameArray = new DarkClusterStrategyNameArray();
darkClusterStrategyNameArray.add(DarkClusterStrategyName.RELATIVE_TRAFFIC);
darkClusterStrategyNameArray.add(DarkClusterStrategyName.CONSTANT_QPS);
DarkClusterConfig config = new DarkClusterConfig().setDarkClusterStrategyPrioritizedList(darkClusterStrategyNameArray);
configMap.put(DARK_CLUSTER_KEY, config);
// these are defaults that will be set if the fields are missing.
config.setMultiplier(DARK_CLUSTER_DEFAULT_MULTIPLIER);
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);
Assert.assertEquals(resultConfigMap.get(DARK_CLUSTER_KEY).getDarkClusterStrategyPrioritizedList().get(0), DarkClusterStrategyName.RELATIVE_TRAFFIC, "expected first strategy to be RELATIVE_TRAFFIC");
Assert.assertEquals(resultConfigMap.get(DARK_CLUSTER_KEY).getDarkClusterStrategyPrioritizedList().get(1), DarkClusterStrategyName.CONSTANT_QPS, "expected first strategy to be CONSTANT_QPS");
}
use of com.linkedin.d2.DarkClusterConfigMap in project rest.li by linkedin.
the class DarkClustersConverterTest method testDarkClustersConverterEmpty.
@Test
public void testDarkClustersConverterEmpty() {
DarkClusterConfigMap configMap = new DarkClusterConfigMap();
DarkClusterConfigMap resultConfigMap = DarkClustersConverter.toConfig(DarkClustersConverter.toProperties(configMap));
Assert.assertEquals(resultConfigMap, configMap);
}
use of com.linkedin.d2.DarkClusterConfigMap in project rest.li by linkedin.
the class ClusterPropertiesSerializerTest method testEmptyDarkClusterJsonSerializer.
@Test
public void testEmptyDarkClusterJsonSerializer() throws PropertySerializationException {
ClusterPropertiesJsonSerializer jsonSerializer = new ClusterPropertiesJsonSerializer();
DarkClusterConfigMap darkClusterConfigMap = new DarkClusterConfigMap();
ClusterProperties property = new ClusterProperties("test", new ArrayList<>(), new HashMap<>(), new HashSet<>(), NullPartitionProperties.getInstance(), Arrays.asList("principal1", "principal2"), DarkClustersConverter.toProperties(darkClusterConfigMap), false);
assertEquals(jsonSerializer.fromBytes(jsonSerializer.toBytes(property)), property);
}
Aggregations