Search in sources :

Example 1 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 2 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 3 with Neo4jJobScheduler

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

the class IndexSamplingJobTrackerTest method shouldWaitForAllJobsToFinish.

@Test(timeout = 5_000)
public void shouldWaitForAllJobsToFinish() throws Throwable {
    // Given
    when(config.jobLimit()).thenReturn(2);
    JobScheduler jobScheduler = new Neo4jJobScheduler();
    jobScheduler.init();
    final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
    final CountDownLatch latch1 = new CountDownLatch(1);
    final CountDownLatch latch2 = new CountDownLatch(1);
    WaitingIndexSamplingJob job1 = new WaitingIndexSamplingJob(indexId11, latch1);
    WaitingIndexSamplingJob job2 = new WaitingIndexSamplingJob(indexId22, latch1);
    jobTracker.scheduleSamplingJob(job1);
    jobTracker.scheduleSamplingJob(job2);
    Future<?> stopping = Executors.newSingleThreadExecutor().submit(() -> {
        latch2.countDown();
        try {
            jobTracker.awaitAllJobs(10, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    });
    // When
    latch2.await();
    assertFalse(stopping.isDone());
    latch1.countDown();
    stopping.get(10, SECONDS);
    // Then
    assertTrue(stopping.isDone());
    assertNull(stopping.get());
    assertTrue(job1.executed);
    assertTrue(job2.executed);
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 4 with Neo4jJobScheduler

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

the class IndexSamplingJobTrackerTest method shouldNotAcceptMoreJobsThanAllowed.

@Test
public void shouldNotAcceptMoreJobsThanAllowed() throws Throwable {
    // given
    when(config.jobLimit()).thenReturn(1);
    JobScheduler jobScheduler = new Neo4jJobScheduler();
    jobScheduler.init();
    final IndexSamplingJobTracker jobTracker = new IndexSamplingJobTracker(config, jobScheduler);
    final DoubleLatch latch = new DoubleLatch();
    final DoubleLatch waitingLatch = new DoubleLatch();
    // when
    assertTrue(jobTracker.canExecuteMoreSamplingJobs());
    jobTracker.scheduleSamplingJob(new IndexSamplingJob() {

        @Override
        public void run() {
            latch.startAndWaitForAllToStart();
            latch.waitForAllToFinish();
        }

        @Override
        public long indexId() {
            return indexId12;
        }
    });
    // then
    latch.waitForAllToStart();
    assertFalse(jobTracker.canExecuteMoreSamplingJobs());
    final AtomicBoolean waiting = new AtomicBoolean(false);
    new Thread(() -> {
        waiting.set(true);
        waitingLatch.startAndWaitForAllToStart();
        jobTracker.waitUntilCanExecuteMoreSamplingJobs();
        waiting.set(false);
        waitingLatch.finish();
    }).start();
    waitingLatch.waitForAllToStart();
    assertTrue(waiting.get());
    latch.finish();
    waitingLatch.waitForAllToFinish();
    assertFalse(waiting.get());
    // eventually we accept new jobs
    while (!jobTracker.canExecuteMoreSamplingJobs()) {
        Thread.yield();
    }
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Example 5 with Neo4jJobScheduler

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

the class NonUniqueIndexTests method newEmbeddedGraphDatabaseWithSlowJobScheduler.

private GraphDatabaseService newEmbeddedGraphDatabaseWithSlowJobScheduler() {
    GraphDatabaseFactoryState graphDatabaseFactoryState = new GraphDatabaseFactoryState();
    graphDatabaseFactoryState.setUserLogProvider(NullLogService.getInstance().getUserLogProvider());
    return new GraphDatabaseFacadeFactory(DatabaseInfo.COMMUNITY, CommunityEditionModule::new) {

        @Override
        protected PlatformModule createPlatform(File storeDir, Config config, Dependencies dependencies, GraphDatabaseFacade graphDatabaseFacade) {
            return new PlatformModule(storeDir, config, databaseInfo, dependencies, graphDatabaseFacade) {

                @Override
                protected Neo4jJobScheduler createJobScheduler() {
                    return newSlowJobScheduler();
                }

                @Override
                protected LogService createLogService(LogProvider userLogProvider) {
                    return NullLogService.getInstance();
                }
            };
        }
    }.newFacade(directory.graphDbDir(), Config.embeddedDefaults(), graphDatabaseFactoryState.databaseDependencies());
}
Also used : Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) Config(org.neo4j.kernel.configuration.Config) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) GraphDatabaseFactoryState(org.neo4j.graphdb.factory.GraphDatabaseFactoryState) GraphDatabaseFacadeFactory(org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) PlatformModule(org.neo4j.kernel.impl.factory.PlatformModule) File(java.io.File) LogService(org.neo4j.kernel.impl.logging.LogService) NullLogService(org.neo4j.kernel.impl.logging.NullLogService)

Aggregations

Neo4jJobScheduler (org.neo4j.kernel.impl.util.Neo4jJobScheduler)12 Test (org.junit.Test)6 Config (org.neo4j.kernel.configuration.Config)6 JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)4 CountDownLatch (java.util.concurrent.CountDownLatch)2 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 DoubleLatch (org.neo4j.test.DoubleLatch)2 File (java.io.File)1 Semaphore (java.util.concurrent.Semaphore)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 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1