Search in sources :

Example 1 with ExposedRaftState

use of org.neo4j.causalclustering.core.consensus.state.ExposedRaftState in project neo4j by neo4j.

the class MembershipWaiterTest method shouldWaitUntilLeaderCommitIsAvailable.

@Test
public void shouldWaitUntilLeaderCommitIsAvailable() throws Exception {
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    MembershipWaiter waiter = new MembershipWaiter(member(0), jobScheduler, () -> dbHealth, 500, NullLogProvider.getInstance());
    InMemoryRaftLog raftLog = new InMemoryRaftLog();
    raftLog.append(new RaftLogEntry(0, valueOf(0)));
    ExposedRaftState raftState = RaftStateBuilder.raftState().votingMembers(member(0)).leaderCommit(0).entryLog(raftLog).commitIndex(0L).build().copy();
    RaftMachine raft = mock(RaftMachine.class);
    when(raft.state()).thenReturn(raftState);
    CompletableFuture<Boolean> future = waiter.waitUntilCaughtUpMember(raft);
    jobScheduler.runJob();
    future.get(1, TimeUnit.SECONDS);
}
Also used : RaftMachine(org.neo4j.causalclustering.core.consensus.RaftMachine) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) ExposedRaftState(org.neo4j.causalclustering.core.consensus.state.ExposedRaftState) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 2 with ExposedRaftState

use of org.neo4j.causalclustering.core.consensus.state.ExposedRaftState in project neo4j by neo4j.

the class MembershipWaiterTest method shouldReturnImmediatelyIfMemberAndCaughtUp.

@Test
public void shouldReturnImmediatelyIfMemberAndCaughtUp() throws Exception {
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    MembershipWaiter waiter = new MembershipWaiter(member(0), jobScheduler, () -> dbHealth, 500, NullLogProvider.getInstance());
    InMemoryRaftLog raftLog = new InMemoryRaftLog();
    raftLog.append(new RaftLogEntry(0, valueOf(0)));
    ExposedRaftState raftState = RaftStateBuilder.raftState().votingMembers(member(0)).leaderCommit(0).entryLog(raftLog).commitIndex(0L).build().copy();
    RaftMachine raft = mock(RaftMachine.class);
    when(raft.state()).thenReturn(raftState);
    CompletableFuture<Boolean> future = waiter.waitUntilCaughtUpMember(raft);
    jobScheduler.runJob();
    jobScheduler.runJob();
    future.get(0, NANOSECONDS);
}
Also used : RaftMachine(org.neo4j.causalclustering.core.consensus.RaftMachine) InMemoryRaftLog(org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog) ExposedRaftState(org.neo4j.causalclustering.core.consensus.state.ExposedRaftState) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) RaftLogEntry(org.neo4j.causalclustering.core.consensus.log.RaftLogEntry) Test(org.junit.Test)

Example 3 with ExposedRaftState

use of org.neo4j.causalclustering.core.consensus.state.ExposedRaftState in project neo4j by neo4j.

the class MembershipWaiterTest method shouldTimeoutIfCaughtUpButNotMember.

@Test
public void shouldTimeoutIfCaughtUpButNotMember() throws Exception {
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    MembershipWaiter waiter = new MembershipWaiter(member(0), jobScheduler, () -> dbHealth, 1, NullLogProvider.getInstance());
    ExposedRaftState raftState = RaftStateBuilder.raftState().votingMembers(member(1)).leaderCommit(0).build().copy();
    RaftMachine raft = mock(RaftMachine.class);
    when(raft.state()).thenReturn(raftState);
    CompletableFuture<Boolean> future = waiter.waitUntilCaughtUpMember(raft);
    jobScheduler.runJob();
    jobScheduler.runJob();
    try {
        future.get(10, MILLISECONDS);
        fail("Should have timed out.");
    } catch (TimeoutException e) {
    // expected
    }
}
Also used : RaftMachine(org.neo4j.causalclustering.core.consensus.RaftMachine) ExposedRaftState(org.neo4j.causalclustering.core.consensus.state.ExposedRaftState) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 4 with ExposedRaftState

use of org.neo4j.causalclustering.core.consensus.state.ExposedRaftState in project neo4j by neo4j.

the class MembershipWaiterTest method shouldTimeoutIfLeaderCommitIsNeverKnown.

@Test
public void shouldTimeoutIfLeaderCommitIsNeverKnown() throws Exception {
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    MembershipWaiter waiter = new MembershipWaiter(member(0), jobScheduler, () -> dbHealth, 1, NullLogProvider.getInstance());
    ExposedRaftState raftState = RaftStateBuilder.raftState().leaderCommit(-1).build().copy();
    RaftMachine raft = mock(RaftMachine.class);
    when(raft.state()).thenReturn(raftState);
    CompletableFuture<Boolean> future = waiter.waitUntilCaughtUpMember(raft);
    jobScheduler.runJob();
    try {
        future.get(10, MILLISECONDS);
        fail("Should have timed out.");
    } catch (TimeoutException e) {
    // expected
    }
}
Also used : RaftMachine(org.neo4j.causalclustering.core.consensus.RaftMachine) ExposedRaftState(org.neo4j.causalclustering.core.consensus.state.ExposedRaftState) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 5 with ExposedRaftState

use of org.neo4j.causalclustering.core.consensus.state.ExposedRaftState in project neo4j by neo4j.

the class MembershipWaiterTest method shouldTimeoutIfMemberButNotCaughtUp.

@Test
public void shouldTimeoutIfMemberButNotCaughtUp() throws Exception {
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    MembershipWaiter waiter = new MembershipWaiter(member(0), jobScheduler, () -> dbHealth, 1, NullLogProvider.getInstance());
    ExposedRaftState raftState = RaftStateBuilder.raftState().votingMembers(member(0), member(1)).leaderCommit(0).build().copy();
    RaftMachine raft = mock(RaftMachine.class);
    when(raft.state()).thenReturn(raftState);
    CompletableFuture<Boolean> future = waiter.waitUntilCaughtUpMember(raft);
    jobScheduler.runJob();
    jobScheduler.runJob();
    try {
        future.get(10, MILLISECONDS);
        fail("Should have timed out.");
    } catch (TimeoutException e) {
    // expected
    }
}
Also used : RaftMachine(org.neo4j.causalclustering.core.consensus.RaftMachine) ExposedRaftState(org.neo4j.causalclustering.core.consensus.state.ExposedRaftState) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)5 ExposedRaftState (org.neo4j.causalclustering.core.consensus.state.ExposedRaftState)5 OnDemandJobScheduler (org.neo4j.test.OnDemandJobScheduler)5 TimeoutException (java.util.concurrent.TimeoutException)3 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)2 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)2