feat(notification-outbox): forward site S&F notifications to central
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using Akka.Actor;
|
||||
using Akka.Cluster.Tools.Client;
|
||||
using Akka.TestKit.Xunit2;
|
||||
using ScadaLink.Commons.Messages.Deployment;
|
||||
using ScadaLink.Commons.Messages.Lifecycle;
|
||||
using ScadaLink.Commons.Messages.Integration;
|
||||
using ScadaLink.Commons.Messages.Notification;
|
||||
using ScadaLink.Commons.Messages.RemoteQuery;
|
||||
using ScadaLink.Communication.Actors;
|
||||
|
||||
@@ -103,6 +105,56 @@ public class SiteCommunicationActorTests : TestKit
|
||||
handlerProbe.ExpectMsg<IntegrationCallRequest>(msg => msg.CorrelationId == "corr1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotificationSubmit_WithCentralClient_ForwardedToCentralAndAckRoutedBack()
|
||||
{
|
||||
// The site forwards a buffered notification to central over the ClusterClient
|
||||
// command/control transport; the central ack must route back to the original
|
||||
// sender (the S&F forwarder's Ask), not to the SiteCommunicationActor.
|
||||
var dmProbe = CreateTestProbe();
|
||||
var centralClientProbe = CreateTestProbe();
|
||||
var siteActor = Sys.ActorOf(Props.Create(() =>
|
||||
new SiteCommunicationActor("site1", _options, dmProbe.Ref)));
|
||||
|
||||
siteActor.Tell(new RegisterCentralClient(centralClientProbe.Ref));
|
||||
|
||||
var submit = new NotificationSubmit(
|
||||
"notif-1", "Operators", "Subj", "Body", "site1", "inst1", "alarmScript",
|
||||
DateTimeOffset.UtcNow);
|
||||
siteActor.Tell(submit);
|
||||
|
||||
// Central client (acting as ClusterClient) receives a ClusterClient.Send wrapping
|
||||
// the NotificationSubmit, addressed to the central communication actor. Fish past
|
||||
// any periodic HeartbeatMessage the actor's timer may interleave.
|
||||
var send = centralClientProbe.FishForMessage<ClusterClient.Send>(
|
||||
s => s.Message is NotificationSubmit);
|
||||
Assert.Equal("/user/central-communication", send.Path);
|
||||
var forwarded = Assert.IsType<NotificationSubmit>(send.Message);
|
||||
Assert.Equal("notif-1", forwarded.NotificationId);
|
||||
|
||||
// The ack is sent to the ClusterClient.Send's Sender — replying as that probe
|
||||
// must land back at the test actor (the original Tell sender).
|
||||
centralClientProbe.Reply(new NotificationSubmitAck("notif-1", Accepted: true, Error: null));
|
||||
ExpectMsg<NotificationSubmitAck>(ack => ack.NotificationId == "notif-1" && ack.Accepted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotificationSubmit_WithoutCentralClient_RepliesWithNonAccepted()
|
||||
{
|
||||
// No ClusterClient registered yet: the submit cannot be forwarded, so the actor
|
||||
// replies with a non-accepted ack and the S&F forwarder treats it as transient.
|
||||
var dmProbe = CreateTestProbe();
|
||||
var siteActor = Sys.ActorOf(Props.Create(() =>
|
||||
new SiteCommunicationActor("site1", _options, dmProbe.Ref)));
|
||||
|
||||
var submit = new NotificationSubmit(
|
||||
"notif-2", "Operators", "Subj", "Body", "site1", null, null,
|
||||
DateTimeOffset.UtcNow);
|
||||
siteActor.Tell(submit);
|
||||
|
||||
ExpectMsg<NotificationSubmitAck>(ack => ack.NotificationId == "notif-2" && !ack.Accepted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EventLogQuery_WithoutHandler_ReturnsFailure()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user