Search in sources :

Example 26 with EquivalentAddressGroup

use of io.grpc.EquivalentAddressGroup in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method onlyEdsClusters_allResourcesRevoked_shutDownChildLbPolicy.

@Test
public void onlyEdsClusters_allResourcesRevoked_shutDownChildLbPolicy() {
    ClusterResolverConfig config = new ClusterResolverConfig(Arrays.asList(edsDiscoveryMechanism1, edsDiscoveryMechanism2), roundRobin);
    deliverLbConfig(config);
    assertThat(xdsClient.watchers.keySet()).containsExactly(EDS_SERVICE_NAME1, EDS_SERVICE_NAME2);
    assertThat(childBalancers).isEmpty();
    reset(helper);
    EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
    EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
    LocalityLbEndpoints localityLbEndpoints1 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint1, 100, true)), 10, /* localityWeight */
    1);
    LocalityLbEndpoints localityLbEndpoints2 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint2, 100, true)), 20, /* localityWeight */
    2);
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, Collections.singletonMap(locality1, localityLbEndpoints1));
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME2, Collections.singletonMap(locality2, localityLbEndpoints2));
    // child LB policy created
    assertThat(childBalancers).hasSize(1);
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    assertThat(((PriorityLbConfig) childBalancer.config).priorities).hasSize(2);
    assertAddressesEqual(Arrays.asList(endpoint1, endpoint2), childBalancer.addresses);
    xdsClient.deliverResourceNotFound(EDS_SERVICE_NAME2);
    xdsClient.deliverResourceNotFound(EDS_SERVICE_NAME1);
    verify(helper).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
    Status expectedError = Status.UNAVAILABLE.withDescription("No usable endpoint from cluster(s): " + Arrays.asList(CLUSTER1, CLUSTER2));
    assertPicker(pickerCaptor.getValue(), expectedError, null);
}
Also used : Status(io.grpc.Status) 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)

Example 27 with EquivalentAddressGroup

use of io.grpc.EquivalentAddressGroup in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method handleEdsResource_ignoreUnhealthyEndpoints.

@Test
public void handleEdsResource_ignoreUnhealthyEndpoints() {
    ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(edsDiscoveryMechanism1), roundRobin);
    deliverLbConfig(config);
    EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
    EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
    LocalityLbEndpoints localityLbEndpoints = LocalityLbEndpoints.create(Arrays.asList(LbEndpoint.create(endpoint1, 100, false), LbEndpoint.create(endpoint2, 100, true)), 10, /* localityWeight */
    1);
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, Collections.singletonMap(locality1, localityLbEndpoints));
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    assertThat(childBalancer.addresses).hasSize(1);
    assertAddressesEqual(Collections.singletonList(endpoint2), childBalancer.addresses);
}
Also used : EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) LocalityLbEndpoints(io.grpc.xds.Endpoints.LocalityLbEndpoints) Test(org.junit.Test)

Example 28 with EquivalentAddressGroup

use of io.grpc.EquivalentAddressGroup in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method handleEdsResource_ignoreLocalitiesWithNoHealthyEndpoints.

@Test
public void handleEdsResource_ignoreLocalitiesWithNoHealthyEndpoints() {
    ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(edsDiscoveryMechanism1), roundRobin);
    deliverLbConfig(config);
    EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
    EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
    LocalityLbEndpoints localityLbEndpoints1 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint1, 100, false)), 10, /* localityWeight */
    1);
    LocalityLbEndpoints localityLbEndpoints2 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint2, 100, true)), 10, /* localityWeight */
    1);
    String priority = CLUSTER1 + "[priority1]";
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, ImmutableMap.of(locality1, localityLbEndpoints1, locality2, localityLbEndpoints2));
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    PriorityLbConfig priorityLbConfig = (PriorityLbConfig) childBalancer.config;
    PriorityChildConfig priorityChildConfig = priorityLbConfig.childConfigs.get(priority);
    ClusterImplConfig clusterImplConfig = (ClusterImplConfig) priorityChildConfig.policySelection.getConfig();
    WeightedTargetConfig weightedTargetConfig = (WeightedTargetConfig) clusterImplConfig.childPolicy.getConfig();
    assertThat(weightedTargetConfig.targets.keySet()).containsExactly(locality2.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 29 with EquivalentAddressGroup

use of io.grpc.EquivalentAddressGroup in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method onlyLogicalDnsCluster_resolutionError_backoffAndRefresh.

@Test
public void onlyLogicalDnsCluster_resolutionError_backoffAndRefresh() {
    InOrder inOrder = Mockito.inOrder(helper, backoffPolicyProvider, backoffPolicy1, backoffPolicy2);
    ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(logicalDnsDiscoveryMechanism), roundRobin);
    deliverLbConfig(config);
    FakeNameResolver resolver = assertResolverCreated("/" + DNS_HOST_NAME);
    assertThat(childBalancers).isEmpty();
    Status error = Status.UNAVAILABLE.withDescription("cannot reach DNS server");
    resolver.deliverError(error);
    inOrder.verify(helper).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
    assertPicker(pickerCaptor.getValue(), error, null);
    assertThat(resolver.refreshCount).isEqualTo(0);
    inOrder.verify(backoffPolicyProvider).get();
    inOrder.verify(backoffPolicy1).nextBackoffNanos();
    assertThat(fakeClock.getPendingTasks()).hasSize(1);
    assertThat(Iterables.getOnlyElement(fakeClock.getPendingTasks()).getDelay(TimeUnit.SECONDS)).isEqualTo(1L);
    fakeClock.forwardTime(1L, TimeUnit.SECONDS);
    assertThat(resolver.refreshCount).isEqualTo(1);
    error = Status.UNKNOWN.withDescription("I am lost");
    resolver.deliverError(error);
    inOrder.verify(helper).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
    inOrder.verify(backoffPolicy1).nextBackoffNanos();
    assertPicker(pickerCaptor.getValue(), error, null);
    assertThat(fakeClock.getPendingTasks()).hasSize(1);
    assertThat(Iterables.getOnlyElement(fakeClock.getPendingTasks()).getDelay(TimeUnit.SECONDS)).isEqualTo(10L);
    fakeClock.forwardTime(10L, TimeUnit.SECONDS);
    assertThat(resolver.refreshCount).isEqualTo(2);
    // Succeed.
    EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
    EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
    resolver.deliverEndpointAddresses(Arrays.asList(endpoint1, endpoint2));
    assertThat(childBalancers).hasSize(1);
    assertAddressesEqual(Arrays.asList(endpoint1, endpoint2), Iterables.getOnlyElement(childBalancers).addresses);
    assertThat(fakeClock.getPendingTasks()).isEmpty();
    inOrder.verifyNoMoreInteractions();
}
Also used : Status(io.grpc.Status) InOrder(org.mockito.InOrder) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) ClusterResolverConfig(io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig) Test(org.junit.Test)

Example 30 with EquivalentAddressGroup

use of io.grpc.EquivalentAddressGroup in project grpc-java by grpc.

the class ClusterResolverLoadBalancerTest method handleEdsResource_ignorePrioritiesWithNoHealthyEndpoints.

@Test
public void handleEdsResource_ignorePrioritiesWithNoHealthyEndpoints() {
    ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(edsDiscoveryMechanism1), roundRobin);
    deliverLbConfig(config);
    EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
    EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
    LocalityLbEndpoints localityLbEndpoints1 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint1, 100, false)), 10, /* localityWeight */
    1);
    LocalityLbEndpoints localityLbEndpoints2 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint2, 200, true)), 10, /* localityWeight */
    2);
    String priority2 = CLUSTER1 + "[priority2]";
    xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, ImmutableMap.of(locality1, localityLbEndpoints1, locality2, localityLbEndpoints2));
    FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
    assertThat(((PriorityLbConfig) childBalancer.config).priorities).containsExactly(priority2);
}
Also used : 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

EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)173 Test (org.junit.Test)133 Subchannel (io.grpc.LoadBalancer.Subchannel)54 SocketAddress (java.net.SocketAddress)42 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)41 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)39 Status (io.grpc.Status)39 Attributes (io.grpc.Attributes)37 CreateSubchannelArgs (io.grpc.LoadBalancer.CreateSubchannelArgs)33 InOrder (org.mockito.InOrder)31 Helper (io.grpc.LoadBalancer.Helper)30 Metadata (io.grpc.Metadata)29 ArrayList (java.util.ArrayList)26 InetSocketAddress (java.net.InetSocketAddress)24 PickResult (io.grpc.LoadBalancer.PickResult)22 UnsupportedClientTransportFactoryBuilder (io.grpc.internal.ManagedChannelImplBuilder.UnsupportedClientTransportFactoryBuilder)20 PolicySelection (io.grpc.internal.ServiceConfigUtil.PolicySelection)20 InitialLoadBalanceResponse (io.grpc.lb.v1.InitialLoadBalanceResponse)19 LoadBalanceResponse (io.grpc.lb.v1.LoadBalanceResponse)19 ClientTransportFactoryBuilder (io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder)18