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);
}
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);
}
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());
}
}
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");
}
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());
}
Aggregations