Search in sources :

Example 36 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry 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 37 with RaftLogEntry

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

the class AppendEntriesRequestTest method shouldRejectDiscontinuousEntries.

@Test
public void shouldRejectDiscontinuousEntries() throws Exception {
    // given
    RaftState state = raftState().myself(myself).build();
    long leaderTerm = state.term() + leaderTermDifference;
    // when
    Outcome outcome = role.handler.handle(appendEntriesRequest().from(leader).leaderTerm(leaderTerm).prevLogIndex(state.entryLog().appendIndex() + 1).prevLogTerm(leaderTerm).logEntry(new RaftLogEntry(leaderTerm, content())).build(), state, log());
    // then
    Response response = (Response) messageFor(outcome, leader);
    assertEquals(state.entryLog().appendIndex(), response.appendIndex());
    assertFalse(response.success());
}
Also used : Response(org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries.Response) 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 38 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry 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 39 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry 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 40 with RaftLogEntry

use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry 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)

Aggregations

RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)87 Test (org.junit.Test)69 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)27 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)25 RaftState (org.neo4j.causalclustering.core.consensus.state.RaftState)20 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)12 RaftLog (org.neo4j.causalclustering.core.consensus.log.RaftLog)10 ReadableRaftState (org.neo4j.causalclustering.core.consensus.state.ReadableRaftState)10 AppendLogEntry (org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry)8 NewLeaderBarrier (org.neo4j.causalclustering.core.consensus.NewLeaderBarrier)7 AppendEntries (org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries)7 MemberId (org.neo4j.causalclustering.identity.MemberId)7 InOrder (org.mockito.InOrder)6 RaftLogCursor (org.neo4j.causalclustering.core.consensus.log.RaftLogCursor)6 ReadableRaftLog (org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog)5 RaftTestGroup (org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup)5 BatchAppendLogEntries (org.neo4j.causalclustering.core.consensus.outcome.BatchAppendLogEntries)5 ShipCommand (org.neo4j.causalclustering.core.consensus.outcome.ShipCommand)5 TruncateLogCommand (org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand)5 File (java.io.File)4