use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testHandleFailure.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleFailure() {
// given
runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
LockedExternalTask task = tasks.get(0);
// when submitting a failure (after a simulated processing time of three seconds)
ClockUtil.setCurrentTime(nowPlus(3000L));
String errorMessage = "errorMessage";
externalTaskService.handleFailure(task.getId(), WORKER_ID, errorMessage, 5, 3000L);
// then the task cannot be immediately acquired again
tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(0, tasks.size());
// and no incident exists because there are still retries left
assertEquals(0, runtimeService.createIncidentQuery().count());
// but when the retry time expires, the task is available again
ClockUtil.setCurrentTime(nowPlus(4000L));
tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(1, tasks.size());
// and the retries and error message are accessible
task = tasks.get(0);
assertEquals(errorMessage, task.getErrorMessage());
assertEquals(5, (int) task.getRetries());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testCompleteReclaimedLockExpiredTask.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testCompleteReclaimedLockExpiredTask() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
// and the lock expires
ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());
// and it is reclaimed by another worker
List<LockedExternalTask> reclaimedTasks = externalTaskService.fetchAndLock(1, "anotherWorkerId").topic(TOPIC_NAME, LOCK_TIME).execute();
// then the first worker cannot complete the task
try {
externalTaskService.complete(externalTasks.get(0).getId(), WORKER_ID);
fail("exception expected");
} catch (ProcessEngineException e) {
assertTextPresent("cannot be completed by worker '" + WORKER_ID + "'. It is locked by worker 'anotherWorkerId'.", e.getMessage());
}
// and the second worker can
externalTaskService.complete(reclaimedTasks.get(0).getId(), "anotherWorkerId");
externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(0, externalTasks.size());
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method handleBpmnErrorReclaimedLockExpiredTask.
/**
* Helpher method which reclaims an external task after the lock is expired.
*/
public void handleBpmnErrorReclaimedLockExpiredTask() {
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
// and the lock expires
ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());
// and it is reclaimed by another worker
List<LockedExternalTask> reclaimedTasks = externalTaskService.fetchAndLock(1, "anotherWorkerId").topic(TOPIC_NAME, LOCK_TIME).execute();
// then the first worker cannot complete the task
try {
externalTaskService.handleBpmnError(externalTasks.get(0).getId(), WORKER_ID, "ERROR-OCCURED");
fail("exception expected");
} catch (ProcessEngineException e) {
assertTextPresent("Bpmn error of External Task " + externalTasks.get(0).getId() + " cannot be reported by worker '" + WORKER_ID + "'. It is locked by worker 'anotherWorkerId'.", e.getMessage());
}
// and the second worker can
externalTaskService.complete(reclaimedTasks.get(0).getId(), "anotherWorkerId");
externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(0, externalTasks.size());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testHandleFailureAndDeleteProcessInstance.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleFailureAndDeleteProcessInstance() {
// given a failed external task with incident
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
LockedExternalTask task = tasks.get(0);
externalTaskService.handleFailure(task.getId(), WORKER_ID, "someError", 0, LOCK_TIME);
// when
runtimeService.deleteProcessInstance(processInstance.getId(), null);
// then
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testSetRetries.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testSetRetries() {
// given
runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
// when
externalTaskService.setRetries(externalTasks.get(0).getId(), 5);
// then
ExternalTask task = externalTaskService.createExternalTaskQuery().singleResult();
assertEquals(5, (int) task.getRetries());
}
Aggregations