using Akka.Actor; using Akka.Cluster; using Akka.Configuration; namespace ZB.MOM.WW.Secrets.Replicator.AkkaDotNet.Tests.DependencyInjection; /// /// One self-joined single-node cluster shared by a test class — the miniature app node the /// replication actor's DistributedPubSub mediator needs. Tests that spawn the actor must give each /// container its own Secrets:Replication:ActorName, since actor names are unique per system. /// public sealed class SingleNodeClusterFixture : IAsyncLifetime { /// The joined, Up actor system. public ActorSystem System { get; private set; } = null!; /// public async Task InitializeAsync() { System = ActorSystem.Create("zb-secrets-order", ConfigurationFactory.ParseString(""" akka { loglevel = WARNING actor.provider = cluster remote.dot-netty.tcp { hostname = "127.0.0.1" public-hostname = "127.0.0.1" port = 0 } } """).WithFallback(AkkaSecretsReplication.SerializationConfig)); Cluster cluster = Cluster.Get(System); cluster.Join(cluster.SelfAddress); DateTime deadline = DateTime.UtcNow + TimeSpan.FromSeconds(20); while (cluster.State.Members.All(m => m.Status != MemberStatus.Up)) { if (DateTime.UtcNow > deadline) { throw new TimeoutException("Single-node cluster never reached Up."); } await Task.Delay(100); } } /// public async Task DisposeAsync() => await System.Terminate(); }