-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[fix][admin] Fix asyncGetRequest to handle 204 #25124
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request fixes the async GET request handling in the Pulsar admin client to properly support HTTP 204 (No Content) responses. The changes ensure that both 200 OK and 204 No Content are treated as successful responses, with 204 completing the future with null since there's no response body.
- Modified
BaseResource.asyncGetRequestto accept both 200 and 204 status codes as successful responses - Added comprehensive test coverage for various HTTP response scenarios (200 with body, 204, 404, 500, and 200 with empty body)
- Exposed the
rootWebTarget via a package-private test method to facilitate testing
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/BaseResource.java | Updated async GET request handler to accept 204 No Content responses and complete the future with null when no body is present |
| pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/PulsarAdminImpl.java | Added package-private getRoot() method with @VisibleForTesting annotation to expose WebTarget for testing |
| pulsar-client-admin/src/test/java/org/apache/pulsar/client/admin/internal/AsyncGetRequestTest.java | New test class providing comprehensive coverage for async GET request scenarios including 200 OK, 204 No Content, 404, 500, and empty body cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...-client-admin/src/test/java/org/apache/pulsar/client/admin/internal/AsyncGetRequestTest.java
Show resolved
Hide resolved
...-client-admin/src/test/java/org/apache/pulsar/client/admin/internal/AsyncGetRequestTest.java
Show resolved
Hide resolved
...-client-admin/src/test/java/org/apache/pulsar/client/admin/internal/AsyncGetRequestTest.java
Show resolved
Hide resolved
...-client-admin/src/test/java/org/apache/pulsar/client/admin/internal/AsyncGetRequestTest.java
Show resolved
Hide resolved
pulsar-client-admin/src/main/java/org/apache/pulsar/client/admin/internal/PulsarAdminImpl.java
Show resolved
Hide resolved
...-client-admin/src/test/java/org/apache/pulsar/client/admin/internal/AsyncGetRequestTest.java
Show resolved
Hide resolved
lhotari
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. However, I'm just wondering whether some existing behavior depends on this change.
|
@lhotari I noticed that
|
@nodece Just wondering if something is currently broken due to the lack of properly handling 204 return code. |
|
I believe most use cases still work today. In my environment, I use the pulsar-admin API to get the replicator dispatch rate of a namespace. This is on a private Pulsar distribution, not upstream Apache Pulsar. That said, Apache Pulsar itself still relies on this behavior in several admin APIs, so proper handling of HTTP 204 responses is required. This PR ensures consistent and correct behavior in those cases. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #25124 +/- ##
=============================================
+ Coverage 38.75% 74.48% +35.73%
- Complexity 13215 33684 +20469
=============================================
Files 1842 1899 +57
Lines 145545 149716 +4171
Branches 16916 17405 +489
=============================================
+ Hits 56400 111512 +55112
+ Misses 81460 29322 -52138
- Partials 7685 8882 +1197
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
(cherry picked from commit bf98773)
(cherry picked from commit bf98773)
Motivation
This pull request improves the handling and testing of asynchronous GET requests in the Pulsar admin client. The main changes ensure that both HTTP 200 (OK) and 204 (No Content) responses are treated as successful, and introduce comprehensive tests to verify correct behavior for various HTTP response scenarios.
Modifications
Enhancements to async GET request handling:
BaseResource.javaso that both HTTP 200 (OK) and 204 (No Content) responses are accepted as successful. For 204 responses, the future is completed withnullsince there is no response body to process.Testing improvements:
AsyncGetRequestTest.javato thoroughly test the async GET request logic. The tests cover successful responses with and without a body (200 and 204), as well as error responses like 404 and 500, and 200 with an empty body.Testability and code maintenance:
rootWebTarget inPulsarAdminImplvia a new@VisibleForTestingmethod to facilitate direct testing of request paths.@VisibleForTestingtoPulsarAdminImpl.java.Documentation
docdoc-requireddoc-not-neededdoc-complete