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

Add support of Duration in RetryTemplateBuilder #344

Merged
merged 2 commits into from
May 31, 2023

Conversation

aahlenst
Copy link
Contributor

Introduce java.time.Duration as an alternative to express timeouts and intervals when building RestTemplate.

@aahlenst
Copy link
Contributor Author

I applied the requested changes and deprecated withinMillis().

@artembilan artembilan added this to the 2.0.2 milestone May 30, 2023
@@ -132,6 +136,36 @@ public RetryTemplateBuilder withinMillis(long timeout) {
return this;
Copy link
Member

Choose a reason for hiding this comment

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

And just delegate to a new method from this deprecated one!
Not sure why do we need to keep a duplication of the logic...

*/
public RetryTemplateBuilder withTimeout(Duration timeout) {
Assert.notNull(timeout, "timeout is null");
return this.withinMillis(timeout.toMillis());
Copy link
Member

Choose a reason for hiding this comment

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

No this. on method calls, please.
And why do you call a deprecated method from here then?

@@ -111,12 +114,14 @@ public void testBasicCustomization() {
/* ---------------- Retry policy -------------- */

@Test
@SuppressWarnings("removal")
public void testFailOnRetryPoliciesConflict() {
assertThatIllegalArgumentException()
.isThrownBy(() -> RetryTemplate.builder().maxAttempts(3).withinMillis(1000).build());
Copy link
Member

Choose a reason for hiding this comment

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

So, why cannot we use a new method then instead of a deprecated one?
Since we have it just deprecated we simply claim that we don't support it any more.

If you have introduced tests for new methods, then this old simply can be removed.

Copy link
Member

@snicoll snicoll May 30, 2023

Choose a reason for hiding this comment

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

It's an existing test that's testing the deprecated code. That isn't so bad, isn't it? As long as there is a new test for the new code.

The test should be flagged with deprecated probably.

@aahlenst
Copy link
Contributor Author

Sorry, my change aversion got out of hand. Problems are hopefully fixed.

* @since 2.0.2
*/
public RetryTemplateBuilder withTimeout(Duration timeout) {
Assert.notNull(timeout, "timeout is null");
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure where you took this pattern from, but it would be better to give an instruction in this message.
When exception is thrown from that Assert.notNull is is already clear that something is wrong: we only just need to say how to fix: "'timeout' must not be null".

And fix the rest of similar messages in this class, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better?

@artembilan artembilan merged commit 41b7df8 into spring-projects:main May 31, 2023
@artembilan
Copy link
Member

Thank you for contribution, @aahlenst ; looking forward for more!

@snicoll snicoll changed the title Introduce java.time.Duration Add support of Duration in RetryTemplateBuilder May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants