use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class TruncateLogCommandTest method shouldTruncateWithGaps.
@Test
public void shouldTruncateWithGaps() throws Exception {
//given
long fromIndex = 1L;
TruncateLogCommand truncateLogCommand = new TruncateLogCommand(fromIndex);
InFlightMap<RaftLogEntry> inFlightMap = new InFlightMap<>();
inFlightMap.put(0L, new RaftLogEntry(0L, valueOf(0)));
inFlightMap.put(2L, new RaftLogEntry(1L, valueOf(1)));
inFlightMap.put(4L, new RaftLogEntry(2L, valueOf(2)));
truncateLogCommand.applyTo(inFlightMap, NullLog.getInstance());
inFlightMap.put(1L, new RaftLogEntry(3L, valueOf(1)));
inFlightMap.put(2L, new RaftLogEntry(4L, valueOf(2)));
assertNotNull(inFlightMap.get(0L));
assertNotNull(inFlightMap.get(1L));
assertNotNull(inFlightMap.get(2L));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class ClusterSafetyViolationsTest method shouldRecogniseSomeMembersBeingInconsistent.
@Test
public void shouldRecogniseSomeMembersBeingInconsistent() throws Exception {
// given
ClusterState clusterState = new ClusterState(asSet(member(0), member(1), member(2)));
clusterState.states.get(member(0)).entryLog.append(new RaftLogEntry(1, valueOf(1)));
clusterState.states.get(member(1)).entryLog.append(new RaftLogEntry(1, valueOf(1)));
clusterState.states.get(member(2)).entryLog.append(new RaftLogEntry(1, valueOf(1)));
clusterState.states.get(member(0)).entryLog.append(new RaftLogEntry(1, valueOf(2)));
clusterState.states.get(member(1)).entryLog.append(new RaftLogEntry(1, valueOf(2)));
clusterState.states.get(member(2)).entryLog.append(new RaftLogEntry(2, valueOf(2)));
commit(clusterState, member(0), 0);
commit(clusterState, member(1), 0);
commit(clusterState, member(2), 0);
// then
assertFalse(inconsistentCommittedLogEntries(clusterState));
// when
commit(clusterState, member(0), 1);
commit(clusterState, member(1), 1);
// then
assertFalse(inconsistentCommittedLogEntries(clusterState));
// when
commit(clusterState, member(2), 1);
// then
assertTrue(inconsistentCommittedLogEntries(clusterState));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class ClusterSafetyViolationsTest method shouldRecogniseInconsistentTerm.
@Test
public void shouldRecogniseInconsistentTerm() throws Exception {
// given
ClusterState clusterState = new ClusterState(asSet(member(0), member(1)));
clusterState.states.get(member(0)).entryLog.append(new RaftLogEntry(1, valueOf(1)));
clusterState.states.get(member(1)).entryLog.append(new RaftLogEntry(1, valueOf(1)));
clusterState.states.get(member(0)).entryLog.append(new RaftLogEntry(1, valueOf(2)));
clusterState.states.get(member(1)).entryLog.append(new RaftLogEntry(2, valueOf(2)));
commit(clusterState, member(0), 0);
commit(clusterState, member(1), 0);
// then
assertFalse(inconsistentCommittedLogEntries(clusterState));
// when
commit(clusterState, member(0), 1);
commit(clusterState, member(1), 1);
// then
assertTrue(inconsistentCommittedLogEntries(clusterState));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class HeartbeatTest method shouldNotResultInCommitIfHistoryMismatches.
@Test
public void shouldNotResultInCommitIfHistoryMismatches() 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()));
RaftMessages.Heartbeat heartbeat = heartbeat().from(leader).commitIndex(// The leader is talking about committing stuff we don't know about
raftLog.appendIndex()).commitIndexTerm(// And is in the same term
leaderTerm).leaderTerm(leaderTerm).build();
Outcome outcome = role.handler.handle(heartbeat, state, log());
assertThat(outcome.getCommitIndex(), Matchers.equalTo(0L));
}
use of org.neo4j.causalclustering.core.consensus.log.RaftLogEntry in project neo4j by neo4j.
the class LeaderTest method leaderShouldDecideToAppendToItsLogAndSendAppendEntriesMessageOnReceiptOfClientProposal.
@Test
public void leaderShouldDecideToAppendToItsLogAndSendAppendEntriesMessageOnReceiptOfClientProposal() throws Exception {
// given
RaftState state = raftState().votingMembers(asSet(myself, member1, member2)).build();
Leader leader = new Leader();
RaftMessages.NewEntry.Request newEntryRequest = new RaftMessages.NewEntry.Request(member(9), CONTENT);
// when
Outcome outcome = leader.handle(newEntryRequest, state, log());
//state.update( outcome );
// then
AppendLogEntry logCommand = (AppendLogEntry) single(outcome.getLogCommands());
assertEquals(0, logCommand.index);
assertEquals(0, logCommand.entry.term());
ShipCommand.NewEntries shipCommand = (ShipCommand.NewEntries) single(outcome.getShipCommands());
assertEquals(shipCommand, new ShipCommand.NewEntries(-1, -1, new RaftLogEntry[] { new RaftLogEntry(0, CONTENT) }));
}
Aggregations