Search in sources :

Example 1 with JobMonitoringParams

use of org.neo4j.scheduler.JobMonitoringParams in project neo4j by neo4j.

the class ThreadPoolTest method poolDoesNotLeakFastJobs.

@Test
void poolDoesNotLeakFastJobs() throws ExecutionException, InterruptedException {
    // When
    var fastJob = threadPool.submit(new JobMonitoringParams(null, null, null), () -> {
    /* do nothing */
    });
    fastJob.waitTermination();
    // Then
    assertEquals(0, threadPool.activeJobCount(), "Active job count should be 0 when job is terminated");
}
Also used : JobMonitoringParams(org.neo4j.scheduler.JobMonitoringParams) Test(org.junit.jupiter.api.Test)

Example 2 with JobMonitoringParams

use of org.neo4j.scheduler.JobMonitoringParams in project neo4j by neo4j.

the class GenericBlockBasedIndexPopulatorTest method setup.

@BeforeEach
void setup() {
    IndexProviderDescriptor providerDescriptor = new IndexProviderDescriptor("test", "v1");
    IndexDirectoryStructure directoryStructure = directoriesByProvider(directory.homePath()).forProvider(providerDescriptor);
    indexFiles = new IndexFiles.Directory(fs, directoryStructure, INDEX_DESCRIPTOR.getId());
    databaseIndexContext = DatabaseIndexContext.builder(pageCache, fs, DEFAULT_DATABASE_NAME).build();
    jobScheduler = JobSchedulerFactory.createInitialisedScheduler();
    populationWorkScheduler = new IndexPopulator.PopulationWorkScheduler() {

        @Override
        public <T> JobHandle<T> schedule(IndexPopulator.JobDescriptionSupplier descriptionSupplier, Callable<T> job) {
            return jobScheduler.schedule(Group.INDEX_POPULATION_WORK, new JobMonitoringParams(null, null, null), job);
        }
    };
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) JobHandle(org.neo4j.scheduler.JobHandle) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) NULL_CONTEXT(org.neo4j.internal.kernel.api.QueryContext.NULL_CONTEXT) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) JobMonitoringParams(org.neo4j.scheduler.JobMonitoringParams) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with JobMonitoringParams

use of org.neo4j.scheduler.JobMonitoringParams in project neo4j by neo4j.

the class BlockBasedIndexPopulatorTest method shouldScheduleMergeOnJobSchedulerWithCorrectGroup.

@Test
void shouldScheduleMergeOnJobSchedulerWithCorrectGroup() throws IndexEntryConflictException, IOException {
    // given
    BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator = instantiatePopulator(NO_MONITOR);
    boolean closed = false;
    try {
        populator.add(batchOfUpdates(), NULL);
        // when
        MutableBoolean called = new MutableBoolean();
        JobScheduler trackingJobScheduler = new JobSchedulerAdapter() {

            @Override
            public <T> JobHandle<T> schedule(Group group, JobMonitoringParams jobMonitoringParams, Callable<T> job) {
                called.setTrue();
                assertThat(group).isSameAs(Group.INDEX_POPULATION_WORK);
                return jobScheduler.schedule(group, jobMonitoringParams, job);
            }
        };
        populator.scanCompleted(nullInstance, wrapScheduler(trackingJobScheduler), NULL);
        assertTrue(called.booleanValue());
        populator.close(true, NULL);
        closed = true;
    } finally {
        if (!closed) {
            populator.close(true, NULL);
        }
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) Group(org.neo4j.scheduler.Group) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) JobSchedulerAdapter(org.neo4j.test.scheduler.JobSchedulerAdapter) JobMonitoringParams(org.neo4j.scheduler.JobMonitoringParams) Callable(java.util.concurrent.Callable) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with JobMonitoringParams

use of org.neo4j.scheduler.JobMonitoringParams in project neo4j by neo4j.

the class IndexPopulationJob method getMonitoringParams.

public JobMonitoringParams getMonitoringParams() {
    return new JobMonitoringParams(subject, databaseName, getMonitoringDescription(), () -> {
        var stateDescriptionBuilder = new StringBuilder();
        // because if there is only one, its name will already be in the job description
        if (populatedIndexes.size() > 1) {
            stateDescriptionBuilder.append("Population of indexes ");
            boolean first = true;
            for (var index : populatedIndexes) {
                if (first) {
                    first = false;
                } else {
                    stateDescriptionBuilder.append(",");
                }
                stateDescriptionBuilder.append("'").append(index.getIndexDescriptor().getName()).append("'");
            }
            stateDescriptionBuilder.append("; ");
        }
        PopulationProgress populationProgress = PopulationProgress.NONE;
        if (storeScan != null) {
            populationProgress = storeScan.getProgress();
        }
        stateDescriptionBuilder.append("Total progress: ").append(populationProgress.toIndexPopulationProgress().getCompletedPercentage()).append("%");
        return stateDescriptionBuilder.toString();
    });
}
Also used : PopulationProgress(org.neo4j.internal.kernel.api.PopulationProgress) JobMonitoringParams(org.neo4j.scheduler.JobMonitoringParams)

Example 5 with JobMonitoringParams

use of org.neo4j.scheduler.JobMonitoringParams in project neo4j by neo4j.

the class PropertyStoreTraceIT method configure.

@ExtensionCallback
void configure(TestDatabaseManagementServiceBuilder builder) {
    var dependencies = new Dependencies();
    // disabling periodic id buffers maintenance jobs
    dependencies.satisfyDependency(new CentralJobScheduler(Clocks.nanoClock()) {

        @Override
        public JobHandle<?> scheduleRecurring(Group group, JobMonitoringParams monitoredJobParams, Runnable runnable, long period, TimeUnit timeUnit) {
            return JobHandle.EMPTY;
        }

        @Override
        public JobHandle<?> scheduleRecurring(Group group, JobMonitoringParams monitoredJobParams, Runnable runnable, long initialDelay, long period, TimeUnit unit) {
            return JobHandle.EMPTY;
        }
    });
    builder.setExternalDependencies(dependencies);
}
Also used : Group(org.neo4j.scheduler.Group) JobHandle(org.neo4j.scheduler.JobHandle) TimeUnit(java.util.concurrent.TimeUnit) Dependencies(org.neo4j.collection.Dependencies) CentralJobScheduler(org.neo4j.kernel.impl.scheduler.CentralJobScheduler) JobMonitoringParams(org.neo4j.scheduler.JobMonitoringParams) ExtensionCallback(org.neo4j.test.extension.ExtensionCallback)

Aggregations

JobMonitoringParams (org.neo4j.scheduler.JobMonitoringParams)5 Test (org.junit.jupiter.api.Test)2 Group (org.neo4j.scheduler.Group)2 JobHandle (org.neo4j.scheduler.JobHandle)2 Callable (java.util.concurrent.Callable)1 TimeUnit (java.util.concurrent.TimeUnit)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Dependencies (org.neo4j.collection.Dependencies)1 PopulationProgress (org.neo4j.internal.kernel.api.PopulationProgress)1 NULL_CONTEXT (org.neo4j.internal.kernel.api.QueryContext.NULL_CONTEXT)1 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)1 IndexDirectoryStructure (org.neo4j.kernel.api.index.IndexDirectoryStructure)1 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)1 CentralJobScheduler (org.neo4j.kernel.impl.scheduler.CentralJobScheduler)1 JobScheduler (org.neo4j.scheduler.JobScheduler)1 ExtensionCallback (org.neo4j.test.extension.ExtensionCallback)1 JobSchedulerAdapter (org.neo4j.test.scheduler.JobSchedulerAdapter)1