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