Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add gRPC exception advice support for factory beans#266

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
bitbrain wants to merge7 commits intoLogNet:master
base:master
Choose a base branch
Loading
frombitbrain:bean-factory-support-for-exception-advice

Conversation

@bitbrain
Copy link

@bitbrainbitbrain commentedNov 24, 2021
edited
Loading

This pull request addresses#265

When currently using@GRpcServiceAdvice on a bean that is being created within a@Configuration like so (Spring Boot 2.5.6):

@BeanpublicGrpcExceptionAdvicegrpcExceptionAdvice() {returnnewGrpcExceptionAdvice(); }

it will produce the following exception on startup:

Caused by: java.lang.NullPointerExceptionat java.base/java.lang.Class.forName0(Native Method)at java.base/java.lang.Class.forName(Class.java:315)at org.lognet.springboot.grpc.autoconfigure.OnMissingErrorHandlerCondition.getMatchOutcome(OnMissingErrorHandlerCondition.java:35)at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)... 95 more

The reason is that the current logic does not support beans created through factory methods:

The solution

larrywest reacted with heart emoji
@codecov
Copy link

codecovbot commentedNov 24, 2021
edited
Loading

Codecov Report

Attention: Patch coverage is71.42857% with2 lines in your changes missing coverage. Please review.

Project coverage is 88.09%. Comparing base(d70346b) to head(860950d).
Report is 102 commits behind head on master.

FilesPatch %Lines
.../autoconfigure/OnMissingErrorHandlerCondition.java71.42%0 Missing and 2 partials⚠️
Additional details and impacted files
@@             Coverage Diff              @@##             master     #266      +/-   ##============================================- Coverage     88.24%   88.09%   -0.15%- Complexity      317      318       +1============================================  Files            50       50                Lines          1531     1537       +6       Branches         86       87       +1     ============================================+ Hits           1351     1354       +3- Misses          143      144       +1- Partials         37       39       +2

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report?Share it here.

@bitbrain
Copy link
Author

I will add tests for this.

@jvmlet
Copy link
Collaborator

what is the spring boot version you are running with?

@bitbrain
Copy link
Author

what is the spring boot version you are running with?

@jvmlet 2.5.6

Miguel Gonzalez Sanchez added2 commitsNovember 29, 2021 09:28
@bitbrain
Copy link
Author

@jvmlet any recommendations on how I can get the code coverage to pass? I checkedhttps://app.codecov.io/gh/LogNet/grpc-spring-boot-starter/compare/266/changes and it seems to have no changes and I also added tests to ensure the bean loading works correctly but it complains about +0.15% coverage decrease.

protoc {
artifact="com.google.protobuf:protoc:${grpcSpringBoot.protocVersion.get()}"

// for apple m1, please add protoc_platform=osx-x86_64 in $HOME/.gradle/gradle.properties
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

On Apple M1 this project currently does not build due to missing artifacts. This is a recommended workaround. I can remove this again if you want.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If the platform can't be inferred dynamically, please add it as configuration optionhere+readme

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is just a workaround and should not be needed as a property of this Spring boot starter. In case we still want to have it I'd suggest to make it as part of another pull request.

In the meantime, I will revert these changes to thegrpc-spring-boot.gradle file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes, this is not starter's feature, but gradle plugin's one. You can have this logic in extension class andgrpc-spring-boot.gradle in separate PR.

bitbrain reacted with thumbs up emoji
@bitbrain
Copy link
Author

bitbrain commentedDec 2, 2021
edited
Loading

I did some digging why that newly added code is not called during the integration tests. Here is my summary. Feedback welcome on how we could change these tests to reproduce this behaviour, as I am currently unable to determine what specifically is causing this behaviour to occur.

Scenario 1: AnnotatedGenericBeanDefinition

This is the current logic within the unit tests of this Spring Boot starter. Setting up the bean like this:

...will internally create anAnnotatedGenericBeanDefinition and set it on the internalbeanFactoryMap within thebeanFactory. As a result,beanDefinition.getBeanClassName() is not null.

Scenario 2: ConfigurationClassBeanDefinitionReader$ConfigurationClassBeanDefinition

Within our codebase, we use a custom Spring Boot starter to define a custom advice like so:

@BeanpublicGrpcExceptionAdvicegrpcExceptionAdvice() {returnnewGrpcExceptionAdvice(); }

which itself looks like this:

@GRpcServiceAdvicepublicclassGrpcExceptionAdvice {/* exception handlers go here*/}

This is literally the same setup, however, for some reason it is using a different bean definition wherebeanDefinition.getBeanClassName() returnsnull and instead the class name can be obtained from the internalMethodMetadata on theAnnotatedBeanDefinition.

Question time!

How can I change the tests within this Spring Boot starter to replicateScenario 2?

@jvmlet
Copy link
Collaborator

See behavior difference if you define the inner advice class as static/non-static

bitbrain reacted with heart emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@jvmletjvmletjvmlet left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@bitbrain@jvmlet

[8]ページ先頭

©2009-2025 Movatter.jp