xds: fix bug in XdsLoadBalancerProvider.parseLoadBalancingConfigPolicy

Resolves #5804
This commit is contained in:
ZHANG Dapeng 2019-05-30 16:37:08 -07:00 committed by GitHub
parent f9decbf69d
commit d8aa42723d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 71 deletions

View File

@ -379,18 +379,16 @@ public final class ServiceConfigUtil {
/** /**
* Extracts the loadbalancer name from xds loadbalancer config. * Extracts the loadbalancer name from xds loadbalancer config.
*/ */
public static String getBalancerNameFromXdsConfig(LbConfig xdsConfig) { public static String getBalancerNameFromXdsConfig(Map<String, ?> rawXdsConfig) {
Map<String, ?> map = xdsConfig.getRawConfigValue(); return getString(rawXdsConfig, XDS_CONFIG_BALANCER_NAME_KEY);
return getString(map, XDS_CONFIG_BALANCER_NAME_KEY);
} }
/** /**
* Extracts list of child policies from xds loadbalancer config. * Extracts list of child policies from xds loadbalancer config.
*/ */
@Nullable @Nullable
public static List<LbConfig> getChildPolicyFromXdsConfig(LbConfig xdsConfig) { public static List<LbConfig> getChildPolicyFromXdsConfig(Map<String, ?> rawXdsConfig) {
Map<String, ?> map = xdsConfig.getRawConfigValue(); List<?> rawChildPolicies = getList(rawXdsConfig, XDS_CONFIG_CHILD_POLICY_KEY);
List<?> rawChildPolicies = getList(map, XDS_CONFIG_CHILD_POLICY_KEY);
if (rawChildPolicies != null) { if (rawChildPolicies != null) {
return unwrapLoadBalancingConfigList(checkObjectList(rawChildPolicies)); return unwrapLoadBalancingConfigList(checkObjectList(rawChildPolicies));
} }
@ -401,9 +399,8 @@ public final class ServiceConfigUtil {
* Extracts list of fallback policies from xds loadbalancer config. * Extracts list of fallback policies from xds loadbalancer config.
*/ */
@Nullable @Nullable
public static List<LbConfig> getFallbackPolicyFromXdsConfig(LbConfig xdsConfig) { public static List<LbConfig> getFallbackPolicyFromXdsConfig(Map<String, ?> rawXdsConfig) {
Map<String, ?> map = xdsConfig.getRawConfigValue(); List<?> rawFallbackPolicies = getList(rawXdsConfig, XDS_CONFIG_FALLBACK_POLICY_KEY);
List<?> rawFallbackPolicies = getList(map, XDS_CONFIG_FALLBACK_POLICY_KEY);
if (rawFallbackPolicies != null) { if (rawFallbackPolicies != null) {
return unwrapLoadBalancingConfigList(checkObjectList(rawFallbackPolicies)); return unwrapLoadBalancingConfigList(checkObjectList(rawFallbackPolicies));
} }

View File

@ -34,75 +34,74 @@ import org.junit.runners.JUnit4;
public class ServiceConfigUtilTest { public class ServiceConfigUtilTest {
@Test @Test
public void getBalancerNameFromXdsConfig() throws Exception { public void getBalancerNameFromXdsConfig() throws Exception {
String lbConfig = "{\"xds_experimental\" : { " String rawLbConfig = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}],"
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
+ "}}"; + "}";
assertEquals( assertEquals(
"dns:///balancer.example.com:8080", "dns:///balancer.example.com:8080",
ServiceConfigUtil.getBalancerNameFromXdsConfig( ServiceConfigUtil.getBalancerNameFromXdsConfig(checkObject(JsonParser.parse(rawLbConfig))));
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig)))));
} }
@Test @Test
public void getChildPolicyFromXdsConfig() throws Exception { public void getChildPolicyFromXdsConfig() throws Exception {
String lbConfig = "{\"xds_experimental\" : { " String rawLbConfig = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}],"
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
+ "}}"; + "}";
LbConfig expectedChildPolicy1 = ServiceConfigUtil.unwrapLoadBalancingConfig( LbConfig expectedChildPolicy1 = ServiceConfigUtil.unwrapLoadBalancingConfig(
checkObject(JsonParser.parse("{\"round_robin\" : {}}"))); checkObject(JsonParser.parse("{\"round_robin\" : {}}")));
LbConfig expectedChildPolicy2 = ServiceConfigUtil.unwrapLoadBalancingConfig( LbConfig expectedChildPolicy2 = ServiceConfigUtil.unwrapLoadBalancingConfig(
checkObject(JsonParser.parse("{\"lbPolicy2\" : {\"key\" : \"val\"}}"))); checkObject(JsonParser.parse("{\"lbPolicy2\" : {\"key\" : \"val\"}}")));
List<LbConfig> childPolicies = ServiceConfigUtil.getChildPolicyFromXdsConfig( List<LbConfig> childPolicies = ServiceConfigUtil.getChildPolicyFromXdsConfig(
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig)))); checkObject(JsonParser.parse(rawLbConfig)));
assertThat(childPolicies).containsExactly(expectedChildPolicy1, expectedChildPolicy2); assertThat(childPolicies).containsExactly(expectedChildPolicy1, expectedChildPolicy2);
} }
@Test @Test
public void getChildPolicyFromXdsConfig_null() throws Exception { public void getChildPolicyFromXdsConfig_null() throws Exception {
String lbConfig = "{\"xds_experimental\" : { " String rawLbConfig = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
+ "}}"; + "}";
List<LbConfig> childPolicies = ServiceConfigUtil.getChildPolicyFromXdsConfig( List<LbConfig> childPolicies = ServiceConfigUtil.getChildPolicyFromXdsConfig(
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig)))); checkObject(JsonParser.parse(rawLbConfig)));
assertThat(childPolicies).isNull(); assertThat(childPolicies).isNull();
} }
@Test @Test
public void getFallbackPolicyFromXdsConfig() throws Exception { public void getFallbackPolicyFromXdsConfig() throws Exception {
String lbConfig = "{\"xds_experimental\" : { " String rawLbConfig = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]," + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}],"
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
+ "}}"; + "}";
LbConfig expectedFallbackPolicy1 = ServiceConfigUtil.unwrapLoadBalancingConfig( LbConfig expectedFallbackPolicy1 = ServiceConfigUtil.unwrapLoadBalancingConfig(
checkObject(JsonParser.parse("{\"lbPolicy3\" : {\"key\" : \"val\"}}"))); checkObject(JsonParser.parse("{\"lbPolicy3\" : {\"key\" : \"val\"}}")));
LbConfig expectedFallbackPolicy2 = ServiceConfigUtil.unwrapLoadBalancingConfig( LbConfig expectedFallbackPolicy2 = ServiceConfigUtil.unwrapLoadBalancingConfig(
checkObject(JsonParser.parse("{\"lbPolicy4\" : {}}"))); checkObject(JsonParser.parse("{\"lbPolicy4\" : {}}")));
List<LbConfig> childPolicies = ServiceConfigUtil.getFallbackPolicyFromXdsConfig( List<LbConfig> childPolicies = ServiceConfigUtil.getFallbackPolicyFromXdsConfig(
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig)))); checkObject(JsonParser.parse(rawLbConfig)));
assertThat(childPolicies).containsExactly(expectedFallbackPolicy1, expectedFallbackPolicy2); assertThat(childPolicies).containsExactly(expectedFallbackPolicy1, expectedFallbackPolicy2);
} }
@Test @Test
public void getFallbackPolicyFromXdsConfig_null() throws Exception { public void getFallbackPolicyFromXdsConfig_null() throws Exception {
String lbConfig = "{\"xds_experimental\" : { " String rawLbConfig = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]" + "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
List<LbConfig> fallbackPolicies = ServiceConfigUtil.getFallbackPolicyFromXdsConfig( List<LbConfig> fallbackPolicies = ServiceConfigUtil.getFallbackPolicyFromXdsConfig(
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfig)))); checkObject(JsonParser.parse(rawLbConfig)));
assertThat(fallbackPolicies).isNull(); assertThat(fallbackPolicies).isNull();
} }

View File

@ -73,11 +73,10 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
static ConfigOrError parseLoadBalancingConfigPolicy( static ConfigOrError parseLoadBalancingConfigPolicy(
Map<String, ?> rawLoadBalancingPolicyConfig, LoadBalancerRegistry registry) { Map<String, ?> rawLoadBalancingPolicyConfig, LoadBalancerRegistry registry) {
try { try {
LbConfig newLbConfig = String newBalancerName =
ServiceConfigUtil.unwrapLoadBalancingConfig(rawLoadBalancingPolicyConfig); ServiceConfigUtil.getBalancerNameFromXdsConfig(rawLoadBalancingPolicyConfig);
String newBalancerName = ServiceConfigUtil.getBalancerNameFromXdsConfig(newLbConfig); LbConfig childPolicy = selectChildPolicy(rawLoadBalancingPolicyConfig, registry);
LbConfig childPolicy = selectChildPolicy(newLbConfig, registry); LbConfig fallbackPolicy = selectFallbackPolicy(rawLoadBalancingPolicyConfig, registry);
LbConfig fallbackPolicy = selectFallbackPolicy(newLbConfig, registry);
return ConfigOrError.fromConfig(new XdsConfig(newBalancerName, childPolicy, fallbackPolicy)); return ConfigOrError.fromConfig(new XdsConfig(newBalancerName, childPolicy, fallbackPolicy));
} catch (RuntimeException e) { } catch (RuntimeException e) {
return ConfigOrError.fromError( return ConfigOrError.fromError(
@ -86,16 +85,20 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
} }
@VisibleForTesting @VisibleForTesting
static LbConfig selectFallbackPolicy(LbConfig lbConfig, LoadBalancerRegistry lbRegistry) { static LbConfig selectFallbackPolicy(
List<LbConfig> fallbackConfigs = ServiceConfigUtil.getFallbackPolicyFromXdsConfig(lbConfig); Map<String, ?> rawLoadBalancingPolicyConfig, LoadBalancerRegistry lbRegistry) {
List<LbConfig> fallbackConfigs =
ServiceConfigUtil.getFallbackPolicyFromXdsConfig(rawLoadBalancingPolicyConfig);
LbConfig fallbackPolicy = selectSupportedLbPolicy(fallbackConfigs, lbRegistry); LbConfig fallbackPolicy = selectSupportedLbPolicy(fallbackConfigs, lbRegistry);
return fallbackPolicy == null ? DEFAULT_FALLBACK_POLICY : fallbackPolicy; return fallbackPolicy == null ? DEFAULT_FALLBACK_POLICY : fallbackPolicy;
} }
@Nullable @Nullable
@VisibleForTesting @VisibleForTesting
static LbConfig selectChildPolicy(LbConfig lbConfig, LoadBalancerRegistry lbRegistry) { static LbConfig selectChildPolicy(
List<LbConfig> childConfigs = ServiceConfigUtil.getChildPolicyFromXdsConfig(lbConfig); Map<String, ?> rawLoadBalancingPolicyConfig, LoadBalancerRegistry lbRegistry) {
List<LbConfig> childConfigs =
ServiceConfigUtil.getChildPolicyFromXdsConfig(rawLoadBalancingPolicyConfig);
return selectSupportedLbPolicy(childConfigs, lbRegistry); return selectSupportedLbPolicy(childConfigs, lbRegistry);
} }

View File

@ -16,15 +16,18 @@
package io.grpc.xds; package io.grpc.xds;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import io.grpc.LoadBalancer; import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.Helper; import io.grpc.LoadBalancer.Helper;
import io.grpc.LoadBalancerProvider; import io.grpc.LoadBalancerProvider;
import io.grpc.LoadBalancerRegistry; import io.grpc.LoadBalancerRegistry;
import io.grpc.NameResolver.ConfigOrError;
import io.grpc.internal.JsonParser; import io.grpc.internal.JsonParser;
import io.grpc.internal.ServiceConfigUtil; import io.grpc.internal.ServiceConfigUtil;
import io.grpc.internal.ServiceConfigUtil.LbConfig; import io.grpc.internal.ServiceConfigUtil.LbConfig;
import io.grpc.xds.XdsLoadBalancer.XdsConfig;
import java.util.Map; import java.util.Map;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -103,19 +106,18 @@ public class XdsLoadBalancerProviderTest {
@Test @Test
public void selectChildPolicy() throws Exception { public void selectChildPolicy() throws Exception {
String lbConfigRaw = "{\"xds_experimental\" : { " String rawLbConfig = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"unsupported_1\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}," + "\"childPolicy\" : [{\"unsupported_1\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}},"
+ "{\"supported_2\" : {\"key\" : \"val\"}}]," + "{\"supported_2\" : {\"key\" : \"val\"}}],"
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
+ "}}"; + "}";
LbConfig expectedChildPolicy = LbConfig expectedChildPolicy =
ServiceConfigUtil.unwrapLoadBalancingConfig( ServiceConfigUtil.unwrapLoadBalancingConfig(
checkObject(JsonParser.parse("{\"supported_1\" : {\"key\" : \"val\"}}"))); checkObject(JsonParser.parse("{\"supported_1\" : {\"key\" : \"val\"}}")));
LbConfig childPolicy = LbConfig childPolicy =
XdsLoadBalancerProvider.selectChildPolicy( XdsLoadBalancerProvider.selectChildPolicy(checkObject(JsonParser.parse(rawLbConfig)),
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfigRaw))),
lbRegistry); lbRegistry);
assertEquals(expectedChildPolicy, childPolicy); assertEquals(expectedChildPolicy, childPolicy);
@ -123,39 +125,60 @@ public class XdsLoadBalancerProviderTest {
@Test @Test
public void selectFallBackPolicy() throws Exception { public void selectFallBackPolicy() throws Exception {
String lbConfigRaw = "{\"xds_experimental\" : { " String rawLbConfig = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]," + "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}}," + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"supported_1\" : {\"key\" : \"val\"}},"
+ "{\"supported_2\" : {\"key\" : \"val\"}}]" + "{\"supported_2\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
LbConfig expectedFallbackPolicy = ServiceConfigUtil.unwrapLoadBalancingConfig( LbConfig expectedFallbackPolicy = ServiceConfigUtil.unwrapLoadBalancingConfig(
checkObject(JsonParser.parse("{\"supported_1\" : {\"key\" : \"val\"}}"))); checkObject(JsonParser.parse("{\"supported_1\" : {\"key\" : \"val\"}}")));
LbConfig fallbackPolicy = XdsLoadBalancerProvider.selectFallbackPolicy( LbConfig fallbackPolicy = XdsLoadBalancerProvider.selectFallbackPolicy(
ServiceConfigUtil.unwrapLoadBalancingConfig(checkObject(JsonParser.parse(lbConfigRaw))), checkObject(JsonParser.parse(rawLbConfig)), lbRegistry);
lbRegistry);
assertEquals(expectedFallbackPolicy, fallbackPolicy); assertEquals(expectedFallbackPolicy, fallbackPolicy);
} }
@Test @Test
public void selectFallBackPolicy_roundRobinIsDefault() throws Exception { public void selectFallBackPolicy_roundRobinIsDefault() throws Exception {
String lbConfigRaw = "{\"xds_experimental\" : { " String rawLbConfig = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]" + "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
+ "}}"; + "}";
LbConfig expectedFallbackPolicy = ServiceConfigUtil.unwrapLoadBalancingConfig( LbConfig expectedFallbackPolicy = ServiceConfigUtil.unwrapLoadBalancingConfig(
checkObject(JsonParser.parse("{\"round_robin\" : {}}"))); checkObject(JsonParser.parse("{\"round_robin\" : {}}")));
LbConfig fallbackPolicy = XdsLoadBalancerProvider.selectFallbackPolicy( LbConfig fallbackPolicy = XdsLoadBalancerProvider.selectFallbackPolicy(
ServiceConfigUtil.unwrapLoadBalancingConfig( checkObject(JsonParser.parse(rawLbConfig)), lbRegistry);
checkObject(JsonParser.parse(lbConfigRaw))),
lbRegistry);
assertEquals(expectedFallbackPolicy, fallbackPolicy); 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") @SuppressWarnings("unchecked")
private static Map<String, ?> checkObject(Object o) { private static Map<String, ?> checkObject(Object o) {
return (Map<String, ?>) o; return (Map<String, ?>) o;

View File

@ -295,11 +295,11 @@ public class XdsLoadBalancerTest {
@Test @Test
public void resolverEvent_standardModeToStandardMode() throws Exception { public void resolverEvent_standardModeToStandardMode() throws Exception {
String lbConfigRaw = "{\"xds_experimental\" : { " String lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}]," + "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
@ -318,10 +318,10 @@ public class XdsLoadBalancerTest {
ArgumentMatchers.<CallOptions>any()); ArgumentMatchers.<CallOptions>any());
lbConfigRaw = "{\"xds_experimental\" : { " lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build(); attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build();
@ -346,11 +346,11 @@ public class XdsLoadBalancerTest {
@Test @Test
public void resolverEvent_standardModeToCustomMode() throws Exception { public void resolverEvent_standardModeToCustomMode() throws Exception {
String lbConfigRaw = "{\"xds_experimental\" : { " String lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}]," + "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
@ -365,11 +365,11 @@ public class XdsLoadBalancerTest {
.newCall(ArgumentMatchers.<MethodDescriptor<?, ?>>any(), .newCall(ArgumentMatchers.<MethodDescriptor<?, ?>>any(),
ArgumentMatchers.<CallOptions>any()); ArgumentMatchers.<CallOptions>any());
lbConfigRaw = "{\"xds_experimental\" : { " lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"supported_2\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}]," + "\"childPolicy\" : [{\"supported_2\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build(); attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build();
@ -392,11 +392,11 @@ public class XdsLoadBalancerTest {
@Test @Test
public void resolverEvent_customModeToStandardMode() throws Exception { public void resolverEvent_customModeToStandardMode() throws Exception {
String lbConfigRaw = "{\"xds_experimental\" : { " String lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"supported_2\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}]," + "\"childPolicy\" : [{\"supported_2\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
@ -413,11 +413,11 @@ public class XdsLoadBalancerTest {
assertThat(lb.getXdsLbStateForTest().childPolicy).isNotNull(); assertThat(lb.getXdsLbStateForTest().childPolicy).isNotNull();
lbConfigRaw = "{\"xds_experimental\" : { " lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}]," + "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build(); attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build();
@ -440,11 +440,11 @@ public class XdsLoadBalancerTest {
@Test @Test
public void resolverEvent_customModeToCustomMode() throws Exception { public void resolverEvent_customModeToCustomMode() throws Exception {
String lbConfigRaw = "{\"xds_experimental\" : { " String lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"supported_2\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}]," + "\"childPolicy\" : [{\"supported_2\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
@ -460,11 +460,11 @@ public class XdsLoadBalancerTest {
.newCall(ArgumentMatchers.<MethodDescriptor<?, ?>>any(), .newCall(ArgumentMatchers.<MethodDescriptor<?, ?>>any(),
ArgumentMatchers.<CallOptions>any()); ArgumentMatchers.<CallOptions>any());
lbConfigRaw = "{\"xds_experimental\" : { " lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"fallback_1\" : {\"key\" : \"val\"}}, {\"unfallback_1\" : {}}]," + "\"childPolicy\" : [{\"fallback_1\" : {\"key\" : \"val\"}}, {\"unfallback_1\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build(); attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build();
@ -486,11 +486,11 @@ public class XdsLoadBalancerTest {
@Test @Test
public void resolverEvent_balancerNameChange() throws Exception { public void resolverEvent_balancerNameChange() throws Exception {
String lbConfigRaw = "{\"xds_experimental\" : { " String lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}]," + "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
@ -505,11 +505,11 @@ public class XdsLoadBalancerTest {
.newCall(ArgumentMatchers.<MethodDescriptor<?, ?>>any(), .newCall(ArgumentMatchers.<MethodDescriptor<?, ?>>any(),
ArgumentMatchers.<CallOptions>any()); ArgumentMatchers.<CallOptions>any());
lbConfigRaw = "{\"xds_experimental\" : { " lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8443\"," + "\"balancerName\" : \"dns:///balancer.example.com:8443\","
+ "\"childPolicy\" : [{\"fallback_1\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}]," + "\"childPolicy\" : [{\"fallback_1\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig2 = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build(); attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig2).build();
@ -765,10 +765,10 @@ public class XdsLoadBalancerTest {
} }
private static Attributes standardModeWithFallback1Attributes() throws Exception { private static Attributes standardModeWithFallback1Attributes() throws Exception {
String lbConfigRaw = "{\"xds_experimental\" : { " String lbConfigRaw = "{"
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"fallbackPolicy\" : [{\"fallback_1\" : { \"fallback_1_option\" : \"yes\"}}]" + "\"fallbackPolicy\" : [{\"fallback_1\" : { \"fallback_1_option\" : \"yes\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
return Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); return Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();
@ -776,11 +776,11 @@ public class XdsLoadBalancerTest {
@Test @Test
public void shutdown_cleanupTimers() throws Exception { public void shutdown_cleanupTimers() throws Exception {
String lbConfigRaw = "{\"xds_experimental\" : { " String lbConfigRaw = "{ "
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\"," + "\"balancerName\" : \"dns:///balancer.example.com:8080\","
+ "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}]," + "\"childPolicy\" : [{\"unsupported\" : {\"key\" : \"val\"}}, {\"unsupported_2\" : {}}],"
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]" + "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"fallback_1\" : {\"key\" : \"val\"}}]"
+ "}}"; + "}";
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw); Map<String, ?> lbConfig = (Map<String, ?>) JsonParser.parse(lbConfigRaw);
Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build(); Attributes attrs = Attributes.newBuilder().set(ATTR_LOAD_BALANCING_CONFIG, lbConfig).build();