コード例 #1
0
        public async Task Should_successfully_open_and_close_signal()
        {
            var result = await Transport.Go("foo", CancellationToken.None);

            if (!result.Success)
            {
                ExceptionDispatchInfo.Capture(result.Exception).Throw();
            }

            result.Success.Should().BeTrue();

            var tcpClient = new TcpClient(AddressFamily.InterNetwork);
            await tcpClient.ConnectAsync(IPAddress.Loopback, PortNumber);

            var deleteResult = await Transport.Stop(null, CancellationToken.None);

            deleteResult.Success.Should().BeTrue();

            await AwaitAssertAsync(async() =>
                                   (await tcpClient.GetStream().ReadAsync(new byte[10], 0, 10)).Should().Be(8));

            var tcpClient2 = new TcpClient(AddressFamily.InterNetwork);
            //Should throw execption as socket will refuse to establish a connection
            await tcpClient2.Awaiting(client => client.ConnectAsync(IPAddress.Loopback, PortNumber))
            .Should().ThrowAsync <SocketException>();

            tcpClient2.Connected.Should().BeFalse();
        }
        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.InterNetwork);
            await tcpClient.ConnectAsync(IPAddress.Loopback, 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.InterNetwork);

            // liveness probe should be disconnected
            tcpClient2.Awaiting(client => client.ConnectAsync(IPAddress.Loopback, tcpPort))
            .Should().Throw <SocketException>();

            //Second client should not be able to connect as socket has been closed
            AwaitCondition(() => !tcpClient2.Connected);
        }