Search in sources :

Example 1 with ExecuteAsyncJobCmd

use of org.activiti.engine.impl.cmd.ExecuteAsyncJobCmd 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));
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
    String jobId = commandExecutor.execute(new Command<String>() {

        public String execute(CommandContext commandContext) {
            TimerEntity timer = createTweetTimer("i'm coding a test", new Date(SOME_TIME + (10 * SECOND)));
            commandContext.getJobEntityManager().schedule(timer);
            return timer.getId();
        }
    });
    AcquiredJobEntities acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd("testLockOwner", 10000, 5));
    assertEquals(0, acquiredJobs.size());
    processEngineConfiguration.getClock().setCurrentTime(new Date(SOME_TIME + (20 * SECOND)));
    acquiredJobs = commandExecutor.execute(new AcquireTimerJobsCmd("testLockOwner", 10000, 5));
    assertEquals(1, acquiredJobs.size());
    JobEntity job = acquiredJobs.getJobs().iterator().next();
    assertEquals(jobId, job.getId());
    assertEquals(0, tweetHandler.getMessages().size());
    commandExecutor.execute(new ExecuteAsyncJobCmd(job));
    assertEquals("i'm coding a test", tweetHandler.getMessages().get(0));
    assertEquals(1, tweetHandler.getMessages().size());
}
Also used : AcquiredJobEntities(org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities) JobEntity(org.activiti.engine.impl.persistence.entity.JobEntity) CommandContext(org.activiti.engine.impl.interceptor.CommandContext) TimerEntity(org.activiti.engine.impl.persistence.entity.TimerEntity) CommandExecutor(org.activiti.engine.impl.interceptor.CommandExecutor) ExecuteAsyncJobCmd(org.activiti.engine.impl.cmd.ExecuteAsyncJobCmd) Date(java.util.Date) AcquireTimerJobsCmd(org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)

Aggregations

Date (java.util.Date)1 AcquiredJobEntities (org.activiti.engine.impl.asyncexecutor.AcquiredJobEntities)1 AcquireTimerJobsCmd (org.activiti.engine.impl.cmd.AcquireTimerJobsCmd)1 ExecuteAsyncJobCmd (org.activiti.engine.impl.cmd.ExecuteAsyncJobCmd)1 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)1 CommandExecutor (org.activiti.engine.impl.interceptor.CommandExecutor)1 JobEntity (org.activiti.engine.impl.persistence.entity.JobEntity)1 TimerEntity (org.activiti.engine.impl.persistence.entity.TimerEntity)1