Separates ApplicationUri from namespace identity so each instance in a redundant pair has a unique server URI while sharing the same Galaxy namespace. Exposes RedundancySupport, ServerUriArray, and dynamic ServiceLevel through the standard OPC UA server object. ServiceLevel is computed from role (Primary/Secondary) and runtime health (MXAccess and DB connectivity). Adds CLI redundancy command, second deployed service instance, and 31 new tests including paired-server integration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.LmxOpcUa.Host.OpcUa;
|
|
|
|
namespace ZB.MOM.WW.LmxOpcUa.Tests.Redundancy
|
|
{
|
|
public class ServiceLevelCalculatorTests
|
|
{
|
|
private readonly ServiceLevelCalculator _calculator = new ServiceLevelCalculator();
|
|
|
|
[Fact]
|
|
public void FullyHealthy_Primary_ReturnsBase()
|
|
{
|
|
_calculator.Calculate(200, mxAccessConnected: true, dbConnected: true).ShouldBe((byte)200);
|
|
}
|
|
|
|
[Fact]
|
|
public void FullyHealthy_Secondary_ReturnsBaseMinusFifty()
|
|
{
|
|
_calculator.Calculate(150, mxAccessConnected: true, dbConnected: true).ShouldBe((byte)150);
|
|
}
|
|
|
|
[Fact]
|
|
public void MxAccessDown_ReducesServiceLevel()
|
|
{
|
|
_calculator.Calculate(200, mxAccessConnected: false, dbConnected: true).ShouldBe((byte)100);
|
|
}
|
|
|
|
[Fact]
|
|
public void DbDown_ReducesServiceLevel()
|
|
{
|
|
_calculator.Calculate(200, mxAccessConnected: true, dbConnected: false).ShouldBe((byte)150);
|
|
}
|
|
|
|
[Fact]
|
|
public void BothDown_ReturnsZero()
|
|
{
|
|
_calculator.Calculate(200, mxAccessConnected: false, dbConnected: false).ShouldBe((byte)0);
|
|
}
|
|
|
|
[Fact]
|
|
public void ClampedTo255()
|
|
{
|
|
_calculator.Calculate(255, mxAccessConnected: true, dbConnected: true).ShouldBe((byte)255);
|
|
}
|
|
|
|
[Fact]
|
|
public void ClampedToZero()
|
|
{
|
|
_calculator.Calculate(50, mxAccessConnected: false, dbConnected: true).ShouldBe((byte)0);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroBase_BothHealthy_ReturnsZero()
|
|
{
|
|
_calculator.Calculate(0, mxAccessConnected: true, dbConnected: true).ShouldBe((byte)0);
|
|
}
|
|
}
|
|
}
|