Search in sources :

Example 1 with OnDemandJobScheduler

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

the class HazelcastClientTest method shouldNotReconnectWhileHazelcastRemainsAvailable.

@Test
public void shouldNotReconnectWhileHazelcastRemainsAvailable() throws Throwable {
    // given
    HazelcastConnector connector = mock(HazelcastConnector.class);
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    HazelcastClient client = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
    when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
    when(hazelcastInstance.getSet(anyString())).thenReturn(new HazelcastSet());
    when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
    when(hazelcastInstance.getExecutorService(anyString())).thenReturn(new StubExecutorService());
    com.hazelcast.core.Cluster cluster = mock(Cluster.class);
    when(hazelcastInstance.getCluster()).thenReturn(cluster);
    Set<Member> members = asSet(makeMember(1), makeMember(2));
    when(cluster.getMembers()).thenReturn(members);
    // when
    client.start();
    jobScheduler.runJob();
    CoreTopology topology;
    for (int i = 0; i < 5; i++) {
        topology = client.coreServers();
        assertEquals(members.size(), topology.members().size());
    }
    // then
    verify(connector, times(1)).connectToHazelcast();
}
Also used : OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) Endpoint(com.hazelcast.core.Endpoint) HazelcastInstance(com.hazelcast.core.HazelcastInstance) IAtomicReference(com.hazelcast.core.IAtomicReference) Cluster(com.hazelcast.core.Cluster) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Example 2 with OnDemandJobScheduler

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

the class HazelcastClientTest method shouldSwallowNPEFromHazelcast.

@Test
public void shouldSwallowNPEFromHazelcast() throws Throwable {
    // given
    Endpoint endpoint = mock(Endpoint.class);
    when(endpoint.getUuid()).thenReturn("12345");
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(hazelcastInstance.getLocalEndpoint()).thenReturn(endpoint);
    when(hazelcastInstance.getMap(anyString())).thenReturn(new HazelcastMap());
    when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
    doThrow(new NullPointerException("boom!!!")).when(hazelcastInstance).shutdown();
    HazelcastConnector connector = mock(HazelcastConnector.class);
    when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    HazelcastClient hazelcastClient = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
    hazelcastClient.start();
    jobScheduler.runJob();
    // when
    hazelcastClient.stop();
// then no NPE has been thrown
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Endpoint(com.hazelcast.core.Endpoint) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) Test(org.junit.Test)

Example 3 with OnDemandJobScheduler

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

the class SegmentedRaftLogVerificationIT method createRaftLog.

@Override
protected RaftLog createRaftLog() throws Throwable {
    FileSystemAbstraction fsa = fsRule.get();
    File directory = new File(RAFT_LOG_DIRECTORY_NAME);
    fsa.mkdir(directory);
    long rotateAtSizeBytes = 128;
    int readerPoolSize = 8;
    LogProvider logProvider = getInstance();
    CoreLogPruningStrategy pruningStrategy = new CoreLogPruningStrategyFactory(raft_log_pruning_strategy.getDefaultValue(), logProvider).newInstance();
    SegmentedRaftLog newRaftLog = new SegmentedRaftLog(fsa, directory, rotateAtSizeBytes, new DummyRaftableContentSerializer(), logProvider, readerPoolSize, Clocks.systemClock(), new OnDemandJobScheduler(), pruningStrategy);
    newRaftLog.init();
    newRaftLog.start();
    return newRaftLog;
}
Also used : LogProvider(org.neo4j.logging.LogProvider) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) File(java.io.File) DummyRaftableContentSerializer(org.neo4j.causalclustering.core.consensus.log.DummyRaftableContentSerializer)

Example 4 with OnDemandJobScheduler

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

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

the class SegmentedRaftLogContractTest method createRaftLog.

@Override
public RaftLog createRaftLog() {
    File directory = new File(RAFT_LOG_DIRECTORY_NAME);
    FileSystemAbstraction fileSystem = fsRule.get();
    fileSystem.mkdir(directory);
    LogProvider logProvider = getInstance();
    CoreLogPruningStrategy pruningStrategy = new CoreLogPruningStrategyFactory("1 entries", logProvider).newInstance();
    return life.add(new SegmentedRaftLog(fileSystem, directory, 1024, new DummyRaftableContentSerializer(), logProvider, 8, Clocks.fakeClock(), new OnDemandJobScheduler(), pruningStrategy));
}
Also used : LogProvider(org.neo4j.logging.LogProvider) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) File(java.io.File) DummyRaftableContentSerializer(org.neo4j.causalclustering.core.consensus.log.DummyRaftableContentSerializer)

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