use of org.neo4j.kernel.impl.util.JobScheduler.JobHandle in project neo4j by neo4j.
the class RobustJobSchedulerWrapperTest method oneOffJobWithExceptionShouldLog.
@Test
public void oneOffJobWithExceptionShouldLog() throws Exception {
// given
Log log = mock(Log.class);
RobustJobSchedulerWrapper robustWrapper = new RobustJobSchedulerWrapper(actualScheduler, log);
AtomicInteger count = new AtomicInteger();
IllegalStateException e = new IllegalStateException();
// when
JobHandle jobHandle = robustWrapper.schedule("JobName", 100, () -> {
count.incrementAndGet();
throw e;
});
// then
assertEventually("run count", count::get, Matchers.equalTo(1), DEFAULT_TIMEOUT_MS, MILLISECONDS);
jobHandle.waitTermination();
verify(log, timeout(DEFAULT_TIMEOUT_MS).times(1)).warn("Uncaught exception", e);
}
use of org.neo4j.kernel.impl.util.JobScheduler.JobHandle in project neo4j by neo4j.
the class Neo4jJobSchedulerTest method shouldNotifyCancelListeners.
@Test
public void shouldNotifyCancelListeners() throws Exception {
// GIVEN
Neo4jJobScheduler neo4jJobScheduler = new Neo4jJobScheduler();
neo4jJobScheduler.init();
// WHEN
AtomicBoolean halted = new AtomicBoolean();
Runnable job = () -> {
while (!halted.get()) {
LockSupport.parkNanos(MILLISECONDS.toNanos(10));
}
};
JobHandle handle = neo4jJobScheduler.schedule(indexPopulation, job);
handle.registerCancelListener(mayBeInterrupted -> halted.set(true));
handle.cancel(false);
// THEN
assertTrue(halted.get());
neo4jJobScheduler.shutdown();
}
Aggregations