Beispiel #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static boolean shouldVoteFor(org.neo4j.causalclustering.core.consensus.state.ReadableRaftState state, org.neo4j.causalclustering.core.consensus.outcome.Outcome outcome, org.neo4j.causalclustering.core.consensus.RaftMessages_AnyVote_Request voteRequest, boolean committedToVotingForAnother, org.neo4j.logging.Log log) throws java.io.IOException
        private static bool ShouldVoteFor(ReadableRaftState state, Outcome outcome, Org.Neo4j.causalclustering.core.consensus.RaftMessages_AnyVote_Request voteRequest, bool committedToVotingForAnother, Log log)
        {
            long     requestTerm         = voteRequest.Term();
            MemberId candidate           = voteRequest.Candidate();
            long     requestLastLogTerm  = voteRequest.LastLogTerm();
            long     requestLastLogIndex = voteRequest.LastLogIndex();
            long     contextTerm         = outcome.Term;
            long     contextLastAppended = state.EntryLog().appendIndex();
            long     contextLastLogTerm  = state.EntryLog().readEntryTerm(contextLastAppended);

            return(ShouldVoteFor(candidate, contextTerm, requestTerm, contextLastLogTerm, requestLastLogTerm, contextLastAppended, requestLastLogIndex, committedToVotingForAnother, log));
        }
Beispiel #2
0
//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
            }
        }
Beispiel #3
0
//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)));
        }
Beispiel #4
0
//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());
        }