Search in sources :

Example 21 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class BoundaryTimerEventTest method testNullExpressionOnTimer.

@Deployment
public void testNullExpressionOnTimer() {
    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put("duration", null);
    // After process start, there should be a timer created
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("testNullExpressionOnTimer", variables);
    // NO job scheduled as null expression set
    TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    List<Job> jobs = jobQuery.list();
    assertThat(jobs).hasSize(0);
    // which means the process is still running waiting for human task input.
    ProcessInstance processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult();
    assertThat(processInstance).isNotNull();
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 22 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery 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");
    TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    List<Job> jobs = jobQuery.list();
    assertThat(jobs).hasSize(3);
    // 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);
    assertThat(jobQuery.count()).isEqualTo(0L);
    // which means that the third task is reached
    Task task = taskService.createTaskQuery().singleResult();
    assertThat(task.getName()).isEqualTo("Third Task");
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 23 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery 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();
    assertThat(task1.getName()).isEqualTo("Main Task");
    TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    List<Job> jobs = jobQuery.list();
    assertThat(jobs).hasSize(1);
    // 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
    assertThat(jobQuery.count()).isEqualTo(0L);
    // we now have both tasks
    assertThat(taskService.createTaskQuery().count()).isEqualTo(2L);
    // end the first
    taskService.complete(task1.getId());
    // we now have one task left
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1L);
    Task task2 = taskService.createTaskQuery().singleResult();
    assertThat(task2.getName()).isEqualTo("Escalation Task");
    // complete the task, the parallel gateway should fire
    taskService.complete(task2.getId());
    // and the process has ended
    assertProcessEnded(pi.getId());
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 24 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery 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();
    assertThat(task1.getName()).isEqualTo("First Task");
    TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    List<Job> jobs = jobQuery.list();
    assertThat(jobs).hasSize(2);
    // 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.createTimerJobQuery().executable().singleResult();
    assertThat(job).isNotNull();
    managementService.moveTimerToExecutableJob(job.getId());
    managementService.executeJob(job.getId());
    // we still have one timer more to fire
    assertThat(jobQuery.count()).isEqualTo(1L);
    // and we are still in the first state, but in the second state as well!
    assertThat(taskService.createTaskQuery().count()).isEqualTo(2L);
    List<Task> taskList = taskService.createTaskQuery().orderByTaskName().desc().list();
    assertThat(taskList.get(0).getName()).isEqualTo("First Task");
    assertThat(taskList.get(1).getName()).isEqualTo("Escalation Task 1");
    // complete the task and end the forked execution
    taskService.complete(taskList.get(1).getId());
    // but we still have the original executions
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1L);
    assertThat(taskService.createTaskQuery().singleResult().getName()).isEqualTo("First Task");
    // 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
    assertThat(jobQuery.count()).isEqualTo(0L);
    // and we are still in the first state, but in the next escalation state as well
    assertThat(taskService.createTaskQuery().count()).isEqualTo(2L);
    taskList = taskService.createTaskQuery().orderByTaskName().desc().list();
    assertThat(taskList.get(0).getName()).isEqualTo("First Task");
    assertThat(taskList.get(1).getName()).isEqualTo("Escalation Task 2");
    // This time we end the main task
    taskService.complete(taskList.get(0).getId());
    // but we still have the escalation task
    assertThat(taskService.createTaskQuery().count()).isEqualTo(1L);
    Task escalationTask = taskService.createTaskQuery().singleResult();
    assertThat(escalationTask.getName()).isEqualTo("Escalation Task 2");
    taskService.complete(escalationTask.getId());
    // now we are really done :-)
    assertProcessEnded(pi.getId());
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 25 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery in project Activiti by Activiti.

the class BoundaryTimerNonInterruptingEventTest method testReceiveTaskWithBoundaryTimer.

@Deployment
public /**
 * see https://activiti.atlassian.net/browse/ACT-1106
 */
void testReceiveTaskWithBoundaryTimer() {
    // Set the clock fixed
    HashMap<String, Object> variables = new HashMap<String, Object>();
    variables.put("timeCycle", "R/PT1H");
    // After process start, there should be a timer created
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("nonInterruptingCycle", variables);
    TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    List<Job> jobs = jobQuery.list();
    assertThat(jobs).hasSize(1);
    // The Execution Query should work normally and find executions in state "task"
    List<Execution> executions = runtimeService.createExecutionQuery().activityId("task").list();
    assertThat(executions).hasSize(1);
    List<String> activeActivityIds = runtimeService.getActiveActivityIds(executions.get(0).getId());
    assertThat(activeActivityIds).hasSize(2);
    Collections.sort(activeActivityIds);
    assertThat(activeActivityIds.get(0)).isEqualTo("task");
    assertThat(activeActivityIds.get(1)).isEqualTo("timer");
    runtimeService.trigger(executions.get(0).getId());
    // // 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);
    // assertThat(jobQuery.count()).isEqualTo(0L);
    // which means the process has ended
    assertProcessEnded(pi.getId());
}
Also used : Execution(org.activiti.engine.runtime.Execution) HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Aggregations

TimerJobQuery (org.activiti.engine.runtime.TimerJobQuery)35 Deployment (org.activiti.engine.test.Deployment)20 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)18 Date (java.util.Date)16 Job (org.activiti.engine.runtime.Job)10 JobQuery (org.activiti.engine.runtime.JobQuery)7 Task (org.activiti.engine.task.Task)5 HashMap (java.util.HashMap)3 Execution (org.activiti.engine.runtime.Execution)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 ProcessInstanceQuery (org.activiti.engine.runtime.ProcessInstanceQuery)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 List (java.util.List)1 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)1 Test (org.junit.Test)1