Files
lmxopcua/tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/DataConnections/GrpcDataConfiguredInterestTests.cs
T

38 lines
2.1 KiB
C#

using Akka.Actor;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
using ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
using ZB.MOM.WW.OtOpcUa.Runtime.Tests.Harness;
using ZB.MOM.WW.OtOpcUa.Runtime.VirtualTags;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections;
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "P08")]
public sealed class GrpcDataConfiguredInterestTests : RuntimeActorTestBase
{
[Fact(Timeout = 30000)]
public void Mux_notifies_only_first_and_last_configured_projected_interest()
{
var events = CreateTestProbe(); var first = CreateTestProbe(); var second = CreateTestProbe();
var sink = new Sink(events.Ref);
var mux = Sys.ActorOf(DependencyMuxActor.Props(interestSink: sink));
var id = ProjectedDataIds.Identifier("mapping", new DataAddress("origin", "urn:raw", "string", "plant/tag"));
var reference = ProjectedDataIds.DependencyReference(DataRealm.Raw, id);
mux.Tell(new DependencyMuxActor.RegisterInterest([reference, "ordinary"], first.Ref));
events.ExpectMsg<Transition>(TimeSpan.FromSeconds(5), cancellationToken: TestContext.Current.CancellationToken).ShouldBe(new Transition(reference, true));
mux.Tell(new DependencyMuxActor.RegisterInterest([reference], second.Ref));
mux.Tell(new DependencyMuxActor.RegisterInterest([reference], first.Ref));
mux.Tell(new DependencyMuxActor.UnregisterInterest(first.Ref));
events.ExpectNoMsg(TimeSpan.FromMilliseconds(100), TestContext.Current.CancellationToken);
mux.Tell(new DependencyMuxActor.UnregisterInterest(second.Ref));
events.ExpectMsg<Transition>(TimeSpan.FromSeconds(5), cancellationToken: TestContext.Current.CancellationToken).ShouldBe(new Transition(reference, false));
}
private sealed record Transition(string Reference, bool Active);
private sealed class Sink(IActorRef target) : IProjectedDependencyInterestSink
{
public void SetInterest(string projectedReference, bool active) => target.Tell(new Transition(projectedReference, active));
}
}