Search in sources :

Example 51 with Outcome

use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.

the class LeaderTest method oldHeartbeatResponseShouldNotPreventStepdown.

@Test
public void oldHeartbeatResponseShouldNotPreventStepdown() throws Exception {
    // given
    RaftState state = raftState().votingMembers(asSet(myself, member1, member2)).build();
    Leader leader = new Leader();
    Outcome outcome = leader.handle(new RaftMessages.HeartbeatResponse(member1), state, log());
    state.update(outcome);
    outcome = leader.handle(new RaftMessages.Timeout.Election(myself), state, log());
    state.update(outcome);
    assertThat(outcome.getRole(), is(LEADER));
    // when
    outcome = leader.handle(new RaftMessages.Timeout.Election(myself), state, log());
    // then
    assertThat(outcome.getRole(), is(FOLLOWER));
}
Also used : Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) ReadableRaftState(org.neo4j.causalclustering.core.consensus.state.ReadableRaftState) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) Test(org.junit.Test)

Example 52 with Outcome

use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.

the class CandidateTest method shouldStayAsCandidateOnReceivingDeniedVoteResponseWithCurrentTerm.

@Test
public void shouldStayAsCandidateOnReceivingDeniedVoteResponseWithCurrentTerm() throws Exception {
    // given
    RaftState state = newState();
    // when
    Outcome outcome = CANDIDATE.handler.handle(voteResponse().term(state.term()).from(member1).deny().build(), state, log());
    // then
    assertEquals(CANDIDATE, outcome.getRole());
}
Also used : Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) Test(org.junit.Test)

Example 53 with Outcome

use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.

the class FollowerTest method shouldAcknowledgeHeartbeats.

@Test
public void shouldAcknowledgeHeartbeats() throws Exception {
    // given
    RaftState state = raftState().myself(myself).term(2).build();
    Follower follower = new Follower();
    Outcome outcome = follower.handle(new RaftMessages.Heartbeat(state.leader(), 2, 2, 2), state, log());
    // then
    Collection<RaftMessages.Directed> outgoingMessages = outcome.getOutgoingMessages();
    assertTrue(outgoingMessages.contains(new RaftMessages.Directed(state.leader(), new RaftMessages.HeartbeatResponse(myself))));
}
Also used : Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) Test(org.junit.Test)

Example 54 with Outcome

use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.

the class FollowerTest method followerShouldTransitToCandidateAndInstigateAnElectionAfterTimeout.

@Test
public void followerShouldTransitToCandidateAndInstigateAnElectionAfterTimeout() throws Exception {
    // given
    RaftState state = raftState().myself(myself).votingMembers(asSet(myself, member1, member2)).build();
    // when
    Outcome outcome = new Follower().handle(new Election(myself), state, log());
    state.update(outcome);
    // then
    assertEquals(CANDIDATE, outcome.getRole());
    assertNotNull(messageFor(outcome, member1));
    assertNotNull(messageFor(outcome, member2));
}
Also used : Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) Election(org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Election) Test(org.junit.Test)

Example 55 with Outcome

use of org.neo4j.causalclustering.core.consensus.outcome.Outcome in project neo4j by neo4j.

the class FollowerTest method followerLearningAboutHigherCommitCausesValuesTobeAppliedToItsLog.

// TODO move this to outcome tests
@Test
public void followerLearningAboutHigherCommitCausesValuesTobeAppliedToItsLog() throws Exception {
    // given
    RaftLog entryLog = new InMemoryRaftLog();
    entryLog.append(new RaftLogEntry(0, new RaftTestGroup(0)));
    RaftState state = raftState().myself(myself).entryLog(entryLog).build();
    Follower follower = new Follower();
    appendSomeEntriesToLog(state, follower, 3, 0, 1);
    // when receiving AppEntries with high leader commit (4)
    Outcome outcome = follower.handle(new AppendEntries.Request(myself, 0, 3, 0, new RaftLogEntry[] { new RaftLogEntry(0, ContentGenerator.content()) }, 4), state, log());
    state.update(outcome);
    // then
    assertEquals(4, state.commitIndex());
}
Also used : InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) RaftTestGroup(org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup) Outcome(org.neo4j.causalclustering.core.consensus.outcome.Outcome) RaftState(org.neo4j.causalclustering.core.consensus.state.RaftState) AppendEntries(org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries) 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

Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)58 Test (org.junit.Test)53 RaftState (org.neo4j.causalclustering.core.consensus.state.RaftState)42 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)27 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)24 ReadableRaftState (org.neo4j.causalclustering.core.consensus.state.ReadableRaftState)19 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)15 AppendEntries (org.neo4j.causalclustering.core.consensus.RaftMessages.AppendEntries)11 RaftLog (org.neo4j.causalclustering.core.consensus.log.RaftLog)11 ReadableRaftLog (org.neo4j.causalclustering.core.consensus.log.ReadableRaftLog)9 FollowerState (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerState)6 FollowerStates (org.neo4j.causalclustering.core.consensus.roles.follower.FollowerStates)6 Log (org.neo4j.logging.Log)6 BatchAppendLogEntries (org.neo4j.causalclustering.core.consensus.outcome.BatchAppendLogEntries)5 ShipCommand (org.neo4j.causalclustering.core.consensus.outcome.ShipCommand)5 MemberId (org.neo4j.causalclustering.identity.MemberId)5 RaftTestGroup (org.neo4j.causalclustering.core.consensus.membership.RaftTestGroup)4 AppendLogEntry (org.neo4j.causalclustering.core.consensus.outcome.AppendLogEntry)4 ReplicatedString (org.neo4j.causalclustering.core.consensus.ReplicatedString)3 TruncateLogCommand (org.neo4j.causalclustering.core.consensus.outcome.TruncateLogCommand)3