use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.
the class TimerManager method scheduleTimers.
protected void scheduleTimers(ProcessDefinitionEntity processDefinition, Process process) {
JobManager jobManager = Context.getCommandContext().getJobManager();
List<TimerJobEntity> timers = getTimerDeclarations(processDefinition, process);
for (TimerJobEntity timer : timers) {
jobManager.scheduleTimerJob(timer);
}
}
use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.
the class ProcessDefinitionEventsTest method testTimerStartEventDeployment.
/**
* test sequence of events for process definition with timer start event
*/
@Deployment(resources = { "org/activiti/engine/test/bpmn/event/timer/StartTimerEventTest.testDurationStartTimerEvent.bpmn20.xml" })
public void testTimerStartEventDeployment() {
ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.createProcessDefinitionQuery().processDefinitionKey("startTimerEventExample").singleResult();
ActivitiEntityEvent processDefinitionCreated = ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, processDefinition);
TimerJobEntity timer = (TimerJobEntity) managementService.createTimerJobQuery().singleResult();
ActivitiEntityEvent timerCreated = ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED, timer);
assertSequence(processDefinitionCreated, timerCreated);
listener.clearEventsReceived();
}
use of org.activiti.engine.impl.persistence.entity.TimerJobEntity in project Activiti by Activiti.
the class BoundaryTimerEventRepeatCompatibilityTest method testRepeatWithoutEnd.
@Deployment
public void testRepeatWithoutEnd() throws Throwable {
Calendar calendar = Calendar.getInstance();
Date baseTime = calendar.getTime();
calendar.add(Calendar.MINUTE, 20);
// expect to stop boundary jobs after 20 minutes
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
DateTime dt = new DateTime(calendar.getTime());
String dateStr = fmt.print(dt);
// reset the timer
Calendar nextTimeCal = Calendar.getInstance();
nextTimeCal.setTime(baseTime);
processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("repeatWithEnd");
runtimeService.setVariable(processInstance.getId(), "EndDateForBoundary", dateStr);
List<Task> tasks = taskService.createTaskQuery().list();
assertThat(tasks).hasSize(1);
Task task = tasks.get(0);
assertThat(task.getName()).isEqualTo("Task A");
// Test Boundary Events
// complete will cause timer to be created
taskService.complete(task.getId());
List<Job> jobs = managementService.createTimerJobQuery().list();
assertThat(jobs).hasSize(1);
// change the job in old mode (the configuration should not be json in
// "old mode" but a simple string).
TimerJobEntity job = (TimerJobEntity) jobs.get(0);
changeConfigurationToPlainText(job);
// boundary events
waitForJobExecutorToProcessAllJobs(2000, 100);
// a new job must be prepared because there are 10 repeats 2 seconds interval
jobs = managementService.createTimerJobQuery().list();
assertThat(jobs).hasSize(1);
for (int i = 0; i < 9; i++) {
nextTimeCal.add(Calendar.SECOND, 2);
processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
waitForJobExecutorToProcessAllJobs(2000, 100);
// a new job must be prepared because there are 10 repeats 2 seconds interval
jobs = managementService.createTimerJobQuery().list();
assertThat(jobs).hasSize(1);
}
nextTimeCal.add(Calendar.SECOND, 2);
processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
try {
waitForJobExecutorToProcessAllJobs(2000, 100);
} catch (Exception ex) {
fail("Should not have any other jobs because the endDate is reached");
}
tasks = taskService.createTaskQuery().list();
task = tasks.get(0);
assertThat(task.getName()).isEqualTo("Task B");
assertThat(tasks).hasSize(1);
taskService.complete(task.getId());
try {
waitForJobExecutorToProcessAllJobs(2000, 500);
} catch (Exception e) {
fail("No jobs should be active here.");
}
// now All the process instances should be completed
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
assertThat(processInstances).hasSize(0);
// no jobs
jobs = managementService.createJobQuery().list();
assertThat(jobs).hasSize(0);
jobs = managementService.createTimerJobQuery().list();
assertThat(jobs).hasSize(0);
// no tasks
tasks = taskService.createTaskQuery().list();
assertThat(tasks).hasSize(0);
}
Aggregations