Java Code Examples for io.grpc.ConnectivityStateInfo#forTransientFailure()

The following examples show how to use io.grpc.ConnectivityStateInfo#forTransientFailure() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HealthCheckingLoadBalancerFactoryTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void serviceConfigDisablesHealthCheckWhenRpcInactive() {
  Attributes resolutionAttrs = attrsWithHealthCheckService("TeeService");
  hcLbEventDelivery.handleResolvedAddressGroups(resolvedAddressList, resolutionAttrs);

  verify(origLb).handleResolvedAddressGroups(same(resolvedAddressList), same(resolutionAttrs));
  verifyNoMoreInteractions(origLb);

  Subchannel subchannel = createSubchannel(0, Attributes.EMPTY);
  assertThat(subchannel).isSameAs(subchannels[0]);
  InOrder inOrder = inOrder(origLb);

  // Underlying subchannel is not READY initially
  ConnectivityStateInfo underlyingErrorState =
      ConnectivityStateInfo.forTransientFailure(
          Status.UNAVAILABLE.withDescription("connection refused"));
  hcLbEventDelivery.handleSubchannelState(subchannel, underlyingErrorState);
  inOrder.verify(origLb).handleSubchannelState(same(subchannel), same(underlyingErrorState));
  inOrder.verifyNoMoreInteractions();

  // NameResolver gives an update without service config, thus health check will be disabled
  hcLbEventDelivery.handleResolvedAddressGroups(resolvedAddressList, Attributes.EMPTY);

  inOrder.verify(origLb).handleResolvedAddressGroups(
      same(resolvedAddressList), same(Attributes.EMPTY));

  // Underlying subchannel is now ready
  hcLbEventDelivery.handleSubchannelState(subchannel, ConnectivityStateInfo.forNonError(READY));

  // Since health check is disabled, READY state is propagated directly.
  inOrder.verify(origLb).handleSubchannelState(
      same(subchannel), eq(ConnectivityStateInfo.forNonError(READY)));

  // and there is no health check activity.
  assertThat(healthImpls[0].calls).isEmpty();

  verifyNoMoreInteractions(origLb);
}
 
Example 2
Source File: HealthCheckingLoadBalancerFactoryTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Test
public void serviceConfigChangesServiceNameWhenRpcInactive() {
  Attributes resolutionAttrs = attrsWithHealthCheckService("TeeService");
  hcLbEventDelivery.handleResolvedAddressGroups(resolvedAddressList, resolutionAttrs);

  verify(origLb).handleResolvedAddressGroups(same(resolvedAddressList), same(resolutionAttrs));
  verifyNoMoreInteractions(origLb);

  Subchannel subchannel = createSubchannel(0, Attributes.EMPTY);
  assertThat(subchannel).isSameAs(subchannels[0]);
  InOrder inOrder = inOrder(origLb);
  HealthImpl healthImpl = healthImpls[0];

  // Underlying subchannel is not READY initially
  ConnectivityStateInfo underlyingErrorState =
      ConnectivityStateInfo.forTransientFailure(
          Status.UNAVAILABLE.withDescription("connection refused"));
  hcLbEventDelivery.handleSubchannelState(subchannel, underlyingErrorState);
  inOrder.verify(origLb).handleSubchannelState(same(subchannel), same(underlyingErrorState));
  inOrder.verifyNoMoreInteractions();

  // Service config returns with the same health check name.
  hcLbEventDelivery.handleResolvedAddressGroups(resolvedAddressList, resolutionAttrs);
  // It's delivered to origLb, but nothing else happens
  inOrder.verify(origLb).handleResolvedAddressGroups(
      same(resolvedAddressList), same(resolutionAttrs));
  assertThat(healthImpl.calls).isEmpty();
  verifyNoMoreInteractions(origLb);

  // Service config returns a different health check name.
  resolutionAttrs = attrsWithHealthCheckService("FooService");
  hcLbEventDelivery.handleResolvedAddressGroups(resolvedAddressList, resolutionAttrs);

  inOrder.verify(origLb).handleResolvedAddressGroups(
      same(resolvedAddressList), same(resolutionAttrs));

  // Underlying subchannel is now ready
  hcLbEventDelivery.handleSubchannelState(subchannel, ConnectivityStateInfo.forNonError(READY));

  // Concluded CONNECTING state
  inOrder.verify(origLb).handleSubchannelState(
      same(subchannel), eq(ConnectivityStateInfo.forNonError(CONNECTING)));

  // Health check RPC is started
  assertThat(healthImpl.calls).hasSize(1);
  // with the new service name
  assertThat(healthImpl.calls.poll().request).isEqualTo(makeRequest("FooService"));

  verifyNoMoreInteractions(origLb);
}
 
Example 3
Source File: HealthCheckingLoadBalancerFactoryTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void serviceConfigDisablesHealthCheckWhenRpcInactive() {
  Attributes resolutionAttrs = attrsWithHealthCheckService("TeeService");
  ResolvedAddresses result1 = ResolvedAddresses.newBuilder()
      .setAddresses(resolvedAddressList)
      .setAttributes(resolutionAttrs)
      .build();
  hcLbEventDelivery.handleResolvedAddresses(result1);

  verify(origLb).handleResolvedAddresses(result1);
  verifyNoMoreInteractions(origLb);

  Subchannel subchannel = createSubchannel(0, Attributes.EMPTY);
  assertThat(unwrap(subchannel)).isSameInstanceAs(subchannels[0]);
  InOrder inOrder = inOrder(origLb, mockStateListeners[0]);

  // Underlying subchannel is not READY initially
  ConnectivityStateInfo underlyingErrorState =
      ConnectivityStateInfo.forTransientFailure(
          Status.UNAVAILABLE.withDescription("connection refused"));
  deliverSubchannelState(0, underlyingErrorState);
  inOrder.verify(mockStateListeners[0]).onSubchannelState(same(underlyingErrorState));
  inOrder.verifyNoMoreInteractions();

  // 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);

  inOrder.verify(origLb).handleResolvedAddresses(result2);

  // Underlying subchannel is now ready
  deliverSubchannelState(0, ConnectivityStateInfo.forNonError(READY));

  // Since health check is disabled, READY state is propagated directly.
  inOrder.verify(mockStateListeners[0]).onSubchannelState(
      eq(ConnectivityStateInfo.forNonError(READY)));

  // and there is no health check activity.
  assertThat(healthImpls[0].calls).isEmpty();

  verifyNoMoreInteractions(origLb, mockStateListeners[0]);
}
 
Example 4
Source File: HealthCheckingLoadBalancerFactoryTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Test
public void serviceConfigChangesServiceNameWhenRpcInactive() {
  Attributes resolutionAttrs = attrsWithHealthCheckService("TeeService");
  ResolvedAddresses result1 = ResolvedAddresses.newBuilder()
      .setAddresses(resolvedAddressList)
      .setAttributes(resolutionAttrs)
      .build();
  hcLbEventDelivery.handleResolvedAddresses(result1);

  verify(origLb).handleResolvedAddresses(result1);
  verifyNoMoreInteractions(origLb);

  Subchannel subchannel = createSubchannel(0, Attributes.EMPTY);
  SubchannelStateListener mockListener = mockStateListeners[0];
  assertThat(unwrap(subchannel)).isSameInstanceAs(subchannels[0]);
  InOrder inOrder = inOrder(origLb, mockListener);
  HealthImpl healthImpl = healthImpls[0];

  // Underlying subchannel is not READY initially
  ConnectivityStateInfo underlyingErrorState =
      ConnectivityStateInfo.forTransientFailure(
          Status.UNAVAILABLE.withDescription("connection refused"));
  deliverSubchannelState(0, underlyingErrorState);
  inOrder.verify(mockListener).onSubchannelState(same(underlyingErrorState));
  inOrder.verifyNoMoreInteractions();

  // Service config returns with the same health check name.
  hcLbEventDelivery.handleResolvedAddresses(result1);
  // It's delivered to origLb, but nothing else happens
  inOrder.verify(origLb).handleResolvedAddresses(result1);
  assertThat(healthImpl.calls).isEmpty();
  verifyNoMoreInteractions(origLb);

  // Service config returns a different health check name.
  resolutionAttrs = attrsWithHealthCheckService("FooService");
  ResolvedAddresses result2 = ResolvedAddresses.newBuilder()
      .setAddresses(resolvedAddressList)
      .setAttributes(resolutionAttrs)
      .build();
  hcLbEventDelivery.handleResolvedAddresses(result2);

  inOrder.verify(origLb).handleResolvedAddresses(result2);

  // Underlying subchannel is now ready
  deliverSubchannelState(0, ConnectivityStateInfo.forNonError(READY));

  // Concluded CONNECTING state
  inOrder.verify(mockListener).onSubchannelState(
      eq(ConnectivityStateInfo.forNonError(CONNECTING)));

  // Health check RPC is started
  assertThat(healthImpl.calls).hasSize(1);
  // with the new service name
  assertThat(healthImpl.calls.poll().request).isEqualTo(makeRequest("FooService"));

  verifyNoMoreInteractions(origLb, mockListener);
}