Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @param <T> the type of the builder
* @author David Syer
* @author Chris Bono
* @author Andrey Litvitski
*/
class ClientPropertiesChannelBuilderCustomizer<T extends ManagedChannelBuilder<T>>
implements GrpcChannelBuilderCustomizer<T> {
Expand All @@ -55,12 +56,14 @@ public void customize(String target, T builder) {
if (targetAllowsLoadBalancer(target)) {
mapper.from(channel.getDefaultLoadBalancingPolicy()).to(builder::defaultLoadBalancingPolicy);
}
if (channel.isEnableKeepAlive()) {
mapper.from(channel.getKeepAliveTime()).to(durationProperty(builder::keepAliveTime));
mapper.from(channel.getKeepAliveTimeout()).to(durationProperty(builder::keepAliveTimeout));
mapper.from(channel.isKeepAliveWithoutCalls()).to(builder::keepAliveWithoutCalls);
}
mapper.from(channel.getMaxInboundMessageSize()).asInt(DataSize::toBytes).to(builder::maxInboundMessageSize);
mapper.from(channel.getMaxInboundMetadataSize()).asInt(DataSize::toBytes).to(builder::maxInboundMetadataSize);
mapper.from(channel.getKeepAliveTime()).to(durationProperty(builder::keepAliveTime));
mapper.from(channel.getKeepAliveTimeout()).to(durationProperty(builder::keepAliveTimeout));
mapper.from(channel.getIdleTimeout()).to(durationProperty(builder::idleTimeout));
mapper.from(channel.isKeepAliveWithoutCalls()).to(builder::keepAliveWithoutCalls);
Map<String, Object> defaultServiceConfig = channel.extractServiceConfig();
if (channel.getHealth().isEnabled()) {
String serviceNameToCheck = (channel.getHealth().getServiceName() != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package org.springframework.boot.grpc.client.autoconfigure;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.inOrder;
Expand Down Expand Up @@ -63,6 +66,7 @@
* Tests for {@link GrpcClientAutoConfiguration}.
*
* @author Chris Bono
* @author Andrey Litvitski
*/
@SuppressWarnings({ "unchecked" })
class GrpcClientAutoConfigurationTests {
Expand Down Expand Up @@ -246,6 +250,21 @@ void userDefinedCustomizerCanRunBeforeAndAfterClientPropsCustomizer() {
});
}

@Test
void keepAliveSettingsNotAppliedWhenDisabled() {
this.contextRunner()
.withPropertyValues("spring.grpc.client.default-channel.enable-keep-alive=false")
.run((context) -> {
var customizer = context.getBean("clientPropertiesChannelCustomizer",
GrpcChannelBuilderCustomizer.class);
ManagedChannelBuilder<?> builder = Mockito.mock();
customizer.customize("default", builder);
then(builder).should(never()).keepAliveTime(anyLong(), any());
then(builder).should(never()).keepAliveTimeout(anyLong(), any());
then(builder).should(never()).keepAliveWithoutCalls(anyBoolean());
});
}

@Test
void clientScanConfigurationAutoConfiguredAsExpected() {
this.contextRunner().run((context) -> assertThat(context).hasSingleBean(ClientScanConfiguration.class));
Expand Down
Loading