use of org.camunda.bpm.engine.runtime.Job in project camunda-bpm-platform by camunda.
the class MigrationBoundaryEventsTest method testMigrateTimerBoundaryEventKeepTrigger.
@Test
public void testMigrateTimerBoundaryEventKeepTrigger() {
// given
BpmnModelInstance sourceProcess = modify(ProcessModels.ONE_TASK_PROCESS).activityBuilder(USER_TASK_ID).boundaryEvent(BOUNDARY_ID).timerWithDuration("PT5S").userTask(AFTER_BOUNDARY_TASK).endEvent().done();
BpmnModelInstance targetProcess = modify(ProcessModels.ONE_TASK_PROCESS).activityBuilder(USER_TASK_ID).boundaryEvent(BOUNDARY_ID).timerWithDuration("PT10M").userTask(AFTER_BOUNDARY_TASK).endEvent().done();
ProcessDefinition sourceProcessDefinition = testHelper.deployAndGetDefinition(sourceProcess);
ProcessDefinition targetProcessDefinition = testHelper.deployAndGetDefinition(targetProcess);
Map<String, String> activities = new HashMap<String, String>();
activities.put(USER_TASK_ID, USER_TASK_ID);
activities.put(BOUNDARY_ID, BOUNDARY_ID);
MigrationPlan migrationPlan = rule.getRuntimeService().createMigrationPlan(sourceProcessDefinition.getId(), targetProcessDefinition.getId()).mapActivities(USER_TASK_ID, USER_TASK_ID).mapActivities(BOUNDARY_ID, BOUNDARY_ID).build();
// when
testHelper.createProcessInstanceAndMigrate(migrationPlan);
// then
testHelper.assertJobMigrated(BOUNDARY_ID, BOUNDARY_ID, TimerExecuteNestedActivityJobHandler.TYPE);
// and it is possible to trigger the event and successfully complete the migrated instance
ManagementService managementService = rule.getManagementService();
Job job = managementService.createJobQuery().singleResult();
managementService.executeJob(job.getId());
testHelper.completeTask(AFTER_BOUNDARY_TASK);
testHelper.assertProcessEnded(testHelper.snapshotBeforeMigration.getProcessInstanceId());
}
use of org.camunda.bpm.engine.runtime.Job in project camunda-bpm-platform by camunda.
the class ConditionalEventTriggeredByExecutionListenerTest method testNonInterruptingSetVariableInTakeListenerWithAsyncBefore.
@Test
public void testNonInterruptingSetVariableInTakeListenerWithAsyncBefore() {
BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent(START_EVENT_ID).userTask(TASK_BEFORE_CONDITION_ID).name(TASK_BEFORE_CONDITION).sequenceFlowId(FLOW_ID).userTask(TASK_WITH_CONDITION_ID).name(TASK_WITH_CONDITION).camundaAsyncBefore().endEvent(END_EVENT_ID).done();
CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
listener.setCamundaExpression(EXPR_SET_VARIABLE);
modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
modelInstance = specifier.specifyConditionalProcess(modelInstance, false);
engine.manageDeployment(repositoryService.createDeployment().addModelInstance(CONDITIONAL_MODEL, modelInstance).deploy());
// given
ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
// when task is completed
taskService.complete(taskQuery.singleResult().getId());
// then take listener sets variable
// non interrupting boundary event is triggered
specifier.assertTaskNames(taskQuery.list(), false, true);
// and job was created
Job job = engine.getManagementService().createJobQuery().singleResult();
assertNotNull(job);
assertEquals(1, conditionEventSubscriptionQuery.list().size());
// when job is executed task is created
engine.getManagementService().executeJob(job.getId());
// when tasks are completed
for (Task task : taskQuery.list()) {
taskService.complete(task.getId());
}
// then no task exist and process instance is ended
tasksAfterVariableIsSet = taskQuery.list();
assertEquals(0, tasksAfterVariableIsSet.size());
assertNull(runtimeService.createProcessInstanceQuery().singleResult());
}
use of org.camunda.bpm.engine.runtime.Job in project camunda-bpm-platform by camunda.
the class CallActivityTest method testTimerOnCallActivity.
@Deployment(resources = { "org/camunda/bpm/engine/test/bpmn/callactivity/CallActivity.testTimerOnCallActivity.bpmn20.xml", "org/camunda/bpm/engine/test/bpmn/callactivity/simpleSubProcess.bpmn20.xml" })
public void testTimerOnCallActivity() {
// After process start, the task in the subprocess should be active
runtimeService.startProcessInstanceByKey("timerOnCallActivity");
TaskQuery taskQuery = taskService.createTaskQuery();
Task taskInSubProcess = taskQuery.singleResult();
assertEquals("Task in subprocess", taskInSubProcess.getName());
Job timer = managementService.createJobQuery().singleResult();
assertNotNull(timer);
managementService.executeJob(timer.getId());
Task escalatedTask = taskQuery.singleResult();
assertEquals("Escalated Task", escalatedTask.getName());
// Completing the task ends the complete process
taskService.complete(escalatedTask.getId());
assertEquals(0, runtimeService.createExecutionQuery().list().size());
}
use of org.camunda.bpm.engine.runtime.Job in project camunda-bpm-platform by camunda.
the class TriggerConditionalEventFromDelegationCodeTest method testNonInterruptingSetVariableInTakeListenerWithAsyncBefore.
@Test
public void testNonInterruptingSetVariableInTakeListenerWithAsyncBefore() {
BpmnModelInstance modelInstance = Bpmn.createExecutableProcess(CONDITIONAL_EVENT_PROCESS_KEY).startEvent().userTask(TASK_BEFORE_CONDITION_ID).name(TASK_BEFORE_CONDITION).sequenceFlowId(FLOW_ID).userTask(TASK_WITH_CONDITION_ID).camundaAsyncBefore().endEvent().done();
CamundaExecutionListener listener = modelInstance.newInstance(CamundaExecutionListener.class);
listener.setCamundaEvent(ExecutionListener.EVENTNAME_TAKE);
listener.setCamundaClass(specifier.getDelegateClass().getName());
modelInstance.<SequenceFlow>getModelElementById(FLOW_ID).builder().addExtensionElement(listener);
deployConditionalEventSubProcess(modelInstance, CONDITIONAL_EVENT_PROCESS_KEY, specifier.getCondition(), false);
// given
ProcessInstance procInst = runtimeService.startProcessInstanceByKey(CONDITIONAL_EVENT_PROCESS_KEY);
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(procInst.getId());
// when task is completed
taskService.complete(taskQuery.singleResult().getId());
// then take listener sets variable
// non interrupting boundary event is triggered
assertEquals(specifier.getExpectedNonInterruptingCount(), taskService.createTaskQuery().taskName(TASK_AFTER_CONDITION).count());
// and job was created
Job job = engine.getManagementService().createJobQuery().singleResult();
assertNotNull(job);
// when job is executed task is created
engine.getManagementService().executeJob(job.getId());
// when all tasks are completed
assertEquals(specifier.getExpectedNonInterruptingCount() + 1, taskQuery.count());
for (Task task : taskQuery.list()) {
taskService.complete(task.getId());
}
// then no task exist and process instance is ended
tasksAfterVariableIsSet = taskQuery.list();
assertEquals(0, tasksAfterVariableIsSet.size());
assertNull(runtimeService.createProcessInstanceQuery().singleResult());
}
use of org.camunda.bpm.engine.runtime.Job in project camunda-bpm-platform by camunda.
the class AsyncAfterTest method testAsyncAfterAndBeforeIntermediateCatchEvent.
@Deployment
public void testAsyncAfterAndBeforeIntermediateCatchEvent() {
// start process instance
ProcessInstance pi = runtimeService.startProcessInstanceByKey("testIntermediateCatchEvent");
// check that no listener is invoked by now
assertNotListenerStartInvoked(pi);
assertNotListenerEndInvoked(pi);
// the process is waiting before the message event
Job job = managementService.createJobQuery().singleResult();
assertNotNull(job);
// execute job to get to the message event
executeAvailableJobs();
// now we need to trigger the message to proceed
runtimeService.correlateMessage("testMessage1");
// now the listener should be invoked
assertListenerStartInvoked(pi);
assertListenerEndInvoked(pi);
// and now the process is waiting *after* the intermediate catch event
job = managementService.createJobQuery().singleResult();
assertNotNull(job);
// after executing the waiting job, the process instance will end
managementService.executeJob(job.getId());
assertProcessEnded(pi.getId());
}
Aggregations