mirror of https://github.com/grpc/grpc-java.git
grpc-core: use retryThrottling from defaultServiceConfig
This commit is contained in:
parent
6e25c03a7b
commit
062ebb4d77
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue