use of org.neo4j.kernel.impl.util.JobScheduler.JobHandle in project neo4j by neo4j.
the class Neo4jJobSchedulerTest method shouldCancelRecurringJob.
@Test
public void shouldCancelRecurringJob() throws Exception {
// Given
long period = 2;
life.start();
JobScheduler.JobHandle jobHandle = scheduler.scheduleRecurring(indexPopulation, countInvocationsJob, period, MILLISECONDS);
awaitFirstInvocation();
// When
jobHandle.cancel(false);
// Then
int recorded = invocations.get();
sleep(period * 100);
assertThat(invocations.get(), equalTo(recorded));
}
use of org.neo4j.kernel.impl.util.JobScheduler.JobHandle in project neo4j by neo4j.
the class RobustJobSchedulerWrapperTest method recurringJobWithErrorShouldStop.
@Test
public void recurringJobWithErrorShouldStop() throws Exception {
// given
RobustJobSchedulerWrapper robustWrapper = new RobustJobSchedulerWrapper(actualScheduler, log);
AtomicInteger count = new AtomicInteger();
Error e = new Error();
// when
JobHandle jobHandle = robustWrapper.scheduleRecurring("JobName", 1, () -> {
count.incrementAndGet();
throw e;
});
// when
// should not keep increasing during this time
Thread.sleep(50);
// then
assertEventually("run count", count::get, Matchers.equalTo(1), DEFAULT_TIMEOUT_MS, MILLISECONDS);
robustWrapper.cancelAndWaitTermination(jobHandle);
verify(log, timeout(DEFAULT_TIMEOUT_MS).times(1)).error("Uncaught error rethrown", e);
}
use of org.neo4j.kernel.impl.util.JobScheduler.JobHandle in project neo4j by neo4j.
the class RobustJobSchedulerWrapperTest method recurringJobWithExceptionShouldKeepRunning.
@Test
public void recurringJobWithExceptionShouldKeepRunning() throws Exception {
// given
RobustJobSchedulerWrapper robustWrapper = new RobustJobSchedulerWrapper(actualScheduler, log);
AtomicInteger count = new AtomicInteger();
IllegalStateException e = new IllegalStateException();
// when
int nRuns = 100;
JobHandle jobHandle = robustWrapper.scheduleRecurring("JobName", 1, () -> {
if (count.get() < nRuns) {
count.incrementAndGet();
throw e;
}
});
// then
assertEventually("run count", count::get, Matchers.equalTo(nRuns), DEFAULT_TIMEOUT_MS, MILLISECONDS);
robustWrapper.cancelAndWaitTermination(jobHandle);
verify(log, timeout(DEFAULT_TIMEOUT_MS).times(nRuns)).warn("Uncaught exception", e);
}
use of org.neo4j.kernel.impl.util.JobScheduler.JobHandle in project neo4j by neo4j.
the class RobustJobSchedulerWrapperTest method shouldBeAbleToCancelJob.
@Test
public void shouldBeAbleToCancelJob() throws Exception {
// given
RobustJobSchedulerWrapper robustWrapper = new RobustJobSchedulerWrapper(actualScheduler, log);
// when
AtomicInteger count = new AtomicInteger();
JobHandle jobHandle = robustWrapper.scheduleRecurring("JobName", 1, count::incrementAndGet);
assertEventually("run count", count::get, Matchers.greaterThanOrEqualTo(100), DEFAULT_TIMEOUT_MS, MILLISECONDS);
// then
robustWrapper.cancelAndWaitTermination(jobHandle);
int finalCount = count.get();
// when
// should not keep increasing during this time
Thread.sleep(50);
// then
assertEquals(finalCount, count.get());
}
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);
}
Aggregations