use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class DnsNameResolverTest method parseServiceConfig_matches.
@Test
public void parseServiceConfig_matches() {
ConfigOrError result = DnsNameResolver.parseServiceConfig(Arrays.asList("grpc_config=[{\"serviceConfig\":{}}]"), new Random(), "localhost");
assertThat(result).isNotNull();
assertThat(result.getError()).isNull();
assertThat(result.getConfig()).isEqualTo(ImmutableMap.of());
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class ClusterManagerLoadBalancerProviderTest method parseLoadBalancingConfig_valid.
@Test
public void parseLoadBalancingConfig_valid() throws IOException {
final Object fooConfig = new Object();
LoadBalancerProvider lbProviderFoo = new LoadBalancerProvider() {
@Override
public boolean isAvailable() {
return true;
}
@Override
public int getPriority() {
return 5;
}
@Override
public String getPolicyName() {
return "foo_policy";
}
@Override
public LoadBalancer newLoadBalancer(Helper helper) {
throw new UnsupportedOperationException("Should not be called");
}
@Override
public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLoadBalancingPolicyConfig) {
return ConfigOrError.fromConfig(fooConfig);
}
};
final Object barConfig = new Object();
LoadBalancerProvider lbProviderBar = new LoadBalancerProvider() {
@Override
public boolean isAvailable() {
return true;
}
@Override
public int getPriority() {
return 5;
}
@Override
public String getPolicyName() {
return "bar_policy";
}
@Override
public LoadBalancer newLoadBalancer(Helper helper) {
throw new UnsupportedOperationException("Should not be called");
}
@Override
public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLoadBalancingPolicyConfig) {
return ConfigOrError.fromConfig(barConfig);
}
};
lbRegistry.register(lbProviderFoo);
lbRegistry.register(lbProviderBar);
String clusterManagerConfigJson = "{\n" + " \"childPolicy\": {\n" + " \"child1\": {\n" + " \"lbPolicy\": [\n" + " {\n" + " \"foo_policy\": {" + " \"config_name\": \"config_value\"\n" + " }\n" + " }\n" + " ]\n" + " },\n" + " \"child2\": {\n" + " \"lbPolicy\": [\n" + " {\n" + " \"bar_policy\": {}\n" + " }, {\n" + " \"unsupported\": {}\n" + " }\n" + " ]\n" + " }\n" + " }\n" + "}";
@SuppressWarnings("unchecked") Map<String, ?> rawLbConfigMap = (Map<String, ?>) JsonParser.parse(clusterManagerConfigJson);
ConfigOrError configOrError = provider.parseLoadBalancingPolicyConfig(rawLbConfigMap);
assertThat(configOrError.getConfig()).isNotNull();
ClusterManagerConfig config = (ClusterManagerConfig) configOrError.getConfig();
assertThat(config.childPolicies).containsExactly("child1", new PolicySelection(lbProviderFoo, fooConfig), "child2", new PolicySelection(lbProviderBar, barConfig));
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class ClusterManagerLoadBalancerProviderTest method parseLoadBalancingPolicyConfig_emptyChildPolicy.
@Test
public void parseLoadBalancingPolicyConfig_emptyChildPolicy() throws IOException {
String clusterManagerConfigJson = "{\n" + " \"childPolicy\": {}\n" + "}";
@SuppressWarnings("unchecked") Map<String, ?> rawLbConfigMap = (Map<String, ?>) JsonParser.parse(clusterManagerConfigJson);
ConfigOrError configOrError = provider.parseLoadBalancingPolicyConfig(rawLbConfigMap);
Status error = configOrError.getError();
assertThat(error.getCode()).isEqualTo(Code.INTERNAL);
assertThat(error.getDescription()).startsWith("No child policy provided for cluster_manager LB policy");
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class CdsLoadBalancerProviderTest method parseCdsLoadBalancingPolicyConfig.
@Test
public void parseCdsLoadBalancingPolicyConfig() throws IOException {
CdsLoadBalancerProvider provider = new CdsLoadBalancerProvider();
String rawCdsLbConfig = "{\n" + " \"cluster\": \"cluster-foo.googleapis.com\"\n" + "}";
@SuppressWarnings("unchecked") Map<String, ?> rawLbConfigMap = (Map<String, ?>) JsonParser.parse(rawCdsLbConfig);
ConfigOrError result = provider.parseLoadBalancingPolicyConfig(rawLbConfigMap);
assertThat(result.getConfig()).isNotNull();
CdsConfig config = (CdsConfig) result.getConfig();
assertThat(config.name).isEqualTo("cluster-foo.googleapis.com");
}
use of io.grpc.NameResolver.ConfigOrError in project grpc-java by grpc.
the class RingHashLoadBalancerProviderTest method parseLoadBalancingConfig_valid.
@Test
public void parseLoadBalancingConfig_valid() throws IOException {
String lbConfig = "{\"minRingSize\" : 10, \"maxRingSize\" : 100}";
ConfigOrError configOrError = provider.parseLoadBalancingPolicyConfig(parseJsonObject(lbConfig));
assertThat(configOrError.getConfig()).isNotNull();
RingHashConfig config = (RingHashConfig) configOrError.getConfig();
assertThat(config.minRingSize).isEqualTo(10L);
assertThat(config.maxRingSize).isEqualTo(100L);
}
Aggregations