use of org.activiti.engine.impl.persistence.entity.TimerEntity in project Activiti by Activiti.
the class ActivityEventsTest method testActivityTimeOutEventInCallActivity.
@Deployment
public void testActivityTimeOutEventInCallActivity() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("timerOnCallActivity");
Job theJob = managementService.createJobQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(theJob);
// Force timer to fire
Calendar timeToFire = Calendar.getInstance();
timeToFire.add(Calendar.HOUR, 2);
timeToFire.add(Calendar.SECOND, 5);
processEngineConfiguration.getClock().setCurrentTime(timeToFire.getTime());
waitForJobExecutorToProcessAllJobs(20000, 500);
// Check timeout-events have been dispatched
assertEquals(4, listener.getEventsReceived().size());
List<String> eventIdList = new ArrayList<String>();
for (ActivitiEvent event : listener.getEventsReceived()) {
assertEquals(ActivitiEventType.ACTIVITY_CANCELLED, event.getType());
assertTrue("TIMER is the cause of the cancellation", ((ActivitiActivityCancelledEvent) event).getCause() instanceof TimerEntity);
eventIdList.add(((ActivitiActivityEventImpl) event).getActivityId());
}
assertTrue(eventIdList.indexOf("innerTask1") >= 0);
assertTrue(eventIdList.indexOf("innerTask2") >= 0);
assertTrue(eventIdList.indexOf("innerFork") >= 0);
assertTrue(eventIdList.indexOf("callActivity") >= 0);
}
use of org.activiti.engine.impl.persistence.entity.TimerEntity in project Activiti by Activiti.
the class JobQueryTest method createJobWithoutExceptionStacktrace.
private void createJobWithoutExceptionStacktrace() {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
JobEntityManager jobManager = commandContext.getJobEntityManager();
timerEntity = new TimerEntity();
timerEntity.setLockOwner(UUID.randomUUID().toString());
timerEntity.setDuedate(new Date());
timerEntity.setRetries(0);
timerEntity.setExceptionMessage("I'm supposed to fail");
jobManager.insert(timerEntity);
assertNotNull(timerEntity.getId());
return null;
}
});
}
use of org.activiti.engine.impl.persistence.entity.TimerEntity 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());
}
use of org.activiti.engine.impl.persistence.entity.TimerEntity in project Activiti by Activiti.
the class ProcessInstanceSuspensionTest method testSuspendedProcessTimerExecution.
@Deployment
public void testSuspendedProcessTimerExecution() throws Exception {
// Process with boundary timer-event that fires in 1 hour
ProcessInstance procInst = runtimeService.startProcessInstanceByKey("suspendProcess");
assertNotNull(procInst);
assertEquals(1, managementService.createJobQuery().processInstanceId(procInst.getId()).count());
// Roll time ahead to be sure timer is due to fire
Calendar tomorrow = Calendar.getInstance();
tomorrow.add(Calendar.DAY_OF_YEAR, 1);
processEngineConfiguration.getClock().setCurrentTime(tomorrow.getTime());
// Check if timer is eligable to be executed, when process in not yet suspended
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutor();
List<TimerEntity> jobs = commandExecutor.execute(new GetUnlockedTimersByDuedateCmd(processEngineConfiguration.getClock().getCurrentTime(), new Page(0, 1)));
assertEquals(1, jobs.size());
// Suspend process instancd
runtimeService.suspendProcessInstanceById(procInst.getId());
// Check if the timer is NOT aquired, even though the duedate is reached
jobs = commandExecutor.execute(new GetUnlockedTimersByDuedateCmd(processEngineConfiguration.getClock().getCurrentTime(), new Page(0, 1)));
assertEquals(0, jobs.size());
}
use of org.activiti.engine.impl.persistence.entity.TimerEntity in project Activiti by Activiti.
the class ProcessDefinitionEventsTest method testTimerStartEventDeployment.
/**
* test sequence of events for process definition with timer start event
*/
@Deployment(resources = { "org/activiti/engine/test/bpmn/event/timer/StartTimerEventTest.testDurationStartTimerEvent.bpmn20.xml" })
public void testTimerStartEventDeployment() {
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery().processDefinitionKey("startTimerEventExample").singleResult();
ActivitiEntityEvent processDefinitionCreated = ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, processDefinition);
TimerEntity timer = (TimerEntity) managementService.createJobQuery().singleResult();
ActivitiEntityEvent timerCreated = ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, timer);
assertSequence(processDefinitionCreated, timerCreated);
listener.clearEventsReceived();
}
Aggregations