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: Add Apache Pulsar module #1103

Merged
merged 16 commits into from
Jun 2, 2024

Conversation

entvex
Copy link
Contributor

@entvex entvex commented Jan 31, 2024

What does this PR do?

This PR introduces Apache Pulsar support to testcontainers-dotnet, enabling users to easily spin up Pulsar containers for testing purposes. It also provides an option to enable TokenAuthentication, allowing for secure Pulsar interactions.

Why is it important?

Apache Pulsar is a rapidly growing distributed messaging system gaining traction in the cloud-native ecosystem. Integrating Pulsar support into testcontainers-dotnet will make it easier for developers to test their applications using Pulsar. Additionally, providing TokenAuthentication support enhances security and privacy in Pulsar-based testing scenarios.

How to test this PR

Run the XUnit tests in the testcontainers-dotnet project to ensure the Pulsar containerization and TokenAuthentication functionality work as expected.

Follow-ups

@HofmeisterAn, I encountered a challenge while adding WithTokenAuthentication capabilities to PulsarBuilder. The current implementation of WithCommand appends commands instead of replacing them, making it difficult to modify container startup commands based on selected Pulsar features. In the testcontainers-java module, the container command is modified just before the container starts, enabling control over its execution. Could you provide suggestions on how to achieve a similar approach in testcontainers-dotnet?

In the java module they seem to have the control to edit it, just before the container starts

Do you have a suggestion on a suggestion on how I should implement this for testcontainers-dotnet ?

Copy link

netlify bot commented Jan 31, 2024

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit f4d5be9
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-dotnet/deploys/665c242add249c0008729202
😎 Deploy Preview https://deploy-preview-1103--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@entvex entvex force-pushed the Testcontainers.Pulsar branch 3 times, most recently from fcc64e3 to 9f198d7 Compare February 5, 2024 09:56
@HofmeisterAn
Copy link
Collaborator

The current implementation of WithCommand appends commands instead of replacing them, making it difficult to modify container startup commands based on selected Pulsar features.

You can apply the final command at the end. We are doing this in other modules too; sometimes it is necessary to configure the wait strategy at the end. You just need to keep a reference somewhere (in the configuration) to decide which command should be used. Or you can use a similar approach we are doing with Kafka and upload a script that gets executed. Does that help?

@entvex
Copy link
Contributor Author

entvex commented Feb 7, 2024

The current implementation of WithCommand appends commands instead of replacing them, making it difficult to modify container startup commands based on selected Pulsar features.

You can apply the final command at the end. We are doing this in other modules too; sometimes it is necessary to configure the wait strategy at the end. You just need to keep a reference somewhere (in the configuration) to decide which command should be used. Or you can use a similar approach we are doing with Kafka and upload a script that gets executed. Does that help?

Yes! Thanks 👍

@entvex entvex force-pushed the Testcontainers.Pulsar branch 3 times, most recently from b31b4c1 to 1ebaa37 Compare February 9, 2024 11:19
@entvex entvex marked this pull request as ready for review February 9, 2024 11:37
@entvex
Copy link
Contributor Author

entvex commented Feb 9, 2024

Hi @HofmeisterAn ,
Testcontainers.Pulsar is now ready for a code review.

@entvex
Copy link
Contributor Author

entvex commented Feb 26, 2024

Dear @HofmeisterAn.
I can see you have started looking at my PR.
Please let me know if you need any help getting it across the finish line 💪.

@HofmeisterAn HofmeisterAn added enhancement New feature or request module An official Testcontainers module labels Mar 11, 2024
@entvex entvex mentioned this pull request Mar 18, 2024
David Jensen and others added 6 commits April 12, 2024 13:09
The Pulsar image has been upgraded from apachepulsar/pulsar:3.0.3 to apachepulsar/pulsar:3.0.4. Moreover, changes are made in the wait strategy to improve the way it handles authentication. A new WaitUntil class has been introduced to manage the authentication token.
@entvex entvex force-pushed the Testcontainers.Pulsar branch from c52101c to b839b1e Compare April 12, 2024 11:09
A new file, PulsarService.cs, has been added, with a struct named PulsarService that allows the creation of different Pulsar services. Changes have also been made to PulsarBuilder.cs, mainly to incorporate the use of PulsarService. Rather than using a constant value, `WithAuthentication()` and `WithFunctionsWorker(bool functionsWorkerEnabled = true)` now use elements from the PulsarService struct. Wait strategy has been updated to better account for various enabled services.
@entvex entvex force-pushed the Testcontainers.Pulsar branch from e4e3581 to bdcef9d Compare April 12, 2024 11:41
@entvex
Copy link
Contributor Author

entvex commented Apr 12, 2024

@HofmeisterAn,
I have successfully integrated the approach you suggested from Couchbase into the pulsar module. During my individual testing, the tests passed without any issues. However, when I queued them to run consecutively, I noticed that the test without authentication was hanging. I am wondering if there might be an issue with the [UsedImplicitly] after you refactored the tests. Could you please take a closer look and let me know if you spot anything?

Thank you for your valuable contribution to the open-source community.

Copy link
Collaborator

@HofmeisterAn HofmeisterAn left a comment

Choose a reason for hiding this comment

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

I am wondering if there might be an issue with the [UsedImplicitly] after you refactored the tests.

No, this controls the usage check (code smell detection).

The issue was with the EnabledServices implementation. You cannot store values in the builder because the builder returns new instances and loses the information without further adjustments (we made this change to support A/B testing). Therefore, the authentication use case was not properly configured. Please take a look at the latest adjustments and let me know what you think. IMO the implementation looks good. However, we should take a final look at the configuration and figure out why the latest version is incompatible. Version 3.2.2 does not start with enabled authentication.

src/Testcontainers.Pulsar/PulsarBuilder.cs Outdated Show resolved Hide resolved
@entvex entvex requested a review from HofmeisterAn April 23, 2024 11:08
@Loydik
Copy link

Loydik commented May 13, 2024

Can you please complete this? This library is needed for my project. Thank you

@entvex
Copy link
Contributor Author

entvex commented May 14, 2024

Can you please complete this? This library is needed for my project. Thank you

I am waiting for a reponse from @HofmeisterAn :)

@HofmeisterAn
Copy link
Collaborator

I stumbled across this discussion where the friends from Go are trying to achieve something similar. Maybe this can help to sort out the issue or align the configuration.

@entvex
Copy link
Contributor Author

entvex commented May 24, 2024

I stumbled across this discussion where the friends from Go are trying to achieve something similar. Maybe this can help to sort out the issue or align the configuration.

Very interesting! Thanks for the link!

Pulsar image version in PulsarBuilder has been updated from 3.0.4 to 3.2.3. The authentication token validity period has been extended from 1 hour to 365 days in both PulsarBuilder and PulsarContainerTest to reduce the impact of a token creation bug in Apache Pulsar. This change significantly reduces the impact of a token creation bug that affected versions 3.2.0 to 3.2.3. The bug is related to mishandling time units (seconds as milliseconds).
@entvex
Copy link
Contributor Author

entvex commented May 29, 2024

Hi @HofmeisterAn,

I've identified a critical bug in Apache Pulsar related to token creation. The issue stems from mishandling time units (specifically, treating seconds as milliseconds). In my latest commit to this module, I've adjusted the expiration time for tokens used in the authentication to be one year. This change mitigates the impact of the token creation bug, which affected versions 3.2.0 to 3.2.3.

@entvex
Copy link
Contributor Author

entvex commented May 29, 2024

The tests now run reliably, so you are free to merge 😄 @HofmeisterAn

@HofmeisterAn
Copy link
Collaborator

specifically, treating seconds as milliseconds

I see. Do you have any additional information, such as official documentation, a related issue, etc., regarding the workaround? Do we set the --expiry-time correct? I can review the PR again sometime this week ✌️.

@entvex
Copy link
Contributor Author

entvex commented May 29, 2024

specifically, treating seconds as milliseconds

I see. Do you have any additional information, such as official documentation, a related issue, etc., regarding the workaround? Do we set the --expiry-time correct? I can review the PR again sometime this week ✌️.

Jep, we have set the --expiry-time correct. But as I mentioned before, the bug is in pulsar. I have already talked to another Apache Pulsar PMC. I'll create an issue and submit a PR for pulsar, but I have not created them yet. Therefore, I can't link to them here.

The issue arises because Apache Pulsar incorrectly treats seconds as milliseconds in specific versions. To address this, we multiply the value by 1000 when using affected versions.
Copy link
Collaborator

@HofmeisterAn HofmeisterAn 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 PR, the efforts, and the patience. Great first contribution 🙏.

@HofmeisterAn HofmeisterAn changed the title Add Apache Pulsar Support to testcontainers-dotnet with Option for TokenAuthentication feat: Add Apache Pulsar module Jun 2, 2024
@HofmeisterAn HofmeisterAn merged commit 4a512ef into testcontainers:develop Jun 2, 2024
11 checks passed
@entvex
Copy link
Contributor Author

entvex commented Jun 2, 2024

Thanks for the PR, the efforts, and the patience. Great first contribution 🙏.

Thanks a lot! It was a pleasure working with you. I hope we can collaborate more modules soon 👍

@entvex entvex deleted the Testcontainers.Pulsar branch June 2, 2024 17:24
@smbecker
Copy link
Contributor

smbecker commented Jun 3, 2024

I noticed that this merged. Do you have an estimate on when it will be available in nuget?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request module An official Testcontainers module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants