Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/Historian/ContinuousHistorizationOptionsTests.cs
T
Joseph Doherty 2a5c717755 feat(historian-gateway): wire ContinuousHistorizationRecorder into DI + hosted lifecycle + meters
Bind ContinuousHistorizationOptions (Enabled/OutboxPath/CommitMode/
CommitIntervalMs/DrainBatchSize/DrainIntervalSeconds/Capacity/backoff) with a
warn-only Validate(); gated on Enabled AND the ServerHistorian gateway being
configured, the Host registers the durable FasterLogHistorizationOutbox (container
-disposed) + a gateway-backed GatewayHistorianValueWriter, and binds outbox
depth/dropped observable gauges on the central scraped meter. WithOtOpcUaRuntimeActors
spawns the recorder (over the same dependency-mux ref) when the options + writer +
outbox resolve, registering ContinuousHistorizationRecorderKey. Spawned with an EMPTY
historized-ref set: the deployed address space builds later, so ref population is a
documented follow-on (a later SetHistorizedRefs feed) — T18 wires the actor + outbox
+ writer + meters; the ref feed is the known remaining gap.

Claude-Session: https://claude.ai/code/session_012SDSQ3AcaXqPcBtDESBRii
2026-06-26 18:47:20 -04:00

50 lines
2.0 KiB
C#

using Xunit;
using ZB.MOM.WW.OtOpcUa.Runtime.Historian;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Historian;
/// <summary>
/// Verifies <see cref="ContinuousHistorizationOptions.Validate"/> self-gates on <c>Enabled</c> and
/// warns (warn-only, never blocks startup) on the two gated misconfigurations: a blank
/// <c>OutboxPath</c> while enabled, and a non-positive <c>CommitIntervalMs</c> under
/// <c>Periodic</c> commit mode. No warning text carries a secret value.
/// </summary>
public sealed class ContinuousHistorizationOptionsTests
{
/// <summary>A disabled recorder yields no warnings regardless of the other knobs.</summary>
[Fact]
public void Disabled_no_warnings()
=> Assert.Empty(new ContinuousHistorizationOptions { Enabled = false }.Validate());
/// <summary>An enabled recorder with a blank outbox directory warns about <c>OutboxPath</c>.</summary>
[Fact]
public void Enabled_requires_outbox_path()
=> Assert.Contains(
new ContinuousHistorizationOptions { Enabled = true, OutboxPath = "" }.Validate(),
m => m.Contains("OutboxPath"));
/// <summary>Periodic commit mode with a non-positive interval warns about <c>CommitIntervalMs</c>.</summary>
[Fact]
public void Periodic_requires_positive_interval()
=> Assert.Contains(
new ContinuousHistorizationOptions
{
Enabled = true,
OutboxPath = "x",
CommitMode = "Periodic",
CommitIntervalMs = 0,
}.Validate(),
m => m.Contains("CommitIntervalMs"));
/// <summary>A fully-configured enabled recorder produces no warnings.</summary>
[Fact]
public void Valid_config_is_clean()
=> Assert.Empty(
new ContinuousHistorizationOptions
{
Enabled = true,
OutboxPath = "/var/lib/otopcua/historization",
CommitMode = "PerEntry",
}.Validate());
}