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