821763a09d
- I-1: an Empty sample is always Bad. The writer stores a non-Bad NaN/Inf as Empty+BadOutOfRange and any other non-Bad Empty as BadNoData; the updater refuses a non-Bad Empty with BadInvalidArgument; reads clamp a legacy non-Bad Empty row to BadNoData (Raw and AtTime). - Tag/source names over 400 chars are refused, never truncated: writer per-tag failure, updater BadInvalidArgument, reads not-found, events none. - HistorianInfoBits masks the historian bits before setting one. - AtTime past now, stepped from the last sample => UncertainDataSubNormal. - Bootstrapper: logger, 5 s negative cache, ClearPool + Warning when sp_releaseapplock fails. - Provider builds its shared state lazily (an invalid Schema no longer throws at Resolve); Kinds is a FrozenSet; Gateway reuses the recorder's DefaultSupportedKinds. - Cleanup: SqlHistorianDataTypes in its own file (updater dup removed), dead Invalidate and unused status consts deleted, named severity masks, alarm writer brace. Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
61 lines
2.5 KiB
C#
61 lines
2.5 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.SqlServer.Tests;
|
|
|
|
public sealed class ValueWriterPrepareTests
|
|
{
|
|
private static readonly DateTime T = new(2026, 10, 9, 1, 2, 3, DateTimeKind.Utc);
|
|
|
|
[Fact]
|
|
public void Non_finite_doubles_become_Empty_and_are_forced_Bad()
|
|
{
|
|
const uint uncertain = 0x40000000u;
|
|
const uint badNoCommunication = 0x80310000u;
|
|
var rows = SqlServerHistorianValueWriter.Prepare(
|
|
[
|
|
new(T, HistorianValue.FromDouble(double.NaN), uncertain),
|
|
new(T.AddTicks(1), HistorianValue.FromDouble(double.PositiveInfinity), 0),
|
|
new(T.AddTicks(2), HistorianValue.FromDouble(double.NegativeInfinity), badNoCommunication),
|
|
new(T.AddTicks(3), HistorianValue.FromDouble(1.5), 0),
|
|
], () => T);
|
|
rows.Select(r => r.Value.Kind).ShouldBe([HistorianValueKind.Empty, HistorianValueKind.Empty, HistorianValueKind.Empty, HistorianValueKind.Double]);
|
|
rows.Select(r => r.StatusCode).ShouldBe([SqlHistorianStatusCodes.BadOutOfRange, SqlHistorianStatusCodes.BadOutOfRange,
|
|
badNoCommunication, 0u]);
|
|
}
|
|
|
|
[Fact]
|
|
public void A_non_bad_Empty_is_stored_BadNoData_and_a_bad_Empty_keeps_its_code()
|
|
{
|
|
var rows = SqlServerHistorianValueWriter.Prepare(
|
|
[
|
|
new(T, HistorianValue.Empty, 0),
|
|
new(T.AddTicks(1), HistorianValue.Empty, 0x40A40000u),
|
|
new(T.AddTicks(2), HistorianValue.Empty, 0x80310000u),
|
|
], () => T);
|
|
rows.Select(r => r.StatusCode).ShouldBe([SqlHistorianStatusCodes.BadNoData, SqlHistorianStatusCodes.BadNoData, 0x80310000u]);
|
|
}
|
|
|
|
[Fact]
|
|
public void Duplicate_timestamps_keep_the_first_and_null_timestamp_uses_the_clock()
|
|
{
|
|
var rows = SqlServerHistorianValueWriter.Prepare(
|
|
[
|
|
new(T, HistorianValue.FromInt64(1), 0), new(T, HistorianValue.FromInt64(2), 0),
|
|
new(null, HistorianValue.FromInt64(3), 0),
|
|
], () => T.AddDays(1));
|
|
rows.Count.ShouldBe(2);
|
|
rows[0].Value.Integer.ShouldBe(1);
|
|
rows[1].TimeUtc.ShouldBe(T.AddDays(1));
|
|
}
|
|
|
|
[Fact]
|
|
public void Data_type_mapping_is_one_table()
|
|
{
|
|
SqlHistorianDataTypes.FromKind(HistorianValueKind.Double).ShouldBe((byte)DriverDataType.Float64);
|
|
SqlHistorianDataTypes.FromKind(HistorianValueKind.Boolean).ShouldBe((byte)DriverDataType.Boolean);
|
|
SqlHistorianDataTypes.FromKind(HistorianValueKind.Empty).ShouldBe((byte)DriverDataType.Float64);
|
|
}
|
|
}
|