Search in sources :

Example 6 with InMemoryRaftLog

use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.

the class AppendEntriesRequestTest method shouldAcceptContinuousEntries.

@Test
public void shouldAcceptContinuousEntries() throws Exception {
    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(((Response) messageFor(outcome, leader)).success());
}
Also used : InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 7 with InMemoryRaftLog

use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.

the class AppendEntriesRequestTest method shouldTruncateOnReceiptOfConflictingEntry.

@Test
public void shouldTruncateOnReceiptOfConflictingEntry() throws Exception {
    // 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(((Response) messageFor(outcome, leader)).success());
    assertThat(outcome.getLogCommands(), hasItem(new TruncateLogCommand(1)));
}
Also used : InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) TruncateLogCommand(org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 8 with InMemoryRaftLog

use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.

the class AppendEntriesRequestTest method bootstrappedLog.

private RaftLog bootstrappedLog() throws IOException {
    InMemoryRaftLog raftLog = new InMemoryRaftLog();
    raftLog.append(new RaftLogEntry(0, content()));
    return raftLog;
}
Also used : InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)

Example 9 with InMemoryRaftLog

use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.

the class MembershipWaiterTest method shouldWaitUntilLeaderCommitIsAvailable.

@Test
public void shouldWaitUntilLeaderCommitIsAvailable() throws Exception {
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    MembershipWaiter waiter = new MembershipWaiter(member(0), jobScheduler, () -> dbHealth, 500, NullLogProvider.getInstance());
    InMemoryRaftLog raftLog = new InMemoryRaftLog();
    raftLog.append(new RaftLogEntry(0, valueOf(0)));
    ExposedRaftState raftState = RaftStateBuilder.raftState().votingMembers(member(0)).leaderCommit(0).entryLog(raftLog).commitIndex(0L).build().copy();
    RaftMachine raft = mock(RaftMachine.class);
    when(raft.state()).thenReturn(raftState);
    CompletableFuture<Boolean> future = waiter.waitUntilCaughtUpMember(raft);
    jobScheduler.runJob();
    future.get(1, TimeUnit.SECONDS);
}
Also used : RaftMachine(org.neo4j.causalclustering.core.consensus.RaftMachine) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) ExposedRaftState(org.neo4j.causalclustering.core.consensus.state.ExposedRaftState) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 10 with InMemoryRaftLog

use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.

the class RaftMembershipManagerTest method membershipManagerShouldRevertToOldMembershipSetAfterTruncationCausesLossOfAllAppendedMembershipSets.

@Test
public void membershipManagerShouldRevertToOldMembershipSetAfterTruncationCausesLossOfAllAppendedMembershipSets() throws Exception {
    // given
    final InMemoryRaftLog raftLog = new InMemoryRaftLog();
    RaftMembershipManager membershipManager = lifeRule.add(raftMembershipManager(raftLog));
    // when
    List<RaftLogCommand> logCommands = asList(new AppendLogEntry(0, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 4))), new AppendLogEntry(1, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 5))), new TruncateLogCommand(1));
    for (RaftLogCommand logCommand : logCommands) {
        logCommand.applyTo(raftLog, log);
    }
    membershipManager.processLog(0, logCommands);
    // then
    assertEquals(new RaftTestGroup(1, 2, 3, 4).getMembers(), membershipManager.votingMembers());
    assertFalse(membershipManager.uncommittedMemberChangeInLog());
}
Also used : InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) TruncateLogCommand(org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand) AppendLogEntry(org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry) RaftLogCommand(org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Aggregations

InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)30 Test (org.junit.Test)27 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)23 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)18 RaftState (org.neo4j.causalclustering.core.consensus.state.RaftState)15 RaftLog (org.neo4j.causalclustering.core.consensus.log.RaftLog)7 AppendEntries (org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries)6 RaftTestGroup (org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup)5 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)4 AppendLogEntry (org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry)4 TruncateLogCommand (org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand)4 ReplicatedString (org.neo4j.causalclustering.core.consensus.ReplicatedString)3 RaftLogCommand (org.neo4j.causalclustering.core.consensus.outcome.RaftLogCommand)3 ReadableRaftState (org.neo4j.causalclustering.core.consensus.state.ReadableRaftState)3 Before (org.junit.Before)2 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)2 FollowerStates (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerStates)2 ExposedRaftState (org.neo4j.causalclustering.core.consensus.state.ExposedRaftState)2 TermState (org.neo4j.causalclustering.core.consensus.term.TermState)2 VoteState (org.neo4j.causalclustering.core.consensus.vote.VoteState)2