Skip to content

Commit 1aaef80

Browse files
Бацура Сергей АлександровичБацура Сергей Александрович
Бацура Сергей Александрович
authored and
Бацура Сергей Александрович
committed
Feat(deadline) changed the name of deadline property to timeout.
1 parent f365af7 commit 1aaef80

File tree

7 files changed

+44
-45
lines changed

7 files changed

+44
-45
lines changed
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,42 @@
2828
import lombok.extern.slf4j.Slf4j;
2929
import net.devh.boot.grpc.client.channelfactory.GrpcChannelConfigurer;
3030
import net.devh.boot.grpc.client.config.GrpcChannelsProperties;
31-
import net.devh.boot.grpc.client.interceptor.DeadlineSetupClientInterceptor;
31+
import net.devh.boot.grpc.client.interceptor.TimeoutSetupClientInterceptor;
3232

3333
/**
34-
* The deadline autoconfiguration for the client.
34+
* The timeout autoconfiguration for the client.
3535
*
3636
* <p>
3737
* You can disable this config by using:
3838
* </p>
3939
*
4040
* <pre>
41-
* <code>@ImportAutoConfiguration(exclude = GrpcClientDeadlineAutoConfiguration.class)</code>
41+
* <code>@ImportAutoConfiguration(exclude = GrpcClientTimeoutAutoConfiguration.class)</code>
4242
* </pre>
4343
*
4444
* @author Sergei Batsura ([email protected])
4545
*/
4646
@Slf4j
4747
@Configuration(proxyBeanMethods = false)
4848
@AutoConfigureBefore(GrpcClientAutoConfiguration.class)
49-
public class GrpcClientDeadlineAutoConfiguration {
49+
public class GrpcClientTimeoutAutoConfiguration {
5050

5151
/**
52-
* Creates a {@link GrpcChannelConfigurer} bean applying the default deadline from config to each new call using a
52+
* Creates a {@link GrpcChannelConfigurer} bean applying the default timeout from config to each new call using a
5353
* {@link ClientInterceptor}.
5454
*
55-
* @param props The properties for deadline configuration.
56-
* @return The GrpcChannelConfigurer bean with interceptor if deadline is configured.
57-
* @see DeadlineSetupClientInterceptor
55+
* @param props The properties for timeout configuration.
56+
* @return The GrpcChannelConfigurer bean with interceptor if timeout is configured.
57+
* @see TimeoutSetupClientInterceptor
5858
*/
5959
@Bean
60-
GrpcChannelConfigurer deadlineGrpcChannelConfigurer(final GrpcChannelsProperties props) {
60+
GrpcChannelConfigurer timeoutGrpcChannelConfigurer(final GrpcChannelsProperties props) {
6161
requireNonNull(props, "properties");
6262

6363
return (channel, name) -> {
64-
Duration deadline = props.getChannel(name).getDeadline();
65-
if (deadline != null && deadline.toMillis() > 0L) {
66-
channel.intercept(new DeadlineSetupClientInterceptor(deadline));
64+
Duration timeout = props.getChannel(name).getTimeout();
65+
if (timeout != null && timeout.toMillis() > 0L) {
66+
channel.intercept(new TimeoutSetupClientInterceptor(timeout));
6767
}
6868
};
6969
}

grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/config/GrpcChannelProperties.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,31 @@ public void setAddress(final String address) {
120120
}
121121

122122
// --------------------------------------------------
123-
// Target Deadline
123+
// Target Timeout
124124
// --------------------------------------------------
125125

126-
private Duration deadline = null;
126+
private Duration timeout = null;
127127

128128
/**
129-
* Gets the default deadline for each new call.
129+
* Gets the default timeout for each new call.
130130
*
131-
* @return The connection deadline or null
132-
* @see #setDeadline(Duration)
131+
* @return The connection timeout or null
132+
* @see #setTimeout(Duration)
133133
*/
134-
public Duration getDeadline() {
135-
return this.deadline;
134+
public Duration getTimeout() {
135+
return this.timeout;
136136
}
137137

138138
/**
139-
* Set the default deadline duration for new calls (on a per call basis). By default and if zero value is
140-
* configured, the deadline will not be used. The default deadline will be ignored, if a deadline has been applied
141-
* manually.
139+
* Set the default timeout duration for new calls (on a per call basis). By default and if zero value is configured,
140+
* the timeout will not be used. The default timeout will be ignored, if a deadline has been applied manually.
142141
*
143-
* @param deadline The connection deadline or null.
142+
* @param timeout The connection timeout or null.
144143
*
145144
* @see CallOptions#withDeadlineAfter(long, TimeUnit)
146145
*/
147-
public void setDeadline(Duration deadline) {
148-
this.deadline = deadline;
146+
public void setTimeout(Duration timeout) {
147+
this.timeout = timeout;
149148
}
150149

151150
// --------------------------------------------------
@@ -510,8 +509,8 @@ public void copyDefaultsFrom(final GrpcChannelProperties config) {
510509
if (this.address == null) {
511510
this.address = config.address;
512511
}
513-
if (this.deadline == null) {
514-
this.deadline = config.deadline;
512+
if (this.timeout == null) {
513+
this.timeout = config.timeout;
515514
}
516515
if (this.defaultLoadBalancingPolicy == null) {
517516
this.defaultLoadBalancingPolicy = config.defaultLoadBalancingPolicy;
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@
2828
import lombok.extern.slf4j.Slf4j;
2929

3030
/**
31-
* Deadline setup client interceptor that create new deadline instance from defaultDeadline.
31+
* Timeout setup client interceptor that create new deadline instance from the timeout.
3232
*
3333
* @author Sergei Batsura ([email protected])
3434
*/
3535
@Slf4j
3636
@RequiredArgsConstructor
37-
public class DeadlineSetupClientInterceptor implements ClientInterceptor {
37+
public class TimeoutSetupClientInterceptor implements ClientInterceptor {
3838

39-
private final Duration defaultDeadline;
39+
private final Duration timeout;
4040

4141
@Override
4242
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
4343
final MethodDescriptor<ReqT, RespT> method,
4444
final CallOptions callOptions,
4545
final Channel next) {
4646

47-
if (defaultDeadline != null && callOptions.getDeadline() == null) {
47+
if (timeout != null && callOptions.getDeadline() == null) {
4848
return next.newCall(method,
49-
callOptions.withDeadlineAfter(defaultDeadline.toMillis(), TimeUnit.MILLISECONDS));
49+
callOptions.withDeadlineAfter(timeout.toMillis(), TimeUnit.MILLISECONDS));
5050
} else {
5151
return next.newCall(method, callOptions);
5252
}

grpc-client-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@
108108
"defaultValue": 0
109109
},
110110
{
111-
"name": "grpc.client.GLOBAL.deadline",
111+
"name": "grpc.client.GLOBAL.timeout",
112112
"type": "java.time.Duration",
113113
"sourceType": "net.devh.boot.grpc.client.config.GrpcChannelProperties",
114-
"description": "The deadline is used to applying from config to each new call."
114+
"description": "The timeout is used to applying from config to each new call. By default and if zero value is configured, the timeout will not be used. The default timeout will be ignored, if a deadline has been applied manually."
115115
},
116116
{
117117
"name": "grpc.client.GLOBAL.security.authority-override",

grpc-client-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ net.devh.boot.grpc.client.autoconfigure.GrpcClientHealthAutoConfiguration
44
net.devh.boot.grpc.client.autoconfigure.GrpcClientMicrometerTraceAutoConfiguration
55
net.devh.boot.grpc.client.autoconfigure.GrpcClientSecurityAutoConfiguration
66
net.devh.boot.grpc.client.autoconfigure.GrpcDiscoveryClientAutoConfiguration
7-
net.devh.boot.grpc.client.autoconfigure.GrpcClientDeadlineAutoConfiguration
7+
net.devh.boot.grpc.client.autoconfigure.GrpcClientTimeoutAutoConfiguration

tests/src/test/java/net/devh/boot/grpc/test/config/BaseAutoConfiguration.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.springframework.context.annotation.Configuration;
2121

2222
import net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration;
23-
import net.devh.boot.grpc.client.autoconfigure.GrpcClientDeadlineAutoConfiguration;
23+
import net.devh.boot.grpc.client.autoconfigure.GrpcClientTimeoutAutoConfiguration;
2424
import net.devh.boot.grpc.common.autoconfigure.GrpcCommonCodecAutoConfiguration;
2525
import net.devh.boot.grpc.server.autoconfigure.GrpcServerAutoConfiguration;
2626
import net.devh.boot.grpc.server.autoconfigure.GrpcServerFactoryAutoConfiguration;
@@ -29,7 +29,7 @@
2929
@Configuration
3030
@ImportAutoConfiguration({GrpcCommonCodecAutoConfiguration.class, GrpcServerAutoConfiguration.class,
3131
GrpcServerFactoryAutoConfiguration.class, GrpcServerSecurityAutoConfiguration.class,
32-
GrpcClientAutoConfiguration.class, GrpcClientDeadlineAutoConfiguration.class})
32+
GrpcClientAutoConfiguration.class, GrpcClientTimeoutAutoConfiguration.class})
3333
public class BaseAutoConfiguration {
3434

3535
}

tests/src/test/java/net/devh/boot/grpc/test/setup/DeadlineTests.java renamed to tests/src/test/java/net/devh/boot/grpc/test/setup/TimeoutSetupTests.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@
3838
import net.devh.boot.grpc.test.proto.SomeType;
3939

4040
/**
41-
* These tests check the property {@link GrpcChannelProperties#getDeadline()}.
41+
* These tests check the property {@link GrpcChannelProperties#getTimeout()} ()}.
4242
*/
43-
public class DeadlineTests {
43+
public class TimeoutSetupTests {
4444

4545
@Slf4j
4646
@SpringBootTest(properties = {
4747
"grpc.client.GLOBAL.address=localhost:9090",
48-
"grpc.client.GLOBAL.deadline=1s",
48+
"grpc.client.GLOBAL.timeout=1s",
4949
"grpc.client.GLOBAL.negotiationType=PLAINTEXT",
5050
})
5151
@SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class})
52-
static class DeadlineSetupTest extends AbstractSimpleServerClientTest {
52+
static class TimeoutSetupTest extends AbstractSimpleServerClientTest {
5353
@Test
5454
@SneakyThrows
5555
@DirtiesContext
56-
void testServiceStubDeadlineEnabledAndSuccessful() {
56+
void testServiceStubTimeoutEnabledAndSuccessful() {
5757
log.info("--- Starting test with unsuccessful and than successful call ---");
5858
final StreamRecorder<SomeType> streamRecorder1 = StreamRecorder.create();
5959
this.testServiceStub.echo(streamRecorder1);
@@ -71,17 +71,17 @@ void testServiceStubDeadlineEnabledAndSuccessful() {
7171
@Slf4j
7272
@SpringBootTest(properties = {
7373
"grpc.client.GLOBAL.address=localhost:9090",
74-
"grpc.client.GLOBAL.deadline=0s",
74+
"grpc.client.GLOBAL.timeout=0s",
7575
"grpc.client.GLOBAL.negotiationType=PLAINTEXT",
7676
})
7777
@SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class})
78-
static class ZeroDeadlineSetupTest extends AbstractSimpleServerClientTest {
78+
static class ZeroTimeoutSetupTest extends AbstractSimpleServerClientTest {
7979

8080
@Test
8181
@SneakyThrows
8282
@DirtiesContext
8383
void testServiceStubManuallyConfiguredDeadlineTakesPrecedenceOfTheConfigOne() {
84-
log.info("--- Starting test that manually configured deadline takes precedence of the config one ---");
84+
log.info("--- Starting test that manually configured deadline takes precedence of the config timeout ---");
8585
final StreamRecorder<SomeType> streamRecorder1 = StreamRecorder.create();
8686
this.testServiceStub.withDeadlineAfter(1L, TimeUnit.SECONDS).echo(streamRecorder1);
8787
assertThrows(ExecutionException.class, () -> streamRecorder1.firstValue().get());

0 commit comments

Comments
 (0)