use of org.activiti.engine.impl.asyncexecutor.AcquiredTimerJobEntities in project Activiti by Activiti.
the class AcquireTimerJobsCmd method execute.
public AcquiredTimerJobEntities execute(CommandContext commandContext) {
AcquiredTimerJobEntities acquiredJobs = new AcquiredTimerJobEntities();
List<TimerJobEntity> timerJobs = commandContext.getTimerJobEntityManager().findTimerJobsToExecute(new Page(0, asyncExecutor.getMaxAsyncJobsDuePerAcquisition()));
for (TimerJobEntity job : timerJobs) {
lockJob(commandContext, job, asyncExecutor.getAsyncJobLockTimeInMillis());
acquiredJobs.addJob(job);
}
return acquiredJobs;
}
use of org.activiti.engine.impl.asyncexecutor.AcquiredTimerJobEntities in project Activiti by Activiti.
the class JobExecutorCmdHappyTest method testJobCommandsWithTimer.
public void testJobCommandsWithTimer() {
// clock gets automatically reset in LogTestCase.runTest
processEngineConfiguration.getClock().setCurrentTime(new Date(SOME_TIME));
AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
String jobId = commandExecutor.execute(new Command<String>() {
public String execute(CommandContext commandContext) {
TimerJobEntity timer = createTweetTimer("i'm coding a test", new Date(SOME_TIME + (10 * SECOND)));
commandContext.getJobManager().scheduleTimerJob(timer);
return timer.getId();
}
});
AcquiredTimerJobEntities acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd(asyncExecutor));
assertThat(acquiredJobs.size()).isEqualTo(0);
processEngineConfiguration.getClock().setCurrentTime(new Date(SOME_TIME + (20 * SECOND)));
acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd(asyncExecutor));
assertThat(acquiredJobs.size()).isEqualTo(1);
TimerJobEntity job = acquiredJobs.getJobs().iterator().next();
assertThat(job.getId()).isEqualTo(jobId);
assertThat(tweetHandler.getMessages()).hasSize(0);
Job executableJob = managementService.moveTimerToExecutableJob(jobId);
commandExecutor.execute(new ExecuteAsyncJobCmd(executableJob.getId()));
assertThat(tweetHandler.getMessages().get(0)).isEqualTo("i'm coding a test");
assertThat(tweetHandler.getMessages()).hasSize(1);
}
Aggregations