Search in sources :

Example 61 with LockedExternalTask

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

the class HistoricExternalTaskLogAuthorizationTest method completeExternalTaskWithFailure.

protected void completeExternalTaskWithFailure(String externalTaskId) {
    List<LockedExternalTask> list = externalTaskService.fetchAndLock(5, WORKER_ID, false).topic(DEFAULT_TOPIC, LOCK_DURATION).execute();
    externalTaskService.handleFailure(externalTaskId, WORKER_ID, "This is an error!", ERROR_DETAILS, 1, 0L);
    externalTaskService.complete(externalTaskId, WORKER_ID);
    // unlock the remaining tasks
    for (LockedExternalTask lockedExternalTask : list) {
        if (!lockedExternalTask.getId().equals(externalTaskId)) {
            externalTaskService.unlock(lockedExternalTask.getId());
        }
    }
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask)

Example 62 with LockedExternalTask

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

the class ExternalTaskQueryTest method testTopicQueryByVariableValue.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskServiceTest.testVariableValueTopicQuery.bpmn20.xml")
public void testTopicQueryByVariableValue() {
    // given
    String topicName1 = "testTopic1";
    String topicName2 = "testTopic2";
    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> topicTasks = externalTaskService.fetchAndLock(3, "externalWorkerId").topic(topicName1, lockDuration).processInstanceVariableEquals(variableName, variableValue1).topic(topicName2, lockDuration).processInstanceVariableEquals(variableName, variableValue2).execute();
    // then
    assertEquals(2, topicTasks.size());
    for (LockedExternalTask externalTask : topicTasks) {
        if (externalTask.getTopicName().equals(topicName1)) {
            assertEquals(variableValue1, externalTask.getVariables().get(variableName));
        } else if (externalTask.getTopicName().equals(topicName2)) {
            assertEquals(variableValue2, externalTask.getVariables().get(variableName));
        } else {
            fail("No other topic name values should be available!");
        }
    }
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 63 with LockedExternalTask

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

the class ExternalTaskQueryTest method testQueryByRetries.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testQueryByRetries() {
    // given
    startInstancesByKey("oneExternalTaskProcess", 5);
    List<LockedExternalTask> tasks = lockInstances(TOPIC_NAME, 10000L, 3, WORKER_ID);
    // two tasks have no retries left
    failInstances(tasks.subList(0, 2), ERROR_MESSAGE, 0, 5000L);
    // one task has retries left
    failInstances(tasks.subList(2, 3), ERROR_MESSAGE, 4, 5000L);
    // when
    List<ExternalTask> tasksWithRetries = externalTaskService.createExternalTaskQuery().withRetriesLeft().list();
    List<ExternalTask> tasksWithoutRetries = externalTaskService.createExternalTaskQuery().noRetriesLeft().list();
    // then
    assertEquals(3, tasksWithRetries.size());
    for (ExternalTask task : tasksWithRetries) {
        assertTrue(task.getRetries() == null || task.getRetries() > 0);
    }
    assertEquals(2, tasksWithoutRetries.size());
    for (ExternalTask task : tasksWithoutRetries) {
        assertTrue(task.getRetries() == 0);
    }
}
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)

Example 64 with LockedExternalTask

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

the class ExternalTaskQueryTest method testQueryByBusinessKeyLocking.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/parallelExternalTaskProcess.bpmn20.xml")
public void testQueryByBusinessKeyLocking() {
    // 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> lockedTopicTasks = externalTaskService.fetchAndLock(3, "externalWorkerId").topic(topicName1, lockDuration).businessKey(businessKey1).topic(topicName2, lockDuration).businessKey(businessKey2).topic(topicName3, lockDuration).businessKey("fakeBusinessKey").execute();
    List<LockedExternalTask> topicTasks = externalTaskService.fetchAndLock(3, "externalWorkerId").topic(topicName1, lockDuration).businessKey(businessKey1).topic(topicName2, 2 * lockDuration).businessKey(businessKey2).topic(topicName3, 2 * lockDuration).businessKey(businessKey1).execute();
    // then
    assertEquals(2, lockedTopicTasks.size());
    assertEquals(1, topicTasks.size());
    LockedExternalTask externalTask = topicTasks.get(0);
    ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(externalTask.getProcessInstanceId()).singleResult();
    assertEquals(businessKey1, pi.getBusinessKey());
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 65 with LockedExternalTask

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

the class ExternalTaskQueryTest method testTopicQueryByBusinessKeyAndVariableValue.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskServiceTest.testVariableValueTopicQuery.bpmn20.xml")
public void testTopicQueryByBusinessKeyAndVariableValue() {
    // given
    String topicName1 = "testTopic1";
    String topicName2 = "testTopic2";
    String topicName3 = "testTopic3";
    String businessKey1 = "testBusinessKey1";
    String businessKey2 = "testBusinessKey2";
    String variableName = "testVariable1";
    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", businessKey1, variables);
    variables.put(variableName, variableValue2);
    runtimeService.startProcessInstanceByKey("parallelExternalTaskProcessTopicQueryVariableValues", businessKey2, variables);
    List<LockedExternalTask> topicTasks = externalTaskService.fetchAndLock(3, "externalWorkerId").topic(topicName1, lockDuration).businessKey(businessKey1).processInstanceVariableEquals(variableName, variableValue1).topic(topicName2, lockDuration).businessKey(businessKey2).processInstanceVariableEquals(variableName, variableValue2).topic(topicName3, lockDuration).businessKey("fakeBusinessKey").execute();
    // then
    assertEquals(2, topicTasks.size());
    for (LockedExternalTask externalTask : topicTasks) {
        ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(externalTask.getProcessInstanceId()).singleResult();
        // topic names are not always in the same order
        if (externalTask.getTopicName().equals(topicName1)) {
            assertEquals(businessKey1, pi.getBusinessKey());
            assertEquals(variableValue1, externalTask.getVariables().get(variableName));
        } else if (externalTask.getTopicName().equals(topicName2)) {
            assertEquals(businessKey2, pi.getBusinessKey());
            assertEquals(variableValue2, externalTask.getVariables().get(variableName));
        } 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)

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