Communication Layer (WP-1–5): - 8 message patterns with correlation IDs, per-pattern timeouts - Central/Site communication actors, transport heartbeat config - Connection failure handling (no central buffering, debug streams killed) Data Connection Layer (WP-6–14, WP-34): - Connection actor with Become/Stash lifecycle (Connecting/Connected/Reconnecting) - OPC UA + LmxProxy adapters behind IDataConnection - Auto-reconnect, bad quality propagation, transparent re-subscribe - Write-back, tag path resolution with retry, health reporting - Protocol extensibility via DataConnectionFactory Site Runtime (WP-15–25, WP-32–33): - ScriptActor/ScriptExecutionActor (triggers, concurrent execution, blocking I/O dispatcher) - AlarmActor/AlarmExecutionActor (ValueMatch/RangeViolation/RateOfChange, in-memory state) - SharedScriptLibrary (inline execution), ScriptRuntimeContext (API) - ScriptCompilationService (Roslyn, forbidden API enforcement, execution timeout) - Recursion limit (default 10), call direction enforcement - SiteStreamManager (per-subscriber bounded buffers, fire-and-forget) - Debug view backend (snapshot + stream), concurrency serialization - Local artifact storage (4 SQLite tables) Health Monitoring (WP-26–28): - SiteHealthCollector (thread-safe counters, connection state) - HealthReportSender (30s interval, monotonic sequence numbers) - CentralHealthAggregator (offline detection 60s, online recovery) Site Event Logging (WP-29–31): - SiteEventLogger (SQLite, 6 event categories, ISO 8601 UTC) - EventLogPurgeService (30-day retention, 1GB cap) - EventLogQueryService (filters, keyword search, keyset pagination) 541 tests pass, zero warnings.
105 lines
3.6 KiB
C#
105 lines
3.6 KiB
C#
using Akka.Actor;
|
|
using Akka.TestKit.Xunit2;
|
|
using ScadaLink.Commons.Messages.Deployment;
|
|
using ScadaLink.Commons.Messages.Lifecycle;
|
|
using ScadaLink.Commons.Messages.Integration;
|
|
using ScadaLink.Commons.Messages.RemoteQuery;
|
|
using ScadaLink.Communication.Actors;
|
|
|
|
namespace ScadaLink.Communication.Tests;
|
|
|
|
/// <summary>
|
|
/// WP-4: Tests for SiteCommunicationActor message routing to local actors.
|
|
/// </summary>
|
|
public class SiteCommunicationActorTests : TestKit
|
|
{
|
|
private readonly CommunicationOptions _options = new();
|
|
|
|
public SiteCommunicationActorTests()
|
|
: base(@"akka.loglevel = DEBUG")
|
|
{
|
|
}
|
|
|
|
[Fact]
|
|
public void DeployCommand_ForwardedToDeploymentManager()
|
|
{
|
|
var dmProbe = CreateTestProbe();
|
|
var siteActor = Sys.ActorOf(Props.Create(() =>
|
|
new SiteCommunicationActor("site1", _options, dmProbe.Ref)));
|
|
|
|
var command = new DeployInstanceCommand(
|
|
"dep1", "inst1", "hash1", "{}", "admin", DateTimeOffset.UtcNow);
|
|
siteActor.Tell(command);
|
|
|
|
dmProbe.ExpectMsg<DeployInstanceCommand>(msg => msg.DeploymentId == "dep1");
|
|
}
|
|
|
|
[Fact]
|
|
public void LifecycleCommands_ForwardedToDeploymentManager()
|
|
{
|
|
var dmProbe = CreateTestProbe();
|
|
var siteActor = Sys.ActorOf(Props.Create(() =>
|
|
new SiteCommunicationActor("site1", _options, dmProbe.Ref)));
|
|
|
|
siteActor.Tell(new DisableInstanceCommand("cmd1", "inst1", DateTimeOffset.UtcNow));
|
|
dmProbe.ExpectMsg<DisableInstanceCommand>();
|
|
|
|
siteActor.Tell(new EnableInstanceCommand("cmd2", "inst1", DateTimeOffset.UtcNow));
|
|
dmProbe.ExpectMsg<EnableInstanceCommand>();
|
|
|
|
siteActor.Tell(new DeleteInstanceCommand("cmd3", "inst1", DateTimeOffset.UtcNow));
|
|
dmProbe.ExpectMsg<DeleteInstanceCommand>();
|
|
}
|
|
|
|
[Fact]
|
|
public void IntegrationCall_WithoutHandler_ReturnsFailure()
|
|
{
|
|
var dmProbe = CreateTestProbe();
|
|
var siteActor = Sys.ActorOf(Props.Create(() =>
|
|
new SiteCommunicationActor("site1", _options, dmProbe.Ref)));
|
|
|
|
var request = new IntegrationCallRequest(
|
|
"corr1", "site1", "inst1", "ExtSys1", "GetData",
|
|
new Dictionary<string, object?>(), DateTimeOffset.UtcNow);
|
|
|
|
siteActor.Tell(request);
|
|
|
|
ExpectMsg<IntegrationCallResponse>(msg =>
|
|
!msg.Success && msg.ErrorMessage == "Integration handler not available");
|
|
}
|
|
|
|
[Fact]
|
|
public void IntegrationCall_WithHandler_ForwardedToHandler()
|
|
{
|
|
var dmProbe = CreateTestProbe();
|
|
var handlerProbe = CreateTestProbe();
|
|
var siteActor = Sys.ActorOf(Props.Create(() =>
|
|
new SiteCommunicationActor("site1", _options, dmProbe.Ref)));
|
|
|
|
// Register integration handler
|
|
siteActor.Tell(new RegisterLocalHandler(LocalHandlerType.Integration, handlerProbe.Ref));
|
|
|
|
var request = new IntegrationCallRequest(
|
|
"corr1", "site1", "inst1", "ExtSys1", "GetData",
|
|
new Dictionary<string, object?>(), DateTimeOffset.UtcNow);
|
|
|
|
siteActor.Tell(request);
|
|
handlerProbe.ExpectMsg<IntegrationCallRequest>(msg => msg.CorrelationId == "corr1");
|
|
}
|
|
|
|
[Fact]
|
|
public void EventLogQuery_WithoutHandler_ReturnsFailure()
|
|
{
|
|
var dmProbe = CreateTestProbe();
|
|
var siteActor = Sys.ActorOf(Props.Create(() =>
|
|
new SiteCommunicationActor("site1", _options, dmProbe.Ref)));
|
|
|
|
var request = new EventLogQueryRequest(
|
|
"corr1", "site1", null, null, null, null, null, null, null, 25, DateTimeOffset.UtcNow);
|
|
|
|
siteActor.Tell(request);
|
|
|
|
ExpectMsg<EventLogQueryResponse>(msg => !msg.Success);
|
|
}
|
|
}
|