Merge branch 'review/wp6' into review/integration
# Conflicts: # docs/requirements/Component-StoreAndForward.md # src/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase/Repositories/DeploymentManagerRepository.cs # src/ZB.MOM.WW.ScadaBridge.StoreAndForward/StoreAndForwardStorage.cs # src/ZB.MOM.WW.ScadaBridge.Transport/Import/BundleImporter.cs # tests/ZB.MOM.WW.ScadaBridge.StoreAndForward.Tests/StoreAndForwardStorageTests.cs
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Google.Protobuf.Collections;
|
||||
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Protocol;
|
||||
using ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Adapters;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests;
|
||||
|
||||
/// <summary>DCL-10 (WP6 6.10): MxGateway quality mapping is table-driven and allocation-free.</summary>
|
||||
public class MxGatewayQualityMapTests
|
||||
{
|
||||
/// <summary>The quality byte maps exactly as the former range switch did.</summary>
|
||||
[Theory]
|
||||
[InlineData(-5, QualityCode.Bad)]
|
||||
[InlineData(0, QualityCode.Bad)]
|
||||
[InlineData(63, QualityCode.Bad)]
|
||||
[InlineData(64, QualityCode.Uncertain)]
|
||||
[InlineData(191, QualityCode.Uncertain)]
|
||||
[InlineData(192, QualityCode.Good)]
|
||||
[InlineData(255, QualityCode.Good)]
|
||||
[InlineData(1000, QualityCode.Good)]
|
||||
public void QualityByte_Maps(int quality, QualityCode expected)
|
||||
=> Assert.Equal(expected, RealMxGatewayClient.MapQuality(quality, new RepeatedField<MxStatusProxy>()));
|
||||
|
||||
/// <summary>A failing status is authoritative Bad; a success status defers to the byte.</summary>
|
||||
[Fact]
|
||||
public void FailingStatus_IsBad()
|
||||
{
|
||||
var ok = new RepeatedField<MxStatusProxy> { new MxStatusProxy { Category = MxStatusCategory.Ok } };
|
||||
var failing = new RepeatedField<MxStatusProxy> { new MxStatusProxy { Category = MxStatusCategory.Ok }, new MxStatusProxy() };
|
||||
Assert.Equal(QualityCode.Good, RealMxGatewayClient.MapQuality(192, ok));
|
||||
Assert.Equal(QualityCode.Bad, RealMxGatewayClient.MapQuality(192, failing));
|
||||
}
|
||||
|
||||
/// <summary>The per-event path allocates nothing (the old Any() boxed the enumerator per call).</summary>
|
||||
[Fact]
|
||||
public void MapQuality_DoesNotAllocate()
|
||||
{
|
||||
var statuses = new RepeatedField<MxStatusProxy> { new MxStatusProxy { Category = MxStatusCategory.Ok } };
|
||||
RealMxGatewayClient.MapQuality(192, statuses); // warm
|
||||
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||
for (var i = 0; i < 10_000; i++)
|
||||
RealMxGatewayClient.MapQuality(192, statuses);
|
||||
Assert.Equal(0, GC.GetAllocatedBytesForCurrentThread() - before);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user