}
@Test
public void testKillExistingDogpiles() throws Exception {
// Test that a trigger for a job that hasn't finished running is ignored.
final CronJobManager cronJobManager = injector.getInstance(CronJobManager.class);
final CountDownLatch firstExecutionTriggered = new CountDownLatch(1);
final CountDownLatch firstExecutionCompleted = new CountDownLatch(1);
final CountDownLatch secondExecutionTriggered = new CountDownLatch(1);
final CountDownLatch secondExecutionCompleted = new CountDownLatch(1);
auroraCronJob.execute(isA(JobExecutionContext.class));
expectLastCall().andAnswer(new IAnswer<Void>() {
@Override
public Void answer() throws Throwable {
firstExecutionTriggered.countDown();
firstExecutionCompleted.await();
return null;
}
});
auroraCronJob.execute(isA(JobExecutionContext.class));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Void answer() throws Throwable {
secondExecutionTriggered.countDown();
secondExecutionCompleted.await();
return null;
}
});
control.replay();
boot();
cronJobManager.createJob(SanitizedCronJob.fromUnsanitized(CRON_JOB));
cronJobManager.startJobNow(JOB_KEY);
firstExecutionTriggered.await();
cronJobManager.startJobNow(JOB_KEY);
assertEquals(1, secondExecutionTriggered.getCount());
firstExecutionCompleted.countDown();
secondExecutionTriggered.await();
secondExecutionTriggered.countDown();
}