35 lines
1.9 KiB
C#
35 lines
1.9 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
|
using ZB.MOM.WW.OtOpcUa.Runtime.DataConnections;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.DataConnections;
|
|
|
|
[Trait("Category", "Unit"), Trait("Feature", "GrpcData"), Trait("Phase", "P07")]
|
|
public sealed class GrpcDataEndpointSelectionTests
|
|
{
|
|
private static readonly DataLimits Limits = new(16, 16, 65536, 16, 4, 65536, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(1), TimeSpan.FromSeconds(5));
|
|
private static DataCapabilities Cap(string node, string role, DataReadiness ready = DataReadiness.Ready, string cluster = "c") =>
|
|
new(1, 1, new(node, "boot", role, 1, 1, 1), ready, DataOperations.Read, new HashSet<DataValueKind>(), Limits, false, 0, cluster);
|
|
|
|
[Fact]
|
|
public void Cluster_requires_authenticated_ready_primary_and_expected_cluster()
|
|
{
|
|
var target = new DataTarget(DataTargetMode.Cluster, "c", null);
|
|
ClusterEndpointSelector.IsEligible(target, Cap("a", "Primary", DataReadiness.Unavailable), false).ShouldBeFalse();
|
|
ClusterEndpointSelector.IsEligible(target, Cap("a", "Primary", cluster: "other"), false).ShouldBeFalse();
|
|
ClusterEndpointSelector.IsEligible(target, Cap("a", "Secondary"), false).ShouldBeFalse();
|
|
ClusterEndpointSelector.IsEligible(target, Cap("a", "Unknown"), false).ShouldBeFalse();
|
|
ClusterEndpointSelector.IsEligible(target, Cap("a", "Primary"), false).ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void Pinned_node_cannot_substitute_partner_and_secondary_requires_explicit_read_consistency()
|
|
{
|
|
var target = new DataTarget(DataTargetMode.Node, "c", "a", DataConsistency.ReadyReplica);
|
|
ClusterEndpointSelector.IsEligible(target, Cap("b", "Primary"), true).ShouldBeFalse();
|
|
ClusterEndpointSelector.IsEligible(target, Cap("a", "Secondary"), true).ShouldBeFalse();
|
|
ClusterEndpointSelector.IsEligible(target, Cap("a", "Secondary"), false).ShouldBeTrue();
|
|
}
|
|
}
|