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]);
}
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);
}
}
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);
}
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);
}
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));
}
Aggregations