Search in sources :

Example 26 with TimerJobQuery

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

the class IntermediateTimerEventTest method testTimerEventWithStartAndDuration.

@Deployment
public void testTimerEventWithStartAndDuration() throws Exception {
    Calendar testStartCal = new GregorianCalendar(2016, 0, 1, 10, 0, 0);
    Date testStartTime = testStartCal.getTime();
    processEngineConfiguration.getClock().setCurrentTime(testStartTime);
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("timerEventWithStartAndDuration");
    List<Task> tasks = taskService.createTaskQuery().list();
    assertThat(tasks).hasSize(1);
    Task task = tasks.get(0);
    assertThat(task.getName()).isEqualTo("Task A");
    TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    assertThat(jobQuery.count()).isEqualTo(0);
    Date startDate = new Date();
    runtimeService.setVariable(pi.getId(), "StartDate", startDate);
    taskService.complete(task.getId());
    jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    assertThat(jobQuery.count()).isEqualTo(1);
    processEngineConfiguration.getClock().setCurrentTime(new Date(startDate.getTime() + 7000L));
    jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    assertThat(jobQuery.count()).isEqualTo(1);
    jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId()).executable();
    assertThat(jobQuery.count()).isEqualTo(0);
    processEngineConfiguration.getClock().setCurrentTime(new Date(startDate.getTime() + 11000L));
    waitForJobExecutorToProcessAllJobs(15000L, 25L);
    jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    assertThat(jobQuery.count()).isEqualTo(0);
    tasks = taskService.createTaskQuery().list();
    assertThat(tasks).hasSize(1);
    task = tasks.get(0);
    assertThat(task.getName()).isEqualTo("Task B");
    taskService.complete(task.getId());
    assertProcessEnded(pi.getProcessInstanceId());
    processEngineConfiguration.getClock().reset();
}
Also used : Task(org.activiti.engine.task.Task) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 27 with TimerJobQuery

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

the class IntermediateTimerEventTest method testCatchingTimerEvent.

@Deployment
public void testCatchingTimerEvent() throws Exception {
    // Set the clock fixed
    Date startTime = new Date();
    // After process start, there should be timer created
    ProcessInstance pi = runtimeService.startProcessInstanceByKey("intermediateTimerEventExample");
    TimerJobQuery jobQuery = managementService.createTimerJobQuery().processInstanceId(pi.getId());
    assertThat(jobQuery.count()).isEqualTo(1);
    // After setting the clock to time '50minutes and 5 seconds', the second timer should fire
    processEngineConfiguration.getClock().setCurrentTime(new Date(startTime.getTime() + ((50 * 60 * 1000) + 5000)));
    waitForJobExecutorToProcessAllJobs(5000L, 25L);
    assertThat(jobQuery.count()).isEqualTo(0);
    assertProcessEnded(pi.getProcessInstanceId());
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 28 with TimerJobQuery

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

the class StartTimerEventTest method testTimerShouldNotBeRemovedWhenUndeployingOldVersion.

// Test for ACT-1533
public void testTimerShouldNotBeRemovedWhenUndeployingOldVersion() throws Exception {
    // Deploy test process
    String processXml = new String(IoUtil.readInputStream(getClass().getResourceAsStream("StartTimerEventTest.testTimerShouldNotBeRemovedWhenUndeployingOldVersion.bpmn20.xml"), ""));
    String firstDeploymentId = repositoryService.createDeployment().addInputStream("StartTimerEventTest.testVersionUpgradeShouldCancelJobs.bpmn20.xml", new ByteArrayInputStream(processXml.getBytes())).deploy().getId();
    // After process start, there should be timer created
    TimerJobQuery jobQuery = managementService.createTimerJobQuery();
    assertThat(jobQuery.count()).isEqualTo(1);
    // we deploy new process version, with some small change
    String processChanged = processXml.replaceAll("beforeChange", "changed");
    String secondDeploymentId = repositoryService.createDeployment().addInputStream("StartTimerEventTest.testVersionUpgradeShouldCancelJobs.bpmn20.xml", new ByteArrayInputStream(processChanged.getBytes())).deploy().getId();
    assertThat(jobQuery.count()).isEqualTo(1);
    // Remove the first deployment
    repositoryService.deleteDeployment(firstDeploymentId, true);
    // The removal of an old version should not affect timer deletion
    // ACT-1533: this was a bug, and the timer was deleted!
    assertThat(jobQuery.count()).isEqualTo(1);
    // Cleanup
    cleanDB();
    repositoryService.deleteDeployment(secondDeploymentId, true);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery)

Example 29 with TimerJobQuery

use of org.activiti.engine.runtime.TimerJobQuery 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
    TimerJobQuery jobQuery = managementService.createTimerJobQuery();
    assertThat(jobQuery.count()).isEqualTo(1);
    moveByMinutes(6);
    String jobId = managementService.createTimerJobQuery().executable().singleResult().getId();
    managementService.moveTimerToExecutableJob(jobId);
    managementService.executeJob(jobId);
    assertThat(jobQuery.count()).isEqualTo(1);
    moveByMinutes(6);
    jobId = managementService.createTimerJobQuery().executable().singleResult().getId();
    managementService.moveTimerToExecutableJob(jobId);
    managementService.executeJob(jobId);
    assertThat(jobQuery.count()).isEqualTo(0);
}
Also used : Date(java.util.Date) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery) Deployment(org.activiti.engine.test.Deployment)

Example 30 with TimerJobQuery

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

the class StartTimerEventTest method testFixedDateStartTimerEvent.

@Deployment
public void testFixedDateStartTimerEvent() throws Exception {
    // After process start, there should be timer created
    TimerJobQuery jobQuery = managementService.createTimerJobQuery();
    assertThat(jobQuery.count()).isEqualTo(1);
    processEngineConfiguration.getClock().setCurrentTime(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse("15/11/2036 11:12:30"));
    waitForJobExecutorToProcessAllJobs(5000L, 200L);
    List<ProcessInstance> pi = runtimeService.createProcessInstanceQuery().processDefinitionKey("startTimerEventExample").list();
    assertThat(pi).hasSize(1);
    assertThat(jobQuery.count()).isEqualTo(0);
}
Also used : ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SimpleDateFormat(java.text.SimpleDateFormat) 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