use of org.activiti.engine.runtime.JobQuery in project Activiti by Activiti.
the class BoundaryTimerEventTest method testMultipleTimersOnUserTask.
/*
* Test for when multiple boundary timer events are defined on the same user
* task
*
* Configuration: - timer 1 -> 2 hours -> secondTask - timer 2 -> 1 hour ->
* thirdTask - timer 3 -> 3 hours -> fourthTask
*
* See process image next to the process xml resource
*/
@Deployment
public void testMultipleTimersOnUserTask() {
// Set the clock fixed
Date startTime = new Date();
// After process start, there should be 3 timers created
ProcessInstance pi = runtimeService.startProcessInstanceByKey("multipleTimersOnUserTask");
JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId());
List<Job> jobs = jobQuery.list();
assertEquals(3, jobs.size());
// After setting the clock to time '1 hour and 5 seconds', the second timer should fire
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
waitForJobExecutorToProcessAllJobs(5000L, 25L);
assertEquals(0L, jobQuery.count());
// which means that the third task is reached
Task task = taskService.createTaskQuery().singleResult();
assertEquals("Third Task", task.getName());
}
use of org.activiti.engine.runtime.JobQuery in project Activiti by Activiti.
the class BoundaryTimerNonInterruptingEventTest method testMultipleTimersOnUserTask.
@Deployment
public void testMultipleTimersOnUserTask() {
// Set the clock fixed
Date startTime = new Date();
// After process start, there should be 3 timers created
ProcessInstance pi = runtimeService.startProcessInstanceByKey("nonInterruptingTimersOnUserTask");
Task task1 = taskService.createTaskQuery().singleResult();
assertEquals("First Task", task1.getName());
JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId());
List<Job> jobs = jobQuery.list();
assertEquals(2, jobs.size());
// After setting the clock to time '1 hour and 5 seconds', the first timer should fire
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
Job job = managementService.createJobQuery().executable().singleResult();
assertNotNull(job);
managementService.executeJob(job.getId());
// we still have one timer more to fire
assertEquals(1L, jobQuery.count());
// and we are still in the first state, but in the second state as well!
assertEquals(2L, taskService.createTaskQuery().count());
List<Task> taskList = taskService.createTaskQuery().orderByTaskName().desc().list();
assertEquals("First Task", taskList.get(0).getName());
assertEquals("Escalation Task 1", taskList.get(1).getName());
// complete the task and end the forked execution
taskService.complete(taskList.get(1).getId());
// but we still have the original executions
assertEquals(1L, taskService.createTaskQuery().count());
assertEquals("First Task", taskService.createTaskQuery().singleResult().getName());
// After setting the clock to time '2 hour and 5 seconds', the second timer should fire
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((2 * 60 * 60 * 1000) + 5000)));
waitForJobExecutorToProcessAllJobs(5000L, 25L);
// no more timers to fire
assertEquals(0L, jobQuery.count());
// and we are still in the first state, but in the next escalation state as well
assertEquals(2L, taskService.createTaskQuery().count());
taskList = taskService.createTaskQuery().orderByTaskName().desc().list();
assertEquals("First Task", taskList.get(0).getName());
assertEquals("Escalation Task 2", taskList.get(1).getName());
// This time we end the main task
taskService.complete(taskList.get(0).getId());
// but we still have the escalation task
assertEquals(1L, taskService.createTaskQuery().count());
Task escalationTask = taskService.createTaskQuery().singleResult();
assertEquals("Escalation Task 2", escalationTask.getName());
taskService.complete(escalationTask.getId());
// now we are really done :-)
assertProcessEnded(pi.getId());
}
use of org.activiti.engine.runtime.JobQuery in project Activiti by Activiti.
the class BoundaryTimerNonInterruptingEventTest method testJoin.
@Deployment
public void testJoin() {
// Set the clock fixed
Date startTime = new Date();
// After process start, there should be 3 timers created
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testJoin");
Task task1 = taskService.createTaskQuery().singleResult();
assertEquals("Main Task", task1.getName());
JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId());
List<Job> jobs = jobQuery.list();
assertEquals(1, jobs.size());
// After setting the clock to time '1 hour and 5 seconds', the first timer should fire
processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((60 * 60 * 1000) + 5000)));
waitForJobExecutorToProcessAllJobs(5000L, 25L);
// timer has fired
assertEquals(0L, jobQuery.count());
// we now have both tasks
assertEquals(2L, taskService.createTaskQuery().count());
// end the first
taskService.complete(task1.getId());
// we now have one task left
assertEquals(1L, taskService.createTaskQuery().count());
Task task2 = taskService.createTaskQuery().singleResult();
assertEquals("Escalation Task", task2.getName());
// complete the task, the parallel gateway should fire
taskService.complete(task2.getId());
// and the process has ended
assertProcessEnded(pi.getId());
}
use of org.activiti.engine.runtime.JobQuery in project Activiti by Activiti.
the class StartTimerEventTest method testVersionUpgradeShouldCancelJobs.
@Deployment
public void testVersionUpgradeShouldCancelJobs() throws Exception {
processEngineConfiguration.getClock().setCurrentTime(new Date());
// After process start, there should be timer created
JobQuery jobQuery = managementService.createJobQuery();
assertEquals(1, jobQuery.count());
//we deploy new process version, with some small change
String process = new String(IoUtil.readInputStream(getClass().getResourceAsStream("StartTimerEventTest.testVersionUpgradeShouldCancelJobs.bpmn20.xml"), "")).replaceAll("beforeChange", "changed");
String id = repositoryService.createDeployment().addInputStream("StartTimerEventTest.testVersionUpgradeShouldCancelJobs.bpmn20.xml", new ByteArrayInputStream(process.getBytes())).deploy().getId();
assertEquals(1, jobQuery.count());
moveByMinutes(5);
waitForJobExecutorOnCondition(10000, 500, new Callable<Boolean>() {
public Boolean call() throws Exception {
//we check that correct version was started
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample").singleResult();
if (processInstance != null) {
String pi = processInstance.getProcessInstanceId();
return "changed".equals(runtimeService.getActiveActivityIds(pi).get(0));
} else {
return false;
}
}
});
assertEquals(1, jobQuery.count());
cleanDB();
repositoryService.deleteDeployment(id, true);
}
use of org.activiti.engine.runtime.JobQuery in project Activiti by Activiti.
the class StartTimerEventTest method testCycleWithLimitStartTimerEvent.
@Deployment
public void testCycleWithLimitStartTimerEvent() throws Exception {
processEngineConfiguration.getClock().setCurrentTime(new Date());
// After process start, there should be timer created
JobQuery jobQuery = managementService.createJobQuery();
assertEquals(1, jobQuery.count());
moveByMinutes(6);
managementService.executeJob(managementService.createJobQuery().singleResult().getId());
assertEquals(1, jobQuery.count());
moveByMinutes(6);
managementService.executeJob(managementService.createJobQuery().singleResult().getId());
assertEquals(0, jobQuery.count());
}
Aggregations