7fd5cb2b56
ClusterClient→gRPC migration Phase 4 (docs/plans/2026-07-22-clusterclient-to-grpc-plan.md). Phases 2/3 proved both directions on gRPC; this removes the Akka transport underneath. Deleted: - AkkaCentralTransport, AkkaSiteTransport (+ their dedicated tests) - ISiteClientFactory + DefaultSiteClientFactory; CentralCommunicationActor legacy ctor + SelectTransport (Host now builds GrpcSiteTransport and injects it) - ClusterClient creation + both ClusterClientReceptionist.RegisterService calls in AkkaHostedService; the RegisterCentralClient message + receive block - CommunicationOptions.CentralContactPoints; the CentralTransport/SiteTransport coexistence flags; the CentralTransportMode/SiteTransportKind enums gRPC is now the only site↔central transport (site→central CentralControlService via GrpcCentralTransport; central→site SiteCommandService via GrpcSiteTransport), both built unconditionally by the Host. NoOpCentralTransport is the fail-loud null-default so TestKit command-dispatch suites still construct the site actor without a wired transport; production always injects GrpcCentralTransport. Config: CentralGrpcEndpoints is now unconditional — CommunicationOptionsValidator rejects blank entries (role-agnostic), and StartupValidator requires a Site node to list >=1 endpoint (fail-fast, mirrors GrpcPsk). Rig configs moved CentralContactPoints -> CentralGrpcEndpoints (docker x6, docker-env2 x2, Host default, deploy/wonder-app-vd03). Kept Akka.Cluster.Tools (ClusterSingleton still used). Tests: build 0/0; Communication.Tests 640, Host.Tests 421 green. Removed the ClusterClient.Send per-site-routing tests (covered by the transport suites), swapped the ISiteClientFactory-based ctors to a substitute ISiteCommandTransport, converted the audit-push integration relay to an in-process bridge transport. Docs: Component-Communication/Host/StoreAndForward, components/Communication, topology-guide, grpc_streams (SUPERSEDED note), the frame-size known-issue (retired amendment), and CLAUDE.md transport decisions. Not included: the dead IntegrationCallRequest path (#32) is a separate user-owned behavioral decision — SiteEnvelope routing is transport-agnostic so it still compiles.
67 lines
2.9 KiB
C#
67 lines
2.9 KiB
C#
using Akka.Actor;
|
|
using Akka.TestKit.Xunit2;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Health;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
|
using ZB.MOM.WW.ScadaBridge.Communication.Actors;
|
|
using ZB.MOM.WW.ScadaBridge.HealthMonitoring;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
|
|
|
|
/// <summary>
|
|
/// Review 01 [Medium]: site→central health reports were fire-and-forget, so a lost
|
|
/// report was invisible to the sender. These tests pin the end-to-end ack: the site actor
|
|
/// always replies to the sender (even when the transport cannot forward — a fail-loud failure,
|
|
/// not silence), and the central actor processes + acks a report it receives.
|
|
/// </summary>
|
|
public class HealthReportAckTests : TestKit
|
|
{
|
|
private readonly CommunicationOptions _options = new();
|
|
|
|
private static SiteHealthReport SampleReport(long seq, string siteId = "site-a") =>
|
|
new(siteId, seq, DateTimeOffset.UtcNow,
|
|
new Dictionary<string, ConnectionHealth>(),
|
|
new Dictionary<string, TagResolutionStatus>(),
|
|
0, 0, new Dictionary<string, int>(), 0, 0, 0, 0);
|
|
|
|
[Fact]
|
|
public void SiteCommunicationActor_NoTransport_RepliesFailure_NotSilence()
|
|
{
|
|
// With no transport injected the actor falls back to the fail-loud
|
|
// NoOpCentralTransport, which answers a Status.Failure so the health transport's
|
|
// Ask sees a transient failure rather than hanging. (Production always injects the
|
|
// gRPC GrpcCentralTransport; this pins the wiring-guard fallback.)
|
|
var dmProbe = CreateTestProbe();
|
|
var siteComm = Sys.ActorOf(Props.Create(() =>
|
|
new SiteCommunicationActor("site-a", _options, dmProbe.Ref)));
|
|
siteComm.Tell(SampleReport(seq: 7));
|
|
ExpectMsg<Status.Failure>();
|
|
}
|
|
|
|
[Fact]
|
|
public void CentralCommunicationActor_OnReport_ProcessesAndAcks()
|
|
{
|
|
var mockRepo = Substitute.For<ISiteRepository>();
|
|
mockRepo.GetAllSitesAsync(Arg.Any<CancellationToken>()).Returns(new List<Site>());
|
|
var aggregator = Substitute.For<ICentralHealthAggregator>();
|
|
|
|
var services = new ServiceCollection();
|
|
services.AddScoped(_ => mockRepo);
|
|
services.AddSingleton(aggregator);
|
|
var sp = services.BuildServiceProvider();
|
|
|
|
var transport = Substitute.For<ISiteCommandTransport>();
|
|
var actor = Sys.ActorOf(Props.Create(() => new CentralCommunicationActor(sp, transport, (TimeSpan?)null)));
|
|
|
|
actor.Tell(SampleReport(seq: 3));
|
|
var ack = ExpectMsg<SiteHealthReportAck>();
|
|
Assert.True(ack.Accepted);
|
|
Assert.Equal(3, ack.SequenceNumber);
|
|
AwaitAssert(() => aggregator.Received().ProcessReport(Arg.Is<SiteHealthReport>(r => r.SequenceNumber == 3)));
|
|
}
|
|
}
|