using Akka.Actor;
using Akka.Configuration;
namespace ZB.MOM.WW.ScadaBridge.Host.Tests;
///
/// Tests for Akka.NET actor system bootstrap.
///
public class AkkaBootstrapTests : IDisposable
{
private ActorSystem? _actorSystem;
/// Releases the resources held by this test class.
public void Dispose()
{
_actorSystem?.Dispose();
}
/// Verifies that the actor system is created with the cluster configuration.
[Fact]
public void ActorSystem_CreatesWithClusterConfig()
{
var hocon = @"
akka {
actor {
provider = cluster
}
remote {
dot-netty.tcp {
hostname = ""localhost""
port = 0
}
}
cluster {
seed-nodes = [""akka.tcp://scadabridge-test@localhost:0""]
roles = [""Central""]
min-nr-of-members = 1
}
coordinated-shutdown {
run-by-clr-shutdown-hook = on
}
}";
var config = ConfigurationFactory.ParseString(hocon);
_actorSystem = ActorSystem.Create("scadabridge-test", config);
Assert.NotNull(_actorSystem);
Assert.Equal("scadabridge-test", _actorSystem.Name);
}
/// Verifies that the HOCON configuration includes coordinated shutdown.
[Fact]
public void ActorSystem_HoconConfig_IncludesCoordinatedShutdown()
{
var hocon = @"
akka {
actor {
provider = cluster
}
remote {
dot-netty.tcp {
hostname = ""localhost""
port = 0
}
}
cluster {
seed-nodes = [""akka.tcp://scadabridge-test@localhost:0""]
roles = [""Central""]
run-coordinated-shutdown-when-down = on
}
coordinated-shutdown {
run-by-clr-shutdown-hook = on
}
}";
var config = ConfigurationFactory.ParseString(hocon);
_actorSystem = ActorSystem.Create("scadabridge-cs-test", config);
var csConfig = _actorSystem.Settings.Config.GetString("akka.coordinated-shutdown.run-by-clr-shutdown-hook");
Assert.Equal("on", csConfig);
var clusterShutdown = _actorSystem.Settings.Config.GetString("akka.cluster.run-coordinated-shutdown-when-down");
Assert.Equal("on", clusterShutdown);
}
}