Skip to content

Commit f365af7

Browse files
Бацура Сергей АлександровичБацура Сергей Александрович
Бацура Сергей Александрович
authored and
Бацура Сергей Александрович
committed
Feat(deadline) add a test showing that the manually configured deadline takes precedence of the config one.
1 parent dd26ff4 commit f365af7

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

grpc-client-spring-boot-starter/src/main/java/net/devh/boot/grpc/client/autoconfigure/GrpcClientDeadlineAutoConfiguration.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
import org.springframework.context.annotation.Bean;
2525
import org.springframework.context.annotation.Configuration;
2626

27-
import io.grpc.CallOptions;
28-
import io.grpc.Channel;
29-
import io.grpc.MethodDescriptor;
27+
import io.grpc.ClientInterceptor;
3028
import lombok.extern.slf4j.Slf4j;
3129
import net.devh.boot.grpc.client.channelfactory.GrpcChannelConfigurer;
3230
import net.devh.boot.grpc.client.config.GrpcChannelsProperties;
@@ -51,10 +49,11 @@
5149
public class GrpcClientDeadlineAutoConfiguration {
5250

5351
/**
54-
* Creates a {@link GrpcChannelConfigurer} bean applying the default deadline from config to each new call using a {@link ClientInterceptor}.
52+
* Creates a {@link GrpcChannelConfigurer} bean applying the default deadline from config to each new call using a
53+
* {@link ClientInterceptor}.
5554
*
5655
* @param props The properties for deadline configuration.
57-
* @return The StubTransformer bean with interceptor if deadline is configured.
56+
* @return The GrpcChannelConfigurer bean with interceptor if deadline is configured.
5857
* @see DeadlineSetupClientInterceptor
5958
*/
6059
@Bean

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ public Duration getDeadline() {
136136
}
137137

138138
/**
139-
* Set the default deadline duration for new calls (on a per call basis).
140-
* By default and if zero value is configured, the deadline will not be used.
141-
* The default deadline will be ignored, if a deadline has been applied manually.
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.
142142
*
143143
* @param deadline The connection deadline or null.
144144
*

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"name": "grpc.client.GLOBAL.deadline",
112112
"type": "java.time.Duration",
113113
"sourceType": "net.devh.boot.grpc.client.config.GrpcChannelProperties",
114-
"description": "A deadline is used to specify a point in time past which a client is unwilling to wait for a response from a server"
114+
"description": "The deadline is used to applying from config to each new call."
115115
},
116116
{
117117
"name": "grpc.client.GLOBAL.security.authority-override",

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.junit.jupiter.api.Assertions.assertThrows;
2222

2323
import java.util.concurrent.ExecutionException;
24+
import java.util.concurrent.TimeUnit;
2425

2526
import org.junit.jupiter.api.Test;
2627
import org.springframework.boot.test.context.SpringBootTest;
@@ -55,7 +56,7 @@ static class DeadlineSetupTest extends AbstractSimpleServerClientTest {
5556
void testServiceStubDeadlineEnabledAndSuccessful() {
5657
log.info("--- Starting test with unsuccessful and than successful call ---");
5758
final StreamRecorder<SomeType> streamRecorder1 = StreamRecorder.create();
58-
StreamObserver<SomeType> echo1 = this.testServiceStub.echo(streamRecorder1);
59+
this.testServiceStub.echo(streamRecorder1);
5960
assertThrows(ExecutionException.class, () -> streamRecorder1.firstValue().get());
6061

6162
final StreamRecorder<SomeType> streamRecorder2 = StreamRecorder.create();
@@ -75,6 +76,18 @@ void testServiceStubDeadlineEnabledAndSuccessful() {
7576
})
7677
@SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class})
7778
static class ZeroDeadlineSetupTest extends AbstractSimpleServerClientTest {
79+
80+
@Test
81+
@SneakyThrows
82+
@DirtiesContext
83+
void testServiceStubManuallyConfiguredDeadlineTakesPrecedenceOfTheConfigOne() {
84+
log.info("--- Starting test that manually configured deadline takes precedence of the config one ---");
85+
final StreamRecorder<SomeType> streamRecorder1 = StreamRecorder.create();
86+
this.testServiceStub.withDeadlineAfter(1L, TimeUnit.SECONDS).echo(streamRecorder1);
87+
assertThrows(ExecutionException.class, () -> streamRecorder1.firstValue().get());
88+
log.info("--- Test completed --- ");
89+
}
90+
7891
}
7992

8093
}

0 commit comments

Comments
 (0)