use of org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry 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) }));
}
use of org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry in project neo4j by neo4j.
the class CandidateTest method shouldBeElectedLeaderOnReceivingGrantedVoteResponseWithCurrentTerm.
@Test
public void shouldBeElectedLeaderOnReceivingGrantedVoteResponseWithCurrentTerm() throws Exception {
// given
RaftState state = RaftStateBuilder.raftState().term(1).myself(myself).votingMembers(member1, member2).replicationMembers(member1, member2).build();
// when
Outcome outcome = CANDIDATE.handler.handle(voteResponse().term(state.term()).from(member1).grant().build(), state, log());
// then
assertEquals(LEADER, outcome.getRole());
assertEquals(true, outcome.electionTimeoutRenewed());
assertThat(outcome.getLogCommands(), hasItem(new AppendLogEntry(0, new RaftLogEntry(state.term(), new NewLeaderBarrier()))));
assertThat(outcome.getOutgoingMessages(), hasItems(new RaftMessages.Directed(member1, new RaftMessages.Heartbeat(myself, state.term(), -1, -1)), new RaftMessages.Directed(member2, new RaftMessages.Heartbeat(myself, state.term(), -1, -1))));
}
use of org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry in project neo4j by neo4j.
the class Appending method appendNewEntry.
static void appendNewEntry(ReadableRaftState ctx, Outcome outcome, ReplicatedContent content) throws IOException {
long prevLogIndex = ctx.entryLog().appendIndex();
long prevLogTerm = prevLogIndex == -1 ? -1 : prevLogIndex > ctx.lastLogIndexBeforeWeBecameLeader() ? ctx.term() : ctx.entryLog().readEntryTerm(prevLogIndex);
RaftLogEntry newLogEntry = new RaftLogEntry(ctx.term(), content);
outcome.addShipCommand(new ShipCommand.NewEntries(prevLogIndex, prevLogTerm, new RaftLogEntry[] { newLogEntry }));
outcome.addLogCommand(new AppendLogEntry(prevLogIndex + 1, newLogEntry));
}
use of org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry 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());
}
use of org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry in project neo4j by neo4j.
the class RaftMembershipManagerTest method membershipManagerShouldRevertToEarlierAppendedMembershipSetAfterTruncationCausesLossOfLastAppened.
@Test
public void membershipManagerShouldRevertToEarlierAppendedMembershipSetAfterTruncationCausesLossOfLastAppened() 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 AppendLogEntry(2, new RaftLogEntry(0, new RaftTestGroup(1, 2, 3, 6))), new TruncateLogCommand(2));
for (RaftLogCommand logCommand : logCommands) {
logCommand.applyTo(raftLog, log);
}
membershipManager.processLog(0, logCommands);
// then
assertEquals(new RaftTestGroup(1, 2, 3, 5).getMembers(), membershipManager.votingMembers());
}
Aggregations