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.
150 lines
5.7 KiB
C#
150 lines
5.7 KiB
C#
using Microsoft.Extensions.Options;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Communication.Tests;
|
|
|
|
/// <summary>
|
|
/// Regression: <see cref="CommunicationOptions"/> timeouts feed per-pattern Ask
|
|
/// deadlines and gRPC keepalive/stream-lifetime settings; a zero/negative value
|
|
/// (or a non-positive <c>GrpcMaxConcurrentStreams</c>) must be rejected at startup
|
|
/// by an <see cref="IValidateOptions{TOptions}"/> with a clear, key-naming message
|
|
/// rather than surfacing at first Ask/gRPC use.
|
|
/// </summary>
|
|
public class CommunicationOptionsValidatorTests
|
|
{
|
|
private static ValidateOptionsResult Validate(CommunicationOptions options) =>
|
|
new CommunicationOptionsValidator().Validate(Options.DefaultName, options);
|
|
|
|
[Fact]
|
|
public void DefaultOptions_AreValid()
|
|
{
|
|
var result = Validate(new CommunicationOptions());
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroDeploymentTimeout_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { DeploymentTimeout = TimeSpan.Zero });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("DeploymentTimeout", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void NonPositiveGrpcMaxConcurrentStreams_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { GrpcMaxConcurrentStreams = 0 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("GrpcMaxConcurrentStreams", result.FailureMessage);
|
|
}
|
|
|
|
// ── Aggregated live alarm cache options (plan #10, Task 6) ───────────────────
|
|
|
|
[Fact]
|
|
public void ZeroLiveAlarmCacheLinger_IsValid()
|
|
{
|
|
// Zero linger = stop the aggregator immediately when the last viewer leaves.
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheLinger = TimeSpan.Zero });
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void NegativeLiveAlarmCacheLinger_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheLinger = TimeSpan.FromSeconds(-1) });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCacheLinger", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroLiveAlarmCacheReconcileInterval_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheReconcileInterval = TimeSpan.Zero });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCacheReconcileInterval", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroLiveAlarmCacheSeedConcurrency_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheSeedConcurrency = 0 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCacheSeedConcurrency", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ExcessiveLiveAlarmCacheSeedConcurrency_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheSeedConcurrency = 65 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCacheSeedConcurrency", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void ZeroLiveAlarmCacheMaxSubscribersPerSite_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCacheMaxSubscribersPerSite = 0 });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCacheMaxSubscribersPerSite", result.FailureMessage);
|
|
}
|
|
|
|
// ── R2 T10: live-delta publish-coalescing window (N6) ────────────────────────
|
|
|
|
[Fact]
|
|
public void ZeroLiveAlarmCachePublishCoalesce_IsValid()
|
|
{
|
|
// Zero = publish per delta (legacy behavior).
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCachePublishCoalesce = TimeSpan.Zero });
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void NegativeLiveAlarmCachePublishCoalesce_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions { LiveAlarmCachePublishCoalesce = TimeSpan.FromMilliseconds(-1) });
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("LiveAlarmCachePublishCoalesce", result.FailureMessage);
|
|
}
|
|
|
|
// ── gRPC central transport endpoints ─────────────────────────────────────────
|
|
// gRPC (CentralControlService) is the only site→central transport after the
|
|
// ClusterClient→gRPC migration's Phase 4. This role-agnostic validator only rejects BLANK
|
|
// entries; an EMPTY list is valid (central nodes legitimately declare none). The role-aware
|
|
// "a Site must list at least one endpoint" rule lives in StartupValidator, tested there.
|
|
|
|
[Fact]
|
|
public void EmptyEndpoints_IsValid()
|
|
{
|
|
// A central node hosts CentralControlService; it does not dial it, so it declares none.
|
|
var result = Validate(new CommunicationOptions
|
|
{
|
|
CentralGrpcEndpoints = new List<string>(),
|
|
});
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void BlankEndpoint_IsRejected()
|
|
{
|
|
var result = Validate(new CommunicationOptions
|
|
{
|
|
CentralGrpcEndpoints = new List<string> { " " },
|
|
});
|
|
Assert.True(result.Failed);
|
|
Assert.Contains("CentralGrpcEndpoints", result.FailureMessage);
|
|
}
|
|
|
|
[Fact]
|
|
public void Endpoints_IsValid()
|
|
{
|
|
var result = Validate(new CommunicationOptions
|
|
{
|
|
CentralGrpcEndpoints = new List<string>
|
|
{
|
|
"http://scadabridge-central-a:8083",
|
|
"http://scadabridge-central-b:8083",
|
|
},
|
|
});
|
|
Assert.True(result.Succeeded, result.FailureMessage);
|
|
}
|
|
}
|