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

Retryer: replace an instance of Date with an epoch millisecond #2170

Merged
merged 8 commits into from
Sep 15, 2023

Conversation

vitalijr2
Copy link
Collaborator

@vitalijr2 vitalijr2 commented Sep 14, 2023

Resolves #2154

We do not use Date as date, every time we calculate epoch milliseconds. The Date class has issues with timezone.

Summary by CodeRabbit

  • Refactor: Replaced usage of Date with Clock in various classes and methods for better time handling.
  • New Feature: Introduced a custom TestClock class for more flexible testing.
  • Refactor: Updated RetryableException to use Long instead of Date for retry-after value, providing more flexibility.
  • Refactor: Improved retry mechanism in Retryer using exponential backoff.
  • Refactor: Replaced usage of DateFormat with DateTimeFormatter in RetryAfterDecoder for modern date/time handling.
  • Test: Updated test cases to reflect changes in the main codebase.
  • Chore: Updated build configuration to exclude certain file types from the build process.

@coderabbitai
Copy link

coderabbitai bot commented Sep 14, 2023

Walkthrough

This pull request introduces significant changes to the codebase, primarily focusing on replacing the usage of Date with Clock in various classes and methods. It also includes improvements to exception handling, retry mechanisms, and date/time parsing. The changes enhance flexibility, maintainability, and alignment with modern Java practices.

Changes

File(s) Summary
core/src/main/java/feign/.../FeignException.java,
core/src/main/java/feign/.../RetryableException.java,
core/src/main/java/feign/.../Retryer.java,
core/src/main/java/feign/.../ErrorDecoder.java
Improved exception handling and retry mechanisms. Replaced Date with Long for retry-after values.
core/src/test/java/feign/.../AsyncFeignTest.java,
core/src/test/java/feign/.../FeignTest.java,
core/src/test/java/feign/.../RetryableExceptionTest.java,
core/src/test/java/feign/.../RetryerTest.java,
core/src/test/java/feign/.../UtilTest.java
Updated test cases to reflect changes in exception handling and retry mechanisms.
core/src/test/java/feign/.../DefaultContractTest.java,
core/src/test/java/feign/.../FeignUnderAsyncTest.java,
hc5/src/test/java/feign/hc5/.../AsyncApacheHttp5ClientTest.java,
java11/src/test/java/feign/http2client/test/.../Http2ClientAsyncTest.java,
okhttp/src/test/java/feign/okhttp/.../OkHttpClientAsyncTest.java
Replaced Date with Clock in various methods and classes. Introduced a custom TestClock class for testing purposes.
pom.xml Added new exclusion patterns to the build configuration.

🐇💻

Code changes here, code changes there,

With every pull request, we show we care.

From Date to Clock, we make the switch,

Making our codebase modern and rich.

So here's to the devs, working night and day,

Your efforts and skills truly light the way! 🌟🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 6

Commits Files that changed from the base of the PR and between b04bf9a and 5289775 commits.
Files selected for processing (9)
  • core/src/main/java/feign/FeignException.java (1 hunks)
  • core/src/main/java/feign/RetryableException.java (4 hunks)
  • core/src/main/java/feign/Retryer.java (3 hunks)
  • core/src/main/java/feign/codec/ErrorDecoder.java (3 hunks)
  • core/src/test/java/feign/AsyncFeignTest.java (6 hunks)
  • core/src/test/java/feign/FeignTest.java (4 hunks)
  • core/src/test/java/feign/RetryableExceptionTest.java (1 hunks)
  • core/src/test/java/feign/RetryerTest.java (4 hunks)
  • core/src/test/java/feign/codec/RetryAfterDecoderTest.java (1 hunks)
Files skipped from review due to trivial changes (2)
  • core/src/main/java/feign/codec/ErrorDecoder.java
  • core/src/test/java/feign/RetryerTest.java
Additional comments (Suppressed): 18
core/src/test/java/feign/RetryableExceptionTest.java (1)
  • 33-38: The test case has been updated to reflect the changes in RetryableException constructor. The Date object has been replaced with a Long value representing epoch milliseconds. Ensure that all other test cases and production code have been updated accordingly.
core/src/main/java/feign/RetryableException.java (4)
  • 35-40: Ensure that all calls to this constructor throughout the codebase have been updated to match the new signature.

  • 53-58: Ensure that all calls to this constructor throughout the codebase have been updated to match the new signature.

  • 71-77: Ensure that all calls to this constructor throughout the codebase have been updated to match the new signature.

  • 91-93: The change from Date to Long for the retryAfter method is a breaking change. Ensure that all usages of this method in the codebase are updated to handle a Long return type instead of a Date.

core/src/main/java/feign/Retryer.java (3)
  • 24-28: The method signature and its functionality remain the same. No issues found.

  • 59-65: The change from e.retryAfter().getTime() to e.retryAfter() is consistent with the PR summary, which states that retryAfter now returns a Long instead of a Date. However, ensure that the returned value is always in milliseconds to maintain consistency across the codebase.

  • 79-93: The logic for calculating the retry interval remains the same, but the return statement has been simplified. This change does not affect the functionality or performance.

core/src/test/java/feign/AsyncFeignTest.java (6)
  • 16-21: The import statement for assertThat from org.assertj.core.api.Assertions has been removed. Ensure that this does not affect any existing assertions in the test cases.

  • 64-64: The import statement for ParameterizedTest from org.junit.jupiter.params has been replaced with ValueSource. If there are parameterized tests in this class, make sure they have been updated to use ValueSource correctly.

  • 503-509: The RetryableException constructor now includes an explicit cast to Long for a null value. This change aligns with the updates made to the RetryableException class as described in the PR summary.

  • 582-587: Similar to the previous comment, the RetryableException constructor now includes an explicit cast to Long for a null value. This change is consistent with the updates made to the RetryableException class.

  • 607-613: Again, the RetryableException constructor now includes an explicit cast to Long for a null value. This change is consistent with the updates made to the RetryableException class.

  • 629-635: Once more, the RetryableException constructor now includes an explicit cast to Long for a null value. This change is consistent with the updates made to the RetryableException class.

core/src/test/java/feign/codec/RetryAfterDecoderTest.java (4)
  • 26-30: The currentTimeMillis() method has been updated to use the parseDateTime function which uses ZonedDateTime.parse instead of the old DateFormat.parse. This change is in line with the PR's goal of replacing Date instances with epoch milliseconds (Long). Ensure that this change does not affect other parts of the codebase where currentTimeMillis() is used.

  • 34-35: The test malformedDateFailsGracefully() now checks for null instead of a non-null value. This change seems to be due to the update in the apply method of RetryAfterDecoder to return null when it encounters an invalid date format. Make sure this behavior is consistent across the codebase.

  • 50-53: The tests rfc822Parses(), relativeSecondsParses(), and relativeSecondsParseDecimalIntegers() have been updated to use the parseDateTime function instead of DateFormat.parse. This aligns with the PR's goal of replacing Date instances with epoch milliseconds (Long). However, ensure that these changes do not affect the expected outcomes of these tests.

  • 56-61: The parseDateTime function has been introduced to parse a date string into epoch milliseconds using ZonedDateTime.parse. This is a good improvement as it simplifies the conversion process and makes the code more readable.

+ private Long parseDateTime(String text) {
+     try {
+       return ZonedDateTime.parse(text, RFC_1123_DATE_TIME).toInstant().toEpochMilli();
+     } catch (NullPointerException | DateTimeParseException exception) {
+       throw new RuntimeException(exception);
+     }
+    }

Comment on lines 276 to 279
format("%s executing %s %s", cause.getMessage(), request.httpMethod(), request.url()),
request.httpMethod(),
cause,
null, request);
(Long) null, request);
Copy link

@coderabbitai coderabbitai bot Sep 14, 2023

Choose a reason for hiding this comment

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

The explicit casting of null to Long is unnecessary and can be confusing. It's better to simply pass null without casting.

-        (Long) null, request);
+        null, request);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It produces error: reference to RetryableException is ambiguous error.

Copy link

Choose a reason for hiding this comment

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

@vitalijr2, the error message you're seeing is likely due to method overloading ambiguity. When there are multiple overloaded methods and the compiler cannot definitively determine which one to use, it throws an "ambiguous method call" error.

In this case, it seems like there might be another errorExecuting method that accepts a null value for the last parameter but with a different type. The explicit (Long) null cast was probably used to resolve this ambiguity.

To fix this issue, we can introduce a variable of type Long set to null, and pass this variable instead. This way, we maintain the clarity of the code while also resolving the method call ambiguity. Here's how you can do it:

Long retryAfter = null;
return new FeignException(
    format("%s executing %s %s", cause.getMessage(), request.httpMethod(), request.url()),
    request.httpMethod(),
    cause,
    retryAfter, 
    request);

This approach makes it clear that a null value of type Long is being passed, without needing to use an explicit cast.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was implemented, see new comment here #2170 (comment)

Copy link

Choose a reason for hiding this comment

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

@vitalijr2, thank you for implementing the suggested changes. I have reviewed your latest commit and it looks good to me. The introduction of a Long variable set to null has resolved the method call ambiguity while maintaining code clarity. Great job! If there are any other parts of the code you'd like me to review, please let me know.

core/src/test/java/feign/FeignTest.java Outdated Show resolved Hide resolved
core/src/test/java/feign/FeignTest.java Outdated Show resolved Hide resolved
core/src/test/java/feign/FeignTest.java Outdated Show resolved Hide resolved
core/src/test/java/feign/FeignTest.java Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between 5289775 and 824dce9 commits.
Files selected for processing (4)
  • core/src/main/java/feign/FeignException.java (1 hunks)
  • core/src/test/java/feign/AsyncFeignTest.java (6 hunks)
  • core/src/test/java/feign/FeignTest.java (5 hunks)
  • core/src/test/java/feign/RetryerTest.java (4 hunks)
Files skipped from review due to trivial changes (2)
  • core/src/test/java/feign/AsyncFeignTest.java
  • core/src/test/java/feign/RetryerTest.java
Additional comments (Suppressed): 5
core/src/test/java/feign/FeignTest.java (5)
  • 57-60: The constant NON_RETRYABLE has been introduced to replace the previously used null value for non-retryable exceptions. This improves code readability and understanding.

  • 536-543: The RetryableException constructor now uses the NON_RETRYABLE constant instead of null. This change enhances code clarity and consistency.

  • 617-623: Similar to the previous hunk, the NON_RETRYABLE constant is used in the RetryableException constructor, improving code readability.

  • 642-648: Again, the NON_RETRYABLE constant is used in place of null, enhancing code clarity and consistency.

  • 664-671: In this hunk as well, the NON_RETRYABLE constant is used in the RetryableException constructor, which improves code readability.

Comment on lines 273 to 281
static FeignException errorExecuting(Request request, IOException cause) {
final Long nonRetryable = null;
return new RetryableException(
-1,
format("%s executing %s %s", cause.getMessage(), request.httpMethod(), request.url()),
request.httpMethod(),
cause,
null, request);
nonRetryable, request);
}
Copy link

Choose a reason for hiding this comment

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

The change from null to final Long nonRetryable = null; doesn't seem to add any value. It just adds an extra line of code and a variable that is not necessary. The previous implementation was more concise and clear.

- final Long nonRetryable = null;
- return new RetryableException(
-     -1,
-     format("%s executing %s %s", cause.getMessage(), request.httpMethod(), request.url()),
-     request.httpMethod(),
-     cause,
-    nonRetryable, request);
+ return new RetryableException(
+     -1,
+     format("%s executing %s %s", cause.getMessage(), request.httpMethod(), request.url()),
+     request.httpMethod(),
+     cause,
+     null, request);

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Commits Files that changed from the base of the PR and between 824dce9 and fc09db3 commits.
Files selected for processing (6)
  • core/src/main/java/feign/RetryableException.java (4 hunks)
  • core/src/test/java/feign/RetryableExceptionTest.java (2 hunks)
  • core/src/test/java/feign/UtilTest.java (2 hunks)
  • hystrix/src/test/java/feign/hystrix/HystrixBuilderTest.java (6 hunks)
  • jaxrs2/src/main/java/feign/jaxrs2/JAXRSClient.java (1 hunks)
  • pom.xml (1 hunks)
Files skipped from review due to trivial changes (4)
  • core/src/test/java/feign/UtilTest.java
  • hystrix/src/test/java/feign/hystrix/HystrixBuilderTest.java
  • jaxrs2/src/main/java/feign/jaxrs2/JAXRSClient.java
  • pom.xml
Additional comments (Suppressed): 7
core/src/test/java/feign/RetryableExceptionTest.java (2)
  • 24-30: The addition of Long retryAfter = 5000L; is a good change as it replaces the previous Date object with a Long representing epoch milliseconds. This should help resolve timezone issues associated with the Date class.

  • 35-43: Ensure that all calls to the RetryableException constructor throughout the codebase have been updated to match the new signature, which now accepts a Long parameter for retryAfter.

core/src/main/java/feign/RetryableException.java (5)
  • 27-27: The serialVersionUID has been updated from 1L to 2L. This is a good practice when making changes to the serialized form of a class, as it helps maintain version control for serialized objects.

  • 35-40: The constructor now accepts Long retryAfter instead of Date retryAfter. Ensure that all calls to this constructor throughout the codebase have been updated to match the new signature.

  • 53-58: Similar to the previous comment, ensure that all calls to this constructor throughout the codebase have been updated to match the new signature.

  • 71-77: Again, ensure that all calls to this constructor throughout the codebase have been updated to match the new signature.

  • 91-93: The retryAfter() method now returns a Long instead of a Date. Ensure that all calls to this method throughout the codebase have been updated to handle the new return type.

Comment on lines +42 to 45
@Deprecated
public RetryableException(int status, String message, HttpMethod httpMethod, Throwable cause,
Date retryAfter, Request request) {
super(status, message, request, cause);
Copy link

@coderabbitai coderabbitai bot Sep 14, 2023

Choose a reason for hiding this comment

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

This constructor is marked as deprecated and still uses Date retryAfter. If this constructor is no longer needed, consider removing it to avoid confusion and potential misuse in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think at least @velo and @kdavisk6 should approve.

Copy link

Choose a reason for hiding this comment

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

Looks like humans are talking. I'll be quiet for now. If you need me again, just tag @coderabbitai in a new comment.

Comment on lines +60 to 63
@Deprecated
public RetryableException(int status, String message, HttpMethod httpMethod, Date retryAfter,
Request request) {
super(status, message, request);
Copy link

Choose a reason for hiding this comment

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

This constructor is marked as deprecated and still uses Date retryAfter. If this constructor is no longer needed, consider removing it to avoid confusion and potential misuse in the future.

Comment on lines +79 to 82
@Deprecated
public RetryableException(int status, String message, HttpMethod httpMethod, Date retryAfter,
Request request, byte[] responseBody, Map<String, Collection<String>> responseHeaders) {
super(status, message, request, responseBody, responseHeaders);
Copy link

Choose a reason for hiding this comment

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

This constructor is marked as deprecated and still uses Date retryAfter. If this constructor is no longer needed, consider removing it to avoid confusion and potential misuse in the future.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between fc09db3 and cd24cc4 commits.
Files selected for processing (11)
  • core/src/test/java/feign/AsyncFeignTest.java (13 hunks)
  • core/src/test/java/feign/DefaultContractTest.java (4 hunks)
  • core/src/test/java/feign/FeignUnderAsyncTest.java (7 hunks)
  • core/src/test/java/feign/codec/DefaultEncoderTest.java (2 hunks)
  • java11/src/test/java/feign/http2client/test/Http2ClientAsyncTest.java (7 hunks)
  • jaxb-jakarta/src/test/java/feign/jaxb/examples/AWSSignatureVersion4.java (2 hunks)
  • jaxb/src/test/java/feign/jaxb/examples/AWSSignatureVersion4.java (3 hunks)
  • json/src/test/java/feign/json/JsonDecoderTest.java (2 hunks)
  • json/src/test/java/feign/json/JsonEncoderTest.java (2 hunks)
  • okhttp/src/test/java/feign/okhttp/OkHttpClientAsyncTest.java (7 hunks)
  • sax/src/test/java/feign/sax/examples/AWSSignatureVersion4.java (3 hunks)
Files skipped from review due to trivial changes (4)
  • jaxb-jakarta/src/test/java/feign/jaxb/examples/AWSSignatureVersion4.java
  • jaxb/src/test/java/feign/jaxb/examples/AWSSignatureVersion4.java
  • json/src/test/java/feign/json/JsonEncoderTest.java
  • sax/src/test/java/feign/sax/examples/AWSSignatureVersion4.java
Additional comments (Suppressed): 41
core/src/test/java/feign/codec/DefaultEncoderTest.java (2)
  • 19-23: The import of java.time.Clock is new and replaces the previous java.util.Date. This change aligns with the PR's goal of replacing Date instances with epoch milliseconds (Long). Ensure that all usages of Date in this file have been replaced accordingly.

  • 54-54: The test case has been updated to use Clock.systemUTC() instead of new Date(). This change is consistent with the PR's goal. However, ensure that the DefaultEncoder.encode() method can handle Clock objects correctly.

-    encoder.encode(new Date(), Date.class, new RequestTemplate());
+    encoder.encode(Clock.systemUTC(), Clock.class, new RequestTemplate());
json/src/test/java/feign/json/JsonDecoderTest.java (2)
  • 29-33: The import of java.util.Date has been replaced with java.time.Clock. This change aligns with the PR's goal of replacing Date instances with a more reliable time mechanism.

  • 147-152: The test case previously checked for an exception when trying to decode into a Date class. Now it checks for an exception when trying to decode into a Clock class. Ensure that this change is consistent with the updated behavior of the JsonDecoder class.

core/src/test/java/feign/DefaultContractTest.java (4)
  • 20-28: The import statements have been updated to include java.time.Clock, java.time.Instant, and java.time.ZoneId which are necessary for the changes made in this PR. The rest of the imports remain unchanged.

  • 315-322: The test method customExpander() has been updated to use Clock instead of Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 586-600: The interface CustomExpander and class ClockToMillis have been updated to use Clock instead of Date. This is a good change as it aligns with the goal of the PR to replace Date instances with epoch milliseconds (Long). However, ensure that all implementations of the Param.Expander interface have been updated accordingly.

  • 879-905: A new class TestClock extending java.time.Clock has been added. This class seems to be used for testing purposes. It overrides the getZone(), withZone(ZoneId zone), and instant() methods from the Clock class. While this class seems to be correctly implemented, it's important to verify its usage across the test cases to ensure it behaves as expected.

core/src/test/java/feign/FeignUnderAsyncTest.java (7)
  • 36-48: The import of java.util.Date has been replaced with imports for java.time.Clock, java.time.Instant, and java.time.ZoneId. This aligns with the PR's goal of replacing Date instances with epoch milliseconds (Long) across the codebase.

  • 203-210: The expand method call now uses a TestClock instance instead of a Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 215-222: The expandList method call now uses a list of TestClock instances instead of Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 227-234: The expandList method call now uses a list of TestClock instances (with null) instead of Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 859-872: The @RequestLine annotations and corresponding method signatures have been updated to use Clock instead of Date. The expander attribute in the @Param annotation has also been updated to use ClockToMillis instead of DateToMillis. Ensure that all calls to these methods throughout the codebase have been updated to match the new signatures.

  • 897-907: The DateToMillis class has been replaced with ClockToMillis. The expand method now casts the value to Clock instead of Date and calls millis() instead of getTime().

  • 1016-1044: A new TestClock class extending java.time.Clock has been added. This class is used to replace Date instances in the test methods. The instant method returns an Instant of epoch milli from the millis field.

java11/src/test/java/feign/http2client/test/Http2ClientAsyncTest.java (7)
  • 24-36: The import of java.util.Date has been replaced with imports for java.time.Clock, java.time.Instant, and java.time.ZoneId. This aligns with the PR's goal of replacing Date instances with epoch milliseconds (Long) across the codebase.

  • 225-233: The expand method now takes a TestClock instance instead of a Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 240-248: The expandList method now takes a list of TestClock instances instead of Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 254-262: The expandList method now takes a list of TestClock instances (including null) instead of Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 867-883: The expand, expandList, and expandArray methods in the TestInterfaceAsync interface now take Clock parameters instead of Date. The expander attribute of the @Param annotation has also been updated to use the new ClockToMillis class. Ensure that all implementations of these methods have been updated accordingly.

  • 908-918: The DateToMillis class has been replaced with the ClockToMillis class, which converts a Clock instance to milliseconds. This change is consistent with the PR's goal of replacing Date instances with epoch milliseconds (Long).

  • 1065-1093: A new TestClock class has been added, extending the Clock class. This class is used in place of Date in the test cases. The instant method returns an Instant object representing the epoch millisecond value stored in the TestClock instance.

core/src/test/java/feign/AsyncFeignTest.java (13)
  • 16-21: The import statement import static org.assertj.core.api.Assertions.assertThat; has been removed. Ensure that this does not affect any existing assertions in the test cases.

  • 36-48: The import statement import java.util.Date; has been replaced with imports for java.time.Clock, java.time.Instant, and java.time.ZoneId. This aligns with the PR's goal of replacing Date instances with epoch milliseconds (Long).

  • 63-74: The import statement import org.junit.jupiter.params.ParameterizedTest; has been removed. Ensure that this does not affect any existing parameterized tests in the test cases.

  • 227-235: The expand method now takes a Clock object instead of a Date object. The TestClock class is used to create a Clock instance with a specific time in milliseconds. This change aligns with the PR's goal of replacing Date instances with epoch milliseconds (Long).

  • 241-250: Similar to the previous comment, the expandList method now takes a list of Clock objects instead of Date objects. The TestClock class is used to create Clock instances with specific times in milliseconds.

  • 256-264: Again, the expandList method now takes a list of Clock objects instead of Date objects. The TestClock class is used to create Clock instances with specific times in milliseconds. This change also handles null values in the list correctly.

  • 507-514: The RetryableException constructor now includes a NON_RETRYABLE constant (which is null) as an argument. This change aligns with the PR's goal of deprecating the previous constructors that used Date.

  • 586-592: Similar to the previous comment, the RetryableException constructor now includes a NON_RETRYABLE constant as an argument.

  • 611-617: Again, the RetryableException constructor now includes a NON_RETRYABLE constant as an argument.

  • 633-640: Once more, the RetryableException constructor now includes a NON_RETRYABLE constant as an argument.

  • 1024-1040: The expand, expandList, and expandArray methods in the TestInterfaceAsync interface now take Clock objects instead of Date objects. The ClockToMillis class is used as a parameter expander to convert Clock instances to milliseconds. This change aligns with the PR's goal of replacing Date instances with epoch milliseconds (Long).

  • 1065-1075: The DateToMillis class has been replaced with the ClockToMillis class, which converts Clock instances to milliseconds. This change aligns with the PR's goal of replacing Date instances with epoch milliseconds (Long).

  • 1252-1279: The TestClock class has been added. It extends the Clock class and overrides the instant method to return an Instant object with a specific time in milliseconds. This class is used in the test cases to create Clock instances with specific times.

okhttp/src/test/java/feign/okhttp/OkHttpClientAsyncTest.java (6)
  • 26-28: The import of java.time.Clock, java.time.Instant, and java.time.ZoneId is a part of the changes to replace Date instances with epoch milliseconds (Long). This change is in line with the PR's goal of resolving timezone issues associated with the Date class.

  • 223-231: The TestInterfaceAsync's expand method now accepts a Clock object instead of a Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature. Also, verify that the server correctly handles the changed query parameter from date to clock.

  • 238-246: Similar to the previous comment, the expandList method now accepts a list of Clock objects instead of Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature. Also, verify that the server correctly handles the changed query parameters from date to clock.

  • 252-260: Again, the expandList method now accepts a list of Clock objects (including nulls) instead of Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature. Also, verify that the server correctly handles the changed query parameters from date to clock.

  • 865-881: The TestInterfaceAsync interface has been updated to use Clock objects instead of Date in its methods. This change aligns with the PR's goal of replacing Date instances with epoch milliseconds (Long). However, ensure that all implementations of this interface have been updated accordingly.

  • 906-916: The ClockToMillis class has been introduced as a replacement for the DateToMillis class. It correctly converts a Clock object to milliseconds. This change is in line with the PR's goal of replacing Date instances with epoch milliseconds (Long).

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between cd24cc4 and 19be653 commits.
Files selected for processing (3)
  • core/src/test/java/feign/FeignTest.java (12 hunks)
  • hc5/src/test/java/feign/hc5/AsyncApacheHttp5ClientTest.java (8 hunks)
  • java11/src/test/java/feign/http2client/test/Http2ClientAsyncTest.java (8 hunks)
Additional comments (Suppressed): 26
java11/src/test/java/feign/http2client/test/Http2ClientAsyncTest.java (8)
  • 16-19: The import statement import static org.assertj.core.api.Assertions.assertThat; has been removed. Ensure that this does not affect any existing assertions in the test cases.

  • 26-28: The new imports for java.time.Clock, java.time.Instant, and java.time.ZoneId are introduced to replace the usage of java.util.Date. This is a good practice as the java.time package provides a more comprehensive API for date and time operations.

  • 224-232: The method api.expand() now accepts an instance of TestClock instead of Date. Make sure that the expand() method in the TestInterfaceAsync interface and its implementations have been updated accordingly.

  • 239-247: Similar to the previous comment, ensure that the expandList() method in the TestInterfaceAsync interface and its implementations have been updated to accept a list of Clock instances instead of Date.

  • 253-261: Again, verify that the expandList() method in the TestInterfaceAsync interface and its implementations have been updated to handle null values in the list of Clock instances.

  • 866-882: The @RequestLine annotations and method signatures have been updated to use Clock instead of Date. This change aligns with the PR's goal of replacing Date with Clock. However, ensure that all calls to these methods throughout the codebase have been updated to match the new signatures.

  • 907-917: The ClockToMillis class correctly implements the Param.Expander interface and overrides the expand() method to convert a Clock instance to milliseconds. This is a correct implementation of the expander pattern.

  • 1064-1092: The TestClock class extends java.time.Clock and overrides its methods to return custom values for testing purposes. This is a good practice for isolating the tests from the system clock.

hc5/src/test/java/feign/hc5/AsyncApacheHttp5ClientTest.java (8)
  • 16-38: The import statements have been updated to reflect the changes in the codebase. The usage of Date has been replaced with Clock, and the necessary imports for Clock, Instant, and ZoneId have been added. The import statement for HttpClientBuilder has been removed as it is no longer used.

  • 41-48: The import statements have been updated to reflect the changes in the codebase. The import statement for JAXRSContract has been removed as it is no longer used, and the import statement for Charsets from Kotlin has also been removed.

  • 177-185: The method api.expand() now accepts a TestClock object instead of a Date object. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 192-200: The method api.expandList() now accepts a list of TestClock objects instead of a list of Date objects. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 206-214: The method api.expandList() now accepts a list of TestClock objects instead of a list of Date objects. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 864-880: The methods expand(), expandList(), and expandArray() in the TestInterfaceAsync interface have been updated to accept Clock objects instead of Date objects. The expander attribute of the @Param annotation has been updated to use the ClockToMillis class instead of the DateToMillis class. Ensure that all implementations of these methods have been updated accordingly.

  • 905-915: The DateToMillis class has been replaced with the ClockToMillis class, which implements the Param.Expander interface. The expand() method now accepts a Clock object and returns its milliseconds value as a string.

  • 1067-1091: A new TestClock class has been added that extends the Clock class. This class is used for testing purposes to simulate a clock with a specific time in milliseconds. The instant() method returns an Instant object representing the epoch millisecond value of the TestClock.

core/src/test/java/feign/FeignTest.java (10)
  • 60-60: The NON_RETRYABLE constant is introduced but it's not clear why it's set to null. Please provide a comment or use a more descriptive name for the constant.

  • 216-219: Ensure that all calls to api.expand() throughout the codebase have been updated to pass a TestClock object instead of a Date.

  • 228-231: Ensure that all calls to api.expandList() throughout the codebase have been updated to pass a list of TestClock objects instead of Date.

  • 240-243: Ensure that all calls to api.expandList() throughout the codebase have been updated to pass a list of TestClock objects instead of Date. Also, verify how null values are handled in the new implementation.

  • 542-543: The RetryableException constructor now accepts a Long parameter for retryAfter. Ensure that this change doesn't break any existing functionality where retryAfter was previously expected to be null.

  • 622-623: The RetryableException constructor now accepts a Long parameter for retryAfter. Ensure that this change doesn't break any existing functionality where retryAfter was previously expected to be null.

  • 648-649: The RetryableException constructor now accepts a Long parameter for retryAfter. Ensure that this change doesn't break any existing functionality where retryAfter was previously expected to be null.

  • 671-672: The RetryableException constructor now accepts a Long parameter for retryAfter. Ensure that this change doesn't break any existing functionality where retryAfter was previously expected to be null.

  • 1178-1185: Ensure that all calls to these methods throughout the codebase have been updated to pass Clock objects instead of Date.

  • 1226-1232: The expand() method in ClockToMillis now expects a Clock object instead of a Date. Ensure that this change doesn't break any existing functionality where a Date was previously expected.

core/src/test/java/feign/FeignTest.java Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between 19be653 and c391472 commits.
Files selected for processing (7)
  • core/src/test/java/feign/AsyncFeignTest.java (13 hunks)
  • core/src/test/java/feign/DefaultContractTest.java (4 hunks)
  • core/src/test/java/feign/FeignTest.java (12 hunks)
  • core/src/test/java/feign/FeignUnderAsyncTest.java (7 hunks)
  • hc5/src/test/java/feign/hc5/AsyncApacheHttp5ClientTest.java (8 hunks)
  • java11/src/test/java/feign/http2client/test/Http2ClientAsyncTest.java (8 hunks)
  • okhttp/src/test/java/feign/okhttp/OkHttpClientAsyncTest.java (7 hunks)
Files skipped from review due to trivial changes (1)
  • java11/src/test/java/feign/http2client/test/Http2ClientAsyncTest.java
Additional comments (Suppressed): 41
core/src/test/java/feign/DefaultContractTest.java (4)
  • 23-28: The import statements have been updated to include java.time.Clock, java.time.Instant, and java.time.ZoneId which are necessary for the changes made in this PR. The rest of the imports remain unchanged.

  • 316-322: The test method customExpander() has been updated to use Clock instead of Date. The parseAndValidateMetadata() method now takes Clock.class as an argument, and the assertion checks that the expander class is ClockToMillis.class. This change aligns with the PR's goal of replacing Date with Clock.

  • 586-600: The CustomExpander interface and the ClockToMillis class have been updated to work with Clock instead of Date. The @RequestLine annotation now includes a clock parameter, and the clock() method takes a Clock object as an argument. The expand() method in ClockToMillis now casts the value to Clock and calls the millis() method. These changes are consistent with the PR's objective of replacing Date with Clock.

  • 879-905: A new TestClock class has been introduced. This class extends Clock and provides a custom implementation for testing purposes. It overrides the getZone(), withZone(), and instant() methods from the Clock class. The instant() method returns an Instant object representing the current epoch millisecond, which is stored in the millis field. This class will be useful for testing code that uses Clock instances.

core/src/test/java/feign/FeignTest.java (8)
  • 60-60: The NON_RETRYABLE constant is introduced but it's not clear why it's set to null. Please ensure that this change doesn't introduce any unexpected behavior in the retry mechanism.

  • 216-219: Ensure that all calls to the expand method throughout the codebase have been updated to pass a Clock instance instead of a Date.

  • 228-231: Ensure that all calls to the expandList method throughout the codebase have been updated to pass a list of Clock instances instead of Date.

  • 240-243: Ensure that all calls to the expandList method throughout the codebase have been updated to pass a list of Clock instances instead of Date, and that they handle null values correctly.

  • 670-673: The RetryableException constructor now accepts a Long parameter for retryAfter. Ensure that this change doesn't affect the retry mechanism and that the NON_RETRYABLE constant (which is null) is handled correctly in all scenarios where RetryableException is used.

  • 1178-1185: Ensure that all calls to these methods throughout the codebase have been updated to match the new signatures, which now accept Clock instances instead of Date.

  • 1226-1232: This new ClockToMillis class replaces the old DateToMillis class. Ensure that this change doesn't introduce any unexpected behavior when expanding parameters.

  • 1400-1422: This new TestClock class provides a custom Clock implementation for testing purposes. It seems to be well-implemented, but please ensure that its usage aligns with the intended test scenarios.

hc5/src/test/java/feign/hc5/AsyncApacheHttp5ClientTest.java (7)
  • 15-38: The import statements have been updated to reflect the changes in the codebase. The usage of java.time.Clock, java.time.Instant, and java.time.ZoneId is new, which aligns with the PR's goal of replacing Date with Clock.

  • 41-48: The import statements are updated here as well. The removal of feign.jaxrs.JAXRSContract and kotlin.text.Charsets indicates that these classes are no longer used in this test file.

  • 177-185: The method api.expand(new TestClock(1234l)) now takes a TestClock instance instead of a Date. Ensure all calls to this method throughout the codebase have been updated to match the new signature.

  • 192-200: Similar to the previous comment, the method api.expandList(Arrays.asList(new TestClock(1234l), new TestClock(12345l))) now takes a list of TestClock instances instead of Date. Verify that all calls to this method have been updated accordingly.

  • 864-880: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [206-880]

The interface TestInterfaceAsync has been updated to use Clock instead of Date. This includes methods like expand, expandList, and expandArray. Make sure all implementations of this interface have been updated to reflect these changes.

  • 905-915: The inner class ClockToMillis replaces the previous DateToMillis and works with Clock instead of Date. This change aligns with the PR's goal of replacing Date with Clock.

  • 1067-1091: A new TestClock class has been introduced, extending java.time.Clock. This class is used for testing purposes and provides a custom Clock implementation. This is a good practice as it allows for more controlled testing.

okhttp/src/test/java/feign/okhttp/OkHttpClientAsyncTest.java (7)
  • 26-35: The import statements have been updated to include java.time.Clock, java.time.Instant, and java.time.ZoneId which are necessary for the new changes. The java.util.Date import has been removed as it's no longer used in this file.

  • 223-231: The expand method now accepts a TestClock instance instead of a Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 238-246: Similar to the previous comment, the expandList method now accepts a list of TestClock instances instead of Date. Verify that all calls to this method have been updated accordingly.

  • 252-260: Again, the expandList method now accepts a list of TestClock instances instead of Date. One of the elements in the list is null. This should be handled correctly by the method implementation.

  • 865-881: The expand, expandList, and expandArray methods in the TestInterfaceAsync interface have been updated to accept Clock instances instead of Date. Also, the expander attribute of the @Param annotation has been changed from DateToMillis to ClockToMillis. Make sure these changes are reflected wherever these methods are called or implemented.

  • 906-916: The DateToMillis class has been replaced with ClockToMillis which implements the Param.Expander interface. The expand method now casts the value to Clock instead of Date and calls the millis method on it. This change aligns with the overall goal of the PR to replace Date with Clock.

  • 1028-1056: A new TestClock class has been introduced which extends the Clock class. This class is used for testing purposes and overrides the getZone, withZone, and instant methods of the Clock class. The instant method returns an Instant object representing the epoch millisecond value stored in the millis field. This is a good approach to mock the Clock behavior in tests.

core/src/test/java/feign/AsyncFeignTest.java (8)
  • 16-21: The import statement import static org.assertj.core.api.Assertions.assertThat; has been removed. Ensure that this does not affect any existing assertions in the test cases.

  • 39-41: New imports related to Java's time API have been added, replacing the previous usage of java.util.Date. This is a good improvement as it provides more flexibility and precision when dealing with dates and times.

  • 66-66: The import statement import org.junit.jupiter.params.ParameterizedTest; has been replaced with import org.junit.jupiter.params.provider.ValueSource;. Make sure that this change doesn't affect any parameterized tests in the codebase.

  • 230-234: The method call api.expand(new Date(1234l)); has been replaced with api.expand(new TestClock(1234l) {});. This change aligns with the PR's goal of replacing Date with Clock. However, ensure that the TestClock class correctly mimics the behavior of Date for the purposes of these tests.

  • 507-514: The RetryableException constructor now includes NON_RETRYABLE as an argument instead of null. This change improves readability by making it clear that the exception is non-retryable.

  • 1027-1040: The @RequestLine annotations and corresponding method signatures have been updated to use Clock instead of Date, and the ClockToMillis expander is used instead of DateToMillis. These changes are consistent with the PR's goal of replacing Date with Clock.

  • 1068-1074: The DateToMillis class has been replaced with ClockToMillis, which converts a Clock instance to milliseconds. This change is consistent with the PR's goal of replacing Date with Clock.

  • 1255-1277: A new TestClock class has been introduced to replace the usage of Date in tests. This class extends Clock and provides a custom implementation for testing purposes. The instant() method returns an Instant object representing the epoch millisecond, which is consistent with the PR's goal of using epoch milliseconds.

core/src/test/java/feign/FeignUnderAsyncTest.java (7)
  • 36-48: The import of java.util.Date has been replaced with java.time.Clock and java.time.Instant, java.time.ZoneId. This change aligns with the PR's goal of replacing Date usage with Clock.

  • 203-210: The expand method now accepts a TestClock instance instead of a Date. Ensure that all calls to this method throughout the codebase have been updated to match the new signature.

  • 215-222: Similar to the previous comment, the expandList method now accepts a list of TestClock instances. Verify that all calls to this method have been updated accordingly.

  • 227-234: Again, the expandList method now accepts a list of TestClock instances, including null values. Ensure that all calls to this method have been updated to match the new signature.

  • 859-872: The expand, expandList, and expandArray methods in the TestInterface now accept Clock instances instead of Date. The expander class has also been changed from DateToMillis to ClockToMillis. Make sure that all implementations and usages of these methods have been updated to reflect these changes.

  • 900-906: The DateToMillis class has been replaced with ClockToMillis, which works with Clock instances. This change is consistent with the PR's goal of replacing Date usage with Clock.

  • 1016-1042: A new TestClock class has been introduced, extending the Clock class. This custom Clock implementation is used for testing purposes. It overrides the getZone, withZone, and instant methods of the Clock class. The instant method returns an Instant of the epoch milli provided in the constructor, while the getZone and withZone methods throw an UnsupportedOperationException. This implementation seems to be suitable for the test scenarios in this class.

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
Copy link
Member

Choose a reason for hiding this comment

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

It's this available on java8? Nice

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between c391472 and 1690c29 commits.
Files selected for processing (1)
  • pom.xml (1 hunks)
Files skipped from review due to trivial changes (1)
  • pom.xml

@velo velo merged commit be25759 into OpenFeign:master Sep 15, 2023
1 check passed
@vitalijr2 vitalijr2 deleted the retry-after branch February 21, 2024 10:57
velo pushed a commit that referenced this pull request Oct 7, 2024
* Retryer: replace an instance of Date with an epoch millisecond

* Style issue: unnecessary explicit casting

* Add another check to RetryableException's test

* Update serialization ID. Resolve some deprecation issues of Integer.

* Remove obsolete Date

* Remove obsolete Date 2

* Resolve issue with overrided method of a mock class
velo pushed a commit that referenced this pull request Oct 8, 2024
* Retryer: replace an instance of Date with an epoch millisecond

* Style issue: unnecessary explicit casting

* Add another check to RetryableException's test

* Update serialization ID. Resolve some deprecation issues of Integer.

* Remove obsolete Date

* Remove obsolete Date 2

* Resolve issue with overrided method of a mock class
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.

ErrorDecoder and retry-after header timezones issue
2 participants