Search in sources :

Example 66 with LockedExternalTask

use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.

the class ExternalTaskQueryTest method testTopicQueryByVariableValueLocking.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskServiceTest.testVariableValueTopicQuery.bpmn20.xml")
public void testTopicQueryByVariableValueLocking() {
    // given
    String topicName1 = "testTopic1";
    String topicName2 = "testTopic2";
    String topicName3 = "testTopic3";
    String variableName = "testVariable";
    String variableValue1 = "testValue1";
    String variableValue2 = "testValue2";
    Map<String, Object> variables = new HashMap<String, Object>();
    Long lockDuration = 60L * 1000L;
    // when
    variables.put(variableName, variableValue1);
    runtimeService.startProcessInstanceByKey("parallelExternalTaskProcessTopicQueryVariableValues", variables);
    variables.put(variableName, variableValue2);
    runtimeService.startProcessInstanceByKey("parallelExternalTaskProcessTopicQueryVariableValues", variables);
    List<LockedExternalTask> lockedTopicTasks = externalTaskService.fetchAndLock(3, "externalWorkerId").topic(topicName1, lockDuration).processInstanceVariableEquals(variableName, variableValue1).topic(topicName2, lockDuration).processInstanceVariableEquals(variableName, variableValue2).execute();
    List<LockedExternalTask> topicTasks = externalTaskService.fetchAndLock(3, "externalWorkerId").topic(topicName1, 2 * lockDuration).processInstanceVariableEquals(variableName, variableValue1).topic(topicName2, 2 * lockDuration).processInstanceVariableEquals(variableName, variableValue2).topic(topicName3, lockDuration).processInstanceVariableEquals(variableName, variableValue2).execute();
    // then
    assertEquals(2, lockedTopicTasks.size());
    assertEquals(1, topicTasks.size());
    LockedExternalTask externalTask = topicTasks.get(0);
    assertEquals(topicName3, externalTask.getTopicName());
    assertEquals(variableValue2, externalTask.getVariables().get(variableName));
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 67 with LockedExternalTask

use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.

the class ExternalTaskQueryTest method testQueryByBusinessKey.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/parallelExternalTaskProcess.bpmn20.xml")
public void testQueryByBusinessKey() {
    // given
    String topicName1 = "topic1";
    String topicName2 = "topic2";
    String topicName3 = "topic3";
    String businessKey1 = "testBusinessKey1";
    String businessKey2 = "testBusinessKey2";
    Long lockDuration = 60L * 1000L;
    runtimeService.startProcessInstanceByKey("parallelExternalTaskProcess", businessKey1);
    runtimeService.startProcessInstanceByKey("parallelExternalTaskProcess", businessKey2);
    // when
    List<LockedExternalTask> topicTasks = externalTaskService.fetchAndLock(3, "externalWorkerId").topic(topicName1, lockDuration).businessKey(businessKey1).topic(topicName2, lockDuration).businessKey(businessKey2).topic(topicName3, lockDuration).businessKey("fakeBusinessKey").execute();
    // then
    assertEquals(2, topicTasks.size());
    for (LockedExternalTask externalTask : topicTasks) {
        ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(externalTask.getProcessInstanceId()).singleResult();
        if (externalTask.getTopicName().equals(topicName1)) {
            assertEquals(businessKey1, pi.getBusinessKey());
        } else if (externalTask.getTopicName().equals(topicName2)) {
            assertEquals(businessKey2, pi.getBusinessKey());
        } else {
            fail("No other topic name values should be available!");
        }
    }
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 68 with LockedExternalTask

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

Example 69 with LockedExternalTask

use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.

the class ExternalTaskServiceTest method testHandleFailureZeroRetries.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleFailureZeroRetries() {
    // given
    runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    LockedExternalTask task = tasks.get(0);
    // when reporting a failure and setting retries to 0
    ClockUtil.setCurrentTime(nowPlus(3000L));
    String errorMessage = "errorMessage";
    externalTaskService.handleFailure(task.getId(), WORKER_ID, errorMessage, 0, 3000L);
    // then the task cannot be fetched anymore even when the lock expires
    ClockUtil.setCurrentTime(nowPlus(4000L));
    tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    assertEquals(0, tasks.size());
    // and an incident has been created
    Incident incident = runtimeService.createIncidentQuery().singleResult();
    assertNotNull(incident);
    assertNotNull(incident.getId());
    assertEquals(errorMessage, incident.getIncidentMessage());
    assertEquals(task.getExecutionId(), incident.getExecutionId());
    assertEquals("externalTask", incident.getActivityId());
    assertEquals(incident.getId(), incident.getCauseIncidentId());
    assertEquals("failedExternalTask", incident.getIncidentType());
    assertEquals(task.getProcessDefinitionId(), incident.getProcessDefinitionId());
    assertEquals(task.getProcessInstanceId(), incident.getProcessInstanceId());
    assertEquals(incident.getId(), incident.getRootCauseIncidentId());
    AssertUtil.assertEqualsSecondPrecision(nowMinus(4000L), incident.getIncidentTimestamp());
    assertEquals(task.getId(), incident.getConfiguration());
    assertNull(incident.getJobDefinitionId());
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Incident(org.camunda.bpm.engine.runtime.Incident) HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 70 with LockedExternalTask

use of org.camunda.bpm.engine.externaltask.LockedExternalTask 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());
}
Also used : ExternalTask(org.camunda.bpm.engine.externaltask.ExternalTask) Task(org.camunda.bpm.engine.task.Task) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) 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