feat(comm): Phase 4 — delete Akka ClusterClient site↔central transport, gRPC-only
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.
This commit is contained in:
+10
-72
@@ -1,47 +1,25 @@
|
||||
using System.Collections.Immutable;
|
||||
using Akka.Actor;
|
||||
using Akka.Cluster.Tools.Client;
|
||||
using Akka.Configuration;
|
||||
using Akka.TestKit.Xunit2;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.Communication;
|
||||
using ZB.MOM.WW.ScadaBridge.Communication.Actors;
|
||||
using ZB.MOM.WW.ScadaBridge.HealthMonitoring;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Transport-agnostic refresh behaviour of <see cref="CentralCommunicationActor"/>: the periodic
|
||||
/// DB refresh evicts deleted sites from the health aggregator. The two former tests here —
|
||||
/// per-site ClusterClient recreate-without-restart-loop and factory-throw resilience — asserted
|
||||
/// Akka <c>AkkaSiteTransport</c> internals (InvalidActorNameException, "No ClusterClient for site")
|
||||
/// and were removed with that transport in the ClusterClient→gRPC migration's Phase 4; the
|
||||
/// equivalent gRPC channel reconcile is covered by the <c>GrpcSiteTransport</c> suites.
|
||||
/// </summary>
|
||||
public class CentralCommunicationActorClientLifecycleTests : TestKit
|
||||
{
|
||||
private static readonly Config TestConfig = ConfigurationFactory.ParseString(@"
|
||||
akka.actor.provider = cluster
|
||||
akka.remote.dot-netty.tcp.port = 0
|
||||
akka.remote.dot-netty.tcp.hostname = localhost")
|
||||
.WithFallback(ClusterClientReceptionist.DefaultConfig());
|
||||
|
||||
public CentralCommunicationActorClientLifecycleTests() : base(TestConfig) { }
|
||||
|
||||
// Empty ServiceProvider with a no-op ISiteRepository so the actor's periodic
|
||||
// db-refresh (fired at PreStart) resolves and returns no sites, keeping the
|
||||
// logs clean; the tests drive SiteAddressCacheLoaded directly.
|
||||
private static IServiceProvider EmptyProvider()
|
||||
{
|
||||
var siteRepo = Substitute.For<ISiteRepository>();
|
||||
siteRepo.GetAllSitesAsync(Arg.Any<CancellationToken>()).Returns(new List<Site>());
|
||||
var services = new ServiceCollection();
|
||||
services.AddScoped(_ => siteRepo);
|
||||
return services.BuildServiceProvider();
|
||||
}
|
||||
|
||||
private static SiteAddressCacheLoaded Load(string siteId, params string[] addrs) =>
|
||||
new(new Dictionary<string, IReadOnlyList<string>>
|
||||
{ [siteId] = addrs.ToList().AsReadOnly() },
|
||||
new[] { siteId },
|
||||
new Dictionary<string, SiteGrpcEndpoints>());
|
||||
|
||||
[Fact]
|
||||
public void PeriodicRefresh_PrunesDeletedSites_FromHealthAggregator()
|
||||
{
|
||||
@@ -57,8 +35,9 @@ public class CentralCommunicationActorClientLifecycleTests : TestKit
|
||||
services.AddSingleton(aggregator);
|
||||
var provider = services.BuildServiceProvider();
|
||||
|
||||
var transport = Substitute.For<ISiteCommandTransport>();
|
||||
var actor = Sys.ActorOf(Props.Create(() => new CentralCommunicationActor(
|
||||
provider, new DefaultSiteClientFactory(), null)));
|
||||
provider, transport, (TimeSpan?)null)));
|
||||
|
||||
// Trigger the refresh (also fires at PreStart, but drive it explicitly so
|
||||
// the assertion is deterministic). The load runs on a detached task and
|
||||
@@ -70,45 +49,4 @@ public class CentralCommunicationActorClientLifecycleTests : TestKit
|
||||
Arg.Is<IReadOnlyCollection<string>>(ids => ids.Contains("site-a"))),
|
||||
TimeSpan.FromSeconds(3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddressEdit_RecreatesClient_WithoutRestartLoop()
|
||||
{
|
||||
var actor = Sys.ActorOf(Props.Create(() => new CentralCommunicationActor(
|
||||
EmptyProvider(), new DefaultSiteClientFactory(), null)));
|
||||
|
||||
// First load creates the client; second load (edited NodeA address) stops
|
||||
// the old one and creates a replacement in the same message handling.
|
||||
// Pre-fix this throws InvalidActorNameException and restarts the actor.
|
||||
EventFilter.Exception<InvalidActorNameException>().Expect(0, () =>
|
||||
{
|
||||
actor.Tell(Load("site-a", "akka.tcp://scadabridge@node-a:8081"));
|
||||
actor.Tell(Load("site-a", "akka.tcp://scadabridge@node-a-edited:8081"));
|
||||
actor.Tell(Load("site-a", "akka.tcp://scadabridge@node-a:8081")); // and back — third generation
|
||||
});
|
||||
|
||||
// The actor must still be alive and routing (not crash-looping):
|
||||
// an envelope for an unknown site produces the "No ClusterClient" warning,
|
||||
// proving the Receive pipeline is healthy.
|
||||
EventFilter.Warning(contains: "No ClusterClient for site").ExpectOne(() =>
|
||||
actor.Tell(new SiteEnvelope("unknown-site", new object())));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FactoryThrow_SkipsSite_DoesNotCrashActor()
|
||||
{
|
||||
var throwingFactory = Substitute.For<ISiteClientFactory>();
|
||||
throwingFactory.Create(Arg.Any<ActorSystem>(), Arg.Any<string>(), Arg.Any<ImmutableHashSet<ActorPath>>())
|
||||
.Returns(_ => throw new InvalidOperationException("boom"));
|
||||
var actor = Sys.ActorOf(Props.Create(() => new CentralCommunicationActor(
|
||||
EmptyProvider(), throwingFactory, null)));
|
||||
|
||||
EventFilter.Error(contains: "Failed to create ClusterClient").ExpectOne(() =>
|
||||
actor.Tell(Load("site-a", "akka.tcp://scadabridge@node-a:8081")));
|
||||
|
||||
// Actor survived — a subsequent envelope for that (unrouted) site still
|
||||
// produces the healthy "No ClusterClient" warning rather than a dead actor.
|
||||
EventFilter.Warning(contains: "No ClusterClient for site").ExpectOne(() =>
|
||||
actor.Tell(new SiteEnvelope("site-a", new object())));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user