feat(historian): drain/capacity/retention config knobs + startup config-warning validation

This commit is contained in:
Joseph Doherty
2026-06-11 13:04:16 -04:00
parent 61b230d79a
commit f215982b93
4 changed files with 84 additions and 3 deletions
@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.AlarmHistorian;
using ZB.MOM.WW.OtOpcUa.Runtime.Historian;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Historian;
@@ -91,4 +92,49 @@ public sealed class AlarmHistorianRegistrationTests
try { Directory.Delete(tempDir, recursive: true); } catch (IOException) { /* best effort */ }
}
}
[Fact]
public void Section_binds_drain_capacity_and_retention_knobs()
{
var config = ConfigFrom(new Dictionary<string, string?>
{
["AlarmHistorian:Enabled"] = "true",
["AlarmHistorian:DrainIntervalSeconds"] = "11",
["AlarmHistorian:Capacity"] = "500",
["AlarmHistorian:DeadLetterRetentionDays"] = "7",
});
var opts = config.GetSection(AlarmHistorianOptions.SectionName).Get<AlarmHistorianOptions>();
opts.ShouldNotBeNull();
opts.DrainIntervalSeconds.ShouldBe(11);
opts.Capacity.ShouldBe(500);
opts.DeadLetterRetentionDays.ShouldBe(7);
}
[Fact]
public void Validate_warns_on_empty_shared_secret_when_enabled()
{
var opts = new AlarmHistorianOptions { Enabled = true, SharedSecret = "", DatabasePath = "/var/h.db" };
opts.Validate().ShouldContain(w => w.Contains("SharedSecret"));
}
[Fact]
public void Validate_warns_on_relative_database_path_when_enabled()
{
var opts = new AlarmHistorianOptions { Enabled = true, SharedSecret = "s", DatabasePath = "alarm-historian.db" };
opts.Validate().ShouldContain(w => w.Contains("DatabasePath"));
}
[Fact]
public void Validate_is_silent_when_correctly_configured()
{
new AlarmHistorianOptions { Enabled = true, SharedSecret = "s", DatabasePath = "/abs/h.db" }.Validate().ShouldBeEmpty();
}
[Fact]
public void Validate_is_silent_when_disabled()
{
new AlarmHistorianOptions { Enabled = false, SharedSecret = "" }.Validate().ShouldBeEmpty();
}
}