Exemplo n.º 1
0
        public void WhenCheckPeerConnectionMessageArrives_ConnectionToPeerEstablishedAndMessageIsSent()
        {
            var peerIdentifier = new ReceiverIdentifier(Guid.NewGuid().ToByteArray());
            var payload        = new CheckPeerConnectionMessage {
                SocketIdentity = peerIdentifier.Identity
            };
            var message = Message.Create(payload);

            subscriberSocket.SetupMessageReceived(message, tokenSource.Token);
            var meta = new ClusterMemberMeta
            {
                ScaleOutUri           = "tcp://127.0.0.2:9009",
                ConnectionEstablished = false,
                LastKnownHeartBeat    = DateTime.UtcNow - TimeSpan.FromMinutes(30)
            };

            connectedPeerRegistry.Setup(m => m.Find(peerIdentifier)).Returns(meta);
            //
            clusterHealthMonitor.Start();
            AsyncOp.Sleep();
            tokenSource.Cancel();
            clusterHealthMonitor.Stop();
            //
            socketFactory.Verify(m => m.CreateRouterSocket(), Times.Once);
            routerSocket.Verify(m => m.SetMandatoryRouting(true), Times.Once);
            routerSocket.Verify(m => m.Connect(new Uri(meta.ScaleOutUri), true), Times.Once);
            routerSocket.Verify(m => m.SendMessage(It.Is <IMessage>(msg => msg.Equals(KinoMessages.Ping))), Times.Once);
            routerSocket.Verify(m => m.Disconnect(new Uri(meta.ScaleOutUri)), Times.Once);
            Assert.LessOrEqual(DateTime.UtcNow - meta.LastKnownHeartBeat, AsyncOp.MultiplyBy(3));
        }
Exemplo n.º 2
0
        public void WhenDeletePeerMessageArrives_PeerIsRemovedFromRegistryAndHealthUriDisconnected(bool connectionEstablished)
        {
            var peerIdentifier = new ReceiverIdentifier(Guid.NewGuid().ToByteArray());
            var payload        = new DeletePeerMessage {
                NodeIdentity = peerIdentifier.Identity
            };
            var message = Message.Create(payload);

            subscriberSocket.SetupMessageReceived(message, tokenSource.Token);
            var meta = new ClusterMemberMeta
            {
                HealthUri             = "tcp://127.0.0.2:9009",
                ConnectionEstablished = connectionEstablished
            };

            connectedPeerRegistry.Setup(m => m.Find(peerIdentifier)).Returns(meta);
            //
            clusterHealthMonitor.Start();
            AsyncOp.Sleep();
            tokenSource.Cancel();
            clusterHealthMonitor.Stop();
            //
            connectedPeerRegistry.Verify(m => m.Remove(peerIdentifier), Times.Once);
            subscriberSocket.Verify(m => m.Disconnect(new Uri(meta.HealthUri)), Times.Exactly(connectionEstablished ? 1 : 0));
        }
Exemplo n.º 3
0
        public void IfStartPeerMonitoringMessadeReceived_ConnectsToPeerHealthUri()
        {
            var healthUri      = new Uri("tcp://127.0.0.2:9090");
            var peerIdentifier = new ReceiverIdentifier(Guid.NewGuid().ToByteArray());
            var payload        = new StartPeerMonitoringMessage
            {
                Uri            = "tcp://127.0.0.1:800",
                SocketIdentity = peerIdentifier.Identity,
                Health         = new global::kino.Messaging.Messages.Health
                {
                    Uri = healthUri.ToSocketAddress(),
                    HeartBeatInterval = TimeSpan.FromMinutes(1)
                }
            };
            var message = Message.Create(payload);
            var meta    = new ClusterMemberMeta
            {
                HealthUri             = payload.Health.Uri,
                HeartBeatInterval     = payload.Health.HeartBeatInterval,
                ScaleOutUri           = payload.Uri,
                LastKnownHeartBeat    = DateTime.UtcNow,
                ConnectionEstablished = false
            };

            connectedPeerRegistry.Setup(m => m.FindOrAdd(It.Is <ReceiverIdentifier>(id => id == peerIdentifier), It.IsAny <ClusterMemberMeta>())).Returns(meta);
            subscriberSocket.SetupMessageReceived(message, tokenSource.Token);
            //
            clusterHealthMonitor.Start();
            TimeSpan.FromMilliseconds(100).Sleep();
            tokenSource.Cancel();
            clusterHealthMonitor.Stop();
            //
            subscriberSocket.Verify(m => m.Connect(healthUri, false), Times.Once);
            Assert.IsTrue(meta.ConnectionEstablished);
        }
        public void FindOrAdd_AddsReceiverIdentityIfItDoesntExistsAndReturnsClusterMemberData()
        {
            var peer = ReceiverIdentities.CreateForActor();
            var clusterMemberMeta = new ClusterMemberMeta();

            //
            Assert.AreEqual(clusterMemberMeta, peerRegistry.FindOrAdd(peer, clusterMemberMeta));
        }
        public void DuplicatedReceiverIdentities_CanNotBeAdded()
        {
            var peer = ReceiverIdentities.CreateForActor();
            var clusterMemberMeta = new ClusterMemberMeta();

            //
            peerRegistry.FindOrAdd(peer, clusterMemberMeta);
            peerRegistry.FindOrAdd(peer, clusterMemberMeta);
            //
            Assert.AreEqual(1, peerRegistry.Count());
        }
Exemplo n.º 6
0
        public void WhenHeartBeatMessageArrives_PeerLastKnwonHeartBeatIsSetToUtcNow()
        {
            var peerIdentifier = new ReceiverIdentifier(Guid.NewGuid().ToByteArray());
            var payload        = new HeartBeatMessage {
                SocketIdentity = peerIdentifier.Identity
            };
            var message = Message.Create(payload);

            subscriberSocket.SetupMessageReceived(message, tokenSource.Token);
            var meta = new ClusterMemberMeta {
                LastKnownHeartBeat = DateTime.UtcNow - TimeSpan.FromHours(20)
            };

            connectedPeerRegistry.Setup(m => m.Find(peerIdentifier)).Returns(meta);
            //
            clusterHealthMonitor.Start();
            AsyncOp.Sleep();
            tokenSource.Cancel();
            clusterHealthMonitor.Stop();
            //
            Assert.LessOrEqual(DateTime.UtcNow - meta.LastKnownHeartBeat, AsyncOp.MultiplyBy(3));
        }
Exemplo n.º 7
0
        public void IfStartPeerMonitoringMessadeReceived_CheckDeadPeersMessageAfterPeerHeartBeatInterval()
        {
            config.StalePeersCheckInterval = TimeSpan.FromMinutes(1);
            var healthUri         = new Uri("tcp://127.0.0.2:9090");
            var heartBeatInterval = TimeSpan.FromMilliseconds(300);
            var peerIdentifier    = new ReceiverIdentifier(Guid.NewGuid().ToByteArray());
            var payload           = new StartPeerMonitoringMessage
            {
                Uri            = "tcp://127.0.0.1:800",
                SocketIdentity = peerIdentifier.Identity,
                Health         = new global::kino.Messaging.Messages.Health
                {
                    Uri = healthUri.ToSocketAddress(),
                    HeartBeatInterval = heartBeatInterval
                }
            };
            var message = Message.Create(payload);
            var meta    = new ClusterMemberMeta
            {
                HealthUri             = payload.Health.Uri,
                HeartBeatInterval     = payload.Health.HeartBeatInterval,
                ScaleOutUri           = payload.Uri,
                LastKnownHeartBeat    = DateTime.UtcNow,
                ConnectionEstablished = false
            };

            connectedPeerRegistry.Setup(m => m.FindOrAdd(It.Is <ReceiverIdentifier>(id => id == peerIdentifier), It.IsAny <ClusterMemberMeta>())).Returns(meta);
            subscriberSocket.SetupMessageReceived(message, tokenSource.Token);
            //
            clusterHealthMonitor.Start();
            heartBeatInterval.MultiplyBy(2).Sleep();
            tokenSource.Cancel();
            clusterHealthMonitor.Stop();
            //
            multiplexingSocket.Verify(m => m.Send(It.Is <IMessage>(msg => msg.Equals(KinoMessages.CheckDeadPeers))), Times.AtLeastOnce);
        }