Search in sources :

Example 1 with Election

use of org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Election in project neo4j by neo4j.

the class FollowerTest method shouldBecomeCandidateOnReceivingElectionTimeoutMessage.

@Test
public void shouldBecomeCandidateOnReceivingElectionTimeoutMessage() throws Exception {
    // given
    RaftState state = raftState().myself(myself).votingMembers(asSet(myself, member1, member2)).build();
    Follower follower = new Follower();
    // when
    Outcome outcome = follower.handle(new Election(myself), 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) Election(org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Election) Test(org.junit.Test)

Example 2 with Election

use of org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Election in project neo4j by neo4j.

the class OutOfOrderDeliveryTest method shouldReOrder.

@Test
public void shouldReOrder() throws Exception {
    // given
    ClusterState clusterState = new ClusterState(asSet(member(0)));
    clusterState.queues.get(member(0)).add(new Election(member(0)));
    clusterState.queues.get(member(0)).add(new Heartbeat(member(0)));
    // when
    ClusterState reOrdered = new OutOfOrderDelivery(member(0)).advance(clusterState);
    // then
    assertEquals(new Heartbeat(member(0)), reOrdered.queues.get(member(0)).poll());
    assertEquals(new Election(member(0)), reOrdered.queues.get(member(0)).poll());
}
Also used : ClusterState(org.neo4j.causalclustering.core.consensus.explorer.ClusterState) Heartbeat(org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Heartbeat) Election(org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Election) Test(org.junit.Test)

Example 3 with Election

use of org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Election 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)

Aggregations

Test (org.junit.Test)3 Election (org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Election)3 Outcome (org.neo4j.causalclustering.core.consensus.outcome.Outcome)2 RaftState (org.neo4j.causalclustering.core.consensus.state.RaftState)2 Heartbeat (org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Heartbeat)1 ClusterState (org.neo4j.causalclustering.core.consensus.explorer.ClusterState)1