a212283104
WP2.6 (arch-review remediation, cross-cutting misc): - SiteExternalSystemRepository: name/ID-indexed ExternalSystemDefinitionCache replaces the fetch-all + reverse-map scan on every by-ID/method lookup; loaded once per redeploy, invalidated by DeploymentManagerActor after HandleDeployArtifacts applies external-system changes. Static JsonSerializerOptions for method-list parsing. - Inbound API: short-TTL ApiMethodCache fronts the per-request ApiMethod repository fetch; invalidated by name via the existing ScriptArtifactChangeSubscriber/ IScriptArtifactChangeBus pipeline, self-healing via TTL for changes the bus doesn't cover (e.g. Management API edits). - StoreAndForward: the cached-call audit-observer queue — the one unbounded channel left in the system — is now bounded (ObserverQueueCapacity, default 10,000) with DropOldest overflow and a dropped-notification counter. - SiteStreamManager: alarm state changes now travel a dedicated publish source/broadcast hub, isolated from the (far higher-volume) attribute path, so an attribute storm can no longer evict a pending alarm transition; the alarm hand-off queue is bounded with a drop counter surfaced on the site health report (SiteStreamAlarmDropCount via the new SiteStreamAlarmDropReporter), and publishing is skipped entirely at zero subscribers on either path. - CLI ManagementHttpClient: explicit 30s HttpClient.Timeout on the shared construction (was the 100s framework default), overridable via SCADABRIDGE_HTTP_TIMEOUT_SECONDS. Deviation: the failback-probe heartbeat item is NOT included — its only viable surface (CentralChannelProvider.cs / heartbeat consumers) lives entirely in the Communication project, explicitly off-limits to this work package this phase. Tests: SiteRuntime.Tests (550), InboundAPI.Tests (278), StoreAndForward.Tests (133), CLI.Tests (390), HealthMonitoring.Tests (97) — all green after full solution build.
99 lines
3.5 KiB
C#
99 lines
3.5 KiB
C#
using Microsoft.Extensions.Options;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.StoreAndForward.Tests;
|
|
|
|
/// <summary>
|
|
/// <see cref="StoreAndForwardOptions"/> retry intervals feed the background sweep
|
|
/// timer (zero/negative trips the timer constructor) and the SQLite path backs the
|
|
/// buffer. These tests assert the <see cref="StoreAndForwardOptionsValidator"/>
|
|
/// rejects a bad <c>ScadaBridge:StoreAndForward</c> section with a clear,
|
|
/// key-naming message rather than crashing later with an opaque exception.
|
|
/// </summary>
|
|
public class StoreAndForwardOptionsValidatorTests
|
|
{
|
|
private static ValidateOptionsResult Validate(StoreAndForwardOptions options) =>
|
|
new StoreAndForwardOptionsValidator().Validate(Options.DefaultName, options);
|
|
|
|
[Fact]
|
|
public void DefaultOptions_AreValid()
|
|
{
|
|
var result = Validate(new StoreAndForwardOptions());
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroDefaultRetryInterval_IsRejected()
|
|
{
|
|
var result = Validate(new StoreAndForwardOptions { DefaultRetryInterval = TimeSpan.Zero });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("DefaultRetryInterval", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroRetryTimerInterval_IsRejected()
|
|
{
|
|
var result = Validate(new StoreAndForwardOptions { RetryTimerInterval = TimeSpan.Zero });
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("RetryTimerInterval", result.FailureMessage);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The inverse of the rule this replaces. Before LocalDb Phase 2 an empty
|
|
/// SqliteDbPath was rejected, because it was the live buffer file and an empty
|
|
/// value failed opaquely at first enqueue. The buffer now lives in the
|
|
/// consolidated LocalDb database, so the key is only the legacy migration
|
|
/// source and an empty value legitimately means "nothing to migrate" — a node
|
|
/// that has already migrated must be able to drop it.
|
|
/// </summary>
|
|
[Fact]
|
|
public void EmptySqliteDbPath_IsAccepted_BecauseThePathIsMigrationOnly()
|
|
{
|
|
var result = Validate(new StoreAndForwardOptions { SqliteDbPath = "" });
|
|
|
|
Assert.False(result.Failed);
|
|
}
|
|
|
|
// ── R2 T9: sweep-tuning eager validation (N4) ──
|
|
|
|
[Theory]
|
|
[InlineData(-1)]
|
|
[InlineData(-500)]
|
|
public void Validate_NegativeSweepBatchLimit_Fails(int limit)
|
|
{
|
|
var result = Validate(new StoreAndForwardOptions { SweepBatchLimit = limit });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("SweepBatchLimit", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_ZeroSweepBatchLimit_IsValidUnlimitedLegacy()
|
|
{
|
|
var result = Validate(new StoreAndForwardOptions { SweepBatchLimit = 0 });
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(0)]
|
|
[InlineData(-4)]
|
|
public void Validate_NonPositiveSweepTargetParallelism_Fails(int parallelism)
|
|
{
|
|
var result = Validate(new StoreAndForwardOptions { SweepTargetParallelism = parallelism });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("SweepTargetParallelism", result.FailureMessage);
|
|
}
|
|
|
|
// ── WP2.6c: bounded observer queue capacity ──
|
|
|
|
[Theory]
|
|
[InlineData(0)]
|
|
[InlineData(-1)]
|
|
public void Validate_NonPositiveObserverQueueCapacity_Fails(int capacity)
|
|
{
|
|
var result = Validate(new StoreAndForwardOptions { ObserverQueueCapacity = capacity });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("ObserverQueueCapacity", result.FailureMessage);
|
|
}
|
|
}
|