use of org.camunda.bpm.engine.externaltask.ExternalTask 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.ExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskQueryTest method testQueryByLockExpirationTime.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testQueryByLockExpirationTime() {
// given
startInstancesByKey("oneExternalTaskProcess", 10);
lockInstances(TOPIC_NAME, 5000L, 3, WORKER_ID);
lockInstances(TOPIC_NAME, 10000L, 4, WORKER_ID);
// when
Date lockDate = new Date(ClockUtil.getCurrentTime().getTime() + 7000L);
List<ExternalTask> lockedExpirationBeforeTasks = externalTaskService.createExternalTaskQuery().lockExpirationBefore(lockDate).list();
List<ExternalTask> lockedExpirationAfterTasks = externalTaskService.createExternalTaskQuery().lockExpirationAfter(lockDate).list();
// then
assertEquals(3, lockedExpirationBeforeTasks.size());
for (ExternalTask task : lockedExpirationBeforeTasks) {
assertNotNull(task.getLockExpirationTime());
assertTrue(task.getLockExpirationTime().getTime() < lockDate.getTime());
}
assertEquals(4, lockedExpirationAfterTasks.size());
for (ExternalTask task : lockedExpirationAfterTasks) {
assertNotNull(task.getLockExpirationTime());
assertTrue(task.getLockExpirationTime().getTime() > lockDate.getTime());
}
}
use of org.camunda.bpm.engine.externaltask.ExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskQueryTest method testQueryByTopicName.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/parallelExternalTaskProcess.bpmn20.xml")
public void testQueryByTopicName() {
// given
startInstancesByKey("parallelExternalTaskProcess", 3);
// when
List<ExternalTask> topic1Tasks = externalTaskService.createExternalTaskQuery().topicName("topic1").list();
// then
assertEquals(3, topic1Tasks.size());
for (ExternalTask task : topic1Tasks) {
assertEquals("topic1", task.getTopicName());
}
}
use of org.camunda.bpm.engine.externaltask.ExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskQueryTest method testQueryById.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testQueryById() {
// given
List<ProcessInstance> processInstances = startInstancesByKey("oneExternalTaskProcess", 2);
List<ExternalTask> tasks = externalTaskService.createExternalTaskQuery().list();
ProcessInstance firstInstance = processInstances.get(0);
ExternalTask firstTask = tasks.get(0);
if (!firstTask.getProcessInstanceId().equals(firstInstance.getId())) {
firstTask = tasks.get(1);
}
// when
ExternalTask resultTask = externalTaskService.createExternalTaskQuery().externalTaskId(firstTask.getId()).singleResult();
// then
assertEquals(firstTask.getId(), resultTask.getId());
}
use of org.camunda.bpm.engine.externaltask.ExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testUpdateRetriesByProcessInstanceQuery.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testUpdateRetriesByProcessInstanceQuery() {
// given
startProcessInstance("oneExternalTaskProcess", 5);
ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery().processDefinitionKey("oneExternalTaskProcess");
// when
externalTaskService.updateRetries().processInstanceQuery(processInstanceQuery).set(5);
// then
List<ExternalTask> tasks = externalTaskService.createExternalTaskQuery().list();
assertEquals(5, tasks.size());
for (ExternalTask task : tasks) {
assertEquals(5, (int) task.getRetries());
}
}
Aggregations