Search in sources :

Example 6 with Neo4jJobScheduler

use of org.neo4j.kernel.impl.util.Neo4jJobScheduler in project neo4j by neo4j.

the class TestMasterCommittingAtSlave method newPropagator.

private TransactionPropagator newPropagator(int slaveCount, int replication, SlavePriority slavePriority, boolean... failingSlaves) throws Exception {
    slaves = instantiateSlaves(slaveCount, failingSlaves);
    Config config = Config.embeddedDefaults(MapUtil.stringMap(HaSettings.tx_push_factor.name(), "" + replication, ClusterSettings.server_id.name(), "" + MasterServerId));
    Neo4jJobScheduler scheduler = cleanup.add(new Neo4jJobScheduler());
    TransactionPropagator result = new TransactionPropagator(TransactionPropagator.from(config, slavePriority), NullLog.getInstance(), new Slaves() {

        @Override
        public Iterable<Slave> getSlaves() {
            return slaves;
        }
    }, new CommitPusher(scheduler));
    // Life
    try {
        scheduler.init();
        scheduler.start();
        result.init();
        result.start();
    } catch (Throwable e) {
        throw Exceptions.launderedException(e);
    }
    return result;
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) TransactionPropagator(org.neo4j.kernel.ha.transaction.TransactionPropagator) Config(org.neo4j.kernel.configuration.Config) CommitPusher(org.neo4j.kernel.ha.transaction.CommitPusher) Slaves(org.neo4j.kernel.ha.com.master.Slaves)

Example 7 with Neo4jJobScheduler

use of org.neo4j.kernel.impl.util.Neo4jJobScheduler in project neo4j by neo4j.

the class ConnectionInfoIT method hzTest.

@Test
public void hzTest() throws Throwable {
    // given
    testSocket = bindPort("0.0.0.0", 4243);
    //when
    AssertableLogProvider logProvider = new AssertableLogProvider();
    AssertableLogProvider userLogProvider = new AssertableLogProvider();
    HazelcastDiscoveryServiceFactory hzFactory = new HazelcastDiscoveryServiceFactory();
    Config config = embeddedDefaults(stringMap(discovery_listen_address.name(), ":" + testSocket.getLocalPort(), CausalClusteringSettings.initial_discovery_members.name(), "localhost:" + testSocket.getLocalPort(), new BoltConnector("bolt").enabled.name(), "true", new HttpConnector("http").enabled.name(), "true"));
    Neo4jJobScheduler jobScheduler = new Neo4jJobScheduler();
    jobScheduler.init();
    CoreTopologyService coreTopologyService = hzFactory.coreTopologyService(config, new MemberId(UUID.randomUUID()), jobScheduler, logProvider, userLogProvider);
    try {
        coreTopologyService.init();
        coreTopologyService.start();
    }//then
     catch (Throwable throwable) {
    //expected
    }
    logProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
    userLogProvider.assertContainsMessageContaining("Hazelcast was unable to start with setting");
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) MemberId(org.neo4j.causalclustering.identity.MemberId) HttpConnector(org.neo4j.kernel.configuration.HttpConnector) HazelcastDiscoveryServiceFactory(org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory) CoreTopologyService(org.neo4j.causalclustering.discovery.CoreTopologyService) BoltConnector(org.neo4j.kernel.configuration.BoltConnector) Config(org.neo4j.kernel.configuration.Config) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 8 with Neo4jJobScheduler

use of org.neo4j.kernel.impl.util.Neo4jJobScheduler in project neo4j by neo4j.

the class ContinuousJobTest method shouldTerminateOnStop.

@Test
public void shouldTerminateOnStop() throws Exception {
    // given: this task is gonna take >20 ms total
    Semaphore semaphore = new Semaphore(-20);
    Runnable task = () -> {
        // 1 ms
        LockSupport.parkNanos(1_000_000);
        semaphore.release();
    };
    Neo4jJobScheduler scheduler = new Neo4jJobScheduler();
    ContinuousJob continuousJob = new ContinuousJob(scheduler, jobGroup, task, NullLogProvider.getInstance());
    // when
    long startTime = System.currentTimeMillis();
    try (Lifespan ignored = new Lifespan(scheduler, continuousJob)) {
        semaphore.acquireUninterruptibly();
    }
    long runningTime = System.currentTimeMillis() - startTime;
    // then
    assertThat(runningTime, lessThan(DEFAULT_TIMEOUT_MS));
    //noinspection StatementWithEmptyBody
    while (semaphore.tryAcquire()) {
    // consume all outstanding permits
    }
    // no more permits should be granted
    semaphore.tryAcquire(10, MILLISECONDS);
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) Semaphore(java.util.concurrent.Semaphore) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Example 9 with Neo4jJobScheduler

use of org.neo4j.kernel.impl.util.Neo4jJobScheduler in project neo4j by neo4j.

the class ContinuousJobTest method shouldRunJobContinuously.

@Test
public void shouldRunJobContinuously() throws Throwable {
    // given
    CountDownLatch latch = new CountDownLatch(10);
    Runnable task = latch::countDown;
    Neo4jJobScheduler scheduler = new Neo4jJobScheduler();
    ContinuousJob continuousJob = new ContinuousJob(scheduler, jobGroup, task, NullLogProvider.getInstance());
    // when
    try (Lifespan ignored = new Lifespan(scheduler, continuousJob)) {
        //then
        assertTrue(latch.await(DEFAULT_TIMEOUT_MS, MILLISECONDS));
    }
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) CountDownLatch(java.util.concurrent.CountDownLatch) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) Test(org.junit.Test)

Example 10 with Neo4jJobScheduler

use of org.neo4j.kernel.impl.util.Neo4jJobScheduler in project neo4j by neo4j.

the class SharedDiscoveryServiceIT method createDiscoveryJob.

private Callable<Void> createDiscoveryJob(MemberId member, DiscoveryServiceFactory disoveryServiceFactory, Set<MemberId> expectedTargetSet) throws ExecutionException, InterruptedException {
    Neo4jJobScheduler jobScheduler = new Neo4jJobScheduler();
    jobScheduler.init();
    CoreTopologyService topologyService = disoveryServiceFactory.coreTopologyService(config(), member, jobScheduler, logProvider, userLogProvider);
    return sharedClientStarter(topologyService, expectedTargetSet);
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler)

Aggregations

Neo4jJobScheduler (org.neo4j.kernel.impl.util.Neo4jJobScheduler)14 Test (org.junit.Test)8 Config (org.neo4j.kernel.configuration.Config)6 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)6 CountDownLatch (java.util.concurrent.CountDownLatch)3 DoubleLatch (org.neo4j.test.DoubleLatch)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)2 LabelScanStoreProvider (org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider)2 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)2 File (java.io.File)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ChannelException (org.jboss.netty.channel.ChannelException)1 CoreTopologyService (org.neo4j.causalclustering.discovery.CoreTopologyService)1 HazelcastDiscoveryServiceFactory (org.neo4j.causalclustering.discovery.HazelcastDiscoveryServiceFactory)1 MemberId (org.neo4j.causalclustering.identity.MemberId)1 ClusterClientModule (org.neo4j.cluster.client.ClusterClientModule)1 NotElectableElectionCredentialsProvider (org.neo4j.cluster.protocol.election.NotElectableElectionCredentialsProvider)1 GraphDatabaseFactoryState (org.neo4j.graphdb.factory.GraphDatabaseFactoryState)1