Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public ValidateOptionsResult Validate(string? name, ActiveMqOptions options)
return Fail("The broker address cannot be null or whitespace.");
}

if (options.Timeout < Timeout.Infinite)
{
return Fail("The timeout cannot be less than infinite (-1).");
}

return Success;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace NetEvolve.HealthChecks.Tests.Integration.Apache.ActiveMq;

using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using NetEvolve.Extensions.XUnit;
using NetEvolve.HealthChecks.Apache.ActiveMq;
using Testcontainers.ActiveMq;
Expand All @@ -25,7 +26,7 @@ private ActiveMqHealthCheckTests(TestContainer container, string? username, stri
public async Task InitializeAsync() => await _container.StartAsync().ConfigureAwait(false);

[Fact]
public async Task AddActiveMq_UseOptionsCreate_ShouldReturnHealthy() =>
public async Task AddActiveMq_UseOptions_ShouldReturnHealthy() =>
await RunAndVerify(healthChecks =>
{
_ = healthChecks.AddActiveMq(
Expand All @@ -40,6 +41,120 @@ await RunAndVerify(healthChecks =>
);
});

[Fact]
public async Task AddActiveMq_UseOptions_ShouldReturnUnhealthy() =>
await RunAndVerify(healthChecks =>
{
_ = healthChecks.AddActiveMq(
"TestContainerUnhealthy",
options =>
{
options.BrokerAddress = "tcp://localhost:65535"; // Unused port
options.Username = "invalid";
options.Password = "invalid";
options.Timeout = 500;
}
);
});

[Fact]
public async Task AddActiveMq_UseOptions_ShouldReturnDegraded() =>
await RunAndVerify(healthChecks =>
{
_ = healthChecks.AddActiveMq(
"TestContainerDegraded",
options =>
{
options.BrokerAddress = _container.GetBrokerAddress();
options.Username = _username;
options.Password = _password;
options.Timeout = 0;
}
);
});

[Fact]
public async Task AddActiveMq_UseConfiguration_ShouldReturnHealthy() =>
await RunAndVerify(
healthChecks => _ = healthChecks.AddActiveMq("TestContainerHealthy"),
config =>
{
var values = new Dictionary<string, string?>(StringComparer.Ordinal)
{
{ "HealthChecks:ActiveMq:TestContainerHealthy:BrokerAddress", _container.GetBrokerAddress() },
{ "HealthChecks:ActiveMq:TestContainerHealthy:Username", _username },
{ "HealthChecks:ActiveMq:TestContainerHealthy:Password", _password },
{ "HealthChecks:ActiveMq:TestContainerHealthy:Timeout", "500" },
};
_ = config.AddInMemoryCollection(values);
}
);

[Fact]
public async Task AddActiveMq_UseConfiguration_ShouldReturnUnhealthy() =>
await RunAndVerify(
healthChecks => _ = healthChecks.AddActiveMq("TestContainerUnhealthy"),
config =>
{
var values = new Dictionary<string, string?>(StringComparer.Ordinal)
{
{ "HealthChecks:ActiveMq:TestContainerUnhealthy:BrokerAddress", "tcp://localhost:65535" },
{ "HealthChecks:ActiveMq:TestContainerUnhealthy:Username", "invalid" },
{ "HealthChecks:ActiveMq:TestContainerUnhealthy:Password", "invalid" },
{ "HealthChecks:ActiveMq:TestContainerUnhealthy:Timeout", "500" },
};
_ = config.AddInMemoryCollection(values);
}
);

[Fact]
public async Task AddActiveMq_UseConfiguration_ShouldReturnDegraded() =>
await RunAndVerify(
healthChecks => _ = healthChecks.AddActiveMq("TestContainerDegraded"),
config =>
{
var values = new Dictionary<string, string?>(StringComparer.Ordinal)
{
{ "HealthChecks:ActiveMq:TestContainerDegraded:BrokerAddress", _container.GetBrokerAddress() },
{ "HealthChecks:ActiveMq:TestContainerDegraded:Username", _username },
{ "HealthChecks:ActiveMq:TestContainerDegraded:Password", _password },
{ "HealthChecks:ActiveMq:TestContainerDegraded:Timeout", "0" },
};
_ = config.AddInMemoryCollection(values);
}
);

[Fact]
public async Task AddActiveMq_UseConfigration_BrokerAddressStringEmpty_ThrowException() =>
await RunAndVerify(
healthChecks => _ = healthChecks.AddActiveMq("TestNoValues"),
config =>
{
var values = new Dictionary<string, string?>(StringComparer.Ordinal)
{
{ "HealthChecks:ActiveMq:TestNoValues:BrokerAddress", "" },
};
_ = config.AddInMemoryCollection(values);
}
);

[Fact]
public async Task AddActiveMq_UseConfigration_TimeoutMinusTwo_ThrowException() =>
await RunAndVerify(
healthChecks => _ = healthChecks.AddActiveMq("TestNoValues"),
config =>
{
var values = new Dictionary<string, string?>(StringComparer.Ordinal)
{
{ "HealthChecks:ActiveMq:TestNoValues:BrokerAddress", _container.GetBrokerAddress() },
{ "HealthChecks:ActiveMq:TestNoValues:Username", _username },
{ "HealthChecks:ActiveMq:TestNoValues:Password", _password },
{ "HealthChecks:ActiveMq:TestNoValues:Timeout", "-2" },
};
_ = config.AddInMemoryCollection(values);
}
);

public sealed class CustomCredentials : ActiveMqHealthCheckTests
{
private static readonly string Username = $"{Guid.NewGuid():D}";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
results: [
{
description: TestNoValues: Unexpected error.,
exception: {
message: The broker address cannot be null or whitespace.,
type: Microsoft.Extensions.Options.OptionsValidationException
},
name: TestNoValues,
status: Unhealthy,
tags: [
activemq,
message-queue
]
}
],
status: Unhealthy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
results: [
{
description: TestNoValues: Unexpected error.,
exception: {
message: The timeout cannot be less than infinite (-1).,
type: Microsoft.Extensions.Options.OptionsValidationException
},
name: TestNoValues,
status: Unhealthy,
tags: [
activemq,
message-queue
]
}
],
status: Unhealthy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
results: [
{
description: TestContainerDegraded: Degraded,
name: TestContainerDegraded,
status: Degraded,
tags: [
activemq,
message-queue
]
}
],
status: Degraded
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
results: [
{
description: TestContainerHealthy: Healthy,
name: TestContainerHealthy,
status: Healthy,
tags: [
activemq,
message-queue
]
}
],
status: Healthy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
results: [
{
description: TestContainerUnhealthy: Unexpected error.,
exception: {
innerExceptions: [
{
message: Unknown error (0xfffffffe),
type: SocketException
}
],
message: Error connecting to localhost:65535.,
type: Apache.NMS.NMSConnectionException
},
name: TestContainerUnhealthy,
status: Unhealthy,
tags: [
activemq,
message-queue
]
}
],
status: Unhealthy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
results: [
{
description: TestContainerDegraded: Degraded,
name: TestContainerDegraded,
status: Degraded,
tags: [
activemq,
message-queue
]
}
],
status: Degraded
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
results: [
{
description: TestContainerUnhealthy: Unexpected error.,
exception: {
innerExceptions: [
{
message: Unknown error (0xfffffffe),
type: SocketException
}
],
message: Error connecting to localhost:65535.,
type: Apache.NMS.NMSConnectionException
},
name: TestContainerUnhealthy,
status: Unhealthy,
tags: [
activemq,
message-queue
]
}
],
status: Unhealthy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
results: [
{
description: TestContainerDegraded: Degraded,
name: TestContainerDegraded,
status: Degraded,
tags: [
activemq,
message-queue
]
}
],
status: Degraded
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
results: [
{
description: TestContainerHealthy: Healthy,
name: TestContainerHealthy,
status: Healthy,
tags: [
activemq,
message-queue
]
}
],
status: Healthy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
results: [
{
description: TestContainerUnhealthy: Unexpected error.,
exception: {
innerExceptions: [
{
message: Unknown error (0xfffffffe),
type: SocketException
}
],
message: Error connecting to localhost:65535.,
type: Apache.NMS.NMSConnectionException
},
name: TestContainerUnhealthy,
status: Unhealthy,
tags: [
activemq,
message-queue
]
}
],
status: Unhealthy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
results: [
{
description: TestNoValues: Unexpected error.,
exception: {
message: The broker address cannot be null or whitespace.,
type: Microsoft.Extensions.Options.OptionsValidationException
},
name: TestNoValues,
status: Unhealthy,
tags: [
activemq,
message-queue
]
}
],
status: Unhealthy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
results: [
{
description: TestNoValues: Unexpected error.,
exception: {
message: The timeout cannot be less than infinite (-1).,
type: Microsoft.Extensions.Options.OptionsValidationException
},
name: TestNoValues,
status: Unhealthy,
tags: [
activemq,
message-queue
]
}
],
status: Unhealthy
}
Loading
Loading