//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRespondNegativelyToAppendEntriesRequestFromEarlierTerm() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRespondNegativelyToAppendEntriesRequestFromEarlierTerm() { // given long leaderTerm = 5; long leaderCommitIndex = 10; long rivalTerm = leaderTerm - 1; long logIndex = 20; RaftLogEntry[] entries = new RaftLogEntry[] { new RaftLogEntry(rivalTerm, ReplicatedInteger.valueOf(99)) }; Leader leader = new Leader(); RaftState state = raftState().term(leaderTerm).commitIndex(leaderCommitIndex).build(); // when Outcome outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(_member1, rivalTerm, logIndex, leaderTerm, entries, leaderCommitIndex), state, Log()); // then assertThat(outcome.Role, equalTo(LEADER)); assertThat(outcome.Term, equalTo(leaderTerm)); Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage response = messageFor(outcome, _member1); assertThat(response, instanceOf(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response))); Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response typedResponse = (Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response)response; assertThat(typedResponse.Term(), equalTo(leaderTerm)); assertThat(typedResponse.Success(), equalTo(false)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStepDownIfAppendEntriesRequestFromLaterTerm() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldStepDownIfAppendEntriesRequestFromLaterTerm() { // given long leaderTerm = 1; long leaderCommitIndex = 10; long rivalTerm = leaderTerm + 1; long logIndex = 20; RaftLogEntry[] entries = new RaftLogEntry[] { new RaftLogEntry(rivalTerm, ReplicatedInteger.valueOf(99)) }; Leader leader = new Leader(); RaftState state = raftState().term(leaderTerm).commitIndex(leaderCommitIndex).build(); // when Outcome outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(_member1, rivalTerm, logIndex, leaderTerm, entries, leaderCommitIndex), state, Log()); // then assertThat(outcome.Role, equalTo(FOLLOWER)); assertThat(outcome.Leader, equalTo(_member1)); assertThat(outcome.Term, equalTo(rivalTerm)); Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage response = messageFor(outcome, _member1); assertThat(response, instanceOf(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response))); Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response typedResponse = (Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response)response; assertThat(typedResponse.Term(), equalTo(rivalTerm)); // Not checking success or failure of append }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSendCompactionInfoIfFailureWithNoEarlierEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldSendCompactionInfoIfFailureWithNoEarlierEntries() { // given Leader leader = new Leader(); long term = 1; long leaderPrevIndex = 3; long followerIndex = leaderPrevIndex - 1; InMemoryRaftLog raftLog = new InMemoryRaftLog(); raftLog.Skip(leaderPrevIndex, term); RaftState state = raftState().term(term).entryLog(raftLog).build(); Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response incomingResponse = appendEntriesResponse().failure().term(term).appendIndex(followerIndex).from(_member1).build(); // when Outcome outcome = leader.Handle(incomingResponse, state, Log()); // then Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage outgoingMessage = messageFor(outcome, _member1); assertThat(outgoingMessage, instanceOf(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo))); Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo typedOutgoingMessage = (Org.Neo4j.causalclustering.core.consensus.RaftMessages_LogCompactionInfo)outgoingMessage; assertThat(typedOutgoingMessage.PrevIndex(), equalTo(leaderPrevIndex)); }
private void ConvertStateFromLeaderTo(RaftState newState) { switch (newState) { case RaftState.Follower: logger.Info($"RaftState {Name}: Leader->Follower"); State = RaftState.Follower; ResetLeaderReadyAfterChangeState(); Monitor.PulseAll(this); HearbeatTimerTask?.Cancel(); HearbeatTimerTask = null; StartLeaderLostTimerTask(); return; case RaftState.Candidate: logger.Error($"RaftState {Name} Impossible! Leader->Candidate"); return; case RaftState.Leader: logger.Error($"RaftState {Name} Impossible! Leader->Leader"); return; } }
public void BecomeMaster(Timer aTimer) { lock (this) { state = RaftState.MASTER; ResetTimeout(aTimer, TIMEOUT); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldHandleBatch() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldHandleBatch() { // given RaftState state = raftState().votingMembers(asSet(_myself, _member1, _member2)).build(); Leader leader = new Leader(); const int batchSize = 3; Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_BatchRequest batchRequest = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_NewEntry_BatchRequest(new IList <Org.Neo4j.causalclustering.core.replication.ReplicatedContent> { valueOf(0), valueOf(1), valueOf(2) }); // when Outcome outcome = leader.Handle(batchRequest, state, Log()); // then BatchAppendLogEntries logCommand = ( BatchAppendLogEntries )single(outcome.LogCommands); assertEquals(0, logCommand.BaseIndex); for (int i = 0; i < batchSize; i++) { assertEquals(0, logCommand.Entries[i].term()); assertEquals(i, (( ReplicatedInteger )logCommand.Entries[i].content()).get()); } ShipCommand.NewEntries shipCommand = (ShipCommand.NewEntries)single(outcome.ShipCommands); assertEquals(shipCommand, new ShipCommand.NewEntries(-1, -1, new RaftLogEntry[] { new RaftLogEntry(0, valueOf(0)), new RaftLogEntry(0, valueOf(1)), new RaftLogEntry(0, valueOf(2)) })); }
public void BecomeFollower(Timer aTimer) { lock (this) { state = RaftState.FOLLOWER; ResetTimeout(aTimer, TIMEOUT + GetRandomDelay(1)); } }
void AppendEntries(RaftMessage message) { //Ignore if message.term < term if (message.Term < currentTerm) { Console.Out.WriteLine("Old term detected. Discarding append entries."); return; } if (string.IsNullOrEmpty(message.Data)) { Console.Out.WriteLine("FOLLOWING ORDERS"); leader = message.Sender; state = RaftState.Follower; votedFor = null; electionTimeout = DateTime.UtcNow.AddMilliseconds(electionWaitPeriod); } else { var data = message.Data.Split('-'); var prevLogIndex = Int32.Parse(data[0]); var prevLogTerm = Int32.Parse(data[1]); var leaderCommitIndex = Int32.Parse(data[2]); //ignore if log doesn't contain an entry at prevLogIndex whos term is equal to prevLogTerm if (log[prevLogIndex] != null) { if (log[prevLogIndex].Term != prevLogTerm) { Console.Out.WriteLine("Incorrect term for previous log entry detected. Discarding append entries."); return; } } Console.Out.WriteLine("DOING WORK"); //If entry conflicts, delete entry and following entries /* * if (log[RaftLogEntry.Index] != null && log[RaftLogEntry.Index].Term != RaftLogEntry.Term) * { * var toBeDeleted = log.Where(x => x.Index >= RaftLogEntry.Index).Select(x => x.Index).ToList(); * foreach(var index in toBeDeleted) * { * log[index] = null; * } * } */ //Append all new entries to log /* * if(leaderCommitIndex > commitIndex) * { * commitIndex = Math.Min(leaderCommitIndex, lastNewEntry); * } */ } }
public void BecomeCandidate(Timer aTimer) { lock (this) { state = RaftState.CANDIDATE; term++; StopTimeout(aTimer); } }
public RaftInfo(PartitionInfo pInfo, bool isMaster) { term = 0; votedTerm = 0; state = isMaster ? RaftState.MASTER : RaftState.FOLLOWER; Logs = new List <KeyValuePair <string, string> >(); PInfo = pInfo; }
private void BecomeLeader() { Console.Out.WriteLine("I AM THE LEADER"); state = RaftState.Leader; heartbeatWaitPeriod = electionWaitPeriod - 1000; heartbeatTimeout = DateTime.UtcNow; foreach (var node in remoteNodes.Keys) { remoteNodes[node].MatchIndex = 0; remoteNodes[node].NextIndex = commitIndex; } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldGeneratePruneCommandsOnRequest() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldGeneratePruneCommandsOnRequest() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().myself(_myself).entryLog(raftLog).build(); // when Org.Neo4j.causalclustering.core.consensus.RaftMessages_PruneRequest pruneRequest = new Org.Neo4j.causalclustering.core.consensus.RaftMessages_PruneRequest(1000); Outcome outcome = Role.handler.handle(pruneRequest, state, Log()); // then assertThat(outcome.LogCommands, hasItem(new PruneLogCommand(1000))); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public ClusterState(java.util.Set<org.neo4j.causalclustering.identity.MemberId> members) throws java.io.IOException public ClusterState(ISet <MemberId> members) { this.Roles = new Dictionary <MemberId, Role>(); this.States = new Dictionary <MemberId, ComparableRaftState>(); this.Queues = new Dictionary <MemberId, LinkedList <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> >(); foreach (MemberId member in members) { Roles[member] = Role.FOLLOWER; RaftState memberState = raftState().myself(member).votingMembers(members).build(); States[member] = new ComparableRaftState(memberState); Queues[member] = new LinkedList <Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage>(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAcceptContinuousEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAcceptContinuousEntries() { InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().myself(_myself).entryLog(raftLog).build(); long leaderTerm = state.Term() + LeaderTermDifference; raftLog.Append(new RaftLogEntry(leaderTerm, content())); // when Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(raftLog.AppendIndex()).prevLogTerm(leaderTerm).logEntry(new RaftLogEntry(leaderTerm, content())).build(), state, Log()); // then assertTrue((( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader)).success()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldAcceptInitialEntryAfterBootstrap() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldAcceptInitialEntryAfterBootstrap() { RaftLog raftLog = BootstrappedLog(); RaftState state = raftState().entryLog(raftLog).myself(_myself).build(); long leaderTerm = state.Term() + LeaderTermDifference; RaftLogEntry logEntry = new RaftLogEntry(leaderTerm, content()); // when Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(0).prevLogTerm(0).logEntry(logEntry).build(), state, Log()); // then assertTrue((( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader)).success()); assertThat(outcome.LogCommands, hasItem(new BatchAppendLogEntries(1, 0, new RaftLogEntry[] { logEntry }))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotResultInCommitIfReferringToFutureEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotResultInCommitIfReferringToFutureEntries() { InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().myself(_myself).entryLog(raftLog).build(); long leaderTerm = state.Term() + LeaderTermDifference; raftLog.Append(new RaftLogEntry(leaderTerm, content())); Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat heartbeat = heartbeat().from(_leader).commitIndex(raftLog.AppendIndex() + 1).commitIndexTerm(leaderTerm).leaderTerm(leaderTerm).build(); Outcome outcome = Role.handler.handle(heartbeat, state, Log()); assertThat(outcome.LogCommands, empty()); }
// TODO: test that shows we don't commit for previous terms //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldSendHeartbeatsToAllClusterMembersOnReceiptOfHeartbeatTick() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldSendHeartbeatsToAllClusterMembersOnReceiptOfHeartbeatTick() { // given RaftState state = raftState().votingMembers(_myself, _member1, _member2).replicationMembers(_myself, _member1, _member2).build(); Leader leader = new Leader(); leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_HeartbeatResponse(_member1), state, Log()); // make sure it has quorum. // when Outcome outcome = leader.Handle(new RaftMessages_Timeout_Heartbeat(_myself), state, Log()); // then assertTrue(messageFor(outcome, _member1) is Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat); assertTrue(messageFor(outcome, _member2) is Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat); }
public RaftMachine(MemberId myself, StateStorage <TermState> termStorage, StateStorage <VoteState> voteStorage, RaftLog entryLog, LeaderAvailabilityTimers leaderAvailabilityTimers, Outbound <MemberId, RaftMessages_RaftMessage> outbound, LogProvider logProvider, RaftMembershipManager membershipManager, RaftLogShippingManager logShipping, InFlightCache inFlightCache, bool refuseToBecomeLeader, bool supportPreVoting, Monitors monitors) { this._myself = myself; this._leaderAvailabilityTimers = leaderAvailabilityTimers; this._outbound = outbound; this._logShipping = logShipping; this._log = logProvider.getLog(this.GetType()); this._membershipManager = membershipManager; this._inFlightCache = inFlightCache; this._state = new RaftState(myself, termStorage, membershipManager, entryLog, voteStorage, inFlightCache, logProvider, supportPreVoting, refuseToBecomeLeader); _raftMessageTimerResetMonitor = monitors.NewMonitor(typeof(RaftMessageTimerResetMonitor)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldRejectDiscontinuousEntries() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldRejectDiscontinuousEntries() { // given RaftState state = raftState().myself(_myself).build(); long leaderTerm = state.Term() + LeaderTermDifference; // when Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(state.EntryLog().appendIndex() + 1).prevLogTerm(leaderTerm).logEntry(new RaftLogEntry(leaderTerm, content())).build(), state, Log()); // then RaftMessages_AppendEntries_Response response = ( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader); assertEquals(state.EntryLog().appendIndex(), response.AppendIndex()); assertFalse(response.Success()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldStepDownWhenLackingHeartbeatResponses() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldStepDownWhenLackingHeartbeatResponses() { // given RaftState state = raftState().votingMembers(asSet(_myself, _member1, _member2)).leader(_myself).build(); Leader leader = new Leader(); leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Timeout_Election(_myself), state, Log()); // when Outcome outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Timeout_Election(_myself), state, Log()); // then assertThat(outcome.Role, not(LEADER)); assertNull(outcome.Leader); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldRejectAppendEntriesResponseWithNewerTermAndBecomeAFollower() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldRejectAppendEntriesResponseWithNewerTermAndBecomeAFollower() { // given RaftState state = raftState().myself(_myself).build(); Leader leader = new Leader(); // when Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response message = appendEntriesResponse().from(_member1).term(state.Term() + 1).build(); Outcome outcome = leader.Handle(message, state, Log()); // then assertEquals(0, count(outcome.OutgoingMessages)); assertEquals(FOLLOWER, outcome.Role); assertEquals(0, count(outcome.LogCommands)); assertEquals(state.Term() + 1, outcome.Term); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldIgnoreHeartbeatFromOlderTerm() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldIgnoreHeartbeatFromOlderTerm() { // given long leaderTerm = 5; long leaderCommitIndex = 10; long rivalTerm = leaderTerm - 1; Leader leader = new Leader(); RaftState state = raftState().term(leaderTerm).commitIndex(leaderCommitIndex).build(); // when Outcome outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat(_member1, rivalTerm, leaderCommitIndex, leaderTerm), state, Log()); // then assertThat(outcome.Role, equalTo(LEADER)); assertThat(outcome.Term, equalTo(leaderTerm)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldCommitEntry() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldCommitEntry() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().entryLog(raftLog).myself(_myself).build(); long leaderTerm = state.Term() + LeaderTermDifference; raftLog.Append(new RaftLogEntry(leaderTerm, content())); // when Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(raftLog.AppendIndex()).prevLogTerm(leaderTerm).leaderCommit(0).build(), state, Log()); // then assertTrue((( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader)).success()); assertThat(outcome.CommitIndex, Matchers.equalTo(0L)); }
internal void ConvertStateTo(RaftState newState) { // 按真值表处理所有情况。 switch (State) { case RaftState.Follower: ConvertStateFromFollwerTo(newState); return; case RaftState.Candidate: ConvertStateFromCandidateTo(newState); return; case RaftState.Leader: ConvertStateFromLeaderTo(newState); return; } }
//Raft Actions void BecomeCandidate() { Console.Out.WriteLine("Becoming candidate"); //Deal with yourself state = RaftState.Candidate; currentTerm = currentTerm + 1; votedFor = _host; electionWaitPeriod = 1500 + GetRandomWaitPeriod(); electionTimeout = DateTime.UtcNow.AddMilliseconds(electionWaitPeriod); Console.Out.WriteLine("Requesting votes"); foreach (var node in remoteNodes.Keys) { remoteNodes[node].VoteGranted = false; Send(RaftMessageType.RequestVote, node, (lastApplied > 0 ? lastApplied + "-" + log[lastApplied].Term : "0-0")); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldNotStepDownWhenReceivedQuorumOfHeartbeatResponses() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldNotStepDownWhenReceivedQuorumOfHeartbeatResponses() { // given RaftState state = raftState().votingMembers(asSet(_myself, _member1, _member2)).build(); Leader leader = new Leader(); // when Outcome outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_HeartbeatResponse(_member1), state, Log()); state.Update(outcome); // we now have quorum and should not step down outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Timeout_Election(_myself), state, Log()); // then assertThat(outcome.Role, @is(LEADER)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldCommitOnMajorityResponse() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldCommitOnMajorityResponse() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); raftLog.Append(new RaftLogEntry(0, new ReplicatedString("lalalala"))); RaftState state = raftState().votingMembers(_member1, _member2).term(0).lastLogIndexBeforeWeBecameLeader(-1).leader(_myself).leaderCommit(-1).entryLog(raftLog).messagesSentToFollower(_member1, raftLog.AppendIndex() + 1).messagesSentToFollower(_member2, raftLog.AppendIndex() + 1).build(); Leader leader = new Leader(); // when a single instance responds (plus self == 2 out of 3 instances) Outcome outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response(_member1, 0, true, 0, 0), state, Log()); // then assertEquals(0L, outcome.CommitIndex); assertEquals(0L, outcome.LeaderCommit); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotCommitAheadOfMatchingHistory() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotCommitAheadOfMatchingHistory() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().entryLog(raftLog).myself(_myself).build(); long leaderTerm = state.Term() + LeaderTermDifference; RaftLogEntry previouslyAppendedEntry = new RaftLogEntry(leaderTerm, content()); raftLog.Append(previouslyAppendedEntry); // when Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(raftLog.AppendIndex() + 1).prevLogTerm(leaderTerm).leaderCommit(0).build(), state, Log()); // then assertFalse((( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader)).success()); assertThat(outcome.LogCommands, empty()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStepDownIfHeartbeatReceivedWithGreaterOrEqualTerm() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldStepDownIfHeartbeatReceivedWithGreaterOrEqualTerm() { // given long leaderTerm = 1; long leaderCommitIndex = 10; long rivalTerm = leaderTerm + 1; Leader leader = new Leader(); RaftState state = raftState().term(leaderTerm).commitIndex(leaderCommitIndex).build(); // when Outcome outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_Heartbeat(_member1, rivalTerm, leaderCommitIndex, leaderTerm), state, Log()); // then assertThat(outcome.Role, equalTo(FOLLOWER)); assertThat(outcome.Leader, equalTo(_member1)); assertThat(outcome.Term, equalTo(rivalTerm)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldTruncateOnReceiptOfConflictingEntry() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldTruncateOnReceiptOfConflictingEntry() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); RaftState state = raftState().myself(_myself).term(5).entryLog(raftLog).build(); long leaderTerm = state.Term() + LeaderTermDifference; raftLog.Append(new RaftLogEntry(state.Term() - 1, content())); raftLog.Append(new RaftLogEntry(state.Term() - 1, content())); // when long previousIndex = raftLog.AppendIndex() - 1; Outcome outcome = Role.handler.handle(appendEntriesRequest().from(_leader).leaderTerm(leaderTerm).prevLogIndex(previousIndex).prevLogTerm(raftLog.ReadEntryTerm(previousIndex)).logEntry(new RaftLogEntry(leaderTerm, content())).build(), state, Log()); // then assertTrue((( RaftMessages_AppendEntries_Response )messageFor(outcome, _leader)).success()); assertThat(outcome.LogCommands, hasItem(new TruncateLogCommand(1))); }