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();
}
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());
}
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);
}
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);
}
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);
}
Aggregations