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);
}
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);
}
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();
}
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);
}
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();
}
Aggregations