use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class FetchExternalTasksCmd method execute.
@Override
public List<LockedExternalTask> execute(CommandContext commandContext) {
validateInput();
for (TopicFetchInstruction instruction : fetchInstructions.values()) {
instruction.ensureVariablesInitialized();
}
List<ExternalTaskEntity> externalTasks = commandContext.getExternalTaskManager().selectExternalTasksForTopics(fetchInstructions.values(), filterByBusinessKey, maxResults, usePriority);
final List<LockedExternalTask> result = new ArrayList<LockedExternalTask>();
for (ExternalTaskEntity entity : externalTasks) {
TopicFetchInstruction fetchInstruction = fetchInstructions.get(entity.getTopicName());
entity.lock(workerId, fetchInstruction.getLockDuration());
LockedExternalTaskImpl resultTask = LockedExternalTaskImpl.fromEntity(entity, fetchInstruction.getVariablesToFetch(), fetchInstruction.isDeserializeVariables());
result.add(resultTask);
}
filterOnOptimisticLockingFailure(commandContext, result);
return result;
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class FetchAndLockHandlerTest method shouldResumeAsyncResponseDueToAvailableTasks.
@Test
public void shouldResumeAsyncResponseDueToAvailableTasks() {
// given
List<LockedExternalTask> tasks = new ArrayList<LockedExternalTask>();
tasks.add(lockedExternalTaskMock);
doReturn(tasks).when(fetchTopicBuilder).execute();
AsyncResponse asyncResponse = mock(AsyncResponse.class);
handler.addPendingRequest(createDto(5000L), asyncResponse, processEngine);
// when
handler.acquire();
// then
verify(asyncResponse).resume(argThat(IsCollectionWithSize.hasSize(1)));
assertThat(handler.getPendingRequests().size(), is(0));
verify(handler).suspend(Long.MAX_VALUE - ClockUtil.getCurrentTime().getTime());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class FetchAndLockRestServiceInteractionTest method shouldFetchWithCustomObjectDeserializationEnabled.
@Test
public void shouldFetchWithCustomObjectDeserializationEnabled() {
when(fetchTopicBuilder.execute()).thenReturn(new ArrayList<LockedExternalTask>(Collections.singleton(lockedExternalTaskMock)));
FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(null, false, true, true);
given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").then().expect().statusCode(Status.OK.getStatusCode()).when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE);
InOrder inOrder = inOrder(fetchTopicBuilder, externalTaskService);
inOrder.verify(externalTaskService).fetchAndLock(5, "aWorkerId", false);
inOrder.verify(fetchTopicBuilder).topic("aTopicName", 12354L);
inOrder.verify(fetchTopicBuilder).variables(Collections.singletonList(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME));
inOrder.verify(fetchTopicBuilder).enableCustomObjectDeserialization();
inOrder.verify(fetchTopicBuilder).execute();
verifyNoMoreInteractions(fetchTopicBuilder, externalTaskService);
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class FetchAndLockRestServiceInteractionTest method shouldFetchWithoutVariables.
@Test
public void shouldFetchWithoutVariables() {
when(fetchTopicBuilder.execute()).thenReturn(new ArrayList<LockedExternalTask>(Collections.singleton(lockedExternalTaskMock)));
FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(null);
given().contentType(ContentType.JSON).body(fetchExternalTasksDto).then().expect().statusCode(Status.OK.getStatusCode()).body("[0].id", equalTo(MockProvider.EXTERNAL_TASK_ID)).when().post(FETCH_EXTERNAL_TASK_URL);
InOrder inOrder = inOrder(fetchTopicBuilder, externalTaskService);
inOrder.verify(externalTaskService).fetchAndLock(5, "aWorkerId", false);
inOrder.verify(fetchTopicBuilder).topic("aTopicName", 12354L);
inOrder.verify(fetchTopicBuilder).execute();
verifyNoMoreInteractions(fetchTopicBuilder, externalTaskService);
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskQueryTest method testTopicQueryByVariableValues.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/ExternalTaskServiceTest.testVariableValueTopicQuery.bpmn20.xml")
public void testTopicQueryByVariableValues() {
// given
String topicName1 = "testTopic1";
String topicName2 = "testTopic2";
String topicName3 = "testTopic3";
String variableName1 = "testVariable1";
String variableName2 = "testVariable2";
String variableName3 = "testVariable3";
String variableValue1 = "testValue1";
String variableValue2 = "testValue2";
String variableValue3 = "testValue3";
String variableValue4 = "testValue4";
String variableValue5 = "testValue5";
String variableValue6 = "testValue6";
Map<String, Object> variables = new HashMap<String, Object>();
Long lockDuration = 60L * 1000L;
// when
variables.put(variableName1, variableValue1);
variables.put(variableName2, variableValue2);
variables.put(variableName3, variableValue3);
runtimeService.startProcessInstanceByKey("parallelExternalTaskProcessTopicQueryVariableValues", variables);
variables.put(variableName1, variableValue4);
variables.put(variableName2, variableValue5);
variables.put(variableName3, variableValue6);
runtimeService.startProcessInstanceByKey("parallelExternalTaskProcessTopicQueryVariableValues", variables);
List<LockedExternalTask> topicTasks = externalTaskService.fetchAndLock(3, "externalWorkerId").topic(topicName1, lockDuration).processInstanceVariableEquals(variableName1, variableValue1).processInstanceVariableEquals(variableName2, variableValue2).topic(topicName2, lockDuration).processInstanceVariableEquals(variableName2, variableValue5).processInstanceVariableEquals(variableName3, variableValue6).topic(topicName3, lockDuration).processInstanceVariableEquals(variableName1, "fakeVariableValue").execute();
// then
assertEquals(2, topicTasks.size());
for (LockedExternalTask externalTask : topicTasks) {
// topic names are not always in the same order
if (externalTask.getTopicName().equals(topicName1)) {
assertEquals(variableValue1, externalTask.getVariables().get(variableName1));
assertEquals(variableValue2, externalTask.getVariables().get(variableName2));
} else if (externalTask.getTopicName().equals(topicName2)) {
assertEquals(variableValue5, externalTask.getVariables().get(variableName2));
assertEquals(variableValue6, externalTask.getVariables().get(variableName3));
} else {
fail("No other topic name values should be available!");
}
}
}
Aggregations