mirror of https://github.com/grpc/grpc-java.git
xds: fix bug in XdsLoadBalancerProvider.parseLoadBalancingConfigPolicy
Resolves #5804
This commit is contained in:
parent
f9decbf69d
commit
d8aa42723d
|
@ -379,18 +379,16 @@ public final class ServiceConfigUtil {
|
|||
/**
|
||||
* Extracts the loadbalancer name from xds loadbalancer config.
|
||||
*/
|
||||
public static String getBalancerNameFromXdsConfig(LbConfig xdsConfig) {
|
||||
Map<String, ?> map = xdsConfig.getRawConfigValue();
|
||||
return getString(map, XDS_CONFIG_BALANCER_NAME_KEY);
|
||||
public static String getBalancerNameFromXdsConfig(Map<String, ?> rawXdsConfig) {
|
||||
return getString(rawXdsConfig, XDS_CONFIG_BALANCER_NAME_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts list of child policies from xds loadbalancer config.
|
||||
*/
|
||||
@Nullable
|
||||
public static List<LbConfig> getChildPolicyFromXdsConfig(LbConfig xdsConfig) {
|
||||
Map<String, ?> map = xdsConfig.getRawConfigValue();
|
||||
List<?> rawChildPolicies = getList(map, XDS_CONFIG_CHILD_POLICY_KEY);
|
||||
public static List<LbConfig> getChildPolicyFromXdsConfig(Map<String, ?> rawXdsConfig) {
|
||||
List<?> rawChildPolicies = getList(rawXdsConfig, XDS_CONFIG_CHILD_POLICY_KEY);
|
||||
if (rawChildPolicies != null) {
|
||||
return unwrapLoadBalancingConfigList(checkObjectList(rawChildPolicies));
|
||||
}
|
||||
|
@ -401,9 +399,8 @@ public final class ServiceConfigUtil {
|
|||
* Extracts list of fallback policies from xds loadbalancer config.
|
||||
*/
|
||||
@Nullable
|
||||
public static List<LbConfig> getFallbackPolicyFromXdsConfig(LbConfig xdsConfig) {
|
||||
Map<String, ?> map = xdsConfig.getRawConfigValue();
|
||||
List<?> rawFallbackPolicies = getList(map, XDS_CONFIG_FALLBACK_POLICY_KEY);
|
||||
public static List<LbConfig> getFallbackPolicyFromXdsConfig(Map<String, ?> rawXdsConfig) {
|
||||
List<?> rawFallbackPolicies = getList(rawXdsConfig, XDS_CONFIG_FALLBACK_POLICY_KEY);
|
||||
if (rawFallbackPolicies != null) {
|
||||
return unwrapLoadBalancingConfigList(checkObjectList(rawFallbackPolicies));
|
||||
}
|
||||
|
|
|
@ -34,75 +34,74 @@ import org.junit.runners.JUnit4;
|
|||
public class ServiceConfigUtilTest {
|
||||
@Test
|
||||
public void getBalancerNameFromXdsConfig() throws Exception {
|
||||
String lbConfig = "{\"xds_experimental\" : { "
|
||||
String rawLbConfig = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
assertEquals(
|
||||
"dns:///balancer.example.com:8080",
|
||||
ServiceConfigUtil.getBalancerNameFromXdsConfig(
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig)))));
|
||||
ServiceConfigUtil.getBalancerNameFromXdsConfig(checkObject(JsonParser.parse(rawLbConfig))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getChildPolicyFromXdsConfig() throws Exception {
|
||||
String lbConfig = "{\"xds_experimental\" : { "
|
||||
String rawLbConfig = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
LbConfig expectedChildPolicy1 = ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||
checkObject(JsonParser.parse("{\"round_robin\" : {}}")));
|
||||
LbConfig expectedChildPolicy2 = ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||
checkObject(JsonParser.parse("{\"lbPolicy2\" : {\"key\" : \"val\"}}")));
|
||||
|
||||
List<LbConfig> childPolicies = ServiceConfigUtil.getChildPolicyFromXdsConfig(
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig))));
|
||||
checkObject(JsonParser.parse(rawLbConfig)));
|
||||
|
||||
assertThat(childPolicies).containsExactly(expectedChildPolicy1, expectedChildPolicy2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getChildPolicyFromXdsConfig_null() throws Exception {
|
||||
String lbConfig = "{\"xds_experimental\" : { "
|
||||
String rawLbConfig = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
|
||||
List<LbConfig> childPolicies = ServiceConfigUtil.getChildPolicyFromXdsConfig(
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig))));
|
||||
checkObject(JsonParser.parse(rawLbConfig)));
|
||||
|
||||
assertThat(childPolicies).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFallbackPolicyFromXdsConfig() throws Exception {
|
||||
String lbConfig = "{\"xds_experimental\" : { "
|
||||
String rawLbConfig = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
LbConfig expectedFallbackPolicy1 = ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||
checkObject(JsonParser.parse("{\"lbPolicy3\" : {\"key\" : \"val\"}}")));
|
||||
LbConfig expectedFallbackPolicy2 = ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||
checkObject(JsonParser.parse("{\"lbPolicy4\" : {}}")));
|
||||
|
||||
List<LbConfig> childPolicies = ServiceConfigUtil.getFallbackPolicyFromXdsConfig(
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig))));
|
||||
checkObject(JsonParser.parse(rawLbConfig)));
|
||||
|
||||
assertThat(childPolicies).containsExactly(expectedFallbackPolicy1, expectedFallbackPolicy2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFallbackPolicyFromXdsConfig_null() throws Exception {
|
||||
String lbConfig = "{\"xds_experimental\" : { "
|
||||
String rawLbConfig = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
|
||||
List<LbConfig> fallbackPolicies = ServiceConfigUtil.getFallbackPolicyFromXdsConfig(
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig))));
|
||||
checkObject(JsonParser.parse(rawLbConfig)));
|
||||
|
||||
assertThat(fallbackPolicies).isNull();
|
||||
}
|
||||
|
|
|
@ -73,11 +73,10 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
|
|||
static ConfigOrError parseLoadBalancingConfigPolicy(
|
||||
Map<String, ?> rawLoadBalancingPolicyConfig, LoadBalancerRegistry registry) {
|
||||
try {
|
||||
LbConfig newLbConfig =
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(rawLoadBalancingPolicyConfig);
|
||||
String newBalancerName = ServiceConfigUtil.getBalancerNameFromXdsConfig(newLbConfig);
|
||||
LbConfig childPolicy = selectChildPolicy(newLbConfig, registry);
|
||||
LbConfig fallbackPolicy = selectFallbackPolicy(newLbConfig, registry);
|
||||
String newBalancerName =
|
||||
ServiceConfigUtil.getBalancerNameFromXdsConfig(rawLoadBalancingPolicyConfig);
|
||||
LbConfig childPolicy = selectChildPolicy(rawLoadBalancingPolicyConfig, registry);
|
||||
LbConfig fallbackPolicy = selectFallbackPolicy(rawLoadBalancingPolicyConfig, registry);
|
||||
return ConfigOrError.fromConfig(new XdsConfig(newBalancerName, childPolicy, fallbackPolicy));
|
||||
} catch (RuntimeException e) {
|
||||
return ConfigOrError.fromError(
|
||||
|
@ -86,16 +85,20 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
|
|||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static LbConfig selectFallbackPolicy(LbConfig lbConfig, LoadBalancerRegistry lbRegistry) {
|
||||
List<LbConfig> fallbackConfigs = ServiceConfigUtil.getFallbackPolicyFromXdsConfig(lbConfig);
|
||||
static LbConfig selectFallbackPolicy(
|
||||
Map<String, ?> rawLoadBalancingPolicyConfig, LoadBalancerRegistry lbRegistry) {
|
||||
List<LbConfig> fallbackConfigs =
|
||||
ServiceConfigUtil.getFallbackPolicyFromXdsConfig(rawLoadBalancingPolicyConfig);
|
||||
LbConfig fallbackPolicy = selectSupportedLbPolicy(fallbackConfigs, lbRegistry);
|
||||
return fallbackPolicy == null ? DEFAULT_FALLBACK_POLICY : fallbackPolicy;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@VisibleForTesting
|
||||
static LbConfig selectChildPolicy(LbConfig lbConfig, LoadBalancerRegistry lbRegistry) {
|
||||
List<LbConfig> childConfigs = ServiceConfigUtil.getChildPolicyFromXdsConfig(lbConfig);
|
||||
static LbConfig selectChildPolicy(
|
||||
Map<String, ?> rawLoadBalancingPolicyConfig, LoadBalancerRegistry lbRegistry) {
|
||||
List<LbConfig> childConfigs =
|
||||
ServiceConfigUtil.getChildPolicyFromXdsConfig(rawLoadBalancingPolicyConfig);
|
||||
return selectSupportedLbPolicy(childConfigs, lbRegistry);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,15 +16,18 @@
|
|||
|
||||
package io.grpc.xds;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import io.grpc.LoadBalancer;
|
||||
import io.grpc.LoadBalancer.Helper;
|
||||
import io.grpc.LoadBalancerProvider;
|
||||
import io.grpc.LoadBalancerRegistry;
|
||||
import io.grpc.NameResolver.ConfigOrError;
|
||||
import io.grpc.internal.JsonParser;
|
||||
import io.grpc.internal.ServiceConfigUtil;
|
||||
import io.grpc.internal.ServiceConfigUtil.LbConfig;
|
||||
import io.grpc.xds.XdsLoadBalancer.XdsConfig;
|
||||
import java.util.Map;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
@ -103,19 +106,18 @@ public class XdsLoadBalancerProviderTest {
|
|||
|
||||
@Test
|
||||
public void selectChildPolicy() throws Exception {
|
||||
String lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
String rawLbConfig = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"unsupported_1\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}},"
|
||||
+ "{\"supported_2\" : {\"key\" : \"val\"}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
LbConfig expectedChildPolicy =
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||
checkObject(JsonParser.parse("{\"supported_1\" : {\"key\" : \"val\"}}")));
|
||||
|
||||
LbConfig childPolicy =
|
||||
XdsLoadBalancerProvider.selectChildPolicy(
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfigRaw))),
|
||||
XdsLoadBalancerProvider.selectChildPolicy(checkObject(JsonParser.parse(rawLbConfig)),
|
||||
lbRegistry);
|
||||
|
||||
assertEquals(expectedChildPolicy, childPolicy);
|
||||
|
@ -123,39 +125,60 @@ public class XdsLoadBalancerProviderTest {
|
|||
|
||||
@Test
|
||||
public void selectFallBackPolicy() throws Exception {
|
||||
String lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
String rawLbConfig = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}},"
|
||||
+ "{\"supported_2\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
LbConfig expectedFallbackPolicy = ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||
checkObject(JsonParser.parse("{\"supported_1\" : {\"key\" : \"val\"}}")));
|
||||
|
||||
LbConfig fallbackPolicy = XdsLoadBalancerProvider.selectFallbackPolicy(
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfigRaw))),
|
||||
lbRegistry);
|
||||
checkObject(JsonParser.parse(rawLbConfig)), lbRegistry);
|
||||
|
||||
assertEquals(expectedFallbackPolicy, fallbackPolicy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectFallBackPolicy_roundRobinIsDefault() throws Exception {
|
||||
String lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
String rawLbConfig = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
LbConfig expectedFallbackPolicy = ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||
checkObject(JsonParser.parse("{\"round_robin\" : {}}")));
|
||||
|
||||
LbConfig fallbackPolicy = XdsLoadBalancerProvider.selectFallbackPolicy(
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||
checkObject(JsonParser.parse(lbConfigRaw))),
|
||||
lbRegistry);
|
||||
checkObject(JsonParser.parse(rawLbConfig)), lbRegistry);
|
||||
|
||||
assertEquals(expectedFallbackPolicy, fallbackPolicy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLoadBalancingConfigPolicy() throws Exception {
|
||||
String rawLbConfig = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"supported_1\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"round_robin\" : {\"key\" : \"val\"}},"
|
||||
+ "{\"supported_2\" : {\"key\" : \"val\"}}]"
|
||||
+ "}";
|
||||
Map<String, ?> rawlbConfigMap = checkObject(JsonParser.parse(rawLbConfig));
|
||||
ConfigOrError configOrError =
|
||||
XdsLoadBalancerProvider.parseLoadBalancingConfigPolicy(rawlbConfigMap, lbRegistry);
|
||||
|
||||
assertThat(configOrError.getError()).isNull();
|
||||
assertThat(configOrError.getConfig()).isInstanceOf(XdsConfig.class);
|
||||
assertThat(configOrError.getConfig()).isEqualTo(
|
||||
new XdsConfig(
|
||||
"dns:///balancer.example.com:8080",
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||
checkObject(JsonParser.parse("{\"supported_1\" : {}}"))),
|
||||
ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||
checkObject(JsonParser.parse("{\"round_robin\" : {\"key\" : \"val\"}}"))))
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, ?> checkObject(Object o) {
|
||||
return (Map<String, ?>) o;
|
||||
|
|
|
@ -295,11 +295,11 @@ public class XdsLoadBalancerTest {
|
|||
|
||||
@Test
|
||||
public void resolverEvent_standardModeToStandardMode() throws Exception {
|
||||
String lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
String lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
|
||||
|
@ -318,10 +318,10 @@ public class XdsLoadBalancerTest {
|
|||
ArgumentMatchers.<CallOptions>any());
|
||||
|
||||
|
||||
lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build();
|
||||
|
@ -346,11 +346,11 @@ public class XdsLoadBalancerTest {
|
|||
|
||||
@Test
|
||||
public void resolverEvent_standardModeToCustomMode() throws Exception {
|
||||
String lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
String lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
|
||||
|
@ -365,11 +365,11 @@ public class XdsLoadBalancerTest {
|
|||
.newCall(ArgumentMatchers.<MethodDescriptor<?, ?>>any(),
|
||||
ArgumentMatchers.<CallOptions>any());
|
||||
|
||||
lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"supported_2\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build();
|
||||
|
@ -392,11 +392,11 @@ public class XdsLoadBalancerTest {
|
|||
|
||||
@Test
|
||||
public void resolverEvent_customModeToStandardMode() throws Exception {
|
||||
String lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
String lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"supported_2\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
|
||||
|
@ -413,11 +413,11 @@ public class XdsLoadBalancerTest {
|
|||
|
||||
assertThat(lb.getXdsLbStateForTest().childPolicy).isNotNull();
|
||||
|
||||
lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build();
|
||||
|
@ -440,11 +440,11 @@ public class XdsLoadBalancerTest {
|
|||
|
||||
@Test
|
||||
public void resolverEvent_customModeToCustomMode() throws Exception {
|
||||
String lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
String lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"supported_2\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
|
||||
|
@ -460,11 +460,11 @@ public class XdsLoadBalancerTest {
|
|||
.newCall(ArgumentMatchers.<MethodDescriptor<?, ?>>any(),
|
||||
ArgumentMatchers.<CallOptions>any());
|
||||
|
||||
lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"fallback_1\" : {\"key\" : \"val\"}}, {\"unfallback_1\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build();
|
||||
|
@ -486,11 +486,11 @@ public class XdsLoadBalancerTest {
|
|||
|
||||
@Test
|
||||
public void resolverEvent_balancerNameChange() throws Exception {
|
||||
String lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
String lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
|
||||
|
@ -505,11 +505,11 @@ public class XdsLoadBalancerTest {
|
|||
.newCall(ArgumentMatchers.<MethodDescriptor<?, ?>>any(),
|
||||
ArgumentMatchers.<CallOptions>any());
|
||||
|
||||
lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8443\","
|
||||
+ "\"childPolicy\" : [{\"fallback_1\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build();
|
||||
|
@ -765,10 +765,10 @@ public class XdsLoadBalancerTest {
|
|||
}
|
||||
|
||||
private static Attributes standardModeWithFallback1Attributes() throws Exception {
|
||||
String lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
String lbConfigRaw = "{"
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"fallbackPolicy\" : [{\"fallback_1\" : { \"fallback_1_option\" : \"yes\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
return Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
|
||||
|
@ -776,11 +776,11 @@ public class XdsLoadBalancerTest {
|
|||
|
||||
@Test
|
||||
public void shutdown_cleanupTimers() throws Exception {
|
||||
String lbConfigRaw = "{\"xds_experimental\" : { "
|
||||
String lbConfigRaw = "{ "
|
||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||
+ "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
|
||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
|
||||
+ "}}";
|
||||
+ "}";
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
|
||||
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
|
||||
|
|
Loading…
Reference in New Issue