Search in sources :

Example 1 with Inbound

use of org.neo4j.causalclustering.messaging.Inbound in project neo4j by neo4j.

the class RaftMachineTest method newMembersShouldBeIncludedInHeartbeatMessages.

@Test
public void newMembersShouldBeIncludedInHeartbeatMessages() throws Exception {
    // Given
    DirectNetworking network = new DirectNetworking();
    final MemberId newMember = member(99);
    DirectNetworking.Inbound newMemberInbound = network.new Inbound(newMember);
    final OutboundMessageCollector messages = new OutboundMessageCollector();
    newMemberInbound.registerHandler(new Inbound.MessageHandler<RaftMessages.RaftMessage>() {

        @Override
        public void handle(RaftMessages.RaftMessage message) {
            messages.send(newMember, message);
        }
    });
    FakeClock fakeClock = Clocks.fakeClock();
    ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService(fakeClock);
    RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).outbound(messages).clock(fakeClock).build();
    raft.installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(myself, member1, member2))));
    raft.startTimers();
    // We make ourselves the leader
    timeouts.invokeTimeout(ELECTION);
    raft.handle(voteResponse().from(member1).term(1).grant().build());
    // When
    raft.setTargetMembershipSet(asSet(myself, member1, member2, newMember));
    network.processMessages();
    timeouts.invokeTimeout(RaftMachine.Timeouts.HEARTBEAT);
    network.processMessages();
    // Then
    assertEquals(RaftMessages.AppendEntries.Request.class, messages.sentTo(newMember).get(0).getClass());
}
Also used : MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) FakeClock(org.neo4j.time.FakeClock) Inbound(org.neo4j.causalclustering.messaging.Inbound) ControlledRenewableTimeoutService(org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService) MemberId(org.neo4j.causalclustering.identity.MemberId) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 MembershipEntry (org.neo4j.causalclustering.core.consensus.membership.MembershipEntry)1 ControlledRenewableTimeoutService (org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService)1 RaftCoreState (org.neo4j.causalclustering.core.state.snapshot.RaftCoreState)1 MemberId (org.neo4j.causalclustering.identity.MemberId)1 Inbound (org.neo4j.causalclustering.messaging.Inbound)1 FakeClock (org.neo4j.time.FakeClock)1