Exemplo n.º 1
0
        private void ProcessElections()
        {
            var gossipUpdate = new GossipMessage.GossipUpdated(_electionsUnit.ClusterInfo);
            _electionsUnit.Publish(gossipUpdate);

            _electionsUnit.Publish(new ElectionMessage.StartElections());

            _electionsUnit.RepublishFromPublisher();
        }
Exemplo n.º 2
0
        private void ProcessElections()
        {
            var gossipUpdate = new GossipMessage.GossipUpdated(_electionsUnit.ClusterInfo);
            _electionsUnit.Publish(gossipUpdate);

            _electionsUnit.Publish(new ElectionMessage.StartElections());

            _electionsUnit.RepublishFromPublisher();
            
            _electionsUnit.RepublishFromPublisher();
            Assert.That(_electionsUnit.Publisher.Messages.All(x => x is HttpMessage.SendOverHttp || x is TimerMessage.Schedule), 
                        Is.True, 
                        "Only OverHttp or Schedule messages are expected.");

            _electionsUnit.RepublishFromPublisher();
        }
        public void Process(int iteration, RandTestQueueItem item)
        {
            var electionsDone = item.Message as ElectionMessage.ElectionsDone;
            if (electionsDone != null)
            {
                MemberInfo[] previousMembers;
                if (_previousGossip.TryGetValue(item.EndPoint, out previousMembers))
                {
                    var masterMemberIndex = Array.FindIndex(previousMembers, x => x.Is(electionsDone.Master.InternalHttpEndPoint));
                    if (masterMemberIndex != -1)
                    {
                        var previousMasterInfo = previousMembers[masterMemberIndex];
                        var masterEndPoint = previousMasterInfo.InternalHttpEndPoint;

                        previousMembers[masterMemberIndex] = 
                            MemberInfo.ForVNode(previousMasterInfo.InstanceId, DateTime.UtcNow, VNodeState.Master, previousMasterInfo.IsAlive,
                                                masterEndPoint, null, masterEndPoint, null, masterEndPoint, masterEndPoint,
                                                -1, 0, 0, -1, -1, Guid.Empty, 0);
                    }
                }
            }

            var updatedGossip = _createUpdatedGossip(iteration, item, _instances, _initialGossip, _previousGossip);
            if (updatedGossip != null)
            {
                if (updatedGossip.Length > _instances.Length)
                    throw new InvalidDataException("Gossip should not contain more items than there are servers in the cluster.");

                _processedItems.Add(item);

                foreach (var memberInfo in updatedGossip)
                {
                    _sendOverHttpProcessor.RegisterEndpointToSkip(memberInfo.ExternalTcpEndPoint, !memberInfo.IsAlive);
                }

                var updateGossipMessage = new GossipMessage.GossipUpdated(new ClusterInfo(updatedGossip));

                _enqueue(item, updateGossipMessage);
                _previousGossip[item.EndPoint] = updatedGossip;

                var master = updateGossipMessage.ClusterInfo.Members.FirstOrDefault(x => x.IsAlive && x.State == VNodeState.Master);
                if (master == null)
                    _enqueue(item, new ElectionMessage.StartElections());
            }
        }
 protected virtual GossipMessage.GossipUpdated GetInitialGossipFor(ElectionsInstance instance, 
                                                                   List<ElectionsInstance> allInstances)
 {
     var members = allInstances.Select(
         x => MemberInfo.ForVNode(x.InstanceId, DateTime.UtcNow, VNodeState.Unknown, true,
                                  x.EndPoint, null, x.EndPoint, null, x.EndPoint, x.EndPoint, -1, 0, 0, -1, -1, Guid.Empty, 0));
     var gossip = new GossipMessage.GossipUpdated(new ClusterInfo(members.ToArray()));
     return gossip;
 }