use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancerTest method resolutionErrorAfterChildLbCreated_propagateErrorIfAllClustersEncounterError.
@Test
public void resolutionErrorAfterChildLbCreated_propagateErrorIfAllClustersEncounterError() {
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 endpoint = makeAddress("endpoint-addr-1");
LocalityLbEndpoints localityLbEndpoints = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint, 100, true)), 10, /* localityWeight */
1);
xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, Collections.singletonMap(locality1, localityLbEndpoints));
// not created until all clusters resolved.
assertThat(childBalancers).isEmpty();
resolver.deliverError(Status.UNKNOWN.withDescription("I am lost"));
// DNS resolution failed, but there are EDS endpoints can be used.
assertThat(childBalancers).hasSize(1);
// child LB created
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
// should not propagate error to child LB
assertThat(childBalancer.upstreamError).isNull();
assertAddressesEqual(Collections.singletonList(endpoint), childBalancer.addresses);
xdsClient.deliverError(Status.RESOURCE_EXHAUSTED.withDescription("out of memory"));
// last cluster's (DNS) error propagated
assertThat(childBalancer.upstreamError).isNotNull();
assertThat(childBalancer.upstreamError.getCode()).isEqualTo(Code.UNKNOWN);
assertThat(childBalancer.upstreamError.getDescription()).isEqualTo("I am lost");
assertThat(childBalancer.shutdown).isFalse();
verify(helper, never()).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), any(SubchannelPicker.class));
}
use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancerTest method handleEdsResource_noHealthyEndpoint.
@Test
public void handleEdsResource_noHealthyEndpoint() {
ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(edsDiscoveryMechanism1), roundRobin);
deliverLbConfig(config);
EquivalentAddressGroup endpoint = makeAddress("endpoint-addr-1");
LocalityLbEndpoints localityLbEndpoints = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint, 100, false)), 10, /* localityWeight */
1);
xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, // single endpoint, unhealthy
Collections.singletonMap(locality1, localityLbEndpoints));
assertThat(childBalancers).isEmpty();
verify(helper).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
assertPicker(pickerCaptor.getValue(), Status.UNAVAILABLE.withDescription("No usable endpoint from cluster(s): " + Collections.singleton(CLUSTER1)), null);
}
use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancerTest method onlyEdsClusters_receivedEndpoints.
@Test
public void onlyEdsClusters_receivedEndpoints() {
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();
// CLUSTER1 has priority 1 (priority3), which has locality 2, which has endpoint3.
// CLUSTER2 has priority 1 (priority1) and 2 (priority2); priority1 has locality1,
// which has endpoint1 and endpoint2; priority2 has locality3, which has endpoint4.
EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
EquivalentAddressGroup endpoint3 = makeAddress("endpoint-addr-3");
EquivalentAddressGroup endpoint4 = makeAddress("endpoint-addr-4");
LocalityLbEndpoints localityLbEndpoints1 = LocalityLbEndpoints.create(Arrays.asList(LbEndpoint.create(endpoint1, 100, true), LbEndpoint.create(endpoint2, 100, true)), 70, /* localityWeight */
1);
LocalityLbEndpoints localityLbEndpoints2 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint3, 100, true)), 10, /* localityWeight */
1);
LocalityLbEndpoints localityLbEndpoints3 = LocalityLbEndpoints.create(Collections.singletonList(LbEndpoint.create(endpoint4, 100, true)), 20, /* localityWeight */
2);
String priority1 = CLUSTER2 + "[priority1]";
String priority2 = CLUSTER2 + "[priority2]";
String priority3 = CLUSTER1 + "[priority1]";
// CLUSTER2: locality1 with priority 1 and locality3 with priority 2.
xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME2, ImmutableMap.of(locality1, localityLbEndpoints1, locality3, localityLbEndpoints3));
// not created until all clusters resolved
assertThat(childBalancers).isEmpty();
// CLUSTER1: locality2 with priority 1.
xdsClient.deliverClusterLoadAssignment(EDS_SERVICE_NAME1, Collections.singletonMap(locality2, localityLbEndpoints2));
// Endpoints of all clusters have been resolved.
assertThat(childBalancers).hasSize(1);
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
assertThat(childBalancer.name).isEqualTo(PRIORITY_POLICY_NAME);
PriorityLbConfig priorityLbConfig = (PriorityLbConfig) childBalancer.config;
assertThat(priorityLbConfig.priorities).containsExactly(priority3, priority1, priority2).inOrder();
PriorityChildConfig priorityChildConfig1 = priorityLbConfig.childConfigs.get(priority1);
assertThat(priorityChildConfig1.ignoreReresolution).isTrue();
assertThat(priorityChildConfig1.policySelection.getProvider().getPolicyName()).isEqualTo(CLUSTER_IMPL_POLICY_NAME);
ClusterImplConfig clusterImplConfig1 = (ClusterImplConfig) priorityChildConfig1.policySelection.getConfig();
assertClusterImplConfig(clusterImplConfig1, CLUSTER2, EDS_SERVICE_NAME2, LRS_SERVER_INFO, 200L, tlsContext, Collections.<DropOverload>emptyList(), WEIGHTED_TARGET_POLICY_NAME);
WeightedTargetConfig weightedTargetConfig1 = (WeightedTargetConfig) clusterImplConfig1.childPolicy.getConfig();
assertThat(weightedTargetConfig1.targets.keySet()).containsExactly(locality1.toString());
WeightedPolicySelection target1 = weightedTargetConfig1.targets.get(locality1.toString());
assertThat(target1.weight).isEqualTo(70);
assertThat(target1.policySelection.getProvider().getPolicyName()).isEqualTo("round_robin");
PriorityChildConfig priorityChildConfig2 = priorityLbConfig.childConfigs.get(priority2);
assertThat(priorityChildConfig2.ignoreReresolution).isTrue();
assertThat(priorityChildConfig2.policySelection.getProvider().getPolicyName()).isEqualTo(CLUSTER_IMPL_POLICY_NAME);
ClusterImplConfig clusterImplConfig2 = (ClusterImplConfig) priorityChildConfig2.policySelection.getConfig();
assertClusterImplConfig(clusterImplConfig2, CLUSTER2, EDS_SERVICE_NAME2, LRS_SERVER_INFO, 200L, tlsContext, Collections.<DropOverload>emptyList(), WEIGHTED_TARGET_POLICY_NAME);
WeightedTargetConfig weightedTargetConfig2 = (WeightedTargetConfig) clusterImplConfig2.childPolicy.getConfig();
assertThat(weightedTargetConfig2.targets.keySet()).containsExactly(locality3.toString());
WeightedPolicySelection target2 = weightedTargetConfig2.targets.get(locality3.toString());
assertThat(target2.weight).isEqualTo(20);
assertThat(target2.policySelection.getProvider().getPolicyName()).isEqualTo("round_robin");
List<EquivalentAddressGroup> priorityAddrs1 = AddressFilter.filter(childBalancer.addresses, priority1);
assertThat(priorityAddrs1).hasSize(2);
assertAddressesEqual(Arrays.asList(endpoint1, endpoint2), priorityAddrs1);
List<EquivalentAddressGroup> priorityAddrs2 = AddressFilter.filter(childBalancer.addresses, priority2);
assertThat(priorityAddrs2).hasSize(1);
assertAddressesEqual(Collections.singletonList(endpoint4), priorityAddrs2);
PriorityChildConfig priorityChildConfig3 = priorityLbConfig.childConfigs.get(priority3);
assertThat(priorityChildConfig3.ignoreReresolution).isTrue();
assertThat(priorityChildConfig3.policySelection.getProvider().getPolicyName()).isEqualTo(CLUSTER_IMPL_POLICY_NAME);
ClusterImplConfig clusterImplConfig3 = (ClusterImplConfig) priorityChildConfig3.policySelection.getConfig();
assertClusterImplConfig(clusterImplConfig3, CLUSTER1, EDS_SERVICE_NAME1, LRS_SERVER_INFO, 100L, tlsContext, Collections.<DropOverload>emptyList(), WEIGHTED_TARGET_POLICY_NAME);
WeightedTargetConfig weightedTargetConfig3 = (WeightedTargetConfig) clusterImplConfig3.childPolicy.getConfig();
assertThat(weightedTargetConfig3.targets.keySet()).containsExactly(locality2.toString());
WeightedPolicySelection target3 = weightedTargetConfig3.targets.get(locality2.toString());
assertThat(target3.weight).isEqualTo(10);
assertThat(target3.policySelection.getProvider().getPolicyName()).isEqualTo("round_robin");
List<EquivalentAddressGroup> priorityAddrs3 = AddressFilter.filter(childBalancer.addresses, priority3);
assertThat(priorityAddrs3).hasSize(1);
assertAddressesEqual(Collections.singletonList(endpoint3), priorityAddrs3);
}
use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancerTest method onlyEdsClusters_resourceNeverExist_returnErrorPicker.
@Test
public void onlyEdsClusters_resourceNeverExist_returnErrorPicker() {
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);
xdsClient.deliverResourceNotFound(EDS_SERVICE_NAME1);
verify(helper, never()).updateBalancingState(any(ConnectivityState.class), // wait for CLUSTER2's results
any(SubchannelPicker.class));
xdsClient.deliverResourceNotFound(EDS_SERVICE_NAME2);
verify(helper).updateBalancingState(eq(ConnectivityState.TRANSIENT_FAILURE), pickerCaptor.capture());
assertPicker(pickerCaptor.getValue(), Status.UNAVAILABLE.withDescription("No usable endpoint from cluster(s): " + Arrays.asList(CLUSTER1, CLUSTER2)), null);
}
use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancerTest method onlyLogicalDnsCluster_refreshNameResolutionRaceWithResolutionError.
@Test
public void onlyLogicalDnsCluster_refreshNameResolutionRaceWithResolutionError() {
InOrder inOrder = Mockito.inOrder(backoffPolicyProvider, backoffPolicy1, backoffPolicy2);
ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(logicalDnsDiscoveryMechanism), roundRobin);
deliverLbConfig(config);
FakeNameResolver resolver = assertResolverCreated("/" + DNS_HOST_NAME);
assertThat(childBalancers).isEmpty();
EquivalentAddressGroup endpoint = makeAddress("endpoint-addr");
resolver.deliverEndpointAddresses(Collections.singletonList(endpoint));
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
assertAddressesEqual(Collections.singletonList(endpoint), childBalancer.addresses);
assertThat(resolver.refreshCount).isEqualTo(0);
verify(helper).ignoreRefreshNameResolutionCheck();
childBalancer.helper.refreshNameResolution();
assertThat(resolver.refreshCount).isEqualTo(1);
resolver.deliverError(Status.UNAVAILABLE.withDescription("I am lost"));
inOrder.verify(backoffPolicyProvider).get();
inOrder.verify(backoffPolicy1).nextBackoffNanos();
assertThat(fakeClock.getPendingTasks()).hasSize(1);
ScheduledTask task = Iterables.getOnlyElement(fakeClock.getPendingTasks());
assertThat(task.getDelay(TimeUnit.SECONDS)).isEqualTo(1L);
fakeClock.forwardTime(100L, TimeUnit.MILLISECONDS);
childBalancer.helper.refreshNameResolution();
assertThat(resolver.refreshCount).isEqualTo(2);
assertThat(task.isCancelled()).isTrue();
assertThat(fakeClock.getPendingTasks()).isEmpty();
resolver.deliverError(Status.UNAVAILABLE.withDescription("I am still lost"));
// active refresh resets backoff sequence
inOrder.verify(backoffPolicyProvider).get();
inOrder.verify(backoffPolicy2).nextBackoffNanos();
task = Iterables.getOnlyElement(fakeClock.getPendingTasks());
assertThat(task.getDelay(TimeUnit.SECONDS)).isEqualTo(5L);
fakeClock.forwardTime(5L, TimeUnit.SECONDS);
assertThat(resolver.refreshCount).isEqualTo(3);
inOrder.verifyNoMoreInteractions();
}
Aggregations