Search in sources :

Example 6 with LockedExternalTask

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

the class ExternalTaskServiceTest method testFetchAllVariables.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskServiceTest.testFetchVariables.bpmn20.xml")
public void testFetchAllVariables() {
    // given
    runtimeService.startProcessInstanceByKey("subProcessExternalTask", Variables.createVariables().putValue("processVar1", 42).putValue("processVar2", 43));
    // when
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    // then
    LockedExternalTask task = externalTasks.get(0);
    verifyVariables(task);
    runtimeService.startProcessInstanceByKey("subProcessExternalTask", Variables.createVariables().putValue("processVar1", 42).putValue("processVar2", 43));
    externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).variables((String[]) null).execute();
    task = externalTasks.get(0);
    verifyVariables(task);
    runtimeService.startProcessInstanceByKey("subProcessExternalTask", Variables.createVariables().putValue("processVar1", 42).putValue("processVar2", 43));
    List<String> list = null;
    externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).variables(list).execute();
    task = externalTasks.get(0);
    verifyVariables(task);
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 7 with LockedExternalTask

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

the class ExternalTaskServiceTest method testSetPriorityLockExpiredTask.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testSetPriorityLockExpiredTask() {
    // given
    runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    // when
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    // and the lock expires without the task being reclaimed
    ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());
    // then the priority can be set
    externalTaskService.setPriority(externalTasks.get(0).getId(), 9);
    externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID, true).topic(TOPIC_NAME, LOCK_TIME).execute();
    assertEquals(1, externalTasks.size());
    assertEquals(externalTasks.get(0).getPriority(), 9);
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) DateTime(org.joda.time.DateTime) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 8 with LockedExternalTask

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

the class ExternalTaskServiceTest method testShouldNotFetchSerializedVariables.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskServiceTest.testFetchVariables.bpmn20.xml")
public void testShouldNotFetchSerializedVariables() {
    // given
    ExternalTaskCustomValue customValue = new ExternalTaskCustomValue();
    customValue.setTestValue("value1");
    runtimeService.startProcessInstanceByKey("subProcessExternalTask", Variables.createVariables().putValue("processVar1", customValue));
    // when
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).variables("processVar1").execute();
    // then
    LockedExternalTask task = externalTasks.get(0);
    VariableMap variables = task.getVariables();
    assertEquals(1, variables.size());
    try {
        variables.get("processVar1");
        fail("did not receive an exception although variable was serialized");
    } catch (IllegalStateException e) {
        assertEquals("Object is not deserialized.", e.getMessage());
    }
}
Also used : VariableMap(org.camunda.bpm.engine.variable.VariableMap) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 9 with LockedExternalTask

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

the class ExternalTaskServiceTest method testHandleBpmnErrorLockExpiredTask.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/twoExternalTaskProcess.bpmn20.xml")
public void testHandleBpmnErrorLockExpiredTask() {
    // given
    runtimeService.startProcessInstanceByKey("twoExternalTaskProcess");
    // when
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    // and the lock expires without the task being reclaimed
    ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());
    externalTaskService.handleBpmnError(externalTasks.get(0).getId(), WORKER_ID, "ERROR-OCCURED");
    externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    assertEquals(0, externalTasks.size());
    assertEquals(0, externalTaskService.createExternalTaskQuery().count());
    Task afterBpmnError = taskService.createTaskQuery().singleResult();
    assertNotNull(afterBpmnError);
    assertEquals(afterBpmnError.getTaskDefinitionKey(), "afterBpmnError");
}
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) DateTime(org.joda.time.DateTime) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 10 with LockedExternalTask

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

the class ExternalTaskServiceTest method testUnlock.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testUnlock() {
    // given
    runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    LockedExternalTask task = externalTasks.get(0);
    // when unlocking the task
    externalTaskService.unlock(task.getId());
    // then it can be acquired again
    externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    assertEquals(1, externalTasks.size());
    LockedExternalTask reAcquiredTask = externalTasks.get(0);
    assertEquals(task.getId(), reAcquiredTask.getId());
}
Also used : 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