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
Add Apache Pulsar Support to testcontainers-dotnet with Option for TokenAuthentication #1103
base: develop
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for testcontainers-dotnet ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
fcc64e3
to
9f198d7
Compare
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 👍 |
b31b4c1
to
1ebaa37
Compare
Hi @HofmeisterAn , |
Dear @HofmeisterAn. |
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.
c52101c
to
b839b1e
Compare
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.
e4e3581
to
bdcef9d
Compare
@HofmeisterAn, Thank you for your valuable contribution to the open-source community. |
Update index.md to reflect that we use pulsar 3.0.4
…ers-dotnet into entvex-Testcontainers.Pulsar
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.
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.
[PublicAPI] | ||
public sealed class PulsarBuilder : ContainerBuilder<PulsarBuilder, PulsarContainer, PulsarConfiguration> | ||
{ | ||
public const string PulsarImage = "apachepulsar/pulsar:3.0.4"; |
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.
Support the latest version 3.2
too.
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.
Thanks for catching the issue with Pulsar 3.2.2! We'll investigate this further, in the Pulsar community.
In the meantime, using Pulsar version 3.0.4 for TestContainers is a good choice. It's an LTS (Long-Term Support) version, which means it will be supported for a longer period compared to Pulsar 3.2.2 (feature release with shorter support ending in 3 months).
The builder's design for A/B testing makes sense. My local TestContainers tests have been running stably as well.
If you think it's ready. Feel free to merge 👍
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.
I would prefer to address the issue right at the beginning of a new module. Fixing it afterwards is usually difficult (without a module owner). While I had a quick look at the issue, it seems like there are two issues:
-
The
/pulsar/secret.key
file is not created when the wait strategy tries to create the auth token. This is simple to fix. Either wait for the file until it exists or catch the exception and handle the error. -
When I wait until the key exists, and the token gets created successfully, I still receive occasionally:
HTTP ERROR 401 Authentication required
. Once in a while, it works.When the wait strategy does not cache the auth token, it seems less likely to fail. Of course, this is not a proper fix.
Both findings indicate some kind of race-condition, and I am not sure if this will happen with version 3.0.4
as well.
Edit: When I add a 5 second delay right at the beginning of the wait strategy (before creating the auth token), the tests seem to run reliable, which confirms the race-condition we need to fix first, I guess.
diff --git a/src/Testcontainers.Pulsar/PulsarBuilder.cs b/src/Testcontainers.Pulsar/PulsarBuilder.cs
index 7b9b835..c9aa35a 100644
--- a/src/Testcontainers.Pulsar/PulsarBuilder.cs
+++ b/src/Testcontainers.Pulsar/PulsarBuilder.cs
@@ -163,6 +163,9 @@ public sealed class PulsarBuilder : ContainerBuilder<PulsarBuilder, PulsarContai
{
try
{
+ await Task.Delay(TimeSpan.FromSeconds(5))
+ .ConfigureAwait(false);
+
_authToken = await container.CreateAuthenticationTokenAsync(TimeSpan.FromHours(1))
.ConfigureAwait(false);
diff --git a/tests/Testcontainers.Pulsar.Tests/PulsarContainerTest.cs b/tests/Testcontainers.Pulsar.Tests/PulsarContainerTest.cs
index 27ae620..dd4def9 100644
--- a/tests/Testcontainers.Pulsar.Tests/PulsarContainerTest.cs
+++ b/tests/Testcontainers.Pulsar.Tests/PulsarContainerTest.cs
@@ -73,7 +73,7 @@ public abstract class PulsarContainerTest : IAsyncLifetime
public sealed class PulsarAuthConfiguration : PulsarContainerTest
{
public PulsarAuthConfiguration()
- : base(new PulsarBuilder().WithAuthentication().Build())
+ : base(new PulsarBuilder().WithAuthentication().WithImage("apachepulsar/pulsar:3.2.2").Build())
{
}
Can you please complete this? This library is needed for my project. Thank you |
I am waiting for a reponse from @HofmeisterAn :) |
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. |
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 ?