//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPerformTruncation() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldPerformTruncation() { // when // we have a log appended up to appendIndex, and committed somewhere before that long appendIndex = 5; long localTermForAllEntries = 1L; Outcome outcome = mock(typeof(Outcome)); ReadableRaftLog logMock = mock(typeof(ReadableRaftLog)); when(logMock.ReadEntryTerm(anyLong())).thenReturn(localTermForAllEntries); // for simplicity, all entries are at term 1 when(logMock.AppendIndex()).thenReturn(appendIndex); ReadableRaftState state = mock(typeof(ReadableRaftState)); when(state.EntryLog()).thenReturn(logMock); when(state.CommitIndex()).thenReturn(appendIndex - 3); // when // the leader asks to append after the commit index an entry that mismatches on term Appending.HandleAppendEntriesRequest(state, outcome, new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(_aMember, localTermForAllEntries, appendIndex - 2, localTermForAllEntries, new RaftLogEntry[] { new RaftLogEntry(localTermForAllEntries + 1, ReplicatedInteger.valueOf(2)) }, appendIndex + 3), NullLog.Instance); // then // we must produce a TruncateLogCommand at the earliest mismatching index verify(outcome, times(1)).addLogCommand(argThat(new LogCommandMatcher(appendIndex - 1))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotAllowTruncationAtCommit() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotAllowTruncationAtCommit() { // given long commitIndex = 5; long localTermForAllEntries = 1L; Outcome outcome = mock(typeof(Outcome)); ReadableRaftLog logMock = mock(typeof(ReadableRaftLog)); when(logMock.ReadEntryTerm(anyLong())).thenReturn(localTermForAllEntries); // for simplicity, all entries are at term 1 when(logMock.AppendIndex()).thenReturn(commitIndex); ReadableRaftState state = mock(typeof(ReadableRaftState)); when(state.EntryLog()).thenReturn(logMock); when(state.CommitIndex()).thenReturn(commitIndex); // when - then try { Appending.HandleAppendEntriesRequest(state, outcome, new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(_aMember, localTermForAllEntries, commitIndex - 1, localTermForAllEntries, new RaftLogEntry[] { new RaftLogEntry(localTermForAllEntries + 1, ReplicatedInteger.valueOf(2)) }, commitIndex + 3), NullLog.Instance); fail("Appending should not allow truncation at or before the commit index"); } catch (System.InvalidOperationException) { // ok } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotAttemptToTruncateAtIndexBeforeTheLogPrevIndex() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldNotAttemptToTruncateAtIndexBeforeTheLogPrevIndex() { // given // a log with prevIndex and prevTerm set ReadableRaftLog logMock = mock(typeof(ReadableRaftLog)); long prevIndex = 5; long prevTerm = 5; when(logMock.PrevIndex()).thenReturn(prevIndex); when(logMock.ReadEntryTerm(prevIndex)).thenReturn(prevTerm); // and which also properly returns -1 as the term for an unknown entry, in this case prevIndex - 2 when(logMock.ReadEntryTerm(prevIndex - 2)).thenReturn(-1L); // also, a state with a given commitIndex, obviously ahead of prevIndex long commitIndex = 10; ReadableRaftState state = mock(typeof(ReadableRaftState)); when(state.EntryLog()).thenReturn(logMock); when(state.CommitIndex()).thenReturn(commitIndex); // which is also the append index when(logMock.AppendIndex()).thenReturn(commitIndex); // when // an appendEntriesRequest arrives for appending entries before the prevIndex (for whatever reason) Outcome outcome = mock(typeof(Outcome)); Appending.HandleAppendEntriesRequest(state, outcome, new Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request(_aMember, prevTerm, prevIndex - 2, prevTerm, new RaftLogEntry[] { new RaftLogEntry(prevTerm, ReplicatedInteger.valueOf(2)) }, commitIndex + 3), NullLog.Instance); // then // there should be no truncate commands. Actually, the whole thing should be a no op verify(outcome, never()).addLogCommand(any()); }
internal CatchupGoal(ReadableRaftLog raftLog, Clock clock, long electionTimeout) { this._raftLog = raftLog; this._clock = clock; this._electionTimeout = electionTimeout; this._targetIndex = raftLog.AppendIndex(); this._startTime = clock.millis(); this._roundCount = 1; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public ComparableRaftLog(org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog raftLog) throws java.io.IOException public ComparableRaftLog(ReadableRaftLog raftLog) { using (RaftLogCursor cursor = raftLog.GetEntryCursor(0)) { while (cursor.Next()) { Append(cursor.get()); } } }
internal CatchupGoalTracker(ReadableRaftLog raftLog, Clock clock, long roundTimeout, long catchupTimeout) { this._raftLog = raftLog; this._clock = clock; this._roundTimeout = roundTimeout; this._catchupTimeout = catchupTimeout; this._targetIndex = raftLog.AppendIndex(); this._startTime = clock.millis(); this._roundStartTime = clock.millis(); this._roundCount = 1; }
internal RaftLogShipper(Outbound <MemberId, Org.Neo4j.causalclustering.core.consensus.RaftMessages_RaftMessage> outbound, LogProvider logProvider, ReadableRaftLog raftLog, Clock clock, TimerService timerService, MemberId leader, MemberId follower, long leaderTerm, long leaderCommit, long retryTimeMillis, int catchupBatchSize, int maxAllowedShippingLag, InFlightCache inFlightCache) { this._outbound = outbound; this._timerService = timerService; this._catchupBatchSize = catchupBatchSize; this._maxAllowedShippingLag = maxAllowedShippingLag; this._log = logProvider.getLog(this.GetType()); this._raftLog = raftLog; this._clock = clock; this._follower = follower; this._leader = leader; this._retryTimeMillis = retryTimeMillis; this._lastLeaderContext = new LeaderContext(leaderTerm, leaderCommit); this._inFlightCache = inFlightCache; }
public InFlightLogEntryReader(ReadableRaftLog raftLog, InFlightCache inFlightCache, bool pruneAfterRead) { this._raftLog = raftLog; this._inFlightCache = inFlightCache; this._pruneAfterRead = pruneAfterRead; }