grpc-core: use retryThrottling from defaultServiceConfig

This commit is contained in:
João Vitor Stein 2024-07-03 12:19:22 -03:00 committed by GitHub
parent 6e25c03a7b
commit 062ebb4d77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 73 additions and 1 deletions

View File

@ -616,7 +616,7 @@ final class ManagedChannelImpl extends ManagedChannel implements
parsedDefaultServiceConfig.getError());
this.defaultServiceConfig =
(ManagedChannelServiceConfig) parsedDefaultServiceConfig.getConfig();
this.lastServiceConfig = this.defaultServiceConfig;
this.transportProvider.throttle = this.defaultServiceConfig.getRetryThrottling();
} else {
this.defaultServiceConfig = null;
}
@ -709,6 +709,11 @@ final class ManagedChannelImpl extends ManagedChannel implements
return realChannel.configSelector.get();
}
@VisibleForTesting
boolean hasThrottle() {
return this.transportProvider.throttle != null;
}
/**
* Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
* cancelled.

View File

@ -4058,6 +4058,40 @@ public class ManagedChannelImplTest {
}
}
@Test
public void disableServiceConfigLookUp_withDefaultConfig_withRetryThrottle() throws Exception {
LoadBalancerRegistry.getDefaultRegistry().register(mockLoadBalancerProvider);
try {
FakeNameResolverFactory nameResolverFactory =
new FakeNameResolverFactory.Builder(expectedUri)
.setServers(ImmutableList.of(addressGroup)).build();
channelBuilder.nameResolverFactory(nameResolverFactory);
channelBuilder.disableServiceConfigLookUp();
channelBuilder.enableRetry();
Map<String, Object> defaultServiceConfig =
parseConfig("{"
+ "\"retryThrottling\":{\"maxTokens\": 1, \"tokenRatio\": 1},"
+ "\"methodConfig\":[{"
+ "\"name\":[{\"service\":\"SimpleService1\"}],"
+ "\"waitForReady\":true"
+ "}]}");
channelBuilder.defaultServiceConfig(defaultServiceConfig);
createChannel();
ArgumentCaptor<ResolvedAddresses> resultCaptor =
ArgumentCaptor.forClass(ResolvedAddresses.class);
verify(mockLoadBalancer).acceptResolvedAddresses(resultCaptor.capture());
assertThat(resultCaptor.getValue().getAddresses()).containsExactly(addressGroup);
assertThat(resultCaptor.getValue().getAttributes().get(InternalConfigSelector.KEY)).isNull();
verify(mockLoadBalancer, never()).handleNameResolutionError(any(Status.class));
assertThat(channel.hasThrottle()).isTrue();
} finally {
LoadBalancerRegistry.getDefaultRegistry().deregister(mockLoadBalancerProvider);
}
}
@Test
public void enableServiceConfigLookUp_noDefaultConfig() throws Exception {
LoadBalancerRegistry.getDefaultRegistry().register(mockLoadBalancerProvider);
@ -4165,6 +4199,39 @@ public class ManagedChannelImplTest {
}
}
@Test
public void enableServiceConfigLookUp_usingDefaultConfig_withRetryThrottling() throws Exception {
LoadBalancerRegistry.getDefaultRegistry().register(mockLoadBalancerProvider);
try {
FakeNameResolverFactory nameResolverFactory =
new FakeNameResolverFactory.Builder(expectedUri)
.setServers(ImmutableList.of(addressGroup)).build();
channelBuilder.nameResolverFactory(nameResolverFactory);
channelBuilder.enableRetry();
Map<String, Object> defaultServiceConfig =
parseConfig("{"
+ "\"retryThrottling\":{\"maxTokens\": 1, \"tokenRatio\": 1},"
+ "\"methodConfig\":[{"
+ "\"name\":[{\"service\":\"SimpleService1\"}],"
+ "\"waitForReady\":true"
+ "}]}");
channelBuilder.defaultServiceConfig(defaultServiceConfig);
createChannel();
ArgumentCaptor<ResolvedAddresses> resultCaptor =
ArgumentCaptor.forClass(ResolvedAddresses.class);
verify(mockLoadBalancer).acceptResolvedAddresses(resultCaptor.capture());
assertThat(resultCaptor.getValue().getAddresses()).containsExactly(addressGroup);
assertThat(resultCaptor.getValue().getAttributes().get(InternalConfigSelector.KEY)).isNull();
verify(mockLoadBalancer, never()).handleNameResolutionError(any(Status.class));
assertThat(channel.hasThrottle()).isTrue();
} finally {
LoadBalancerRegistry.getDefaultRegistry().deregister(mockLoadBalancerProvider);
}
}
@Test
public void enableServiceConfigLookUp_resolverReturnsNoConfig_noDefaultConfig() {
LoadBalancerRegistry.getDefaultRegistry().register(mockLoadBalancerProvider);