use of io.grpc.LoadBalancer.ResolvedAddresses in project grpc-java by grpc.
the class ServiceConfigErrorHandlingTest method emptyAddresses_validConfig_lbDoesNotNeedAddress.
@Test
public void emptyAddresses_validConfig_lbDoesNotNeedAddress() throws Exception {
FakeNameResolverFactory nameResolverFactory = new FakeNameResolverFactory.Builder(expectedUri).setServers(Collections.<EquivalentAddressGroup>emptyList()).build();
channelBuilder.nameResolverFactory(nameResolverFactory);
when(mockLoadBalancer.canHandleEmptyAddressListFromNameResolution()).thenReturn(true);
Map<String, Object> rawServiceConfig = parseJson("{\"loadBalancingConfig\": [{\"mock_lb\": {\"check\": \"val\"}}]}");
nameResolverFactory.nextRawServiceConfig.set(rawServiceConfig);
createChannel();
ArgumentCaptor<ResolvedAddresses> resultCaptor = ArgumentCaptor.forClass(ResolvedAddresses.class);
verify(mockLoadBalancer).handleResolvedAddresses(resultCaptor.capture());
ResolvedAddresses resolvedAddresses = resultCaptor.getValue();
assertThat(resolvedAddresses.getAddresses()).isEmpty();
assertThat(resolvedAddresses.getLoadBalancingPolicyConfig()).isEqualTo("val");
;
verify(mockLoadBalancer, never()).handleNameResolutionError(any(Status.class));
assertThat(channel.getState(false)).isNotEqualTo(ConnectivityState.TRANSIENT_FAILURE);
}
use of io.grpc.LoadBalancer.ResolvedAddresses in project grpc-java by grpc.
the class GracefulSwitchLoadBalancerTest method handleResolvedAddressesAndNameResolutionErrorForwardedToLatestPolicy.
@Test
public void handleResolvedAddressesAndNameResolutionErrorForwardedToLatestPolicy() {
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[0]));
LoadBalancer lb0 = balancers.get(lbPolicies[0]);
Helper helper0 = helpers.get(lb0);
SubchannelPicker picker = mock(SubchannelPicker.class);
helper0.updateBalancingState(READY, picker);
ResolvedAddresses addresses = newFakeAddresses();
gracefulSwitchLb.handleResolvedAddresses(addresses);
verify(lb0).handleResolvedAddresses(addresses);
gracefulSwitchLb.handleNameResolutionError(Status.DATA_LOSS);
verify(lb0).handleNameResolutionError(Status.DATA_LOSS);
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[1]));
LoadBalancer lb1 = balancers.get(lbPolicies[1]);
addresses = newFakeAddresses();
gracefulSwitchLb.handleResolvedAddresses(addresses);
verify(lb0, never()).handleResolvedAddresses(addresses);
verify(lb1).handleResolvedAddresses(addresses);
gracefulSwitchLb.handleNameResolutionError(Status.ALREADY_EXISTS);
verify(lb0, never()).handleNameResolutionError(Status.ALREADY_EXISTS);
verify(lb1).handleNameResolutionError(Status.ALREADY_EXISTS);
gracefulSwitchLb.switchTo(lbProviders.get(lbPolicies[2]));
verify(lb1).shutdown();
LoadBalancer lb2 = balancers.get(lbPolicies[2]);
addresses = newFakeAddresses();
gracefulSwitchLb.handleResolvedAddresses(addresses);
verify(lb0, never()).handleResolvedAddresses(addresses);
verify(lb1, never()).handleResolvedAddresses(addresses);
verify(lb2).handleResolvedAddresses(addresses);
gracefulSwitchLb.handleNameResolutionError(Status.CANCELLED);
verify(lb0, never()).handleNameResolutionError(Status.CANCELLED);
verify(lb1, never()).handleNameResolutionError(Status.CANCELLED);
verify(lb2).handleNameResolutionError(Status.CANCELLED);
verifyNoMoreInteractions(lb0, lb1, lb2);
}
Aggregations