-
Notifications
You must be signed in to change notification settings - Fork 63
Add autoconfig for reflection service and friends #26 #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7160f27
https://github.com/spring-projects-experimental/spring-grpc/issues/26…
CyberZujo fb74492
Update spring-grpc-spring-boot-autoconfigure/src/main/java/org/spring…
CyberZujo 2415c6c
https://github.com/spring-projects-experimental/spring-grpc/issues/26…
CyberZujo 507ade0
https://github.com/spring-projects-experimental/spring-grpc/issues/26…
CyberZujo 05f518c
https://github.com/spring-projects-experimental/spring-grpc/issues/26…
CyberZujo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| spring.application.name=grpc-server | ||
| grpc.server.reflection.enabled=false | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../org/springframework/grpc/autoconfigure/server/GrpcServerReflectionAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package org.springframework.grpc.autoconfigure.server; | ||
|
|
||
| import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| import io.grpc.BindableService; | ||
| import io.grpc.protobuf.services.ProtoReflectionService; | ||
|
|
||
| /** | ||
| * {@link EnableAutoConfiguration Auto-configuration} for gRPC Reflection service | ||
| * <p> | ||
| * grpc.reflection.enabled=true must be present in configuration in order for the | ||
dsyer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * auto-configuration to execute | ||
| * | ||
| * @author Haris Zujo | ||
| */ | ||
| @Configuration | ||
dsyer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @ConditionalOnClass(BindableService.class) | ||
CyberZujo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public class GrpcServerReflectionAutoConfiguration { | ||
|
|
||
| @Bean | ||
| @ConditionalOnProperty(name = "grpc.server.reflection.enabled", havingValue = "true") | ||
dsyer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public BindableService serverReflection() { | ||
| return ProtoReflectionService.newInstance(); | ||
| } | ||
|
|
||
| } | ||
2 changes: 2 additions & 0 deletions
2
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| org.springframework.grpc.autoconfigure.server.GrpcServerFactoryAutoConfiguration | ||
| org.springframework.grpc.autoconfigure.server.GrpcServerAutoConfiguration | ||
| org.springframework.grpc.autoconfigure.client.GrpcClientAutoConfiguration | ||
| org.springframework.grpc.autoconfigure.server.GrpcServerReflectionAutoConfiguration | ||
|
|
34 changes: 34 additions & 0 deletions
34
...springframework/grpc/autoconfigure/server/GrpcServerReflectionAutoConfigurationTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package org.springframework.grpc.autoconfigure.server; | ||
|
|
||
| import io.grpc.BindableService; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
| import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
| import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
| import org.springframework.grpc.server.lifecycle.GrpcServerLifecycle; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class GrpcServerReflectionAutoConfigurationTests { | ||
|
|
||
| private ApplicationContextRunner contextRunner() { | ||
| return new ApplicationContextRunner() | ||
| .withConfiguration(AutoConfigurations.of(GrpcServerReflectionAutoConfiguration.class)) | ||
| .withBean("noopServerLifecylcle", GrpcServerLifecycle.class, Mockito::mock); | ||
| } | ||
|
|
||
| @Test | ||
CyberZujo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void whenReflectionEnabledThenCreateBean() { | ||
| this.contextRunner() | ||
| .withPropertyValues("grpc.server.reflection.enabled=true") | ||
| .run((context) -> assertThat(context).hasSingleBean(BindableService.class)); | ||
| } | ||
|
|
||
| @Test | ||
| void whenReflectionDisabledThenSkipBeanCreation() { | ||
| this.contextRunner() | ||
| .withPropertyValues("grpc.server.reflection.enabled=false") | ||
| .run((context) -> assertThat(context).doesNotHaveBean(BindableService.class)); | ||
| } | ||
|
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.