Search in sources :

Example 11 with OnDemandJobScheduler

use of org.neo4j.test.OnDemandJobScheduler in project neo4j by neo4j.

the class SegmentedRaftLogRotationTest method createRaftLog.

private SegmentedRaftLog createRaftLog(long rotateAtSize) throws IOException {
    LogProvider logProvider = getInstance();
    CoreLogPruningStrategy pruningStrategy = new CoreLogPruningStrategyFactory(raft_log_pruning_strategy.getDefaultValue(), logProvider).newInstance();
    return new SegmentedRaftLog(fileSystemRule.get(), testDirectory.directory(), rotateAtSize, new DummyRaftableContentSerializer(), logProvider, 0, Clocks.fakeClock(), new OnDemandJobScheduler(), pruningStrategy);
}
Also used : LogProvider(org.neo4j.logging.LogProvider) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) DummyRaftableContentSerializer(org.neo4j.causalclustering.core.consensus.log.DummyRaftableContentSerializer)

Example 12 with OnDemandJobScheduler

use of org.neo4j.test.OnDemandJobScheduler in project neo4j by neo4j.

the class SegmentedRaftLogRotationTruncationPruneTest method createRaftLog.

private RaftLog createRaftLog() throws Exception {
    File directory = new File(RAFT_LOG_DIRECTORY_NAME);
    FileSystemAbstraction fileSystem = new EphemeralFileSystemAbstraction();
    fileSystem.mkdir(directory);
    LogProvider logProvider = getInstance();
    CoreLogPruningStrategy pruningStrategy = new CoreLogPruningStrategyFactory("1 entries", logProvider).newInstance();
    SegmentedRaftLog newRaftLog = new SegmentedRaftLog(fileSystem, directory, 1, new DummyRaftableContentSerializer(), logProvider, 8, Clocks.fakeClock(), new OnDemandJobScheduler(), pruningStrategy);
    newRaftLog.start();
    return newRaftLog;
}
Also used : LogProvider(org.neo4j.logging.LogProvider) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) File(java.io.File) DummyRaftableContentSerializer(org.neo4j.causalclustering.core.consensus.log.DummyRaftableContentSerializer)

Example 13 with OnDemandJobScheduler

use of org.neo4j.test.OnDemandJobScheduler 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 14 with OnDemandJobScheduler

use of org.neo4j.test.OnDemandJobScheduler 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 15 with OnDemandJobScheduler

use of org.neo4j.test.OnDemandJobScheduler 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)

Aggregations

OnDemandJobScheduler (org.neo4j.test.OnDemandJobScheduler)20 Test (org.junit.Test)12 LogProvider (org.neo4j.logging.LogProvider)9 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 File (java.io.File)6 DummyRaftableContentSerializer (org.neo4j.causalclustering.core.consensus.log.DummyRaftableContentSerializer)6 Cluster (com.hazelcast.core.Cluster)5 IAtomicReference (com.hazelcast.core.IAtomicReference)5 Member (com.hazelcast.core.Member)5 RaftMachine (org.neo4j.causalclustering.core.consensus.RaftMachine)5 ExposedRaftState (org.neo4j.causalclustering.core.consensus.state.ExposedRaftState)5 Endpoint (com.hazelcast.core.Endpoint)4 TimeoutException (java.util.concurrent.TimeoutException)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 Client (com.hazelcast.core.Client)2 ClientService (com.hazelcast.core.ClientService)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InMemoryRaftLog (org.neo4j.causalclustering.core.consensus.log.InMemoryRaftLog)2 RaftLogEntry (org.neo4j.causalclustering.core.consensus.log.RaftLogEntry)2 CoreReplicatedContentMarshal (org.neo4j.causalclustering.messaging.CoreReplicatedContentMarshal)2