Example #1
0
        public void IfSomeClusterNodeIsNotHealthy_ConnectionMessageIsSent()
        {
            messageHub.Start(TimeSpan.FromSeconds(3));
            synodConfigProvider.Object.HeartBeatInterval.MultiplyBy(synodConfigProvider.Object.MissingHeartBeatsBeforeReconnect + 1).Sleep();
            messageHub.Stop();
            //
            var clusterHealthInfo = messageHub.GetClusterHealthInfo();

            Assert.True(clusterHealthInfo.All(hi => !hi.IsHealthy()));
            publisherSocket.Verify(m => m.SendMessage(It.Is <IMessage>(msg => msg.Equals(MessageIdentifier.Create <ReconnectClusterMemberMessage>()))),
                                   Times.AtLeast(clusterHealthInfo.Count()));
        }
Example #2
0
        public void WhenHeartBeatMessageArrives_LastKnownHeartBeatIsUpdated()
        {
            synodConfigProvider.Setup(m => m.MissingHeartBeatsBeforeReconnect).Returns(1);
            messageHub = new IntercomMessageHub(socketFactory.Object,
                                                synodConfigProvider.Object,
                                                perfCounterManager.Object,
                                                logger.Object);
            var messageCount = 1;
            var deadNode     = messageHub.GetClusterHealthInfo().First();
            var message      = Message.Create(new HeartBeatMessage {
                NodeUri = deadNode.NodeUri.ToSocketAddress()
            });

            subscriberSocket.Setup(m => m.ReceiveMessage(It.IsAny <CancellationToken>())).Returns(() => messageCount-- > 0 ? message : null);

            synodConfigProvider.Object
            .HeartBeatInterval
            .MultiplyBy(synodConfigProvider.Object.MissingHeartBeatsBeforeReconnect + 1)
            .Sleep();
            var timeout = synodConfigProvider.Object
                          .HeartBeatInterval
                          .DivideBy(2);

            //
            Assert.False(deadNode.IsHealthy());
            messageHub.Start(timeout);
            timeout.Sleep();
            messageHub.Stop();
            //
            Assert.True(deadNode.IsHealthy());
        }