0658d244d0
- HistoryUpdate items with SourceTimestamp > now + ServerHistorian:HistoryUpdateMaxFutureSkew (default 1 day, <=0 disables) => BadOutOfRange in the node manager (every backend, never sent); clock injected via OtOpcUaNodeManager.Clock (host TimeProvider). - HistoryUpdate is Primary-only: off-Primary => BadInvalidState per node, after authorization, same IDriverPrimaryRoleSource verdict as the native-ack gate; HistoryRead ungated. - SqlServer: base schema requirement back to v1; SupportsModifiedTrail (v>=2). On v1 with AutoCreateSchema=false: writes/reads/events/retention work, modified reads + HistoryUpdate => BadHistoryOperationUnsupported with nothing sent, retention skips SampleModified, one Warning per boot. - QuestDB integration test pinning wall-clock TTL (far-future row evicts only partitions older than the TTL by the wall clock), with a positive control. - Docs: Historian.md, Configuration.md, security.md, CLAUDE.md (incl. QuestDB retry duplicates, #674.4 anonymous-readable trail with ACL off, #674.5 not implemented). Co-Authored-By: Claude <noreply@anthropic.com>
60 lines
2.9 KiB
C#
60 lines
2.9 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.SqlServer.Tests;
|
|
|
|
public sealed class SchemaScriptTests
|
|
{
|
|
[Fact]
|
|
public void Go_splitting_ignores_go_inside_other_text_and_drops_empties()
|
|
{
|
|
var parts = SqlServerSchemaBootstrapper.SplitBatches("A\nGO\n go \nB GO C\nGO\n").ToArray();
|
|
parts.ShouldBe(["A", "B GO C"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void Embedded_script_is_present_and_matches_the_docs_copy()
|
|
{
|
|
var asm = typeof(SqlServerSchemaBootstrapper).Assembly;
|
|
using var s = asm.GetManifestResourceStream("Schema.001_initial.sql");
|
|
s.ShouldNotBeNull();
|
|
var text = new StreamReader(s!).ReadToEnd();
|
|
text.ShouldContain("$(Schema)");
|
|
text.ShouldContain("PRIMARY KEY NONCLUSTERED");
|
|
text.ShouldContain("CREATE CLUSTERED INDEX CX_Event_Time");
|
|
text.ShouldNotContain("IX_Event_Time");
|
|
|
|
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
|
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "ZB.MOM.WW.OtOpcUa.slnx"))) dir = dir.Parent;
|
|
dir.ShouldNotBeNull();
|
|
File.ReadAllText(Path.Combine(dir!.FullName, "docs/historian/sqlserver/001_initial.sql")).ShouldBe(text);
|
|
}
|
|
|
|
/// <summary>
|
|
/// #668: schema v2 (the Part 11 modification trail) is embedded, matches its docs copy, records version 2 (which
|
|
/// must equal <see cref="SqlServerSchemaBootstrapper.ModifiedTrailVersion"/>), and carries none of the constructs an
|
|
/// <c>OUTPUT … INTO</c> target forbids (FOREIGN KEY / CHECK / trigger) — any of them would fail every HistoryUpdate.
|
|
/// </summary>
|
|
[Fact]
|
|
public void Schema_v2_sample_modified_is_embedded_matches_the_docs_copy_and_is_a_legal_output_into_target()
|
|
{
|
|
var asm = typeof(SqlServerSchemaBootstrapper).Assembly;
|
|
using var s = asm.GetManifestResourceStream("Schema.002_sample_modified.sql");
|
|
s.ShouldNotBeNull();
|
|
var text = new StreamReader(s!).ReadToEnd();
|
|
text.ShouldContain("[SampleModified]");
|
|
text.ShouldContain("PRIMARY KEY CLUSTERED (TagId, SourceTimeUtc, ModifiedId)");
|
|
text.ShouldContain("VALUES (2, SYSUTCDATETIME())");
|
|
SqlServerSchemaBootstrapper.ModifiedTrailVersion.ShouldBe(2);
|
|
SqlServerSchemaBootstrapper.RequiredVersion.ShouldBe(1); // #674: v1 is still served, without the trail
|
|
var ddl = string.Join('\n', text.Split('\n').Where(l => !l.TrimStart().StartsWith("--", StringComparison.Ordinal)));
|
|
ddl.ShouldNotContain("FOREIGN KEY", Case.Insensitive);
|
|
ddl.ShouldNotContain("CHECK", Case.Insensitive);
|
|
ddl.ShouldNotContain("TRIGGER", Case.Insensitive);
|
|
|
|
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
|
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "ZB.MOM.WW.OtOpcUa.slnx"))) dir = dir.Parent;
|
|
File.ReadAllText(Path.Combine(dir!.FullName, "docs/historian/sqlserver/002_sample_modified.sql")).ShouldBe(text);
|
|
}
|
|
}
|