using Xunit;
using ZB.MOM.WW.OtOpcUa.Runtime.Historian;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Historian;
///
/// Verifies self-gates on Enabled and
/// warns (warn-only, never blocks startup) on the two gated misconfigurations: a blank
/// OutboxPath while enabled, and a non-positive CommitIntervalMs under
/// Periodic commit mode. No warning text carries a secret value.
///
public sealed class ContinuousHistorizationOptionsTests
{
/// A disabled recorder yields no warnings regardless of the other knobs.
[Fact]
public void Disabled_no_warnings()
=> Assert.Empty(new ContinuousHistorizationOptions { Enabled = false }.Validate());
/// An enabled recorder with a blank outbox directory warns about OutboxPath.
[Fact]
public void Enabled_requires_outbox_path()
=> Assert.Contains(
new ContinuousHistorizationOptions { Enabled = true, OutboxPath = "" }.Validate(),
m => m.Contains("OutboxPath"));
/// Periodic commit mode with a non-positive interval warns about CommitIntervalMs.
[Fact]
public void Periodic_requires_positive_interval()
=> Assert.Contains(
new ContinuousHistorizationOptions
{
Enabled = true,
OutboxPath = "x",
CommitMode = "Periodic",
CommitIntervalMs = 0,
}.Validate(),
m => m.Contains("CommitIntervalMs"));
///
/// Pins the shipped defaults, which are a tuned set rather than arbitrary numbers: the drain is
/// bounded-parallel over an in-memory peek (so a wide DrainBatchSize is cheap and a narrow
/// one lets the outbox fill during a gateway hiccup), Capacity is the #538 disk backstop,
/// and MaxWriteAttempts is the #538 poison-tag budget. The shipped
/// appsettings.json restates these values, so a silent drift between the two is exactly
/// what this test exists to catch.
///
[Fact]
public void Defaults_are_the_documented_batch_era_values()
{
var options = new ContinuousHistorizationOptions();
Assert.Equal("PerEntry", options.CommitMode);
Assert.Equal(1024, options.DrainBatchSize);
Assert.Equal(8, options.DrainConcurrency);
Assert.Equal(500_000, options.Capacity);
Assert.Equal(5, options.MaxWriteAttempts);
}
/// A fully-configured enabled recorder produces no warnings.
[Fact]
public void Valid_config_is_clean()
=> Assert.Empty(
new ContinuousHistorizationOptions
{
Enabled = true,
OutboxPath = "/var/lib/otopcua/historization",
CommitMode = "PerEntry",
}.Validate());
}