Search in sources :

Example 11 with ResolvedAddresses

use of io.grpc.LoadBalancer.ResolvedAddresses in project grpc-java by grpc.

the class HealthCheckingLoadBalancerFactoryTest method serviceConfigDisablesHealthCheckWhenRetryPending.

@Test
public void serviceConfigDisablesHealthCheckWhenRetryPending() {
    Attributes resolutionAttrs = attrsWithHealthCheckService("TeeService");
    ResolvedAddresses result = ResolvedAddresses.newBuilder().setAddresses(resolvedAddressList).setAttributes(resolutionAttrs).build();
    hcLbEventDelivery.handleResolvedAddresses(result);
    verify(origLb).handleResolvedAddresses(result);
    verifyNoMoreInteractions(origLb);
    Subchannel subchannel = createSubchannel(0, Attributes.EMPTY);
    assertThat(unwrap(subchannel)).isSameInstanceAs(subchannels[0]);
    InOrder inOrder = inOrder(origLb, mockStateListeners[0]);
    deliverSubchannelState(0, ConnectivityStateInfo.forNonError(READY));
    inOrder.verify(mockStateListeners[0]).onSubchannelState(eq(ConnectivityStateInfo.forNonError(CONNECTING)));
    inOrder.verifyNoMoreInteractions();
    HealthImpl healthImpl = healthImpls[0];
    assertThat(healthImpl.calls).hasSize(1);
    // Server closes the stream without responding.  Client in retry backoff
    assertThat(clock.getPendingTasks()).isEmpty();
    healthImpl.calls.poll().responseObserver.onCompleted();
    assertThat(clock.getPendingTasks()).hasSize(1);
    inOrder.verify(mockStateListeners[0]).onSubchannelState(unavailableStateWithMsg("Health-check stream unexpectedly closed with " + Status.OK + " for 'TeeService'"));
    // NameResolver gives an update without service config, thus health check will be disabled
    ResolvedAddresses result2 = ResolvedAddresses.newBuilder().setAddresses(resolvedAddressList).setAttributes(Attributes.EMPTY).build();
    hcLbEventDelivery.handleResolvedAddresses(result2);
    // Retry timer is cancelled
    assertThat(clock.getPendingTasks()).isEmpty();
    // No retry was attempted
    assertThat(healthImpl.calls).isEmpty();
    // Subchannel uses original state
    inOrder.verify(mockStateListeners[0]).onSubchannelState(eq(ConnectivityStateInfo.forNonError(READY)));
    inOrder.verify(origLb).handleResolvedAddresses(result2);
    verifyNoMoreInteractions(origLb, mockStateListeners[0]);
}
Also used : InOrder(org.mockito.InOrder) Subchannel(io.grpc.LoadBalancer.Subchannel) Attributes(io.grpc.Attributes) ResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses) Test(org.junit.Test)

Example 12 with ResolvedAddresses

use of io.grpc.LoadBalancer.ResolvedAddresses in project grpc-java by grpc.

the class ManagedChannelImplTest method healthCheckingConfigPropagated.

@Test
public void healthCheckingConfigPropagated() throws Exception {
    LoadBalancerRegistry.getDefaultRegistry().register(mockLoadBalancerProvider);
    try {
        FakeNameResolverFactory nameResolverFactory = new FakeNameResolverFactory.Builder(expectedUri).setServers(Collections.singletonList(new EquivalentAddressGroup(socketAddress))).build();
        channelBuilder.nameResolverFactory(nameResolverFactory);
        Map<String, Object> rawServiceConfig = parseConfig("{\"healthCheckConfig\": {\"serviceName\": \"service1\"}}");
        ManagedChannelServiceConfig managedChannelServiceConfig = createManagedChannelServiceConfig(rawServiceConfig, null);
        nameResolverFactory.nextConfigOrError.set(ConfigOrError.fromConfig(managedChannelServiceConfig));
        createChannel();
        ArgumentCaptor<ResolvedAddresses> resultCaptor = ArgumentCaptor.forClass(ResolvedAddresses.class);
        verify(mockLoadBalancer).handleResolvedAddresses(resultCaptor.capture());
        assertThat(resultCaptor.getValue().getAttributes().get(LoadBalancer.ATTR_HEALTH_CHECKING_CONFIG)).containsExactly("serviceName", "service1");
    } finally {
        LoadBalancerRegistry.getDefaultRegistry().deregister(mockLoadBalancerProvider);
    }
}
Also used : EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) UnsupportedClientTransportFactoryBuilder(io.grpc.internal.ManagedChannelImplBuilder.UnsupportedClientTransportFactoryBuilder) ClientTransportFactoryBuilder(io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder) ResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses) Test(org.junit.Test)

Example 13 with ResolvedAddresses

use of io.grpc.LoadBalancer.ResolvedAddresses in project grpc-java by grpc.

the class ManagedChannelImplIdlenessTest method newCallExitsIdleness.

@Test
public void newCallExitsIdleness() throws Exception {
    ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
    call.start(mockCallListener, new Metadata());
    verify(mockLoadBalancerProvider).newLoadBalancer(any(Helper.class));
    deliverResolutionResult();
    ArgumentCaptor<ResolvedAddresses> resolvedAddressCaptor = ArgumentCaptor.forClass(ResolvedAddresses.class);
    verify(mockLoadBalancer).handleResolvedAddresses(resolvedAddressCaptor.capture());
    assertThat(resolvedAddressCaptor.getValue().getAddresses()).containsExactlyElementsIn(servers);
}
Also used : Helper(io.grpc.LoadBalancer.Helper) Metadata(io.grpc.Metadata) ResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses) Test(org.junit.Test)

Example 14 with ResolvedAddresses

use of io.grpc.LoadBalancer.ResolvedAddresses in project grpc-java by grpc.

the class ChildLbResolvedAddressFactoryTest method create.

@Test
public void create() {
    List<EquivalentAddressGroup> addrs = new ArrayList<>();
    addrs.add(new EquivalentAddressGroup(mock(SocketAddress.class)));
    Attributes attr = Attributes.newBuilder().build();
    ChildLbResolvedAddressFactory factory = new ChildLbResolvedAddressFactory(addrs, attr);
    Object config1 = new Object();
    ResolvedAddresses resolvedAddress = factory.create(config1);
    assertThat(resolvedAddress.getAddresses()).isEqualTo(addrs);
    assertThat(resolvedAddress.getAttributes()).isEqualTo(attr);
    assertThat(resolvedAddress.getLoadBalancingPolicyConfig()).isEqualTo(config1);
    Object config2 = "different object";
    resolvedAddress = factory.create(config2);
    assertThat(resolvedAddress.getAddresses()).isEqualTo(addrs);
    assertThat(resolvedAddress.getAttributes()).isEqualTo(attr);
    assertThat(resolvedAddress.getLoadBalancingPolicyConfig()).isEqualTo(config2);
}
Also used : EquivalentAddressGroup(io.grpc.EquivalentAddressGroup) ArrayList(java.util.ArrayList) Attributes(io.grpc.Attributes) ResolvedAddresses(io.grpc.LoadBalancer.ResolvedAddresses) Test(org.junit.Test)

Example 15 with ResolvedAddresses

use of io.grpc.LoadBalancer.ResolvedAddresses in project grpc-java by grpc.

the class ManagedChannelImplTest method nameResolverReturnsEmptySubLists_optionallyAllowed.

@Test
public void nameResolverReturnsEmptySubLists_optionallyAllowed() throws Exception {
    when(mockLoadBalancer.canHandleEmptyAddressListFromNameResolution()).thenReturn(true);
    // Pass a FakeNameResolverFactory with an empty list and LB config
    FakeNameResolverFactory nameResolverFactory = new FakeNameResolverFactory.Builder(expectedUri).build();
    String rawLbConfig = "{ \"setting1\": \"high\" }";
    Object parsedLbConfig = new Object();
    Map<String, Object> rawServiceConfig = parseConfig("{\"loadBalancingConfig\": [ {\"mock_lb\": " + rawLbConfig + " } ] }");
    ManagedChannelServiceConfig parsedServiceConfig = createManagedChannelServiceConfig(rawServiceConfig, new PolicySelection(mockLoadBalancerProvider, parsedLbConfig));
    nameResolverFactory.nextConfigOrError.set(ConfigOrError.fromConfig(parsedServiceConfig));
    channelBuilder.nameResolverFactory(nameResolverFactory);
    createChannel();
    // LoadBalancer received the empty list and the LB config
    verify(mockLoadBalancerProvider).newLoadBalancer(any(Helper.class));
    ArgumentCaptor<ResolvedAddresses> resultCaptor = ArgumentCaptor.forClass(ResolvedAddresses.class);
    verify(mockLoadBalancer).handleResolvedAddresses(resultCaptor.capture());
    assertThat(resultCaptor.getValue().getAddresses()).isEmpty();
    assertThat(resultCaptor.getValue().getLoadBalancingPolicyConfig()).isEqualTo(parsedLbConfig);
    // A no resolution retry
    assertEquals(0, timer.numPendingTasks(NAME_RESOLVER_REFRESH_TASK_FILTER));
}
Also used : Helper(io.grpc.LoadBalancer.Helper) PolicySelection(io.grpc.internal.ServiceConfigUtil.PolicySelection) 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