public async Task Should_load_custom_AkkaHealthCheck() { Config config = @" akka.healthcheck.liveness.provider = ""Akka.HealthCheck.Tests.AkkaHealthCheckSpecs+CustomHealthCheckProvider+FakeName, Akka.HealthCheck.Tests"" akka.healthcheck.readiness.provider = ""Akka.HealthCheck.Tests.AkkaHealthCheckSpecs+CustomHealthCheckProvider+FakeName, Akka.HealthCheck.Tests"" "; using (var system = ActorSystem.Create("foo", config)) { var healthCheck = AkkaHealthCheck.For(system); // should be misconfigured healthCheck.Settings.Misconfigured.Should().BeTrue(); // check that the custom plugins were NOT loaded healthCheck.Settings.LivenessProbeProvider.Should().Be(typeof(DefaultLivenessProvider)); healthCheck.Settings.ReadinessProbeProvider.Should().Be(typeof(DefaultReadinessProvider)); // when misconfigured, probes should report that we are neither live nor ready var livenessStatus = await healthCheck.LivenessProbe.Ask <LivenessStatus>(GetCurrentLiveness.Instance, TimeSpan.FromSeconds(1)); livenessStatus.IsLive.Should().BeFalse(); var readinessStatus = await healthCheck.ReadinessProbe.Ask <ReadinessStatus>(GetCurrentReadiness.Instance, TimeSpan.FromSeconds(1)); readinessStatus.IsReady.Should().BeFalse(); } }
public void AkkaPersistenceLivenessProbeProviderSettingsTest_Should_Load() { var healthCheck = AkkaHealthCheck.For(Sys); healthCheck.Settings.Misconfigured.Should().BeFalse(); healthCheck.Settings.LivenessProbeProvider.Should().Be(typeof(AkkaPersistenceLivenessProbeProvider)); }
public async Task Should_load_custom_HealthCheck_system_correctly() { // forces the plugin to load var healthCheck = AkkaHealthCheck.For(Sys); var readinessSubscriber = CreateTestProbe(); var livenessSubscriber = CreateTestProbe(); healthCheck.LivenessProbe.Tell(new SubscribeToLiveness(livenessSubscriber)); healthCheck.ReadinessProbe.Tell(new SubscribeToReadiness(readinessSubscriber)); livenessSubscriber.ExpectMsg <LivenessStatus>().IsLive.Should().BeTrue(); readinessSubscriber.ExpectMsg <ReadinessStatus>().IsReady.Should().BeTrue(); var filePath = healthCheck.Settings.ReadinessTransportSettings.As <FileTransportSettings>().FilePath; var tcpPort = healthCheck.Settings.LivenessTransportSettings.As <SocketTransportSettings>().Port; // check to see that our probes are up and running using the supplied transports AwaitCondition(() => File.Exists(filePath)); var tcpClient = new TcpClient(AddressFamily.InterNetworkV6); await tcpClient.ConnectAsync(IPAddress.IPv6Loopback, tcpPort); // force shutdown of the ActorSystem and verify that probes are stopped await Sys.Terminate(); // Readiness probe should not exist AwaitCondition(() => !File.Exists(filePath)); //Created a new client to see if it would be able to connect. var tcpClient2 = new TcpClient(AddressFamily.InterNetworkV6); // liveness probe should be disconnected try { await tcpClient2.ConnectAsync(IPAddress.IPv6Loopback, tcpPort); var bytesRead = await tcpClient.GetStream().ReadAsync(new byte[10], 0, 10); bytesRead.Should().Be(0); } catch { } //Second client should not be able to connect as socket has been closed AwaitCondition(() => !tcpClient2.Connected); }
public async Task Should_load_default_AkkaHealthCheck() { using (var system = ActorSystem.Create("foo")) { var healthCheck = AkkaHealthCheck.For(system); healthCheck.Settings.Misconfigured.Should().BeFalse(); var livenessStatus = await healthCheck.LivenessProbe.Ask <LivenessStatus>(GetCurrentLiveness.Instance, TimeSpan.FromSeconds(1)); livenessStatus.IsLive.Should().BeTrue(); var readinessStatus = await healthCheck.ReadinessProbe.Ask <ReadinessStatus>(GetCurrentReadiness.Instance, TimeSpan.FromSeconds(1)); readinessStatus.IsReady.Should().BeTrue(); } }
static void Main(string[] args) { var hocon = @"{ akka{ healthcheck{ log-config-on-start = on liveness{ transport = tcp tcp.port = 8080} readiness{ transport = file file.path = ""snapshot.txt""} }}"; var config = ConfigurationFactory.ParseString(hocon); var actorSystem = ActorSystem.Create("Probe", config); var healthCheck = AkkaHealthCheck.For(actorSystem); actorSystem.WhenTerminated.Wait(); }
private static void StartActorSystem() { Config clusterConfig = ConfigurationFactory.ParseString(@" petabridge.cmd{ host = ""0.0.0.0"" port = 9111 } akka { log-config-on-start = on actor { provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"" ask-timeout = 60s debug { receive = on autoreceive = on lifecycle = on event-stream = on unhandled = on } deployment { /SecondRouter { router = round-robin-group routees.paths = [""/user/SecondRouter""] cluster { enabled = on allow-local-routees = off use-role = SecondRouter } } /FirstRouter/FirstActor { router = round-robin-pool resizer { enabled = on lower-bound = 5 upper-bound = 10 pressure-threshold = 1 rampup-rate = 0.2 backoff-threshold = 0.3 backoff-rate = 0.1 messages-per-resize = 5 } } } } remote { maximum-payload-bytes = 83886080 bytes dot-netty.tcp { hostname = ""127.0.0.1"" port = 9112 connection-timeout = 15 s send-buffer-size = 256000b receive-buffer-size = 256000b maximum-frame-size = 83886080b backlog = 4096 } } cluster { seed-nodes = [""akka.tcp://[email protected]:4053""] roles = [""FirstRouter""] } } "); _actorSystem = ActorSystem.Create("myactorsystem", clusterConfig); _akkaHealthCheck = AkkaHealthCheck.For(_actorSystem); // create pbm host PetabridgeCmd cmd = PetabridgeCmd.Get(_actorSystem); cmd.RegisterCommandPalette(ClusterCommands.Instance); cmd.RegisterCommandPalette(RemoteCommands.Instance); cmd.Start(); SecondRouterActor = _actorSystem.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "SecondRouter"); RouterActor = _actorSystem.ActorOf(Props.Create <RouterActor>(SecondRouterActor), "FirstRouter"); //Wait for actor system to be initialize Thread.Sleep(6000); for (int i = 0; i < 10; i++) { var result = (User)(RouterActor.Ask(new GetUserMessage(i)).Result); Console.WriteLine($"Name: {result.Name} - Surname: {result.Surname} - UserId: {result.UserId} - UserGroupId: {result.UserGroup.UserGroupId} - UserGroupName: {result.UserGroup.UserGroupName}"); } }
private static void StartActorSystem() { Config clusterConfig = ConfigurationFactory.ParseString(@" petabridge.cmd{ host = ""0.0.0.0"" port = 9113 } akka { log-config-on-start = on actor { provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"" ask-timeout = 60s debug { receive = on autoreceive = on lifecycle = on event-stream = on unhandled = on } deployment { /SecondRouter/SecondActor { router = round-robin-pool resizer { enabled = on lower-bound = 5 upper-bound = 10 pressure-threshold = 1 rampup-rate = 0.2 backoff-threshold = 0.3 backoff-rate = 0.1 messages-per-resize = 5 } } } } remote { maximum-payload-bytes = 83886080 bytes dot-netty.tcp { hostname = ""127.0.0.1"" port = 9114 connection-timeout = 15 s send-buffer-size = 256000b receive-buffer-size = 256000b maximum-frame-size = 83886080b backlog = 4096 } } cluster { seed-nodes = [""akka.tcp://[email protected]:4053""] roles = [""SecondRouter""] } } "); _actorSystem = ActorSystem.Create("myactorsystem", clusterConfig); _akkaHealthCheck = AkkaHealthCheck.For(_actorSystem); // create pbm host PetabridgeCmd cmd = PetabridgeCmd.Get(_actorSystem); cmd.RegisterCommandPalette(ClusterCommands.Instance); cmd.RegisterCommandPalette(RemoteCommands.Instance); cmd.Start(); RouterActor = _actorSystem.ActorOf(Props.Create <RouterActor>(), "SecondRouter"); }