Search in sources :

Example 16 with JobScheduler

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

the class SwitchToSlaveCopyThenBranchTest method updatesPulledAndPullingScheduledOnSwitchToSlave.

@Test
public void updatesPulledAndPullingScheduledOnSwitchToSlave() throws Throwable {
    SwitchToSlaveCopyThenBranch switchToSlave = newSwitchToSlaveSpy();
    when(fs.fileExists(any(File.class))).thenReturn(true);
    JobScheduler jobScheduler = mock(JobScheduler.class);
    LifeSupport communicationLife = mock(LifeSupport.class);
    URI localhost = getLocalhostUri();
    final UpdatePullerScheduler pullerScheduler = new UpdatePullerScheduler(jobScheduler, NullLogProvider.getInstance(), updatePuller, 10L);
    when(pullerFactory.createUpdatePullerScheduler(updatePuller)).thenReturn(pullerScheduler);
    // emulate lifecycle start call on scheduler
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            pullerScheduler.init();
            return null;
        }
    }).when(communicationLife).start();
    switchToSlave.switchToSlave(communicationLife, localhost, localhost, mock(CancellationRequest.class));
    verify(updatePuller).tryPullUpdates();
    verify(communicationLife).add(pullerScheduler);
    verify(jobScheduler).scheduleRecurring(eq(JobScheduler.Groups.pullUpdates), any(Runnable.class), eq(10L), eq(10L), eq(TimeUnit.MILLISECONDS));
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) UpdatePullerScheduler(org.neo4j.kernel.ha.UpdatePullerScheduler) URI(java.net.URI) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File) CancellationRequest(org.neo4j.helpers.CancellationRequest) Test(org.junit.Test)

Example 17 with JobScheduler

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

the class RecordStorageEngineRule method get.

private RecordStorageEngine get(FileSystemAbstraction fs, PageCache pageCache, SchemaIndexProvider schemaIndexProvider, DatabaseHealth databaseHealth, File storeDirectory, Function<BatchTransactionApplierFacade, BatchTransactionApplierFacade> transactionApplierTransformer) {
    if (!fs.fileExists(storeDirectory) && !fs.mkdir(storeDirectory)) {
        throw new IllegalStateException();
    }
    IdGeneratorFactory idGeneratorFactory = new EphemeralIdGenerator.Factory();
    LabelScanStoreProvider labelScanStoreProvider = nativeLabelScanStoreProvider(storeDirectory, fs, pageCache);
    LegacyIndexProviderLookup legacyIndexProviderLookup = mock(LegacyIndexProviderLookup.class);
    when(legacyIndexProviderLookup.all()).thenReturn(Iterables.empty());
    IndexConfigStore indexConfigStore = new IndexConfigStore(storeDirectory, fs);
    JobScheduler scheduler = life.add(new Neo4jJobScheduler());
    Config config = Config.defaults();
    Supplier<KernelTransactionsSnapshot> txSnapshotSupplier = () -> new KernelTransactionsSnapshot(Collections.emptySet(), 0);
    return life.add(new ExtendedRecordStorageEngine(storeDirectory, config, idGeneratorFactory, IdReuseEligibility.ALWAYS, new CommunityIdTypeConfigurationProvider(), pageCache, fs, NullLogProvider.getInstance(), mock(PropertyKeyTokenHolder.class), mock(LabelTokenHolder.class), mock(RelationshipTypeTokenHolder.class), () -> {
    }, new StandardConstraintSemantics(), scheduler, mock(TokenNameLookup.class), new ReentrantLockService(), schemaIndexProvider, IndexingService.NO_MONITOR, databaseHealth, labelScanStoreProvider, legacyIndexProviderLookup, indexConfigStore, new SynchronizedArrayIdOrderingQueue(20), txSnapshotSupplier, transactionApplierTransformer));
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) LabelScanStoreProvider(org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider) NeoStoreDataSourceRule.nativeLabelScanStoreProvider(org.neo4j.test.rule.NeoStoreDataSourceRule.nativeLabelScanStoreProvider) LegacyIndexProviderLookup(org.neo4j.kernel.impl.api.LegacyIndexProviderLookup) Config(org.neo4j.kernel.configuration.Config) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) KernelTransactionsSnapshot(org.neo4j.kernel.impl.api.KernelTransactionsSnapshot) Neo4jJobScheduler(org.neo4j.kernel.impl.util.Neo4jJobScheduler) CommunityIdTypeConfigurationProvider(org.neo4j.kernel.impl.store.id.configuration.CommunityIdTypeConfigurationProvider) SynchronizedArrayIdOrderingQueue(org.neo4j.kernel.impl.util.SynchronizedArrayIdOrderingQueue) ReentrantLockService(org.neo4j.kernel.impl.locking.ReentrantLockService) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics)

Example 18 with JobScheduler

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

the class IndexSamplingJobTrackerTest method shouldAcceptNewJobWhenRunningJobFinishes.

@Test(timeout = 5_000)
public void shouldAcceptNewJobWhenRunningJobFinishes() 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 AtomicBoolean lastJobExecuted = new AtomicBoolean();
    jobTracker.scheduleSamplingJob(new IndexSamplingJob() {

        @Override
        public long indexId() {
            return indexId11;
        }

        @Override
        public void run() {
            latch.waitForAllToStart();
        }
    });
    // When
    Executors.newSingleThreadExecutor().execute(() -> {
        jobTracker.waitUntilCanExecuteMoreSamplingJobs();
        jobTracker.scheduleSamplingJob(new IndexSamplingJob() {

            @Override
            public long indexId() {
                return indexId22;
            }

            @Override
            public void run() {
                lastJobExecuted.set(true);
                latch.finish();
            }
        });
    });
    assertFalse(jobTracker.canExecuteMoreSamplingJobs());
    latch.startAndWaitForAllToStart();
    latch.waitForAllToFinish();
    // Then
    assertTrue(lastJobExecuted.get());
}
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)

Aggregations

JobScheduler (org.neo4j.kernel.impl.util.JobScheduler)18 Test (org.junit.Test)9 Config (org.neo4j.kernel.configuration.Config)7 Neo4jJobScheduler (org.neo4j.kernel.impl.util.Neo4jJobScheduler)7 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)6 File (java.io.File)5 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)4 Monitors (org.neo4j.kernel.monitoring.Monitors)4 LabelScanStoreProvider (org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider)3 LogService (org.neo4j.kernel.impl.logging.LogService)3 Procedures (org.neo4j.kernel.impl.proc.Procedures)3 Log (org.neo4j.logging.Log)3 LogProvider (org.neo4j.logging.LogProvider)3 DoubleLatch (org.neo4j.test.DoubleLatch)3 IOException (java.io.IOException)2 URI (java.net.URI)2 Clock (java.time.Clock)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CountDownLatch (java.util.concurrent.CountDownLatch)2