use of org.camunda.bpm.engine.externaltask.ExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testExtendLockTime.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testExtendLockTime() {
final Date oldCurrentTime = ClockUtil.getCurrentTime();
try {
// given
runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
ClockUtil.setCurrentTime(nowMinus(1000));
List<LockedExternalTask> lockedTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
// when
Date extendLockTime = new Date();
ClockUtil.setCurrentTime(extendLockTime);
externalTaskService.extendLock(lockedTasks.get(0).getId(), WORKER_ID, LOCK_TIME);
// then
ExternalTask taskWithExtendedLock = externalTaskService.createExternalTaskQuery().locked().singleResult();
assertNotNull(taskWithExtendedLock);
AssertUtil.assertEqualsSecondPrecision(new Date(extendLockTime.getTime() + LOCK_TIME), taskWithExtendedLock.getLockExpirationTime());
} finally {
ClockUtil.setCurrentTime(oldCurrentTime);
}
}
use of org.camunda.bpm.engine.externaltask.ExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testExternalTaskExecutionTreeCompaction.
@Deployment
public void testExternalTaskExecutionTreeCompaction() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("concurrentExternalTaskProcess");
List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
LockedExternalTask externalTask = tasks.get(0);
Task userTask = taskService.createTaskQuery().singleResult();
// when the user task completes meanwhile, thereby trigger execution tree compaction
taskService.complete(userTask.getId());
// then the external task can still be completed
externalTaskService.complete(externalTask.getId(), WORKER_ID);
tasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(0, tasks.size());
assertProcessEnded(processInstance.getId());
}
use of org.camunda.bpm.engine.externaltask.ExternalTask 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.ExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testExtendLockTimeWithoutLock.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testExtendLockTimeWithoutLock() {
// given
runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
ExternalTask externalTask = externalTaskService.createExternalTaskQuery().singleResult();
// when
try {
externalTaskService.extendLock(externalTask.getId(), WORKER_ID, 100);
fail("Exception expected");
} catch (BadUserRequestException e) {
assertTrue(e.getMessage().contains("The lock of the External Task " + externalTask.getId() + " cannot be extended by worker '" + WORKER_ID));
}
}
use of org.camunda.bpm.engine.externaltask.ExternalTask 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