Search in sources :

Example 1 with ChildLoadBalancingPolicy

use of io.grpc.rls.LbPolicyConfiguration.ChildLoadBalancingPolicy in project grpc-java by grpc.

the class LbPolicyConfigurationTest method childLoadBalancingPolicy_effectiveChildPolicy.

@Test
public void childLoadBalancingPolicy_effectiveChildPolicy() {
    LoadBalancerProvider mockProvider = mock(LoadBalancerProvider.class);
    ChildLoadBalancingPolicy childLbPolicy = new ChildLoadBalancingPolicy("targetFieldName", ImmutableMap.<String, Object>of("foo", "bar"), mockProvider);
    assertThat(childLbPolicy.getEffectiveChildPolicy("target")).containsExactly("foo", "bar", "targetFieldName", "target");
    assertThat(childLbPolicy.getEffectiveLbProvider()).isEqualTo(mockProvider);
}
Also used : ChildLoadBalancingPolicy(io.grpc.rls.LbPolicyConfiguration.ChildLoadBalancingPolicy) LoadBalancerProvider(io.grpc.LoadBalancerProvider) Test(org.junit.Test)

Example 2 with ChildLoadBalancingPolicy

use of io.grpc.rls.LbPolicyConfiguration.ChildLoadBalancingPolicy in project grpc-java by grpc.

the class RlsLoadBalancerProvider method parseLoadBalancingPolicyConfig.

@Override
public ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLoadBalancingConfigPolicy) {
    try {
        RouteLookupConfig routeLookupConfig = new RouteLookupConfigConverter().convert(JsonUtil.getObject(rawLoadBalancingConfigPolicy, "routeLookupConfig"));
        Map<String, ?> routeLookupChannelServiceConfig = JsonUtil.getObject(rawLoadBalancingConfigPolicy, "routeLookupChannelServiceConfig");
        ChildLoadBalancingPolicy lbPolicy = ChildLoadBalancingPolicy.create(JsonUtil.getString(rawLoadBalancingConfigPolicy, "childPolicyConfigTargetFieldName"), JsonUtil.checkObjectList(checkNotNull(JsonUtil.getList(rawLoadBalancingConfigPolicy, "childPolicy"))));
        return ConfigOrError.fromConfig(new LbPolicyConfiguration(routeLookupConfig, routeLookupChannelServiceConfig, lbPolicy));
    } catch (Exception e) {
        return ConfigOrError.fromError(Status.INVALID_ARGUMENT.withDescription("can't parse config: " + e.getMessage()).withCause(e));
    }
}
Also used : ChildLoadBalancingPolicy(io.grpc.rls.LbPolicyConfiguration.ChildLoadBalancingPolicy) RouteLookupConfig(io.grpc.rls.RlsProtoData.RouteLookupConfig) RouteLookupConfigConverter(io.grpc.rls.RlsProtoConverters.RouteLookupConfigConverter)

Aggregations

ChildLoadBalancingPolicy (io.grpc.rls.LbPolicyConfiguration.ChildLoadBalancingPolicy)2 LoadBalancerProvider (io.grpc.LoadBalancerProvider)1 RouteLookupConfigConverter (io.grpc.rls.RlsProtoConverters.RouteLookupConfigConverter)1 RouteLookupConfig (io.grpc.rls.RlsProtoData.RouteLookupConfig)1 Test (org.junit.Test)1