private RaftLog BootstrappedLog() { InMemoryRaftLog raftLog = new InMemoryRaftLog(); raftLog.Append(new RaftLogEntry(0, content())); return(raftLog); }
//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))); }
// TODO move this someplace else, since log no longer holds the commit //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldCommitAllPreviouslyAppendedEntriesWhenCommittingLaterEntryInSameTerm() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldCommitAllPreviouslyAppendedEntriesWhenCommittingLaterEntryInSameTerm() { // given InMemoryRaftLog raftLog = new InMemoryRaftLog(); raftLog.Append(new RaftLogEntry(0, new ReplicatedString("first!"))); raftLog.Append(new RaftLogEntry(0, new ReplicatedString("second"))); raftLog.Append(new RaftLogEntry(0, new ReplicatedString("third"))); RaftState state = raftState().votingMembers(_myself, _member1, _member2).term(0).entryLog(raftLog).messagesSentToFollower(_member1, raftLog.AppendIndex() + 1).messagesSentToFollower(_member2, raftLog.AppendIndex() + 1).build(); Leader leader = new Leader(); // when Outcome outcome = leader.Handle(new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response(_member1, 0, true, 2, 2), state, Log()); state.Update(outcome); // then assertEquals(2, state.CommitIndex()); }
// TODO: rethink this test, it does too much //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void leaderShouldSpawnMismatchCommandOnFailure() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void LeaderShouldSpawnMismatchCommandOnFailure() { // given /* * A leader who * - has an append index of 100 * - knows about instance 2 * - assumes that instance 2 is fully caught up */ Leader leader = new Leader(); MemberId instance2 = member(2); FollowerState instance2State = CreateArtificialFollowerState(100); ReadableRaftState state = mock(typeof(ReadableRaftState)); FollowerStates <MemberId> followerState = new FollowerStates <MemberId>(); followerState = new FollowerStates <MemberId>(followerState, instance2, instance2State); RaftLog log = new InMemoryRaftLog(); for (int i = 0; i <= 100; i++) { log.Append(new RaftLogEntry(0, valueOf(i))); } when(state.CommitIndex()).thenReturn(-1L); when(state.EntryLog()).thenReturn(log); when(state.FollowerStates()).thenReturn(followerState); when(state.Term()).thenReturn(4L); // both leader and follower are in the same term // when // that leader is asked to handle a response from that follower that says that the follower is still missing // things Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Response response = appendEntriesResponse().failure().appendIndex(0).matchIndex(-1).term(4).from(instance2).build(); Outcome outcome = leader.Handle(response, state, mock(typeof(Log))); // then int mismatchCount = 0; foreach (ShipCommand shipCommand in outcome.ShipCommands) { if (shipCommand is ShipCommand.Mismatch) { mismatchCount++; } } assertThat(mismatchCount, greaterThan(0)); }
//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()); }
//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 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)); }
//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 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); }