コード例 #1
0
        public virtual void Init()
        {
            var sendOverHttpHandler = GetSendOverHttpProcessor();

            for (int i = 0; i < InstancesCnt; ++i)
            {
                var inputBus  = new InMemoryBus(string.Format("ELECTIONS-INPUT-BUS-{0}", i));
                var outputBus = new InMemoryBus(string.Format("ELECTIONS-OUTPUT-BUS-{0}", i));
                var endPoint  = new IPEndPoint(BaseEndPoint.Address, BaseEndPoint.Port + i);
                var nodeInfo  = new VNodeInfo(Guid.NewGuid(), 0, endPoint, endPoint, endPoint, endPoint, endPoint,
                                              endPoint);
                _instances.Add(new ElectionsInstance(nodeInfo.InstanceId, endPoint, inputBus, outputBus));

                sendOverHttpHandler.RegisterEndPoint(endPoint, inputBus);

                var electionsService = new Core.Services.ElectionsService(outputBus,
                                                                          nodeInfo,
                                                                          InstancesCnt,
                                                                          new InMemoryCheckpoint(),
                                                                          new InMemoryCheckpoint(),
                                                                          new FakeEpochManager(),
                                                                          () => - 1, 0);
                electionsService.SubscribeMessages(inputBus);

                outputBus.Subscribe(sendOverHttpHandler);
                outputBus.Subscribe(new TimerMessageProcessor(Rnd,
                                                              Runner,
                                                              endPoint,
                                                              inputBus,
                                                              _timerMinDelay,
                                                              _timerMaxDelay));
                outputBus.Subscribe(new InnerBusMessagesProcessor(Runner, endPoint, inputBus));
            }
        }
コード例 #2
0
        public ElectionsServiceUnit(ClusterSettings clusterSettings)
        {
            Publisher = new FakePublisher();

            _bus = new InMemoryBus(GetType().Name);
            var memberInfo = MemberInfo.Initial(clusterSettings.Self.NodeInfo.InstanceId, InitialDate,
                                                VNodeState.Unknown, true,
                                                clusterSettings.Self.NodeInfo.InternalTcp,
                                                clusterSettings.Self.NodeInfo.InternalSecureTcp,
                                                clusterSettings.Self.NodeInfo.ExternalTcp,
                                                clusterSettings.Self.NodeInfo.ExternalSecureTcp,
                                                clusterSettings.Self.NodeInfo.HttpEndPoint,
                                                clusterSettings.Self.NodePriority,
                                                clusterSettings.Self.ReadOnlyReplica);

            ElectionsService = new Core.Services.ElectionsService(Publisher,
                                                                  memberInfo,
                                                                  clusterSettings.ClusterNodesCount,
                                                                  new InMemoryCheckpoint(WriterCheckpoint),
                                                                  new InMemoryCheckpoint(ChaserCheckpoint),
                                                                  new FakeEpochManager(),
                                                                  () => - 1, 0, new FakeTimeProvider());
            ElectionsService.SubscribeMessages(_bus);

            InputMessages = new List <Message>();

            InitialClusterSettings = clusterSettings;
            InitialClusterInfo     = BuildClusterInfo(clusterSettings);
            ClusterInfo            = new ClusterInfo(InitialClusterInfo.Members);
        }
コード例 #3
0
        public virtual void Init()
        {
            var sendOverHttpHandler = GetSendOverHttpProcessor();

            for (int i = 0; i < InstancesCnt; ++i)
            {
                var inputBus = new InMemoryBus(string.Format("ELECTIONS-INPUT-BUS-{0}", i));
                var outputBus = new InMemoryBus(string.Format("ELECTIONS-OUTPUT-BUS-{0}", i));
                var endPoint = new IPEndPoint(BaseEndPoint.Address, BaseEndPoint.Port + i);
                var nodeInfo = new VNodeInfo(Guid.NewGuid(), endPoint, endPoint, endPoint, endPoint, endPoint, endPoint);
                _instances.Add(new ElectionsInstance(nodeInfo.InstanceId, endPoint, inputBus, outputBus));

                sendOverHttpHandler.RegisterEndPoint(endPoint, inputBus);

                var electionsService = new Core.Services.ElectionsService(outputBus,
                                                                             nodeInfo,
                                                                             InstancesCnt,
                                                                             new InMemoryCheckpoint(),
                                                                             new InMemoryCheckpoint(),
                                                                             new FakeEpochManager(),
                                                                             () => -1, 0);
                electionsService.SubscribeMessages(inputBus);

                outputBus.Subscribe(sendOverHttpHandler);
                outputBus.Subscribe(new TimerMessageProcessor(Rnd,
                                                              Runner,
                                                              endPoint,
                                                              inputBus,
                                                              _timerMinDelay,
                                                              _timerMaxDelay));
                outputBus.Subscribe(new InnerBusMessagesProcessor(Runner, endPoint, inputBus));
            }
        }
コード例 #4
0
        public ElectionsServiceUnit(ClusterSettings clusterSettings)
        {
            Publisher = new FakePublisher();

            _bus             = new InMemoryBus(GetType().Name);
            ElectionsService = new Core.Services.ElectionsService(Publisher,
                                                                  clusterSettings.Self.NodeInfo,
                                                                  clusterSettings.ClusterNodesCount,
                                                                  new InMemoryCheckpoint(WriterCheckpoint),
                                                                  new InMemoryCheckpoint(ChaserCheckpoint),
                                                                  new FakeEpochManager(),
                                                                  () => - 1, 0, new FakeTimeProvider());
            ElectionsService.SubscribeMessages(_bus);

            InputMessages = new List <Message>();

            InitialClusterSettings = clusterSettings;
            InitialClusterInfo     = BuildClusterInfo(clusterSettings);
            ClusterInfo            = new ClusterInfo(InitialClusterInfo.Members);
        }
コード例 #5
0
        public void Setup()
        {
            var address    = IPAddress.Loopback;
            var members    = new List <MemberInfo>();
            var seeds      = new List <IPEndPoint>();
            var seedSource = new ReallyNotSafeFakeGossipSeedSource(seeds);

            _nodes = new Dictionary <IPEndPoint, IPublisher>();
            for (int i = 0; i < 3; i++)
            {
                var inputBus  = new InMemoryBus($"ELECTIONS-INPUT-BUS-NODE-{i}", watchSlowMsg: false);
                var outputBus = new InMemoryBus($"ELECTIONS-OUTPUT-BUS-NODE-{i}", watchSlowMsg: false);
                var endPoint  = new IPEndPoint(address, 1000 + i);
                seeds.Add(endPoint);
                var instanceId = Guid.Parse($"101EFD13-F9CD-49BE-9C6D-E6AF9AF5540{i}");
                members.Add(MemberInfo.ForVNode(instanceId, DateTime.UtcNow, VNodeState.Unknown, true,
                                                endPoint, null, endPoint, null, endPoint, endPoint, -1, 0, 0, -1, -1, Guid.Empty, 0, false)
                            );
                var nodeInfo = new VNodeInfo(instanceId, 0, endPoint, endPoint, endPoint, endPoint, endPoint,
                                             endPoint, false);
                _fakeTimeProvider = new FakeTimeProvider();
                _scheduler        = new FakeScheduler(new FakeTimer(), _fakeTimeProvider);
                var timerService = new TimerService(_scheduler);

                var         writerCheckpoint   = new InMemoryCheckpoint();
                var         readerCheckpoint   = new InMemoryCheckpoint();
                var         epochManager       = new FakeEpochManager();
                Func <long> lastCommitPosition = () => - 1;
                var         electionsService   = new Core.Services.ElectionsService(outputBus,
                                                                                    nodeInfo,
                                                                                    3,
                                                                                    writerCheckpoint,
                                                                                    readerCheckpoint,
                                                                                    epochManager,
                                                                                    () => - 1, 0, new FakeTimeProvider());
                electionsService.SubscribeMessages(inputBus);

                outputBus.Subscribe <HttpMessage.SendOverHttp>(this);
                var nodeId = i;
                outputBus.Subscribe(new AdHocHandler <Message>(
                                        m => {
                    switch (m)
                    {
                    case TimerMessage.Schedule sm:
                        TestContext.WriteLine(
                            $"Node {nodeId} : Delay {sm.TriggerAfter} : {sm.ReplyMessage.GetType()}");
                        timerService.Handle(sm);
                        break;

                    case HttpMessage.SendOverHttp hm:
                        TestContext.WriteLine($"Node {nodeId} : EP {hm.EndPoint} : {hm.Message.GetType()}");
                        break;

                    default:
                        TestContext.WriteLine($"Node {nodeId} : EP {m.GetType()}");
                        inputBus.Publish(m);
                        break;
                    }
                }
                                        ));
                _nodes.Add(endPoint, inputBus);

                var gossip = new NodeGossipService(outputBus, seedSource, nodeInfo, writerCheckpoint, readerCheckpoint,
                                                   epochManager, lastCommitPosition, 0, TimeSpan.FromMilliseconds(500), TimeSpan.FromDays(1),
                                                   _fakeTimeProvider);
                inputBus.Subscribe <SystemMessage.SystemInit>(gossip);
                inputBus.Subscribe <GossipMessage.RetrieveGossipSeedSources>(gossip);
                inputBus.Subscribe <GossipMessage.GotGossipSeedSources>(gossip);
                inputBus.Subscribe <GossipMessage.Gossip>(gossip);
                inputBus.Subscribe <GossipMessage.GossipReceived>(gossip);
                inputBus.Subscribe <SystemMessage.StateChangeMessage>(gossip);
                inputBus.Subscribe <GossipMessage.GossipSendFailed>(gossip);
                inputBus.Subscribe <GossipMessage.UpdateNodePriority>(gossip);
                inputBus.Subscribe <SystemMessage.VNodeConnectionEstablished>(gossip);
                inputBus.Subscribe <SystemMessage.VNodeConnectionLost>(gossip);
            }

            _members = members;
        }