protected AppendEntryBaseTest() { // Arrange var mocker = new AutoMocker(); ServerIdentifier = new ServerIdentifier(); mocker.Use(ServerIdentifier); mocker.Setup<ISubject<AppendEntryMessage>>(p => p.Subscribe(It.IsAny<IObserver<AppendEntryMessage>>())) .Callback<IObserver<AppendEntryMessage>>((o) => { AppendEntryCallback = o; }); AppendEntryCallback = mocker.Get<ISubject<AppendEntryMessage>>(); AppendEntryResult = new Subject<AppendEntryResultMessage>(); Election = new Election(); LogReplication = new LogReplication(); AppendEntry = new Rafting.AppendEntry(AppendEntryResult, mocker.Get<ISubject<AppendEntryMessage>>(), mocker.Get<IHartbeatTimer>(), LogReplication, Election, mocker.Get<ILoggerFactory>(), new RaftOptions(), mocker.Get<ServerIdentifier>(), null); }
public void DisposeAndStateDoesNotChangeAfterHartbeatTest() { var mocker = new AutoMocker(); var serverIdentifier = new ServerIdentifier(); mocker.Use(serverIdentifier); var options = new RaftOptions(); options.Hartbeat.FromMilliseconds = 50; options.Hartbeat.ToMilliseconds = 50; var timer = new HartbeatTimer(options, mocker.Get<ILoggerFactory>(), serverIdentifier); var state = ServerStateType.Leader; var dispose = timer.Subscribe((s) => { state = s; }); dispose.Dispose(); Thread.Sleep(100); Assert.Equal(ServerStateType.Leader, state); }
public CandidateBaseTests() { var mocker = new AutoMocker(); ServerIdentifier = new ServerIdentifier(); mocker.Use(ServerIdentifier); Election = new Election(); RequestVoteResult = new Subject<RequestVoteResultMessage>(); RequestVote = new Subject<RequestVoteMessage>(); MockVotingSystem = mocker.GetMock<IVotingSystem>(); Candidate = new Rafting.States.Candidate(mocker.Get<ServerIdentifier>(), mocker.Get<IElectionTimer>(), RequestVote, RequestVoteResult, MockVotingSystem.Object, Election, mocker.Get<ILogReplication>(), mocker.Get<Nodes>(), mocker.Get<ILoggerFactory>(), new RaftOptions()); }
protected VoteReceivedBaseTests() { // Arrange var mocker = new AutoMocker(); ServerIdentifier = new ServerIdentifier(); mocker.Use(ServerIdentifier); mocker.Setup<ISubject<RequestVoteMessage>>(p => p.Subscribe(It.IsAny<IObserver<RequestVoteMessage>>())) .Callback<IObserver<RequestVoteMessage>>((o) => { RequestVoteCallback = o; }); RequestVoteCallback = mocker.Get<ISubject<RequestVoteMessage>>(); Election = new Election(); Message = new RequestVoteResultMessage(); mocker.Setup<ISubject<RequestVoteResultMessage>>(p => p.OnNext(It.IsAny<RequestVoteResultMessage>())) .Callback<RequestVoteResultMessage>((o) => { Message = o; }); VoteReceived = new Rafting.VoteReceived(mocker.Get<ISubject<RequestVoteResultMessage>>(), mocker.Get<ServerIdentifier>(), mocker.Get<ISubject<RequestVoteMessage>>(), Election, mocker.Get<ILoggerFactory>(), new Nodes(), new RaftOptions(), mocker.Get<ILogReplication>()); }
public void LogNotReplicatedOverMajority() { // Arrange var votedFor = Guid.NewGuid(); Election.CurrentTerm = 1; Election.VotedFor = votedFor; var node = new ServerIdentifier(); Nodes.Add(node); Nodes.Add(new ServerIdentifier()); Nodes.Add(new ServerIdentifier()); // Act Leader.EntryReplyMessageRecived(new AppendEntryResultMessage() { Term = 1, Success = true, LogIndex = 1, LogTerm = 1, From = node }); // Assert Assert.Equal(1, Election.CurrentTerm); Assert.Equal(votedFor, Election.VotedFor); Assert.Equal(2, Leader.NextIndex[node]); Assert.Equal(1, Leader.MatchIndex[node]); }
public Candidate(ServerIdentifier serverIdentifier, IElectionTimer electionTimer, IObserver<RequestVoteMessage> requestVote, IObservable<RequestVoteResultMessage> voteReply, IVotingSystem votingSystem, IElection election, ILogReplication logReplication, Nodes nodes, ILoggerFactory loggerFactory, RaftOptions options) { isDispose = false; _electionTimer = electionTimer; _requestVote = requestVote; _voteReply = voteReply; _votingSystem = votingSystem; _serverIdentifier = serverIdentifier; _election = election; _options = options; _logger = loggerFactory.CreateLogger(nameof(Candidate) + " " + serverIdentifier); _election.CurrentTerm++; _election.VotedFor = _serverIdentifier.Id; _logReplication = logReplication; _nodes = nodes; if (_options.UseLogging) _logger.LogInformation($"{nameof(ServerStateType.Candidate)}"); RequestElection(); }
public LoginController(ILogger <LoginController> logger, IPlexClient plexClient, IAuthValidator authValidator) { _logger = logger; _plexClient = plexClient; _authValidator = authValidator; _serverIdentifier = plexClient.GetPlexServerIdentifier(); }
public ServiceRegistry(ServerIdentifier serverIdentifier, RaftOptions options, IRaftClient raftClient) { _options = options; _raftClient = raftClient; _serverIdentifier = serverIdentifier; _list = new ConcurrentDictionary<Node, DateTimeOffset>(); _self = new Node() { Identifier = _serverIdentifier, Name = _options.ServiceName, Address = _options.IpAddress.ToString() }; }
public Follower(ILoggerFactory loggerFactory, Nodes nodes, RaftOptions options, ServerIdentifier serverIdentifier) { isDispose = false; _options = options; _serverIdentifier = serverIdentifier; nodes.Clear(); _logger = loggerFactory.CreateLogger(nameof(Follower) + " " + serverIdentifier); if (_options.UseLogging) _logger.LogInformation($"{nameof(ServerStateType.Follower)}"); }
public LoginController(ILogger <LoginController> logger, IPlexClient plexClient, IAuthValidator authValidator, IConfigurationService configuration) { this._logger = logger; this._plexClient = plexClient; this._authValidator = authValidator; var id = configuration.GetConfig().ServerIdentifier; if (id == null) { var pref = configuration.GetConfig().PlexPreferencesFile; serverIdentifier = plexClient.GetLocalServerIdentifier(pref ?? "Preferences.xml"); } else { serverIdentifier = new ServerIdentifier(id); } }
private static MetadataContainer DeserializeBody(BinaryReader input, MetadataContainer config, FastAccessList <object> referenceTracking = null) { var nbServerMap = input.ReadInt32(); for (var i = 0; i < nbServerMap; i++) { var src = ServerIdentifier.Deserialize(input); var dst = ServerIdentifier.Deserialize(input); config.ServerMap.Add(src, dst); } var nbConnection = input.ReadInt32(); for (var i = 0; i < nbConnection; i++) { config.ConnectionStrings.Add(SqlConnection.Deserialize(input)); } config.Metadatas = AppMetadata.Deserialize(input, referenceTracking); return(config); }
public void CommitLogs() { // Arrange var votedFor = Guid.NewGuid(); Election.CurrentTerm = 1; Election.VotedFor = votedFor; var node1 = new ServerIdentifier(); var node2 = new ServerIdentifier(); var node3 = new ServerIdentifier(); Nodes.Add(node1); Nodes.Add(node2); Nodes.Add(node3); Nodes.Add(new ServerIdentifier()); Leader.MatchIndex.AddOrUpdate(node2, 1, (oldKey, oldValue) => 1); Leader.MatchIndex.AddOrUpdate(node3, 1, (oldKey, oldValue) => 1); // Act Leader.EntryReplyMessageRecived(new AppendEntryResultMessage() { Term = 1, Success = true, LogIndex = 1, LogTerm = 1, From = node1 }); // Assert Assert.Equal(1, Election.CurrentTerm); Assert.Equal(votedFor, Election.VotedFor); Assert.Equal(2, Leader.NextIndex[node1]); Assert.Equal(1, Leader.MatchIndex[node1]); }
public void SubscribeTest() { var mocker = new AutoMocker(); var serverIdentifier = new ServerIdentifier(); mocker.Use(serverIdentifier); var options = new RaftOptions(); options.Hartbeat.FromMilliseconds = 0; options.Hartbeat.ToMilliseconds = 0; var timer = new HartbeatTimer(options, mocker.Get<ILoggerFactory>(), serverIdentifier); var state = ServerStateType.Leader; timer.Subscribe((s) => { state = s; }); Thread.Sleep(100); Assert.Equal(ServerStateType.Candidate, state); }
public IQueryHelper GetQueryHelper(ServerIdentifier server) => _queryHelpers[server.ServerId];
public IQueryHelper this[ServerIdentifier server] => _queryHelpers[server.ServerId];
public Leader(IElection election, IHartbeatTimer hartbeat, IObservable<AppendEntryResultMessage> reply, IObserver<AppendEntryMessage> append, IObserver<ClientResultMessage> clientReply, IObservable<ClientMessage> client, ILogReplication logReplication, Nodes nodes, ILoggerFactory loggerFactory, RaftOptions options, ServerIdentifier serverIdentifier) { _isDispose = false; _hartbeat = hartbeat; _append = append; _clientReply = clientReply; _client = client; _logReplication = logReplication; _nodes = nodes; _options = options; _serverIdentifier = serverIdentifier; _election = election; _logger = loggerFactory.CreateLogger(nameof(Leader) + " " + serverIdentifier); if (_options.UseLogging) _logger.LogInformation($"{nameof(ServerStateType.Leader)}"); // Reinitialized after election NextIndex = new ConcurrentDictionary<ServerIdentifier, int>(); MatchIndex = new ConcurrentDictionary<ServerIdentifier, int>(); _hartbeat.Leader(SendHartbeat); _replyDispose = reply.Subscribe(EntryReplyMessageRecived); _clientReplyDispose = client.Subscribe(ClientMessageRecived); }
public LeaderBaseTests() { var mocker = new AutoMocker(); ServerIdentifier = new ServerIdentifier(); mocker.Use(ServerIdentifier); Election = new Election(); AppendEntryResult = new Subject<AppendEntryResultMessage>(); AppendEntry = new Subject<AppendEntryMessage>(); LogReplication = new LogReplication(); Nodes = new Nodes(); Leader = new Rafting.States.Leader( Election, mocker.Get<IHartbeatTimer>(), AppendEntryResult, AppendEntry, mocker.Get<IObserver<ClientResultMessage>>(), mocker.Get<IObservable<ClientMessage>>(), LogReplication, Nodes, mocker.Get<ILoggerFactory>(), new RaftOptions(), mocker.Get<ServerIdentifier>()); }