use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.
the class BatchAppendLogEntriesTest method shouldApplyFromOffsetOnly.
@Test
public void shouldApplyFromOffsetOnly() throws Exception {
// given
InMemoryRaftLog raftLog = new InMemoryRaftLog();
BatchAppendLogEntries batchAppendLogEntries = new BatchAppendLogEntries(0, 2, new RaftLogEntry[] { entryA, entryB, entryC, entryD });
// when
batchAppendLogEntries.applyTo(raftLog, log);
// then
assertEquals(entryC, readLogEntry(raftLog, 0));
assertEquals(entryD, readLogEntry(raftLog, 1));
assertEquals(1, raftLog.appendIndex());
}
use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.
the class MembershipWaiterTest method shouldReturnImmediatelyIfMemberAndCaughtUp.
@Test
public void shouldReturnImmediatelyIfMemberAndCaughtUp() 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();
jobScheduler.runJob();
future.get(0, NANOSECONDS);
}
use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog 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();
}
use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.
the class AppendEntriesRequestTest method shouldNotCommitAheadOfMatchingHistory.
@Test
public void shouldNotCommitAheadOfMatchingHistory() throws Exception {
// given
InMemoryRaftLog raftLog = new InMemoryRaftLog();
RaftState state = raftState().entryLog(raftLog).myself(myself).build();
long leaderTerm = state.term() + leaderTermDifference;
RaftLogEntry previouslyAppendedEntry = new RaftLogEntry(leaderTerm, content());
raftLog.append(previouslyAppendedEntry);
// when
Outcome outcome = role.handler.handle(appendEntriesRequest().from(leader).leaderTerm(leaderTerm).prevLogIndex(raftLog.appendIndex() + 1).prevLogTerm(leaderTerm).leaderCommit(0).build(), state, log());
// then
assertFalse(((Response) messageFor(outcome, leader)).success());
assertThat(outcome.getLogCommands(), empty());
}
use of org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog in project neo4j by neo4j.
the class AppendEntriesRequestTest method shouldAppendNewEntryAndCommitPreviouslyAppendedEntry.
@Test
public void shouldAppendNewEntryAndCommitPreviouslyAppendedEntry() throws Exception {
// given
InMemoryRaftLog raftLog = new InMemoryRaftLog();
RaftState state = raftState().entryLog(raftLog).myself(myself).build();
long leaderTerm = state.term() + leaderTermDifference;
RaftLogEntry previouslyAppendedEntry = new RaftLogEntry(leaderTerm, content());
raftLog.append(previouslyAppendedEntry);
RaftLogEntry newLogEntry = new RaftLogEntry(leaderTerm, content());
// when
Outcome outcome = role.handler.handle(appendEntriesRequest().from(leader).leaderTerm(leaderTerm).prevLogIndex(raftLog.appendIndex()).prevLogTerm(leaderTerm).logEntry(newLogEntry).leaderCommit(0).build(), state, log());
// then
assertTrue(((Response) messageFor(outcome, leader)).success());
assertThat(outcome.getCommitIndex(), Matchers.equalTo(0L));
assertThat(outcome.getLogCommands(), hasItem(new BatchAppendLogEntries(1, 0, new RaftLogEntry[] { newLogEntry })));
}
Aggregations