53978ca638
#694 item 3 — historiangw#27 is fixed and now live-verified through OtOpcUa: - ServerHistorian:Gateway:EnableNativeTimeWeighted defaults to true (false is the kill switch for a gateway older than 9f711c1). TimeAverage / Total are served and advertised again (12 aggregates). - The gateway sends the interval as max(1, round(ms)) and AVEVA clips its last interval at the request end (live). NativeAggregatePlan therefore sends a multi-interval grid only for whole-ms intervals; a fractional interval is read one interval per request (at most 1,000, else BadTooManyOperations), and every one-interval request goes out rounded UP to whole ms so AVEVA answers one clipped row. Live, a 3.0004 s clipped interval sent at its own width lost its last 0.4 ms (Total 123 vs 123.0172). #746 — HistorianGateway Contracts/Client 1.0.0 surface: - Alarm history: GatewayAlarmHistorianWriter sends SendEvents batches of <=200. A failed per-event result is re-sent alone via SendEvent (classified as before); a refused batch (InvalidArgument etc.) goes event by event so a poison event dead-letters alone; a systemic fault retries the rest without sending more; Unimplemented (older gateway) falls back to SendEvent for good. IHistorianGatewayClient.SendEventsAsync defaults to Unimplemented. - Events reads: a capped page sends cap + 1 as ReadEventsRequest.max_events, so the gateway completes the stream instead of the client cancelling it. An ambiguous capped answer (foreign rows filtered out of the server's cut) or a refused cap is re-read uncapped with the existing EventDrainBudget drain. Tests: GatewayServerCappedEventsTests, GatewayAlarmWriterBatchTests, GatewayNativeWholeMillisecondGridTests (gateway-faithful rounding fake), gate tests flipped to the new default; every new test mutation-checked (each mutation of the production change fails at least one). Live harness AvevaGatewayHistorianFollowupsLiveGateTests (read-only) for #694/#700/#746. Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
65 lines
3.6 KiB
C#
65 lines
3.6 KiB
C#
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Core.Abstractions; // HistoryAggregateType
|
|
using ZB.MOM.WW.HistorianGateway.Contracts.Grpc; // RetrievalMode
|
|
using ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Mapping;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Tests.Mapping;
|
|
|
|
public sealed class AggregateModeMapperTests
|
|
{
|
|
[Theory]
|
|
[InlineData(HistoryAggregateType.TimeAverage, RetrievalMode.TimeWeightedAverage)]
|
|
[InlineData(HistoryAggregateType.Total, RetrievalMode.Integral)]
|
|
public void Maps_each_aggregate(HistoryAggregateType a, RetrievalMode expected)
|
|
=> Assert.Equal(expected, AggregateModeMapper.ToRetrievalMode(a));
|
|
|
|
[Fact] // matrix guard: every member is either mapped or explicitly reported as not supported
|
|
public void Every_aggregate_member_is_mapped_or_reports_not_supported()
|
|
{
|
|
var original = new[] { HistoryAggregateType.Total, HistoryAggregateType.TimeAverage };
|
|
Assert.Equal(original.OrderBy(a => a), AggregateModeMapper.NativeAggregates.OrderBy(a => a));
|
|
foreach (var a in Enum.GetValues<HistoryAggregateType>())
|
|
{
|
|
if (original.Contains(a))
|
|
_ = AggregateModeMapper.ToRetrievalMode(a);
|
|
else
|
|
Assert.Throws<HistoryAggregateNotSupportedException>(() => AggregateModeMapper.ToRetrievalMode(a));
|
|
}
|
|
}
|
|
|
|
[Theory] // #679: AVEVA has no arithmetic mean and no sample count; #681: the per-sample aggregates are raw-evaluated, not native
|
|
[InlineData(HistoryAggregateType.Average)]
|
|
[InlineData(HistoryAggregateType.Count)]
|
|
[InlineData(HistoryAggregateType.Minimum)]
|
|
[InlineData(HistoryAggregateType.Maximum)]
|
|
public void Per_sample_aggregates_have_no_native_mode(HistoryAggregateType a)
|
|
=> Assert.Throws<HistoryAggregateNotSupportedException>(() => AggregateModeMapper.ToRetrievalMode(a));
|
|
|
|
[Fact] // #682/#681: the served (= advertised) set is the native members plus the raw-evaluated per-sample families,
|
|
// and the data source returns exactly that static
|
|
public void Served_is_exactly_the_mapped_members_and_the_data_source_declares_it()
|
|
{
|
|
foreach (var a in Enum.GetValues<HistoryAggregateType>())
|
|
{
|
|
var native = AggregateModeMapper.NativeAggregates.Contains(a);
|
|
var perSample = ZB.MOM.WW.OtOpcUa.Driver.Historian.Sql.Common.AggregateFamilies.FamilyOf(a) is
|
|
ZB.MOM.WW.OtOpcUa.Driver.Historian.Sql.Common.AggregateFamily.Simple
|
|
or ZB.MOM.WW.OtOpcUa.Driver.Historian.Sql.Common.AggregateFamily.StartEnd
|
|
or ZB.MOM.WW.OtOpcUa.Driver.Historian.Sql.Common.AggregateFamily.ActualTime;
|
|
Assert.Equal(native || perSample, GatewayHistorianDataSource.ServedAggregates.Contains(a));
|
|
if (!native) Assert.Throws<HistoryAggregateNotSupportedException>(() => AggregateModeMapper.ToRetrievalMode(a));
|
|
}
|
|
Assert.Equal(12, GatewayHistorianDataSource.ServedAggregates.Count);
|
|
|
|
// The native pair follows ServerHistorian:Gateway:EnableNativeTimeWeighted (default on) — see GatewayNativeTimeWeightedGateTests.
|
|
var source = new GatewayHistorianDataSource(
|
|
new FakeHistorianGatewayClient(), Microsoft.Extensions.Logging.Abstractions.NullLogger<GatewayHistorianDataSource>.Instance,
|
|
enableNativeTimeWeighted: true);
|
|
Assert.Same(GatewayHistorianDataSource.ServedAggregates, source.SupportedAggregates);
|
|
}
|
|
|
|
[Fact]
|
|
public void Undefined_value_is_a_programming_error_not_a_not_supported()
|
|
=> Assert.Throws<ArgumentOutOfRangeException>(() => AggregateModeMapper.ToRetrievalMode((HistoryAggregateType)9999));
|
|
}
|