Search in sources :

Example 6 with ControlledRenewableTimeoutService

use of org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService in project neo4j by neo4j.

the class RaftMachineTest method shouldNotBecomeLeaderByVotesFromFutureTerm.

@Test
public void shouldNotBecomeLeaderByVotesFromFutureTerm() throws Exception {
    // Given
    FakeClock fakeClock = Clocks.fakeClock();
    ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService(fakeClock);
    RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).clock(fakeClock).build();
    raft.installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(myself, member1, member2))));
    raft.startTimers();
    timeouts.invokeTimeout(ELECTION);
    // When
    raft.handle(voteResponse().from(member1).term(2).grant().build());
    raft.handle(voteResponse().from(member2).term(2).grant().build());
    assertThat(raft.isLeader(), is(false));
    assertEquals(raft.term(), 2L);
}
Also used : MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) FakeClock(org.neo4j.time.FakeClock) ControlledRenewableTimeoutService(org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService) Test(org.junit.Test)

Example 7 with ControlledRenewableTimeoutService

use of org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService in project neo4j by neo4j.

the class RaftMachineTest method shouldNotBecomeLeaderByVotesFromOldTerm.

@Test
public void shouldNotBecomeLeaderByVotesFromOldTerm() throws Exception {
    // Given
    FakeClock fakeClock = Clocks.fakeClock();
    ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService(fakeClock);
    RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).clock(fakeClock).build();
    raft.installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(myself, member1, member2))));
    raft.startTimers();
    timeouts.invokeTimeout(ELECTION);
    // When
    raft.handle(voteResponse().from(member1).term(0).grant().build());
    raft.handle(voteResponse().from(member2).term(0).grant().build());
    // Then
    assertThat(raft.isLeader(), is(false));
}
Also used : MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) FakeClock(org.neo4j.time.FakeClock) ControlledRenewableTimeoutService(org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService) Test(org.junit.Test)

Example 8 with ControlledRenewableTimeoutService

use of org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService in project neo4j by neo4j.

the class RaftMachineTest method shouldNotBecomeLeaderWhenMembersVoteNo.

@Test
public void shouldNotBecomeLeaderWhenMembersVoteNo() throws Exception {
    // Given
    FakeClock fakeClock = Clocks.fakeClock();
    ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService(fakeClock);
    RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).clock(fakeClock).build();
    raft.installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(myself, member1, member2))));
    raft.startTimers();
    timeouts.invokeTimeout(ELECTION);
    // When
    raft.handle(voteResponse().from(member1).term(1).deny().build());
    raft.handle(voteResponse().from(member2).term(1).deny().build());
    // Then
    assertThat(raft.isLeader(), is(false));
}
Also used : MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) FakeClock(org.neo4j.time.FakeClock) ControlledRenewableTimeoutService(org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService) Test(org.junit.Test)

Example 9 with ControlledRenewableTimeoutService

use of org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService in project neo4j by neo4j.

the class RaftMachineTest method shouldMonitorLeaderNotFound.

@Test
public void shouldMonitorLeaderNotFound() throws Exception {
    // Given
    ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService();
    Monitors monitors = new Monitors();
    LeaderNotFoundMonitor leaderNotFoundMonitor = new StubLeaderNotFoundMonitor();
    monitors.addMonitorListener(leaderNotFoundMonitor);
    RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).monitors(monitors).build();
    raft.installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(myself, member1, member2))));
    try {
        // When
        // There is no leader
        raft.getLeader();
        fail("Should have thrown exception");
    }// Then
     catch (NoLeaderFoundException e) {
        // expected
        assertEquals(1, leaderNotFoundMonitor.leaderNotFoundExceptions());
    }
}
Also used : MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) Monitors(org.neo4j.kernel.monitoring.Monitors) ControlledRenewableTimeoutService(org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService) Test(org.junit.Test)

Example 10 with ControlledRenewableTimeoutService

use of org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService in project neo4j by neo4j.

the class RaftMachineTest method shouldBecomeLeaderInMajorityOf5.

@Test
public void shouldBecomeLeaderInMajorityOf5() throws Exception {
    // Given
    FakeClock fakeClock = Clocks.fakeClock();
    ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService(fakeClock);
    RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).clock(fakeClock).build();
    raft.installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(myself, member1, member2, member3, member4))));
    raft.startTimers();
    timeouts.invokeTimeout(ELECTION);
    raft.handle(voteResponse().from(member1).term(1).grant().build());
    assertThat(raft.isLeader(), is(false));
    // When
    raft.handle(voteResponse().from(member2).term(1).grant().build());
    // Then
    assertThat(raft.isLeader(), is(true));
}
Also used : MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) FakeClock(org.neo4j.time.FakeClock) ControlledRenewableTimeoutService(org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)18 ControlledRenewableTimeoutService (org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService)18 MembershipEntry (org.neo4j.causalclustering.core.consensus.membership.MembershipEntry)17 RaftCoreState (org.neo4j.causalclustering.core.state.snapshot.RaftCoreState)17 FakeClock (org.neo4j.time.FakeClock)17 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)3 RaftMachineBuilder (org.neo4j.causalclustering.core.consensus.RaftMachineBuilder)3 TestMessageBuilders.voteRequest (org.neo4j.causalclustering.core.consensus.TestMessageBuilders.voteRequest)3 RaftMessages (org.neo4j.causalclustering.core.consensus.RaftMessages)2 TestMessageBuilders.appendEntriesRequest (org.neo4j.causalclustering.core.consensus.TestMessageBuilders.appendEntriesRequest)1 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)1 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)1 MemberIdSet (org.neo4j.causalclustering.core.consensus.membership.MemberIdSet)1 MemberId (org.neo4j.causalclustering.identity.MemberId)1 Inbound (org.neo4j.causalclustering.messaging.Inbound)1 Monitors (org.neo4j.kernel.monitoring.Monitors)1