Search in sources :

Example 96 with Job

use of org.activiti.engine.runtime.Job 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
    JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId());
    List<Job> jobs = jobQuery.list();
    assertEquals(0, jobs.size());
    // which means the process is still running waiting for human task input.
    ProcessInstance processInstance = processEngine.getRuntimeService().createProcessInstanceQuery().processInstanceId(pi.getId()).singleResult();
    assertNotNull(processInstance);
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JobQuery(org.activiti.engine.runtime.JobQuery) Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Example 97 with Job

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

the class BoundaryTimerEventTest method testRepeatTimerDuration.

@Deployment
public void testRepeatTimerDuration() throws Exception {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyy.MM.dd hh:mm");
    Date currentTime = simpleDateFormat.parse("2015.10.01 11:01");
    processEngineConfiguration.getClock().setCurrentTime(currentTime);
    runtimeService.startProcessInstanceByKey("repeattimertest");
    long twentyFourHours = 24L * 60L * 60L * 1000L;
    Date previousDueDate = null;
    // Move clock, job should fire
    for (int i = 0; i < 3; i++) {
        Job job = managementService.createJobQuery().singleResult();
        // Verify due date
        if (previousDueDate != null) {
            assertTrue(job.getDuedate().getTime() - previousDueDate.getTime() >= twentyFourHours);
        }
        previousDueDate = job.getDuedate();
        currentTime = new Date(currentTime.getTime() + twentyFourHours + (60 * 1000));
        processEngineConfiguration.getClock().setCurrentTime(currentTime);
        managementService.executeJob(job.getId());
    }
}
Also used : Job(org.activiti.engine.runtime.Job) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 98 with Job

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

the class BoundaryTimerEventTest method testBoundaryTimerEvent2.

@Deployment
public void testBoundaryTimerEvent2() throws Exception {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyy.MM.dd hh:mm");
    Date currentTime = simpleDateFormat.parse("2015.10.01 11:01");
    processEngineConfiguration.getClock().setCurrentTime(currentTime);
    runtimeService.startProcessInstanceByKey("timerprocess");
    // just wait for 2 seconds to run any job if it's the case
    try {
        waitForJobExecutorToProcessAllJobs(2000, 200);
    } catch (Exception ex) {
    //expected exception because the boundary timer event created a timer job to be executed after 10 minutes
    }
    // there should be a userTask waiting for user input
    List<Task> tasks = taskService.createTaskQuery().list();
    assertEquals(1, tasks.size());
    assertEquals("Start", tasks.get(0).getName());
    List<Job> jobList = managementService.createJobQuery().list();
    assertEquals(1, jobList.size());
    // after another 2 minutes
    long tenMinutes = 2L * 60L * 1000L;
    currentTime = new Date(currentTime.getTime() + tenMinutes);
    processEngineConfiguration.getClock().setCurrentTime(currentTime);
    try {
        waitForJobExecutorToProcessAllJobs(2000, 200);
    } catch (Exception ex) {
        ex.getCause();
    //expected exception because a new job is prepared
    }
    // there should be no userTask
    tasks = taskService.createTaskQuery().list();
    assertEquals(0, tasks.size());
    jobList = managementService.createJobQuery().list();
    assertEquals(0, jobList.size());
}
Also used : Task(org.activiti.engine.task.Task) Job(org.activiti.engine.runtime.Job) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 99 with Job

use of org.activiti.engine.runtime.Job 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());
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JobQuery(org.activiti.engine.runtime.JobQuery) Job(org.activiti.engine.runtime.Job) Date(java.util.Date) Deployment(org.activiti.engine.test.Deployment)

Example 100 with Job

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

the class BoundaryTimerEventTest method testRepeatingTimerWithCancelActivity.

@Deployment
public void testRepeatingTimerWithCancelActivity() {
    runtimeService.startProcessInstanceByKey("repeatingTimerAndCallActivity");
    assertEquals(1, managementService.createJobQuery().count());
    assertEquals(1, taskService.createTaskQuery().count());
    // Firing job should cancel the user task, destroy the scope,
    // re-enter the task and recreate the task. A new timer should also be created.
    // This didn't happen before 5.11 (new jobs kept being created). See ACT-1427
    Job job = managementService.createJobQuery().singleResult();
    managementService.executeJob(job.getId());
    assertEquals(1, managementService.createJobQuery().count());
    assertEquals(1, taskService.createTaskQuery().count());
}
Also used : Job(org.activiti.engine.runtime.Job) Deployment(org.activiti.engine.test.Deployment)

Aggregations

Job (org.activiti.engine.runtime.Job)110 Deployment (org.activiti.engine.test.Deployment)76 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)55 Task (org.activiti.engine.task.Task)39 Date (java.util.Date)23 Calendar (java.util.Calendar)16 DelegateTask (org.activiti.engine.delegate.DelegateTask)11 HashMap (java.util.HashMap)10 ActivitiEvent (org.activiti.engine.delegate.event.ActivitiEvent)10 JobQuery (org.activiti.engine.runtime.JobQuery)8 ActivitiException (org.activiti.engine.ActivitiException)6 SimpleDateFormat (java.text.SimpleDateFormat)5 ArrayList (java.util.ArrayList)5 DefaultClockImpl (org.activiti.engine.impl.util.DefaultClockImpl)5 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)5 Clock (org.activiti.engine.runtime.Clock)5 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)4