Search in sources :

Example 6 with RaftLog

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

the class AppendEntriesRequestTest method shouldAcceptInitialEntriesAfterBootstrap.

@Test
public void shouldAcceptInitialEntriesAfterBootstrap() throws Exception {
    RaftLog raftLog = bootstrappedLog();
    RaftState state = raftState().entryLog(raftLog).myself(myself).build();
    long leaderTerm = state.term() + leaderTermDifference;
    RaftLogEntry logEntry1 = new RaftLogEntry(leaderTerm, content());
    RaftLogEntry logEntry2 = new RaftLogEntry(leaderTerm, content());
    // when
    Outcome outcome = role.handler.handle(appendEntriesRequest().from(leader).leaderTerm(leaderTerm).prevLogIndex(0).prevLogTerm(0).logEntry(logEntry1).logEntry(logEntry2).build(), state, log());
    // then
    assertTrue(((Response) messageFor(outcome, leader)).success());
    assertThat(outcome.getLogCommands(), hasItem(new BatchAppendLogEntries(1, 0, new RaftLogEntry[] { logEntry1, logEntry2 })));
}
Also used : Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) BatchAppendLogEntries(org.neo4j.causalclustering.core.consensus.outcome.BatchAppendLogEntries) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) RaftLog(org.neo4j.causalclustering.core.consensus.log.RaftLog) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 7 with RaftLog

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

the class AppendEntriesRequestTest method shouldAcceptInitialEntryAfterBootstrap.

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

Example 8 with RaftLog

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

the class AppendEntriesMessageFlowTest method setup.

@Before
public void setup() throws IOException {
    // given
    RaftLog raftLog = new InMemoryRaftLog();
    raftLog.append(new RaftLogEntry(0, new RaftTestGroup(0)));
    raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).raftLog(raftLog).outbound(outbound).build();
}
Also used : RaftMachineBuilder(org.neo4j.causalclustering.core.consensus.RaftMachineBuilder) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) RaftTestGroup(org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) RaftLog(org.neo4j.causalclustering.core.consensus.log.RaftLog) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Before(org.junit.Before)

Example 9 with RaftLog

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

the class RaftLogShipperTest method setup.

@Before
public void setup() {
    // defaults
    outbound = new OutboundMessageCollector();
    raftLog = new InMemoryRaftLog();
    clock = Clocks.systemClock();
    leader = member(0);
    follower = member(1);
    leaderTerm = 0;
    leaderCommit = 0;
    retryTimeMillis = 100000;
    logProvider = mock(LogProvider.class);
    log = mock(Log.class);
    when(logProvider.getLog(RaftLogShipper.class)).thenReturn(log);
}
Also used : LogProvider(org.neo4j.logging.LogProvider) OutboundMessageCollector(org.neo4j.causalclustering.core.consensus.OutboundMessageCollector) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) Log(org.neo4j.logging.Log) RaftLog(org.neo4j.causalclustering.core.consensus.log.RaftLog) Before(org.junit.Before)

Example 10 with RaftLog

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

the class FollowerTest method followerLearningAboutHigherCommitCausesValuesTobeAppliedToItsLog.

// TODO move this to outcome tests
@Test
public void followerLearningAboutHigherCommitCausesValuesTobeAppliedToItsLog() throws Exception {
    // given
    RaftLog entryLog = new InMemoryRaftLog();
    entryLog.append(new RaftLogEntry(0, new RaftTestGroup(0)));
    RaftState state = raftState().myself(myself).entryLog(entryLog).build();
    Follower follower = new Follower();
    appendSomeEntriesToLog(state, follower, 3, 0, 1);
    // when receiving AppEntries with high leader commit (4)
    Outcome outcome = follower.handle(new AppendEntries.Request(myself, 0, 3, 0, new RaftLogEntry[] { new RaftLogEntry(0, ContentGenerator.content()) }, 4), state, log());
    state.update(outcome);
    // then
    assertEquals(4, state.commitIndex());
}
Also used : InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) RaftTestGroup(org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) AppendEntries(org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) RaftLog(org.neo4j.causalclustering.core.consensus.log.RaftLog) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Aggregations

RaftLog (org.neo4j.causalclustering.core.consensus.log.RaftLog)11 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)10 Test (org.junit.Test)9 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)9 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)7 RaftState (org.neo4j.causalclustering.core.consensus.state.RaftState)6 RaftTestGroup (org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup)5 AppendEntries (org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries)4 Before (org.junit.Before)2 BatchAppendLogEntries (org.neo4j.causalclustering.core.consensus.outcome.BatchAppendLogEntries)2 Log (org.neo4j.logging.Log)2 OutboundMessageCollector (org.neo4j.causalclustering.core.consensus.OutboundMessageCollector)1 RaftMachineBuilder (org.neo4j.causalclustering.core.consensus.RaftMachineBuilder)1 RaftMessage (org.neo4j.causalclustering.core.consensus.RaftMessages.RaftMessage)1 ReplicatedString (org.neo4j.causalclustering.core.consensus.ReplicatedString)1 TestMessageBuilders.appendEntriesRequest (org.neo4j.causalclustering.core.consensus.TestMessageBuilders.appendEntriesRequest)1 ReadableRaftLog (org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog)1 ShipCommand (org.neo4j.causalclustering.core.consensus.outcome.ShipCommand)1 FollowerState (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState)1 FollowerStates (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerStates)1