}
private void triggerDataPurgeJobNow() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
SchedulerLocal schedulerBean = LookupUtil.getSchedulerBean();
schedulerBean.scheduleSimpleCronJob(DataPurgeJob.class, true, false, "0 0 0 1 1 ? 2099", null);
schedulerBean.addGlobalJobListener(new JobListener() {
@Override
public String getName() {
return "DataPurgeJobTestListener";
}
@Override
public void jobExecutionVetoed(JobExecutionContext arg0) {
}
@Override
public void jobToBeExecuted(JobExecutionContext arg0) {
}
@Override
public void jobWasExecuted(JobExecutionContext c, JobExecutionException e) {
if (c.getJobDetail().getJobClass().getName().equals(DataPurgeJob.class.getName())) {
latch.countDown(); // the data purge job is finished! let our test continue
}
}
});
try {
// trigger the data purge job so it executes immediately - this does not block
DataPurgeJob.purgeNow();
// wait for the job to finish - abort the test if it takes too long
assertTrue("Data purge job didn't complete in a timely fashion", latch.await(60, TimeUnit.SECONDS));
} finally {
schedulerBean.deleteJob(DataPurgeJob.class.getName(), DataPurgeJob.class.getName());
}
}