Skip to content

Commit

Permalink
Started Rework of the waitStrategy so it is more reliable.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Jensen committed Mar 20, 2024
1 parent c3e77a7 commit 863f239
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
30 changes: 27 additions & 3 deletions src/Testcontainers.Pulsar/PulsarBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,26 @@ public PulsarBuilder WithFunctionsWorker(bool functionsWorkerEnabled = true)
public override PulsarContainer Build()
{
Validate();
return new PulsarContainer(DockerResourceConfiguration);

var waitStrategy = Wait.ForUnixContainer();

waitStrategy = waitStrategy.UntilHttpRequestIsSucceeded(request
=> request
.ForPath("/admin/v2/clusters")
.ForPort(PulsarWebServicePort)
.ForResponseMessageMatching(VerifyPulsarStatusAsync));

//To Do How do I access PulsarContainer.CreateAuthenticationTokenAsync so i can get the auth token?
// waitStrategy = waitStrategy.UntilHttpRequestIsSucceeded(request
// => request
// .ForPath("/admin/v2/clusters")
// .ForPort(PulsarWebServicePort)
// .ForResponseMessageMatching(VerifyPulsarStatusAsync)
// .WithHeader("Authorization", ));

var pulsarBuilder = WithWaitStrategy(waitStrategy);

return new PulsarContainer(pulsarBuilder.DockerResourceConfiguration);
}

/// <inheritdoc />
Expand All @@ -94,10 +113,9 @@ protected override PulsarBuilder Init()
.WithFunctionsWorker(false)
.WithEntrypoint("/bin/sh", "-c")
.WithCommand("while [ ! -f " + StartupScriptFilePath + " ]; do sleep 0.1; done; " + StartupScriptFilePath)
.WithWaitStrategy(Wait.ForUnixContainer().UntilCommandIsCompleted("bin/pulsar-admin", "clusters", "list"))
.WithStartupCallback((container, ct) => container.CopyStartupScriptAsync(ct));
}

/// <inheritdoc />
protected override PulsarBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration)
{
Expand All @@ -115,4 +133,10 @@ protected override PulsarBuilder Merge(PulsarConfiguration oldValue, PulsarConfi
{
return new PulsarBuilder(new PulsarConfiguration(oldValue, newValue));
}

private async Task<bool> VerifyPulsarStatusAsync(System.Net.Http.HttpResponseMessage response)
{
var readAsStringAsync = await response.Content.ReadAsStringAsync();
return readAsStringAsync == "[\"standalone\"]";
}
}
12 changes: 10 additions & 2 deletions src/Testcontainers.Pulsar/PulsarConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,20 @@ public PulsarConfiguration(PulsarConfiguration oldValue, PulsarConfiguration new
}

/// <summary>
///
/// Gets or sets the flag indicating whether authentication is enabled for the Pulsar container.
/// </summary>
/// <remarks>
/// By default, authentication is disabled.
/// Setting this property to true enables authentication for the Pulsar container.
/// </remarks>
public bool? AuthenticationEnabled { get; }

/// <summary>
///
/// Gets or sets a value indicating whether the functions worker is enabled.
/// </summary>
/// <remarks>
/// The functions worker is responsible for executing functions within Pulsar.
/// By default, the functions worker is not enabled.
/// </remarks>
public bool? FunctionsWorkerEnabled { get; }
}

0 comments on commit 863f239

Please sign in to comment.