Search in sources :

Example 76 with LockedExternalTask

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());
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 77 with LockedExternalTask

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());
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) DateTime(org.joda.time.DateTime) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 78 with LockedExternalTask

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());
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) DateTime(org.joda.time.DateTime) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 79 with LockedExternalTask

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());
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 80 with LockedExternalTask

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());
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)91 Deployment (org.camunda.bpm.engine.test.Deployment)58 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)33 Test (org.junit.Test)21 ExternalTask (org.camunda.bpm.engine.externaltask.ExternalTask)15 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)10 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)9 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)9 Incident (org.camunda.bpm.engine.runtime.Incident)8 DateTime (org.joda.time.DateTime)8 Task (org.camunda.bpm.engine.task.Task)7 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)6 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)6 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)5 FetchExternalTasksExtendedDto (org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto)5 VariableMap (org.camunda.bpm.engine.variable.VariableMap)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 ExternalTaskQueryBuilder (org.camunda.bpm.engine.externaltask.ExternalTaskQueryBuilder)3 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)3 InOrder (org.mockito.InOrder)3