示例#1
0
        public void FollowerShouldReturnRetryIfNoLeader()
        {
            _node         = new NothingNode();
            _currentState = new CurrentState(_currentState.Id, _currentState.CurrentTerm, _currentState.VotedFor, _currentState.CommitIndex, _currentState.LastApplied, _currentState.LeaderId);
            var follower = new Follower(_currentState, _fsm, _log, _random, _node, _settings, _rules, _peers);
            var response = follower.Accept(new FakeCommand());
            var error    = (ErrorResponse <FakeCommand>)response;

            error.Error.ShouldBe("Please retry command later. Unable to find leader.");
        }
示例#2
0
        public async Task FollowerShouldForwardCommandToLeader()
        {
            _node = new NothingNode();
            var leaderId = Guid.NewGuid().ToString();
            var leader   = new FakePeer(leaderId);

            _peers = new List <IPeer>
            {
                leader
            };
            _currentState = new CurrentState(_currentState.Id, _currentState.CurrentTerm, _currentState.VotedFor, _currentState.CommitIndex, _currentState.LastApplied, leaderId);
            var follower = new Follower(_currentState, _fsm, _log, _random, _node, _settings, _rules, _peers, _loggerFactory.Object);
            var response = await follower.Accept(new FakeCommand());

            response.ShouldBeOfType <OkResponse <FakeCommand> >();
            leader.ReceivedCommands.ShouldBe(1);
        }