use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.
the class RaftStateBuilder method build.
public RaftState build() throws IOException {
StateStorage<TermState> termStore = new InMemoryStateStorage<>(new TermState());
StateStorage<VoteState> voteStore = new InMemoryStateStorage<>(new VoteState());
StubMembership membership = new StubMembership(votingMembers, replicationMembers);
RaftState state = new RaftState(myself, termStore, membership, entryLog, voteStore, new InFlightMap<>(), NullLogProvider.getInstance());
Collection<RaftMessages.Directed> noMessages = Collections.emptyList();
List<RaftLogCommand> noLogCommands = Collections.emptyList();
state.update(new Outcome(null, term, leader, leaderCommit, votedFor, votesForMe, lastLogIndexBeforeWeBecameLeader, followerStates, false, noLogCommands, noMessages, emptySet(), commitIndex, emptySet()));
return state;
}
use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.
the class ClusterSafetyViolationsTest method commit.
private void commit(ClusterState clusterState, MemberId member, long commitIndex) throws IOException {
ComparableRaftState state = clusterState.states.get(member);
Outcome outcome = new Outcome(clusterState.roles.get(member), state);
outcome.setCommitIndex(commitIndex);
state.update(outcome);
}
use of org.neo4j.causalclustering.core.consensus.outcome.Outcome 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.outcome.Outcome 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 })));
}
use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.
the class AppendEntriesRequestTest method shouldCommitEntry.
@Test
public void shouldCommitEntry() throws Exception {
// given
InMemoryRaftLog raftLog = new InMemoryRaftLog();
RaftState state = raftState().entryLog(raftLog).myself(myself).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).leaderCommit(0).build(), state, log());
// then
assertTrue(((Response) messageFor(outcome, leader)).success());
assertThat(outcome.getCommitIndex(), Matchers.equalTo(0L));
}
Aggregations