Search in sources :

Example 1 with Heartbeat

use of org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Heartbeat 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 2 with Heartbeat

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

the class LeaderTest method leaderShouldSendHeartbeatsToAllClusterMembersOnReceiptOfHeartbeatTick.

// TODO: test that shows we don't commit for previous terms
@Test
public void leaderShouldSendHeartbeatsToAllClusterMembersOnReceiptOfHeartbeatTick() throws Exception {
    // given
    RaftState state = raftState().votingMembers(myself, member1, member2).replicationMembers(myself, member1, member2).build();
    Leader leader = new Leader();
    // make sure it has quorum.
    leader.handle(new RaftMessages.HeartbeatResponse(member1), state, log());
    // when
    Outcome outcome = leader.handle(new Heartbeat(myself), state, log());
    // then
    assertTrue(messageFor(outcome, member1) instanceof RaftMessages.Heartbeat);
    assertTrue(messageFor(outcome, member2) instanceof RaftMessages.Heartbeat);
}
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) Heartbeat(org.neo4j.causalclustering.core.consensus.RaftMessages.Timeout.Heartbeat) RaftMessages(org.neo4j.causalclustering.core.consensus.RaftMessages) Test(org.junit.Test)

Aggregations

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