Implement LmxOpcUa server — all 6 phases complete
Full OPC UA server on .NET Framework 4.8 (x86) exposing AVEVA System Platform Galaxy tags via MXAccess. Mirrors Galaxy object hierarchy as OPC UA address space, translating contained-name browse paths to tag-name runtime references. Components implemented: - Configuration: AppConfiguration with 4 sections, validator - Domain: ConnectionState, Quality, Vtq, MxDataTypeMapper, error codes - MxAccess: StaComThread, MxAccessClient (partial classes), MxProxyAdapter using strongly-typed ArchestrA.MxAccess COM interop - Galaxy Repository: SQL queries (hierarchy, attributes, change detection), ChangeDetectionService with auto-rebuild on deploy - OPC UA Server: LmxNodeManager (CustomNodeManager2), LmxOpcUaServer, OpcUaServerHost with programmatic config, SecurityPolicy None - Status Dashboard: HTTP server with HTML/JSON/health endpoints - Integration: Full 14-step startup, graceful shutdown, component wiring 175 tests (174 unit + 1 integration), all passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.LmxOpcUa.Host.GalaxyRepository;
|
||||
using ZB.MOM.WW.LmxOpcUa.Tests.Helpers;
|
||||
|
||||
namespace ZB.MOM.WW.LmxOpcUa.Tests.GalaxyRepository
|
||||
{
|
||||
public class ChangeDetectionServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task FirstPoll_AlwaysTriggers()
|
||||
{
|
||||
var repo = new FakeGalaxyRepository { LastDeployTime = new DateTime(2024, 1, 1) };
|
||||
var service = new ChangeDetectionService(repo, intervalSeconds: 1);
|
||||
var triggered = false;
|
||||
service.OnGalaxyChanged += () => triggered = true;
|
||||
|
||||
service.Start();
|
||||
await Task.Delay(500);
|
||||
service.Stop();
|
||||
|
||||
triggered.ShouldBe(true);
|
||||
service.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SameTimestamp_DoesNotTriggerAgain()
|
||||
{
|
||||
var repo = new FakeGalaxyRepository { LastDeployTime = new DateTime(2024, 1, 1) };
|
||||
var service = new ChangeDetectionService(repo, intervalSeconds: 1);
|
||||
var triggerCount = 0;
|
||||
service.OnGalaxyChanged += () => Interlocked.Increment(ref triggerCount);
|
||||
|
||||
service.Start();
|
||||
await Task.Delay(2500); // Should have polled at least twice
|
||||
service.Stop();
|
||||
|
||||
triggerCount.ShouldBe(1); // Only the first poll
|
||||
service.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ChangedTimestamp_TriggersAgain()
|
||||
{
|
||||
var repo = new FakeGalaxyRepository { LastDeployTime = new DateTime(2024, 1, 1) };
|
||||
var service = new ChangeDetectionService(repo, intervalSeconds: 1);
|
||||
var triggerCount = 0;
|
||||
service.OnGalaxyChanged += () => Interlocked.Increment(ref triggerCount);
|
||||
|
||||
service.Start();
|
||||
await Task.Delay(500);
|
||||
|
||||
// Change the deploy time
|
||||
repo.LastDeployTime = new DateTime(2024, 2, 1);
|
||||
await Task.Delay(1500);
|
||||
service.Stop();
|
||||
|
||||
triggerCount.ShouldBeGreaterThanOrEqualTo(2);
|
||||
service.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FailedPoll_DoesNotCrash_RetriesNext()
|
||||
{
|
||||
var repo = new FakeGalaxyRepository { LastDeployTime = new DateTime(2024, 1, 1) };
|
||||
var service = new ChangeDetectionService(repo, intervalSeconds: 1);
|
||||
var triggerCount = 0;
|
||||
service.OnGalaxyChanged += () => Interlocked.Increment(ref triggerCount);
|
||||
|
||||
service.Start();
|
||||
await Task.Delay(500);
|
||||
|
||||
// Make it fail
|
||||
repo.ShouldThrow = true;
|
||||
await Task.Delay(1500);
|
||||
|
||||
// Restore and it should recover
|
||||
repo.ShouldThrow = false;
|
||||
repo.LastDeployTime = new DateTime(2024, 3, 1);
|
||||
await Task.Delay(1500);
|
||||
service.Stop();
|
||||
|
||||
// Should have triggered at least on first poll and on the changed timestamp
|
||||
triggerCount.ShouldBeGreaterThanOrEqualTo(1);
|
||||
service.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Stop_BeforeStart_DoesNotThrow()
|
||||
{
|
||||
var repo = new FakeGalaxyRepository();
|
||||
var service = new ChangeDetectionService(repo, intervalSeconds: 30);
|
||||
service.Stop(); // Should not throw
|
||||
service.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user