Search in sources :

Example 16 with ClusterImplConfig

use of io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method edsClustersWithLeastRequestEndpointLbPolicy.

@Test
public void edsClustersWithLeastRequestEndpointLbPolicy() {
    ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(edsDiscoveryMechanism1), leastRequest);
    deliverLbConfig(config);
    assertThat(xdsClient.watchers.keySet()).containsExactly(EDS_SERVICE_NAME1);
    assertThat(childBalancers).isEmpty();
    // Simple case with one priority and one locality
    EquivalentAddressGroup endpoint = makeAddress("endpoint-addr-1");
    LocalityLbEndpoints localityLbEndpoints = LocalityLbEndpoints.create(Arrays.asList(LbEndpoint.create(endpoint, 0, /* loadBalancingWeight */
    true)), 100, /* localityWeight */
    1);
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, ImmutableMap.of(locality1, localityLbEndpoints));
    assertThat(childBalancers).hasSize(1);
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    assertThat(childBalancer.addresses).hasSize(1);
    EquivalentAddressGroup addr = childBalancer.addresses.get(0);
    assertThat(addr.getAddresses()).isEqualTo(endpoint.getAddresses());
    assertThat(childBalancer.name).isEqualTo(PRIORITY_POLICY_NAME);
    PriorityLbConfig priorityLbConfig = (PriorityLbConfig) childBalancer.config;
    assertThat(priorityLbConfig.priorities).containsExactly(CLUSTER1 + "[priority1]");
    PriorityChildConfig priorityChildConfig = Iterables.getOnlyElement(priorityLbConfig.childConfigs.values());
    assertThat(priorityChildConfig.policySelection.getProvider().getPolicyName()).isEqualTo(CLUSTER_IMPL_POLICY_NAME);
    ClusterImplConfig clusterImplConfig = (ClusterImplConfig) priorityChildConfig.policySelection.getConfig();
    assertClusterImplConfig(clusterImplConfig, CLUSTER1, EDS_SERVICE_NAME1, LRS_SERVER_INFO, 100L, tlsContext, Collections.<DropOverload>emptyList(), WEIGHTED_TARGET_POLICY_NAME);
    WeightedTargetConfig weightedTargetConfig = (WeightedTargetConfig) clusterImplConfig.childPolicy.getConfig();
    assertThat(weightedTargetConfig.targets.keySet()).containsExactly(locality1.toString());
}
Also used : PriorityChildConfig(io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig.PriorityChildConfig) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) PriorityLbConfig(io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) WeightedTargetConfig(io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedTargetConfig) LocalityLbEndpoints(io.grpc.xds.Endpoints.LocalityLbEndpoints) ClusterImplConfig(io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig) Test(org.junit.Test)

Aggregations

ClusterImplConfig (io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig)16 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)13 WeightedPolicySelection (io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedPolicySelection)11 PolicySelection (io.grpc.internal.ServiceConfigUtil.PolicySelection)10 WeightedTargetConfig (io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedTargetConfig)10 Test (org.junit.Test)10 LoadBalancerProvider (io.grpc.LoadBalancerProvider)8 PriorityChildConfig (io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig.PriorityChildConfig)7 Subchannel (io.grpc.LoadBalancer.Subchannel)6 ClusterResolverConfig (io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig)5 PriorityLbConfig (io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig)5 PickResult (io.grpc.LoadBalancer.PickResult)4 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)4 LocalityLbEndpoints (io.grpc.xds.Endpoints.LocalityLbEndpoints)4 ClusterStats (io.grpc.xds.Stats.ClusterStats)4 ClientStreamTracer (io.grpc.ClientStreamTracer)3 Metadata (io.grpc.Metadata)3 CreateSubchannelArgs (io.grpc.LoadBalancer.CreateSubchannelArgs)2 DropOverload (io.grpc.xds.Endpoints.DropOverload)2 Attributes (io.grpc.Attributes)1