Search in sources :

Example 1 with LockedExternalTask

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;
}
Also used : ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) LockedExternalTaskImpl(org.camunda.bpm.engine.impl.externaltask.LockedExternalTaskImpl) TopicFetchInstruction(org.camunda.bpm.engine.impl.externaltask.TopicFetchInstruction) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask)

Example 2 with LockedExternalTask

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());
}
Also used : ArrayList(java.util.ArrayList) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) AsyncResponse(javax.ws.rs.container.AsyncResponse) Test(org.junit.Test)

Example 3 with LockedExternalTask

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);
}
Also used : InOrder(org.mockito.InOrder) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) FetchExternalTasksExtendedDto(org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 4 with LockedExternalTask

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);
}
Also used : InOrder(org.mockito.InOrder) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) FetchExternalTasksExtendedDto(org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 5 with LockedExternalTask

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!");
        }
    }
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)91 Deployment (org.camunda.bpm.engine.test.Deployment)58 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)33 Test (org.junit.Test)21 ExternalTask (org.camunda.bpm.engine.externaltask.ExternalTask)15 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)10 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)9 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)9 Incident (org.camunda.bpm.engine.runtime.Incident)8 DateTime (org.joda.time.DateTime)8 Task (org.camunda.bpm.engine.task.Task)7 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)6 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)6 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)5 FetchExternalTasksExtendedDto (org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto)5 VariableMap (org.camunda.bpm.engine.variable.VariableMap)5 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 ExternalTaskQueryBuilder (org.camunda.bpm.engine.externaltask.ExternalTaskQueryBuilder)3 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)3 InOrder (org.mockito.InOrder)3