This is an automated email from the ASF dual-hosted git repository.

blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new d0d8e45  Upgrade Testcontainers version and streamline Pulsar 
configuration (#226)
d0d8e45 is described below

commit d0d8e45a7d2aa85fb67862ccf95ac7e8a22201b4
Author: entvex <[email protected]>
AuthorDate: Mon Jun 17 14:32:14 2024 +0200

    Upgrade Testcontainers version and streamline Pulsar configuration (#226)
    
    This commit enhances the Testcontainers version used in tests and 
incorporates the 'Testcontainers.Pulsar' package for improved integration. It 
significantly streamlines the establishment process for Pulsar during 
integration tests. The environment configuration and token creation procedures 
are now managed using specific methods from the 'Testcontainers.Pulsar' 
package. Additionally, the Testcontainers image version has also been updated.
    
    Co-authored-by: David Jensen <[email protected]>
---
 tests/DotPulsar.Tests/DotPulsar.Tests.csproj |  3 +-
 tests/DotPulsar.Tests/IntegrationFixture.cs  | 45 +++++-----------------------
 2 files changed, 9 insertions(+), 39 deletions(-)

diff --git a/tests/DotPulsar.Tests/DotPulsar.Tests.csproj 
b/tests/DotPulsar.Tests/DotPulsar.Tests.csproj
index 7633898..777784b 100644
--- a/tests/DotPulsar.Tests/DotPulsar.Tests.csproj
+++ b/tests/DotPulsar.Tests/DotPulsar.Tests.csproj
@@ -24,7 +24,8 @@
     <PackageReference Include="K4os.Compression.LZ4" Version="1.3.8" />
     <PackageReference Include="NSubstitute" Version="5.1.0" />
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
-    <PackageReference Include="Testcontainers" Version="3.8.0" />
+    <PackageReference Include="Testcontainers" Version="3.9.0" />
+    <PackageReference Include="Testcontainers.Pulsar" Version="3.9.0" />
     <PackageReference Include="ToxiproxyNetCore" Version="1.0.35" />
     <PackageReference Include="xunit" Version="2.8.1" />
     <PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
diff --git a/tests/DotPulsar.Tests/IntegrationFixture.cs 
b/tests/DotPulsar.Tests/IntegrationFixture.cs
index cf882d9..09f0010 100644
--- a/tests/DotPulsar.Tests/IntegrationFixture.cs
+++ b/tests/DotPulsar.Tests/IntegrationFixture.cs
@@ -18,6 +18,7 @@ using DotNet.Testcontainers.Builders;
 using DotNet.Testcontainers.Containers;
 using DotNet.Testcontainers.Networks;
 using DotPulsar.Abstractions;
+using Testcontainers.Pulsar;
 using Toxiproxy.Net;
 using Xunit.Abstractions;
 using Xunit.Sdk;
@@ -33,7 +34,7 @@ public class IntegrationFixture : IAsyncLifetime
     private readonly CancellationTokenSource _cts;
     private readonly IMessageSink _messageSink;
     private readonly INetwork _network;
-    private readonly IContainer _pulsarCluster;
+    private readonly PulsarContainer _pulsarCluster;
     private readonly IContainer _toxiProxy;
     private Client _toxiProxyClient;
     private Connection _toxiProxyConnection;
@@ -45,31 +46,12 @@ public class IntegrationFixture : IAsyncLifetime
         _messageSink = messageSink;
         _cts = new CancellationTokenSource(TimeSpan.FromMinutes(10));
 
-        var environmentVariables = new Dictionary<string, string>
-        {
-            { "PULSAR_PREFIX_tokenSecretKey", $"file://{SecretKeyPath}" },
-            { "PULSAR_PREFIX_authenticationRefreshCheckSeconds", "5" },
-            { "superUserRoles", UserName },
-            { "authenticationEnabled", "true" },
-            { "authorizationEnabled", "true" },
-            { "authenticationProviders", 
"org.apache.pulsar.broker.authentication.AuthenticationProviderToken" },
-            { "authenticateOriginalAuthData", "false" },
-            { "brokerClientAuthenticationPlugin", AuthenticationPlugin },
-            { "CLIENT_PREFIX_authPlugin", AuthenticationPlugin }
-        };
-
-        var arguments =
-            $"bin/pulsar tokens create-secret-key --output {SecretKeyPath} && 
" +
-            $"export brokerClientAuthenticationParameters=token:$(bin/pulsar 
tokens create --secret-key {SecretKeyPath} --subject {UserName}) && " +
-            $"export 
CLIENT_PREFIX_authParams=$brokerClientAuthenticationParameters && 
bin/apply-config-from-env.py conf/standalone.conf && " +
-            $"bin/apply-config-from-env-with-prefix.py CLIENT_PREFIX_ 
conf/client.conf && bin/pulsar standalone --no-functions-worker";
-
         _network = new NetworkBuilder()
             .WithName(Guid.NewGuid().ToString("D"))
             .Build();
 
         _toxiProxy = new ContainerBuilder()
-            .WithImage("ghcr.io/shopify/toxiproxy:2.7.0")
+            .WithImage("ghcr.io/shopify/toxiproxy:2.9.0")
             .WithPortBinding(ToxiProxyControlPort, true)
             .WithPortBinding(ToxiProxyPort, true)
             .WithHostname("toxiproxy")
@@ -77,13 +59,10 @@ public class IntegrationFixture : IAsyncLifetime
             
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(strategy 
=> strategy.ForPath("/version").ForPort(ToxiProxyControlPort)))
             .Build();
 
-        _pulsarCluster = new ContainerBuilder()
-            .WithImage("apachepulsar/pulsar:3.1.3")
-            .WithEnvironment(environmentVariables)
-            .WithHostname("pulsar")
+        _pulsarCluster = new PulsarBuilder()
+            .WithAuthentication()
             .WithNetwork(_network)
-            
.WithWaitStrategy(Wait.ForUnixContainer().UntilCommandIsCompleted(["/bin/bash", 
"-c", "bin/pulsar-admin clusters list"]))
-            .WithCommand("/bin/bash", "-c", arguments)
+            .WithHostname("pulsar")
             .Build();
 
         ServiceUrl = new 
Uri($"pulsar://{_pulsarCluster.Hostname}:{PulsarPort}");
@@ -148,17 +127,7 @@ public class IntegrationFixture : IAsyncLifetime
 
     public async Task<string> CreateToken(TimeSpan expiryTime, 
CancellationToken cancellationToken)
     {
-        var arguments = $"bin/pulsar tokens create --secret-key 
{SecretKeyPath} --subject {UserName}";
-
-        if (expiryTime != Timeout.InfiniteTimeSpan)
-            arguments += $" --expiry-time {expiryTime.TotalSeconds}s";
-
-        var result = await _pulsarCluster.ExecAsync(["/bin/bash", "-c", 
arguments], cancellationToken);
-
-        if (result.ExitCode != 0)
-            throw new InvalidOperationException($"Could not create the token: 
{result.Stderr}");
-
-        return result.Stdout.Trim();
+        return await _pulsarCluster.CreateAuthenticationTokenAsync(expiryTime, 
cancellationToken);
     }
 
     private static string CreateTopicName() => 
$"persistent://public/default/{Guid.NewGuid():N}";

Reply via email to