use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testHandleFailureSuspendedTask.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleFailureSuspendedTask() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
LockedExternalTask task = externalTasks.get(0);
// when suspending the process instance
runtimeService.suspendProcessInstanceById(processInstance.getId());
// then a failure cannot be reported
try {
externalTaskService.handleFailure(externalTasks.get(0).getId(), WORKER_ID, "error", 5, LOCK_TIME);
fail("expected exception");
} catch (ProcessEngineException e) {
assertTextPresent("ExternalTask with id '" + task.getId() + "' is suspended", e.getMessage());
}
assertProcessNotEnded(processInstance.getId());
// when activating the process instance again
runtimeService.activateProcessInstanceById(processInstance.getId());
// then the failure can be reported successfully
externalTaskService.handleFailure(externalTasks.get(0).getId(), WORKER_ID, "error", 5, LOCK_TIME);
ExternalTask updatedTask = externalTaskService.createExternalTaskQuery().singleResult();
assertEquals(5, (int) updatedTask.getRetries());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testFetchNextWithPriority.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskWithPriorityProcess.bpmn20.xml")
public void testFetchNextWithPriority() {
// given
runtimeService.startProcessInstanceByKey("twoExternalTaskWithPriorityProcess");
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID, true).topic(TOPIC_NAME, LOCK_TIME).execute();
// then the task is locked
assertEquals(1, externalTasks.size());
LockedExternalTask task = externalTasks.get(0);
long firstPrio = task.getPriority();
AssertUtil.assertEqualsSecondPrecision(nowPlus(LOCK_TIME), task.getLockExpirationTime());
// another task with next higher priority can be claimed
externalTasks = externalTaskService.fetchAndLock(1, "anotherWorkerId", true).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(1, externalTasks.size());
assertTrue(firstPrio >= externalTasks.get(0).getPriority());
// the expiration time expires
ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());
// first can be claimed
externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID, true).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(1, externalTasks.size());
assertEquals(firstPrio, externalTasks.get(0).getPriority());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testComplete.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskProcess.bpmn20.xml")
public void testComplete() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("twoExternalTaskProcess");
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
externalTaskService.complete(externalTasks.get(0).getId(), WORKER_ID);
// then
externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(0, externalTasks.size());
ActivityInstance activityInstance = runtimeService.getActivityInstance(processInstance.getId());
assertThat(activityInstance).hasStructure(describeActivityInstanceTree(processInstance.getProcessDefinitionId()).activity("afterExternalTask").done());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testFetchVariables.
@Deployment
public void testFetchVariables() {
// given
runtimeService.startProcessInstanceByKey("subProcessExternalTask", Variables.createVariables().putValue("processVar1", 42).putValue("processVar2", 43));
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).variables("processVar1", "subProcessVar", "taskVar").execute();
// then
LockedExternalTask task = externalTasks.get(0);
VariableMap variables = task.getVariables();
assertEquals(3, variables.size());
assertEquals(42, variables.get("processVar1"));
assertEquals(44L, variables.get("subProcessVar"));
assertEquals(45L, variables.get("taskVar"));
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testFetchMultipleTopics.
@Deployment
public void testFetchMultipleTopics() {
// given a process instance with external tasks for topics "topic1", "topic2", and "topic3"
runtimeService.startProcessInstanceByKey("parallelExternalTaskProcess");
// when fetching tasks for two topics
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic("topic1", LOCK_TIME).topic("topic2", LOCK_TIME * 2).execute();
// then those two tasks are locked
assertEquals(2, tasks.size());
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());
AssertUtil.assertEqualsSecondPrecision(nowPlus(LOCK_TIME), topic1Task.getLockExpirationTime());
assertEquals("topic2", topic2Task.getTopicName());
AssertUtil.assertEqualsSecondPrecision(nowPlus(LOCK_TIME * 2), topic2Task.getLockExpirationTime());
// and the third task can still be fetched
tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic("topic1", LOCK_TIME).topic("topic2", LOCK_TIME * 2).topic("topic3", LOCK_TIME * 3).execute();
assertEquals(1, tasks.size());
LockedExternalTask topic3Task = tasks.get(0);
assertEquals("topic3", topic3Task.getTopicName());
AssertUtil.assertEqualsSecondPrecision(nowPlus(LOCK_TIME * 3), topic3Task.getLockExpirationTime());
}
Aggregations