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

Refactor of HttpSender implementations with Factory Pattern (1/2) #171

Merged
merged 9 commits into from
Aug 29, 2023
Merged

Refactor of HttpSender implementations with Factory Pattern (1/2) #171

merged 9 commits into from
Aug 29, 2023

Conversation

aprodhomme-dkt
Copy link
Contributor

@aprodhomme-dkt aprodhomme-dkt commented Jun 30, 2023

This PR aims to have clearer responsibilities between the multiple HttpSender implementations. This is required to increase code coverage before introducing a new way to retrieve an access token (see 2nd PR: #172)

Changes:

  • refactor Http senders to expose a factory HttpSenderFactory and provide an implementation according to the configuration
  • Use abstraction AbstractHttpSender for sending message and sending with retry
  • Every Http request is handled by a HttpSender implementation, even retrieving an access token with AccessTokenHttpSender
  • Each HttpSender implementation creates its own HttpRequestBuilder with separate responsibilities

This refactor allows to test the HttpRequest that is sent to the API publisher and it covers all scenarios depending on the configuration.

- refactor Http senders to expose a factory `HttpSenderFactory` and provide an implementation according to the configuration
- Use abstraction `AbstractHttpSender` for sending message and sending with retry
- Every Http request is handled by a `HttpSender` implementation, even retrieving an access token with `AccessTokenHttpSender`
- Each `HttpSender` implementation creates its own `HttpRequestBuilder` with separate responsibilities
- Add Code coverage on `sender` package to test the HttpRequest configuration
@aprodhomme-dkt aprodhomme-dkt requested review from a team as code owners June 30, 2023 13:03
@aprodhomme-dkt aprodhomme-dkt changed the title feature: Several refactors to make the code maintainable and testable Refactor of HttpSender implementations with Factory Pattern Jun 30, 2023
@aprodhomme-dkt aprodhomme-dkt changed the title Refactor of HttpSender implementations with Factory Pattern Refactor of HttpSender implementations with Factory Pattern (1/2) Jun 30, 2023
Copy link
Contributor

@jeqo jeqo left a comment

Choose a reason for hiding this comment

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

Some comments on the main implementation. Will look into the tests a bit later.

Thanks @aprodhomme-dkt !

@aprodhomme-dkt aprodhomme-dkt requested a review from jeqo July 13, 2023 12:12
Copy link
Contributor

@jeqo jeqo left a comment

Choose a reason for hiding this comment

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

@aprodhomme-dkt this is looking good! Thanks for helping me understand some of the changes.
I've added some additional comments on both PRs, mostly cosmetic.

@aprodhomme-dkt aprodhomme-dkt requested a review from jeqo July 25, 2023 14:41
Copy link
Contributor

@jeqo jeqo left a comment

Choose a reason for hiding this comment

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

@aprodhomme-dkt thanks for applying most suggestions! I think there's a last missing nit to resolve; otherwise I'm happy to approve this PR.

Thanks again for the efforts here.

@@ -26,9 +26,9 @@ interface HttpResponseHandler {

Logger LOGGER = LoggerFactory.getLogger(HttpResponseHandler.class);

void onResponse(final HttpResponse<String> response) throws IOException;
void onResponse(final HttpResponse<String> response, int retriesNumber) throws IOException;
Copy link
Contributor

Choose a reason for hiding this comment

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

the last nit missing

@aprodhomme-dkt
Copy link
Contributor Author

Here you go :)

@aprodhomme-dkt aprodhomme-dkt requested a review from jeqo July 26, 2023 09:53
Copy link
Contributor

@jeqo jeqo left a comment

Choose a reason for hiding this comment

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

A couple of Test classes may need to be renamed

@aprodhomme-dkt aprodhomme-dkt requested a review from jeqo July 27, 2023 09:44
@aprodhomme-dkt
Copy link
Contributor Author

aprodhomme-dkt commented Aug 3, 2023

@jeqo any news on those PRs?

Copy link
Contributor

@jjaakola-aiven jjaakola-aiven left a comment

Choose a reason for hiding this comment

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

PR looks good to me, just two small changes requested.

jeqo
jeqo previously approved these changes Aug 8, 2023
Copy link
Contributor

@jeqo jeqo left a comment

Choose a reason for hiding this comment

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

@aprodhomme-dkt thanks for this contribution! I'm preemptively approving this, and we can merge it once Jaarkko's suggestions are resolved.

# Conflicts:
#	src/main/java/io/aiven/kafka/connect/http/HttpSinkTask.java
@aprodhomme-dkt aprodhomme-dkt requested a review from jeqo August 29, 2023 09:26
@aprodhomme-dkt
Copy link
Contributor Author

Hi @jeqo and @jjaakola-aiven, thanks for your reviews. I have just took into account your last comments.

@jeqo jeqo merged commit db88315 into Aiven-Open:main Aug 29, 2023
@jeqo
Copy link
Contributor

jeqo commented Aug 29, 2023

Thanks, @aprodhomme-dkt! Let's have a look at #172 to wrap up this contribution 🙌🏽

@aprodhomme-dkt aprodhomme-dkt deleted the refactor_for_coverage branch November 8, 2023 16:22
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.

3 participants