Exemplo n.º 1
0
        public void PeerIsDisconnected_OnlyIfPeerConnectionActionIsDisconnect(PeerConnectionAction peerConnectionAction)
        {
            var receiverNodeIdentifier = new ReceiverIdentifier(Guid.NewGuid().ToByteArray());
            var payload = new UnregisterUnreachableNodeMessage {
                ReceiverNodeIdentity = receiverNodeIdentifier.Identity
            };
            var message          = Message.Create(payload);
            var peerRemoveResult = new PeerRemoveResult
            {
                ConnectionAction = peerConnectionAction,
                Uri = new Uri("tcp://127.0.0.1:9009")
            };

            externalRoutingTable.Setup(m => m.RemoveNodeRoute(receiverNodeIdentifier)).Returns(peerRemoveResult);
            //
            handler.Handle(message, backendSocket.Object);
            //
            externalRoutingTable.Verify(m => m.RemoveNodeRoute(receiverNodeIdentifier), Times.Once);
            backendSocket.Verify(m => m.Disconnect(peerRemoveResult.Uri), Times.Exactly(peerConnectionAction == PeerConnectionAction.Disconnect ? 1 : 0));
            clusterHealthMonitor.Verify(m => m.DeletePeer(receiverNodeIdentifier), Times.Exactly(peerConnectionAction != PeerConnectionAction.KeepConnection ? 1 : 0));
        }
Exemplo n.º 2
0
        public void IfPeerRemovalConnectionActionNotEqualsKeepConnection_ClusterHealthMonitorDeletesPeer(PeerConnectionAction peerConnectionAction)
        {
            securityProvider.Setup(m => m.GetDomain(It.IsAny <byte[]>())).Returns(domain);
            var receiverNodeIdentity = Guid.NewGuid().ToByteArray();
            var payload    = CreateUnregisterMessageRoutePayload(receiverNodeIdentity);
            var message    = Message.Create(payload).As <Message>();
            var callsCount = payload.Routes.SelectMany(r => r.MessageContracts).Count();

            message.SetDomain(domain);
            var peerRemoveResult = new PeerRemoveResult
            {
                ConnectionAction = peerConnectionAction,
                Uri = new Uri("tcp://127.0.0.1:9090")
            };

            externalRoutingTable.Setup(m => m.RemoveMessageRoute(It.IsAny <ExternalRouteRemoval>())).Returns(peerRemoveResult);
            //
            handler.Handle(message, backEndSocket.Object);
            //
            clusterHealthMonitor.Verify(m => m.DeletePeer(new ReceiverIdentifier(payload.ReceiverNodeIdentity)),
                                        Times.Exactly(peerConnectionAction != PeerConnectionAction.KeepConnection ? callsCount : 0));
        }
Exemplo n.º 3
0
        public void IfPeerRemovalConnectionActionIsDisconnect_ScaleOutBackendSocketIsDisconnectedFromPeer(PeerConnectionAction peerConnectionAction)
        {
            securityProvider.Setup(m => m.GetDomain(It.IsAny <byte[]>())).Returns(domain);
            var receiverNodeIdentity = Guid.NewGuid().ToByteArray();
            var payload    = CreateUnregisterMessageRoutePayload(receiverNodeIdentity);
            var message    = Message.Create(payload).As <Message>();
            var callsCount = payload.Routes.SelectMany(r => r.MessageContracts).Count();

            message.SetDomain(domain);
            var peerRemoveResult = new PeerRemoveResult
            {
                ConnectionAction = peerConnectionAction,
                Uri = new Uri("tcp://127.0.0.1:9090")
            };

            externalRoutingTable.Setup(m => m.RemoveMessageRoute(It.IsAny <ExternalRouteRemoval>())).Returns(peerRemoveResult);
            //
            handler.Handle(message, backEndSocket.Object);
            //
            backEndSocket.Verify(m => m.Disconnect(peerRemoveResult.Uri), Times.Exactly(peerConnectionAction == PeerConnectionAction.Disconnect ? callsCount : 0));
        }