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.
80 lines
3.5 KiB
C#
80 lines
3.5 KiB
C#
using Akka.Actor;
|
|
using Akka.TestKit.Xunit2;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.Extensions.Options;
|
|
using NSubstitute;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Deployment;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Messages.Deployment;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Deployment;
|
|
using ZB.MOM.WW.ScadaBridge.Communication.Actors;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
|
|
|
|
/// <summary>
|
|
/// Tests that <see cref="CentralCommunicationActor"/> routes a site→central
|
|
/// <see cref="ReconcileSiteRequest"/> through the scoped <see cref="ReconcileService"/>
|
|
/// and pipes the resulting <see cref="ReconcileSiteResponse"/> back to the original
|
|
/// sender (the site's ClusterClient path). Mirrors the audit-ingest routing tests.
|
|
/// </summary>
|
|
public class CentralCommunicationActorReconcileTests : TestKit
|
|
{
|
|
[Fact]
|
|
public void ReconcileSiteRequest_RoutesResponseToSender()
|
|
{
|
|
var deploymentRepo = Substitute.For<IDeploymentManagerRepository>();
|
|
var siteRepo = Substitute.For<ISiteRepository>();
|
|
|
|
// GetAllSitesAsync is called by the actor's periodic refresh; keep it empty.
|
|
siteRepo.GetAllSitesAsync(Arg.Any<CancellationToken>())
|
|
.Returns(new List<Site>());
|
|
|
|
siteRepo.GetSiteByIdentifierAsync("site1", Arg.Any<CancellationToken>())
|
|
.Returns(new Site("Site One", "site1") { Id = 7 });
|
|
|
|
deploymentRepo.GetExpectedDeploymentsForSiteAsync(7, Arg.Any<CancellationToken>())
|
|
.Returns(new List<ExpectedDeployment>
|
|
{
|
|
new(2, "inst-B", "rev2", "dep-B", true),
|
|
});
|
|
deploymentRepo.GetDeployedSnapshotByInstanceIdAsync(2, Arg.Any<CancellationToken>())
|
|
.Returns(new DeployedConfigSnapshot("dep-B", "rev2", "{\"cfg\":\"B\"}"));
|
|
deploymentRepo.StagePendingIfAbsentAsync(
|
|
Arg.Any<int>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(),
|
|
Arg.Any<string>(), Arg.Any<DateTimeOffset>(), Arg.Any<DateTimeOffset>(),
|
|
Arg.Any<CancellationToken>())
|
|
.Returns(true);
|
|
|
|
var options = Options.Create(new CommunicationOptions
|
|
{
|
|
CentralFetchBaseUrl = "https://central.example:9000",
|
|
PendingDeploymentTtl = TimeSpan.FromMinutes(5),
|
|
});
|
|
|
|
var services = new ServiceCollection();
|
|
services.AddScoped(_ => deploymentRepo);
|
|
services.AddScoped(_ => siteRepo);
|
|
services.AddSingleton(options);
|
|
services.AddSingleton<Microsoft.Extensions.Logging.ILogger<ReconcileService>>(
|
|
NullLogger<ReconcileService>.Instance);
|
|
services.AddScoped<ReconcileService>();
|
|
var sp = services.BuildServiceProvider();
|
|
|
|
var transport = Substitute.For<ISiteCommandTransport>();
|
|
var actor = Sys.ActorOf(Props.Create(() => new CentralCommunicationActor(sp, transport, (TimeSpan?)null)));
|
|
|
|
// Node B is missing inst-B entirely → it should come back as a gap item.
|
|
actor.Tell(new ReconcileSiteRequest(
|
|
"site1", "node-b",
|
|
new Dictionary<string, string>()));
|
|
|
|
var response = ExpectMsg<ReconcileSiteResponse>(TimeSpan.FromSeconds(5));
|
|
var gap = Assert.Single(response.Gap);
|
|
Assert.Equal("inst-B", gap.InstanceUniqueName);
|
|
Assert.Equal("dep-B", gap.DeploymentId);
|
|
Assert.False(string.IsNullOrWhiteSpace(gap.FetchToken));
|
|
}
|
|
}
|