mirror of https://github.com/grpc/grpc-java.git
core: fix a bug in health check config propgation. (#6804)
The condition "effectiveServiceConfig != validServiceConfig" should
have been deleted in commit 2162ad0436.
The condition was there before that commit because
NAME_RESOLVER_SERVICE_CONFIG was already in "attrs", thus it needed to
be re-added only if "effectiveServiceConfig" differs from the original
"validServiceConfig".
In contrast, ATTR_HEALTH_CHECKING_CONFIG is not in the original
"attrs" and always needs to be added.
This commit is contained in:
parent
7be75a0bcb
commit
4a2c5d6e9c
|
|
@ -1399,7 +1399,6 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
Attributes effectiveAttrs = resolutionResult.getAttributes();
|
Attributes effectiveAttrs = resolutionResult.getAttributes();
|
||||||
// Call LB only if it's not shutdown. If LB is shutdown, lbHelper won't match.
|
// Call LB only if it's not shutdown. If LB is shutdown, lbHelper won't match.
|
||||||
if (NameResolverListener.this.helper == ManagedChannelImpl.this.lbHelper) {
|
if (NameResolverListener.this.helper == ManagedChannelImpl.this.lbHelper) {
|
||||||
if (effectiveServiceConfig != validServiceConfig) {
|
|
||||||
Map<String, ?> healthCheckingConfig =
|
Map<String, ?> healthCheckingConfig =
|
||||||
effectiveServiceConfig.getHealthCheckingConfig();
|
effectiveServiceConfig.getHealthCheckingConfig();
|
||||||
if (healthCheckingConfig != null) {
|
if (healthCheckingConfig != null) {
|
||||||
|
|
@ -1407,7 +1406,6 @@ final class ManagedChannelImpl extends ManagedChannel implements
|
||||||
.set(LoadBalancer.ATTR_HEALTH_CHECKING_CONFIG, healthCheckingConfig)
|
.set(LoadBalancer.ATTR_HEALTH_CHECKING_CONFIG, healthCheckingConfig)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Status handleResult = helper.lb.tryHandleResolvedAddresses(
|
Status handleResult = helper.lb.tryHandleResolvedAddresses(
|
||||||
ResolvedAddresses.newBuilder()
|
ResolvedAddresses.newBuilder()
|
||||||
|
|
|
||||||
|
|
@ -3918,6 +3918,36 @@ public class ManagedChannelImplTest {
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final class ChannelBuilder
|
private static final class ChannelBuilder
|
||||||
extends AbstractManagedChannelImplBuilder<ChannelBuilder> {
|
extends AbstractManagedChannelImplBuilder<ChannelBuilder> {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue