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.
84 lines
3.4 KiB
C#
84 lines
3.4 KiB
C#
using Akka.Actor;
|
|
using Akka.TestKit.Xunit2;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
|
using ZB.MOM.WW.ScadaBridge.Communication.Actors;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
|
|
|
|
/// <summary>
|
|
/// Regression tests for Communication-004 — coordinator actors must declare an
|
|
/// explicit <c>Resume</c> supervision strategy per the CLAUDE.md decision
|
|
/// ("Resume for coordinator actors"). A child fault under the default
|
|
/// (Restart) strategy would wipe a child's in-memory state; the long-lived
|
|
/// coordinators own per-site transport resources and must not silently discard
|
|
/// their children on a transient fault.
|
|
/// </summary>
|
|
public class CoordinatorSupervisionTests : TestKit
|
|
{
|
|
/// <summary>
|
|
/// Test-only subclass that exposes the protected <see cref="SupervisorStrategy"/>
|
|
/// so the configured directive can be asserted directly.
|
|
/// </summary>
|
|
private sealed class CentralCommunicationActorProbe : CentralCommunicationActor
|
|
{
|
|
public CentralCommunicationActorProbe(IServiceProvider sp, ISiteCommandTransport transport)
|
|
: base(sp, transport) { }
|
|
|
|
public SupervisorStrategy GetSupervisorStrategy() => SupervisorStrategy();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test-only subclass that exposes the protected <see cref="SupervisorStrategy"/>.
|
|
/// </summary>
|
|
private sealed class SiteCommunicationActorProbe : SiteCommunicationActor
|
|
{
|
|
public SiteCommunicationActorProbe(string siteId, CommunicationOptions options, IActorRef dm)
|
|
: base(siteId, options, dm) { }
|
|
|
|
public SupervisorStrategy GetSupervisorStrategy() => SupervisorStrategy();
|
|
}
|
|
|
|
private static IServiceProvider EmptyServiceProvider()
|
|
{
|
|
var mockRepo = Substitute.For<ISiteRepository>();
|
|
mockRepo.GetAllSitesAsync(Arg.Any<CancellationToken>())
|
|
.Returns(new List<Commons.Entities.Sites.Site>());
|
|
var services = new ServiceCollection();
|
|
services.AddScoped(_ => mockRepo);
|
|
return services.BuildServiceProvider();
|
|
}
|
|
|
|
[Fact]
|
|
public void CentralCommunicationActor_SupervisorStrategy_IsResume()
|
|
{
|
|
var sp = EmptyServiceProvider();
|
|
var transport = Substitute.For<ISiteCommandTransport>();
|
|
|
|
var actorRef = new Akka.TestKit.TestActorRef<CentralCommunicationActorProbe>(
|
|
Sys, Props.Create(() => new CentralCommunicationActorProbe(sp, transport)));
|
|
|
|
var strategy = actorRef.UnderlyingActor.GetSupervisorStrategy();
|
|
|
|
var oneForOne = Assert.IsType<OneForOneStrategy>(strategy);
|
|
var directive = oneForOne.Decider.Decide(new InvalidOperationException("transient child fault"));
|
|
Assert.Equal(Directive.Resume, directive);
|
|
}
|
|
|
|
[Fact]
|
|
public void SiteCommunicationActor_SupervisorStrategy_IsResume()
|
|
{
|
|
var dmProbe = CreateTestProbe();
|
|
|
|
var actorRef = new Akka.TestKit.TestActorRef<SiteCommunicationActorProbe>(
|
|
Sys, Props.Create(() => new SiteCommunicationActorProbe("site1", new CommunicationOptions(), dmProbe.Ref)));
|
|
|
|
var strategy = actorRef.UnderlyingActor.GetSupervisorStrategy();
|
|
|
|
var oneForOne = Assert.IsType<OneForOneStrategy>(strategy);
|
|
var directive = oneForOne.Decider.Decide(new InvalidOperationException("transient child fault"));
|
|
Assert.Equal(Directive.Resume, directive);
|
|
}
|
|
}
|