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

feat(client): support push query termination in Java client #5371

Merged
merged 4 commits into from
May 16, 2020

Conversation

vcrfxia
Copy link
Contributor

@vcrfxia vcrfxia commented May 15, 2020

Description

^ via the /close-query endpoint. This PR also adds a test to check that StreamedQueryResult objects are properly completed when the underlying query is terminated.

Testing done

Unit tests.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@vcrfxia vcrfxia requested a review from a team as a code owner May 15, 2020 03:03
@vcrfxia vcrfxia requested a review from purplefox May 15, 2020 03:05
Copy link
Contributor

@purplefox purplefox left a comment

Choose a reason for hiding this comment

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

Nice!

recordParser.exceptionHandler(responseHandler::handleException);
}

private static void handleSuccessfulCloseQueryResponse(final CompletableFuture<Void> cf) {
Copy link
Contributor

Choose a reason for hiding this comment

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

These methods and the one above seem like overkill - I'd probably just put them in the lambda.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above, I've refactored this. Hopefully your concerns have been addressed indirectly.

@@ -158,15 +188,10 @@ private HttpClientRequest configureBasicAuth(final HttpClientRequest request) {
private static <T> void handleResponse(
final HttpClientResponse response,
final CompletableFuture<T> cf,
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems odd to pass in both a cf and a Handler to signal back both exceptionally and successful results. Can't the cf do both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored this to be less convoluted.

"/query-stream",
response -> handleResponse(response, cf, responseHandlerSupplier))
path,
response -> handleResponse(response, cf, successfulResponseHandler))
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need to pass in successfulResponseHandler here, you can just call cf.thenAccept(this::successfulResponseHandler) (or similar) in this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not quite. The CompletableFuture will succeed even if the response status is not 200. The successful response handler is only meant to be called if the response status is 200, else the error handling logic should be called. I realize the way this is currently set up is a bit convoluted, though, so I've refactored it to be more readable.

Copy link
Contributor Author

@vcrfxia vcrfxia left a comment

Choose a reason for hiding this comment

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

Thanks for the review, @purplefox ! I've added a slight refactor to (hopefully) make this more readable. LMK if I haven't addressed your concerns and I'll open a follow-up.

"/query-stream",
response -> handleResponse(response, cf, responseHandlerSupplier))
path,
response -> handleResponse(response, cf, successfulResponseHandler))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not quite. The CompletableFuture will succeed even if the response status is not 200. The successful response handler is only meant to be called if the response status is 200, else the error handling logic should be called. I realize the way this is currently set up is a bit convoluted, though, so I've refactored it to be more readable.

@@ -158,15 +188,10 @@ private HttpClientRequest configureBasicAuth(final HttpClientRequest request) {
private static <T> void handleResponse(
final HttpClientResponse response,
final CompletableFuture<T> cf,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored this to be less convoluted.

recordParser.exceptionHandler(responseHandler::handleException);
}

private static void handleSuccessfulCloseQueryResponse(final CompletableFuture<Void> cf) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As above, I've refactored this. Hopefully your concerns have been addressed indirectly.

@vcrfxia vcrfxia merged commit 62dacca into confluentinc:master May 16, 2020
@vcrfxia vcrfxia deleted the java-client-terminate-query branch May 16, 2020 23:54
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.

2 participants