Search in sources :

Example 16 with JobHandle

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

the class CentralJobSchedulerTest method mustRespectDesiredParallelismSetPriorToPoolCreation.

@Test
void mustRespectDesiredParallelismSetPriorToPoolCreation() throws Exception {
    life.start();
    AtomicInteger counter = new AtomicInteger();
    AtomicInteger max = new AtomicInteger();
    scheduler.setParallelism(Group.CYPHER_WORKER, 3);
    Runnable runnable = () -> {
        counter.getAndIncrement();
        LockSupport.parkNanos(MILLISECONDS.toNanos(50));
        int currentMax;
        int currentVal;
        do {
            currentVal = counter.get();
            currentMax = max.get();
        } while (!max.compareAndSet(currentMax, Math.max(currentMax, currentVal)));
        LockSupport.parkNanos(MILLISECONDS.toNanos(50));
        counter.getAndDecrement();
    };
    List<JobHandle<?>> handles = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        handles.add(scheduler.schedule(Group.CYPHER_WORKER, NOT_MONITORED, runnable));
    }
    for (JobHandle<?> handle : handles) {
        handle.waitTermination();
    }
    assertThat(max.get()).isLessThanOrEqualTo(3);
}
Also used : JobHandle(org.neo4j.scheduler.JobHandle) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 17 with JobHandle

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

the class IndexSamplingControllerTest method shouldForegroundSampleAllTheIndexes.

@Test
void shouldForegroundSampleAllTheIndexes() throws InterruptedException, ExecutionException, TimeoutException {
    // given
    IndexSamplingController controller = newSamplingController(always(false), logProvider);
    when(indexProxy.getState()).thenReturn(ONLINE);
    when(anotherIndexProxy.getState()).thenReturn(ONLINE);
    indexMap.putIndexProxy(anotherIndexProxy);
    JobHandle jobHandle = mock(JobHandle.class);
    JobHandle anotherJobHandle = mock(JobHandle.class);
    when(tracker.scheduleSamplingJob(job)).thenReturn(jobHandle);
    when(tracker.scheduleSamplingJob(anotherJob)).thenReturn(anotherJobHandle);
    // when
    IndexSamplingMode mode = foregroundRebuildUpdated(60);
    controller.sampleIndexes(mode);
    // then
    verify(jobFactory).create(indexId, indexProxy);
    verify(tracker).scheduleSamplingJob(job);
    verify(jobFactory).create(anotherIndexId, anotherIndexProxy);
    verify(tracker).scheduleSamplingJob(anotherJob);
    verify(jobHandle).waitTermination(anyLong(), any(TimeUnit.class));
    verify(anotherJobHandle).waitTermination(anyLong(), any(TimeUnit.class));
    verifyNoMoreInteractions(jobFactory, tracker, jobHandle, anotherJobHandle);
}
Also used : JobHandle(org.neo4j.scheduler.JobHandle) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test)

Example 18 with JobHandle

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

the class KernelTransactionTimeoutMonitorSchedulerTest method startJobTransactionMonitor.

@Test
void startJobTransactionMonitor() {
    JobHandle jobHandle = Mockito.mock(JobHandle.class);
    when(jobScheduler.scheduleRecurring(eq(Group.TRANSACTION_TIMEOUT_MONITOR), any(JobMonitoringParams.class), eq(transactionMonitor), anyLong(), any(TimeUnit.class))).thenReturn(jobHandle);
    TransactionMonitorScheduler monitorScheduler = new TransactionMonitorScheduler(transactionMonitor, jobScheduler, 7, "test database");
    monitorScheduler.start();
    verify(jobScheduler).scheduleRecurring(eq(Group.TRANSACTION_TIMEOUT_MONITOR), any(JobMonitoringParams.class), eq(transactionMonitor), eq(7L), eq(TimeUnit.MILLISECONDS));
    monitorScheduler.stop();
    verify(jobHandle).cancel();
}
Also used : JobHandle(org.neo4j.scheduler.JobHandle) TimeUnit(java.util.concurrent.TimeUnit) JobMonitoringParams(org.neo4j.scheduler.JobMonitoringParams) TransactionMonitorScheduler(org.neo4j.kernel.impl.api.transaction.monitor.TransactionMonitorScheduler) Test(org.junit.jupiter.api.Test)

Example 19 with JobHandle

use of org.neo4j.scheduler.JobHandle 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)

Example 20 with JobHandle

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

the class ScheduledJobHandle method cancel.

@Override
public void cancel() {
    monitoredJobs.remove(this);
    state.set(FAILED);
    JobHandle handle = latestHandle;
    if (handle != null) {
        handle.cancel();
    }
    for (CancelListener cancelListener : cancelListeners) {
        cancelListener.cancelled();
    }
    scheduler.cancelTask(this);
    // Release the handle to allow waitTermination() to observe the cancellation.
    handleRelease.release();
}
Also used : JobHandle(org.neo4j.scheduler.JobHandle) CancelListener(org.neo4j.scheduler.CancelListener)

Aggregations

JobHandle (org.neo4j.scheduler.JobHandle)20 Test (org.junit.jupiter.api.Test)14 RepeatedTest (org.junit.jupiter.api.RepeatedTest)9 TimeUnit (java.util.concurrent.TimeUnit)3 JobMonitoringParams (org.neo4j.scheduler.JobMonitoringParams)3 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)2 CancellationException (java.util.concurrent.CancellationException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Dependencies (org.neo4j.collection.Dependencies)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 PopulationWorkScheduler (org.neo4j.kernel.api.index.IndexPopulator.PopulationWorkScheduler)1 TransactionMonitorScheduler (org.neo4j.kernel.impl.api.transaction.monitor.TransactionMonitorScheduler)1 CentralJobScheduler (org.neo4j.kernel.impl.scheduler.CentralJobScheduler)1