use of org.neo4j.scheduler.JobHandle in project neo4j by neo4j.
the class ScheduledJobHandle method waitTermination.
@Override
public void waitTermination() throws ExecutionException, InterruptedException {
handleRelease.await();
RuntimeException runtimeException = null;
try {
JobHandle handleDelegate = this.latestHandle;
if (handleDelegate != null) {
handleDelegate.waitTermination();
}
} catch (RuntimeException t) {
runtimeException = t;
}
if (state.get() == FAILED) {
Throwable exception = this.lastException;
if (exception != null) {
var executionException = new ExecutionException(exception);
if (runtimeException != null) {
executionException.addSuppressed(runtimeException);
}
throw executionException;
} else {
throw Exceptions.chain(new CancellationException(), runtimeException);
}
}
}
use of org.neo4j.scheduler.JobHandle in project neo4j by neo4j.
the class CentralJobSchedulerTest method longRunningScheduledJobsMustNotDelayOtherLongRunningJobs.
@Test
void longRunningScheduledJobsMustNotDelayOtherLongRunningJobs() {
life.start();
List<JobHandle<?>> handles = new ArrayList<>(30);
AtomicLong startedCounter = new AtomicLong();
BinaryLatch blockLatch = new BinaryLatch();
Runnable task = () -> {
startedCounter.incrementAndGet();
blockLatch.await();
};
for (int i = 0; i < 10; i++) {
handles.add(scheduler.schedule(Group.INDEX_POPULATION, NOT_MONITORED, task, 0, TimeUnit.MILLISECONDS));
}
for (int i = 0; i < 10; i++) {
handles.add(scheduler.scheduleRecurring(Group.INDEX_POPULATION, NOT_MONITORED, task, Integer.MAX_VALUE, TimeUnit.MILLISECONDS));
}
for (int i = 0; i < 10; i++) {
handles.add(scheduler.scheduleRecurring(Group.INDEX_POPULATION, NOT_MONITORED, task, 0, Integer.MAX_VALUE, TimeUnit.MILLISECONDS));
}
long deadline = TimeUnit.SECONDS.toNanos(10) + System.nanoTime();
do {
if (startedCounter.get() == handles.size()) {
// All jobs got started. We're good!
blockLatch.release();
for (JobHandle<?> handle : handles) {
handle.cancel();
}
return;
}
} while (System.nanoTime() < deadline);
fail("Only managed to start " + startedCounter.get() + " tasks in 10 seconds, when " + handles.size() + " was expected.");
}
use of org.neo4j.scheduler.JobHandle 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);
}
};
}
use of org.neo4j.scheduler.JobHandle in project neo4j by neo4j.
the class PartMergerTest method setUp.
@BeforeEach
void setUp() {
scheduler = new ThreadPoolJobScheduler();
populationWorkScheduler = new PopulationWorkScheduler() {
@Override
public <T> JobHandle<T> schedule(IndexPopulator.JobDescriptionSupplier descriptionSupplier, Callable<T> job) {
return scheduler.schedule(Group.INDEX_POPULATION_WORK, NOT_MONITORED, job);
}
};
}
use of org.neo4j.scheduler.JobHandle in project neo4j by neo4j.
the class TimeBasedTaskSchedulerTest method delayedTasksMustNotRunIfCancelledFirst.
@Test
void delayedTasksMustNotRunIfCancelledFirst() {
MonitoredCancelListener cancelListener = new MonitoredCancelListener();
JobHandle handle = scheduler.submit(Group.STORAGE_MAINTENANCE, counter::incrementAndGet, 100, 0);
handle.registerCancelListener(cancelListener);
clock.forward(90, TimeUnit.NANOSECONDS);
scheduler.tick();
handle.cancel();
clock.forward(10, TimeUnit.NANOSECONDS);
scheduler.tick();
pools.getThreadPool(Group.STORAGE_MAINTENANCE).shutDown();
assertThat(counter.get()).isEqualTo(0);
assertTrue(cancelListener.isCanceled());
assertThrows(CancellationException.class, handle::waitTermination);
}
Aggregations