Search in sources :

Example 31 with ResolvedAddresses

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);
}
Also used : Status(io.grpc.Status) EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) UnsupportedClientTransportFactoryBuilder(io.grpc.internal.ManagedChannelImplBuilder.UnsupportedClientTransportFactoryBuilder) ResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses) Test(org.junit.Test)

Example 32 with ResolvedAddresses

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);
}
Also used : Helper(io.grpc.LoadBalancer.Helper) SubchannelPicker(io.grpc.LoadBalancer.SubchannelPicker) LoadBalancer(io.grpc.LoadBalancer) ResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses) Test(org.junit.Test)

Aggregations

ResolvedAddresses (io.grpc.LoadBalancer.ResolvedAddresses)32 Test (org.junit.Test)31 Attributes (io.grpc.Attributes)16 Status (io.grpc.Status)12 InOrder (org.mockito.InOrder)10 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)9 Subchannel (io.grpc.LoadBalancer.Subchannel)9 UnsupportedClientTransportFactoryBuilder (io.grpc.internal.ManagedChannelImplBuilder.UnsupportedClientTransportFactoryBuilder)9 Helper (io.grpc.LoadBalancer.Helper)8 SubchannelStateListener (io.grpc.LoadBalancer.SubchannelStateListener)8 LoadBalancer (io.grpc.LoadBalancer)4 ConfigOrError (io.grpc.NameResolver.ConfigOrError)3 AutoConfiguredLoadBalancer (io.grpc.internal.AutoConfiguredLoadBalancerFactory.AutoConfiguredLoadBalancer)3 PolicySelection (io.grpc.internal.ServiceConfigUtil.PolicySelection)3 ForwardingLoadBalancerHelper (io.grpc.util.ForwardingLoadBalancerHelper)3 InetSocketAddress (java.net.InetSocketAddress)3 ConnectivityStateInfo (io.grpc.ConnectivityStateInfo)2 InternalConfigSelector (io.grpc.InternalConfigSelector)2 ServingStatus (io.grpc.health.v1.HealthCheckResponse.ServingStatus)2 SocketAddress (java.net.SocketAddress)2