Skip to content
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

Expose the MethodInvocation in the MethodInvocationRetryCallback #172

Conversation

mariusneo
Copy link
Contributor

Expose the MethodInvocation in the MethodInvocationRetryCallback in order to permit to concrete RetryListener implementations to inspect in detail the method called as well as its arguments. This information can be used in the retry listener for either detailed logging or monitoring for the proxied method invocations.

This pull-request has emerged based on the discussions held in #119 for the need of exposing detailed information about the AOP intercepted methods on which the spring-retry logic is being applied.

…rder to permit to concrete RetryListener implementations to inspect in detail the method called as well as its arguments. This information can be used in the retry listener for either detailed logging or monitoring for the proxied method invocations.
README.md Show resolved Hide resolved
Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

Here is some review from me.

The solution is OK with me though...

pom.xml Outdated
@@ -218,6 +218,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

Isn't there a way to avoid one more dependency?

I'm not a fun to introduce a dependency just for one test-case.

We would need to manage its dependency in the future and handle code for compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.
I've dropped the hamcrest-all dependency and used vanilla junit 4 assertions.

BTW @artembilan would it make sense to have a conversion of the tests of the project to junit 5 ? I'd be willing to do this.

Copy link
Member

Choose a reason for hiding this comment

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

This project is still aimed to support Java 6 and that's why it's Spring base like is 4.x, too.

I'm not sure that it is going to be so easy to move to JUnit 5 and still support Spring 4 and Java 6...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to https://junit.org/junit5/docs/current/user-guide/#overview-java-versions it needs at least java 8.
In the README.md of the project is not mentioned though a reference about the supported java/spring versions. I guess it would make sense to have this.

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, in the nearby issue #154 we with @dsyer are experimenting around async retry and CompletableFutures, so it would be generally good to know whether the switching to java8 is impossible due to major backward compatibility issues (and we should consider a separate module), or possible.

Copy link
Member

Choose a reason for hiding this comment

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

There is a ListenableFuture abstraction in Spring for that reason.
Although it is fully different story and not related to what you are doing here...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ashamukov thanks for pointing out the existence of async-retry project. I didn't know about it before.

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Copy link
Member

Choose a reason for hiding this comment

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

I think there was the reason to keep static imports in the end of the list.
I even believe that Checkstyle is going to fail with your change...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've came across mvn spring-javaformat:apply and this helped me in doing the reformatting.

When doing the checkstyle checks on the other hand (via mvn validate and the checkstyle config taken from https://github.com/spring-io/spring-javaformat the build fails with quite a lot of problems).

README.md Outdated Show resolved Hide resolved
Copy link
Member

@artembilan artembilan left a comment

Choose a reason for hiding this comment

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

LGTM

@dsyer , @garyrussell ?

@garyrussell
Copy link
Contributor

Maybe it's time to bump master to 2.0.0.B-S and use Java8 (default methods)?

@artembilan
Copy link
Member

to bump master to 2.0.0.B-S

Well, I would consider that in the separate issue: not sure how those default methods can help us here with the MethodInvocation propagation...

@garyrussell
Copy link
Contributor

The overloaded methods taking the invocation can be default methods on the existing RecoveryCallback - calling the old methods by default; avoiding the need for the ...Support class.

@garyrussell
Copy link
Contributor

And all those instanceof tests.

@artembilan
Copy link
Member

The problem with MethodInvocation is that is only has its specific context withing RetryOperationsInterceptor .
When we call RetryTemplate.execute() directly there is no any MethodInvocation context.

I agree that it looks cleaner from the hierarchy and API perspective, but it is really an abuse of language features when we definitely deal with particular context only and don't care about it in other places.

I may miss something else, don't count on me as a final decision stop...

@garyrussell
Copy link
Contributor

Forget that, it won't work; you need something to hold the invocation. So I guess I'm ok with this.

@mariusneo
Copy link
Contributor Author

Are there open issues in the current pull request or can it be merged ?

@artembilan
Copy link
Member

It is approved on my side and looks like Garry has expressed his OK as well.

So, we need only @dsyer 's 👍 since he is a project lead.

Thanks for understanding.

@dsyer dsyer merged commit e2b0555 into spring-projects:master Apr 23, 2019
@dsyer dsyer added this to the 1.3.0 milestone Apr 23, 2019
@dsyer dsyer mentioned this pull request Apr 23, 2019
@mariusneo mariusneo deleted the feature/expose-method-invocation-retry-callback branch April 23, 2019 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants