Skip to content

Commit

Permalink
Feat(deadline) add a test showing that the manually configured deadli…
Browse files Browse the repository at this point in the history
…ne takes precedence of the config one.
  • Loading branch information
Бацура Сергей Александрович authored and Бацура Сергей Александрович committed Sep 5, 2024
1 parent dd26ff4 commit 1927fc4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.MethodDescriptor;
import io.grpc.ClientInterceptor;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.client.channelfactory.GrpcChannelConfigurer;
import net.devh.boot.grpc.client.config.GrpcChannelsProperties;
Expand All @@ -51,7 +49,8 @@
public class GrpcClientDeadlineAutoConfiguration {

/**
* Creates a {@link GrpcChannelConfigurer} bean applying the default deadline from config to each new call using a {@link ClientInterceptor}.
* Creates a {@link GrpcChannelConfigurer} bean applying the default deadline from config to each new call using a
* {@link ClientInterceptor}.
*
* @param props The properties for deadline configuration.
* @return The StubTransformer bean with interceptor if deadline is configured.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public Duration getDeadline() {
}

/**
* Set the default deadline duration for new calls (on a per call basis).
* By default and if zero value is configured, the deadline will not be used.
* The default deadline will be ignored, if a deadline has been applied manually.
* Set the default deadline duration for new calls (on a per call basis). By default and if zero value is
* configured, the deadline will not be used. The default deadline will be ignored, if a deadline has been applied
* manually.
*
* @param deadline The connection deadline or null.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"name": "grpc.client.GLOBAL.deadline",
"type": "java.time.Duration",
"sourceType": "net.devh.boot.grpc.client.config.GrpcChannelProperties",
"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"
"description": "The deadline is used to applying from config to each new call."
},
{
"name": "grpc.client.GLOBAL.security.authority-override",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

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

final StreamRecorder<SomeType> streamRecorder2 = StreamRecorder.create();
Expand All @@ -75,6 +76,18 @@ void testServiceStubDeadlineEnabledAndSuccessful() {
})
@SpringJUnitConfig(classes = {ServiceConfiguration.class, BaseAutoConfiguration.class})
static class ZeroDeadlineSetupTest extends AbstractSimpleServerClientTest {

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

}

}

0 comments on commit 1927fc4

Please sign in to comment.