use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig in project grpc-java by grpc.
the class ClusterResolverLoadBalancerTest method onlyLogicalDnsCluster_handleRefreshNameResolution.
@Test
public void onlyLogicalDnsCluster_handleRefreshNameResolution() {
ClusterResolverConfig config = new ClusterResolverConfig(Collections.singletonList(logicalDnsDiscoveryMechanism), roundRobin);
deliverLbConfig(config);
FakeNameResolver resolver = assertResolverCreated("/" + DNS_HOST_NAME);
assertThat(childBalancers).isEmpty();
EquivalentAddressGroup endpoint1 = makeAddress("endpoint-addr-1");
EquivalentAddressGroup endpoint2 = makeAddress("endpoint-addr-2");
resolver.deliverEndpointAddresses(Arrays.asList(endpoint1, endpoint2));
assertThat(resolver.refreshCount).isEqualTo(0);
verify(helper).ignoreRefreshNameResolutionCheck();
FakeLoadBalancer childBalancer = Iterables.getOnlyElement(childBalancers);
childBalancer.helper.refreshNameResolution();
assertThat(resolver.refreshCount).isEqualTo(1);
}
use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig 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);
}
use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig 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);
}
use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig 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());
}
use of io.grpc.xds.ClusterResolverLoadBalancerProvider.ClusterResolverConfig 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();
}
Aggregations