use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testFetch.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testFetch() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
// then
assertEquals(1, externalTasks.size());
LockedExternalTask task = externalTasks.get(0);
assertNotNull(task.getId());
assertEquals(processInstance.getId(), task.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), task.getProcessDefinitionId());
assertEquals("externalTask", task.getActivityId());
assertEquals("oneExternalTaskProcess", task.getProcessDefinitionKey());
assertEquals(TOPIC_NAME, task.getTopicName());
ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId()).getActivityInstances("externalTask")[0];
assertEquals(activityInstance.getId(), task.getActivityInstanceId());
assertEquals(activityInstance.getExecutionIds()[0], task.getExecutionId());
AssertUtil.assertEqualsSecondPrecision(nowPlus(LOCK_TIME), task.getLockExpirationTime());
assertEquals(WORKER_ID, task.getWorkerId());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testFetchWithPriority.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskWithPriorityProcess.bpmn20.xml")
public void testFetchWithPriority() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoExternalTaskWithPriorityProcess");
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID, true).topic(TOPIC_NAME, LOCK_TIME).execute();
// then
assertEquals(1, externalTasks.size());
LockedExternalTask task = externalTasks.get(0);
assertNotNull(task.getId());
assertEquals(processInstance.getId(), task.getProcessInstanceId());
assertEquals(processInstance.getProcessDefinitionId(), task.getProcessDefinitionId());
assertEquals("externalTaskWithPrio", task.getActivityId());
assertEquals("twoExternalTaskWithPriorityProcess", task.getProcessDefinitionKey());
assertEquals(TOPIC_NAME, task.getTopicName());
assertEquals(7, task.getPriority());
ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId()).getActivityInstances("externalTaskWithPrio")[0];
assertEquals(activityInstance.getId(), task.getActivityInstanceId());
assertEquals(activityInstance.getExecutionIds()[0], task.getExecutionId());
AssertUtil.assertEqualsSecondPrecision(nowPlus(LOCK_TIME), task.getLockExpirationTime());
assertEquals(WORKER_ID, task.getWorkerId());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testHandleBpmnErrorNullWorkerId.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleBpmnErrorNullWorkerId() {
runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
LockedExternalTask task = tasks.get(0);
try {
externalTaskService.handleBpmnError(task.getId(), null, "ERROR-OCCURED");
fail("exception expected");
} catch (ProcessEngineException e) {
assertTextPresent("workerId is null", e.getMessage());
}
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testFetchMultipleTopicsWithVariables.
@Deployment
public void testFetchMultipleTopicsWithVariables() {
// given a process instance with external tasks for topics "topic1" and "topic2"
// both have local variables "var1" and "var2"
runtimeService.startProcessInstanceByKey("parallelExternalTaskProcess", Variables.createVariables().putValue("var1", 0).putValue("var2", 0));
// when
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic("topic1", LOCK_TIME).variables("var1", "var2").topic("topic2", LOCK_TIME).variables("var1").execute();
LockedExternalTask topic1Task = "topic1".equals(tasks.get(0).getTopicName()) ? tasks.get(0) : tasks.get(1);
LockedExternalTask topic2Task = "topic2".equals(tasks.get(0).getTopicName()) ? tasks.get(0) : tasks.get(1);
assertEquals("topic1", topic1Task.getTopicName());
assertEquals("topic2", topic2Task.getTopicName());
// then the correct variables have been fetched
VariableMap topic1Variables = topic1Task.getVariables();
assertEquals(2, topic1Variables.size());
assertEquals(1L, topic1Variables.get("var1"));
assertEquals(1L, topic1Variables.get("var2"));
VariableMap topic2Variables = topic2Task.getVariables();
assertEquals(1, topic2Variables.size());
assertEquals(2L, topic2Variables.get("var1"));
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class PurgeDatabaseTest method executeComplexBpmnProcess.
private void executeComplexBpmnProcess(boolean complete) {
VariableMap variables = Variables.createVariables();
variables.put("key", "value");
engineRule.getRuntimeService().startProcessInstanceByKey(PROCESS_DEF_KEY, variables);
// execute start event
Job job = engineRule.getManagementService().createJobQuery().singleResult();
engineRule.getManagementService().executeJob(job.getId());
// fetch tasks and jobs
List<LockedExternalTask> externalTasks = engineRule.getExternalTaskService().fetchAndLock(1, "worker").topic("external", 1500).execute();
job = engineRule.getManagementService().createJobQuery().singleResult();
Task task = engineRule.getTaskService().createTaskQuery().singleResult();
// complete
if (complete) {
engineRule.getManagementService().setJobRetries(job.getId(), 0);
engineRule.getManagementService().executeJob(job.getId());
engineRule.getExternalTaskService().complete(externalTasks.get(0).getId(), "worker");
engineRule.getTaskService().complete(task.getId());
}
}
Aggregations