Search in sources :

Example 11 with LocalityLbEndpoints

use of io.grpc.xds.Endpoints.LocalityLbEndpoints in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method edsClustersAndLogicalDnsCluster_receivedEndpoints.

@Test
public void edsClustersAndLogicalDnsCluster_receivedEndpoints() {
    ClusterResolverConfig config = new ClusterResolverConfig(Arrays.asList(edsDiscoveryMechanism1, logicalDnsDiscoveryMechanism), roundRobin);
    deliverLbConfig(config);
    assertThat(xdsClient.watchers.keySet()).containsExactly(EDS_SERVICE_NAME1);
    FakeNameResolver resolver = assertResolverCreated("/" + DNS_HOST_NAME);
    assertThat(childBalancers).isEmpty();
    // DNS endpoint
    EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
    // DNS endpoint
    EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
    // EDS endpoint
    EquivalentAddressGroup endpoint3 = makeAddress("endpoint-addr-3");
    resolver.deliverEndpointAddresses(Arrays.asList(endpoint1, endpoint2));
    LocalityLbEndpoints localityLbEndpoints = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint3, 100, true)), 10, /* localityWeight */
    1);
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, Collections.singletonMap(locality1, localityLbEndpoints));
    assertThat(childBalancers).hasSize(1);
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    assertThat(((PriorityLbConfig) childBalancer.config).priorities).containsExactly(CLUSTER1 + "[priority1]", CLUSTER_DNS + "[priority0]").inOrder();
    assertAddressesEqual(Arrays.asList(endpoint3, endpoint1, endpoint2), // ordered by cluster then addresses
    childBalancer.addresses);
    assertAddressesEqual(AddressFilter.filter(AddressFilter.filter(childBalancer.addresses, CLUSTER1 + "[priority1]"), locality1.toString()), Collections.singletonList(endpoint3));
    assertAddressesEqual(AddressFilter.filter(AddressFilter.filter(childBalancer.addresses, CLUSTER_DNS + "[priority0]"), Locality.create("", "", "").toString()), Arrays.asList(endpoint1, endpoint2));
}
Also used : EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) LocalityLbEndpoints(io.grpc.xds.Endpoints.LocalityLbEndpoints) Test(org.junit.Test)

Example 12 with LocalityLbEndpoints

use of io.grpc.xds.Endpoints.LocalityLbEndpoints 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)

Example 13 with LocalityLbEndpoints

use of io.grpc.xds.Endpoints.LocalityLbEndpoints in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method handleNameResolutionErrorFromUpstream_afterChildLbCreated_fallThrough.

@Test
public void handleNameResolutionErrorFromUpstream_afterChildLbCreated_fallThrough() {
    ClusterResolverConfig config = new ClusterResolverConfig(Arrays.asList(edsDiscoveryMechanism1, logicalDnsDiscoveryMechanism), roundRobin);
    deliverLbConfig(config);
    assertThat(xdsClient.watchers.keySet()).containsExactly(EDS_SERVICE_NAME1);
    FakeNameResolver resolver = assertResolverCreated("/" + DNS_HOST_NAME);
    assertThat(childBalancers).isEmpty();
    reset(helper);
    EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
    EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
    LocalityLbEndpoints localityLbEndpoints = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint1, 100, true)), 10, /* localityWeight */
    1);
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, Collections.singletonMap(locality1, localityLbEndpoints));
    resolver.deliverEndpointAddresses(Collections.singletonList(endpoint2));
    assertThat(childBalancers).hasSize(1);
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    assertThat(((PriorityLbConfig) childBalancer.config).priorities).containsExactly(CLUSTER1 + "[priority1]", CLUSTER_DNS + "[priority0]");
    assertAddressesEqual(Arrays.asList(endpoint1, endpoint2), childBalancer.addresses);
    loadBalancer.handleNameResolutionError(Status.UNAVAILABLE.withDescription("unreachable"));
    assertThat(childBalancer.upstreamError.getCode()).isEqualTo(Code.UNAVAILABLE);
    assertThat(childBalancer.upstreamError.getDescription()).isEqualTo("unreachable");
    verify(helper, never()).updateBalancingState(any(ConnectivityState.class), any(SubchannelPicker.class));
}
Also used : SubchannelPicker(io.grpc.LoadBalancer.SubchannelPicker) ConnectivityState(io.grpc.ConnectivityState) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) PriorityLbConfig(io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) LocalityLbEndpoints(io.grpc.xds.Endpoints.LocalityLbEndpoints) Test(org.junit.Test)

Aggregations

LocalityLbEndpoints (io.grpc.xds.Endpoints.LocalityLbEndpoints)13 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)12 ClusterResolverConfig (io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig)12 Test (org.junit.Test)12 PriorityLbConfig (io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig)8 ClusterImplConfig (io.grpc.xds.ClusterImplLoadBalancerProvider.ClusterImplConfig)4 PriorityChildConfig (io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig.PriorityChildConfig)4 WeightedTargetConfig (io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedTargetConfig)3 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)2 LbPolicy (io.envoyproxy.envoy.config.cluster.v3.Cluster.LbPolicy)1 ConnectivityState (io.grpc.ConnectivityState)1 Status (io.grpc.Status)1 BackoffPolicy (io.grpc.internal.BackoffPolicy)1 DropOverload (io.grpc.xds.Endpoints.DropOverload)1 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)1 RingHashConfig (io.grpc.xds.RingHashLoadBalancer.RingHashConfig)1 HashPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy)1 RetryPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.RetryPolicy)1 WeightedPolicySelection (io.grpc.xds.WeightedTargetLoadBalancerProvider.WeightedPolicySelection)1 ArrayList (java.util.ArrayList)1