Search in sources :

Example 46 with LockedExternalTask

use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.

the class FetchAndLockHandlerTest method shouldResumeAsyncResponseDueToTimeoutExpired_1.

@Test
public void shouldResumeAsyncResponseDueToTimeoutExpired_1() {
    // given
    doReturn(Collections.emptyList()).when(fetchTopicBuilder).execute();
    AsyncResponse asyncResponse = mock(AsyncResponse.class);
    handler.addPendingRequest(createDto(5000L), asyncResponse, processEngine);
    handler.acquire();
    // assume
    assertThat(handler.getPendingRequests().size(), is(1));
    verify(handler).suspend(5000L);
    List<LockedExternalTask> tasks = new ArrayList<LockedExternalTask>();
    tasks.add(lockedExternalTaskMock);
    doReturn(tasks).when(fetchTopicBuilder).execute();
    addSecondsToClock(5);
    // 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 47 with LockedExternalTask

use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.

the class FetchAndLockRestServiceInteractionTest method shouldThrowProcessEngineExceptionDuringTimeout.

@Test
public void shouldThrowProcessEngineExceptionDuringTimeout() {
    FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(500L);
    when(fetchTopicBuilder.execute()).thenReturn(Collections.<LockedExternalTask>emptyList()).thenReturn(Collections.<LockedExternalTask>emptyList()).thenThrow(new ProcessEngineException("anExceptionMessage"));
    given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").then().expect().body("type", equalTo(ProcessEngineException.class.getSimpleName())).body("message", equalTo("anExceptionMessage")).statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE);
    verify(fetchTopicBuilder, atLeastOnce()).execute();
}
Also used : LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) FetchExternalTasksExtendedDto(org.camunda.bpm.engine.rest.dto.externaltask.FetchExternalTasksExtendedDto) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test) AbstractRestServiceTest(org.camunda.bpm.engine.rest.AbstractRestServiceTest)

Example 48 with LockedExternalTask

use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.

the class FetchAndLockRestServiceInteractionTest method shouldResponseImmediatelyDueToAvailableTasks.

@Test
public void shouldResponseImmediatelyDueToAvailableTasks() {
    when(fetchTopicBuilder.execute()).thenReturn(new ArrayList<LockedExternalTask>(Collections.singleton(lockedExternalTaskMock)));
    FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(500L);
    given().contentType(ContentType.JSON).body(fetchExternalTasksDto).then().expect().body("size()", is(1)).statusCode(Status.OK.getStatusCode()).when().post(FETCH_EXTERNAL_TASK_URL);
}
Also used : 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 49 with LockedExternalTask

use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.

the class FetchAndLockRestServiceInteractionTest method shouldFetchAndLock.

@Test
public void shouldFetchAndLock() {
    when(fetchTopicBuilder.execute()).thenReturn(new ArrayList<LockedExternalTask>(Collections.singleton(lockedExternalTaskMock)));
    FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(null, true, true, false);
    given().contentType(ContentType.JSON).body(fetchExternalTasksDto).pathParam("name", "default").then().expect().statusCode(Status.OK.getStatusCode()).body("[0].id", equalTo(MockProvider.EXTERNAL_TASK_ID)).body("[0].topicName", equalTo(MockProvider.EXTERNAL_TASK_TOPIC_NAME)).body("[0].workerId", equalTo(MockProvider.EXTERNAL_TASK_WORKER_ID)).body("[0].lockExpirationTime", equalTo(MockProvider.EXTERNAL_TASK_LOCK_EXPIRATION_TIME)).body("[0].processInstanceId", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)).body("[0].executionId", equalTo(MockProvider.EXAMPLE_EXECUTION_ID)).body("[0].activityId", equalTo(MockProvider.EXAMPLE_ACTIVITY_ID)).body("[0].activityInstanceId", equalTo(MockProvider.EXAMPLE_ACTIVITY_INSTANCE_ID)).body("[0].processDefinitionId", equalTo(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).body("[0].processDefinitionKey", equalTo(MockProvider.EXAMPLE_PROCESS_DEFINITION_KEY)).body("[0].tenantId", equalTo(MockProvider.EXAMPLE_TENANT_ID)).body("[0].retries", equalTo(MockProvider.EXTERNAL_TASK_RETRIES)).body("[0].errorMessage", equalTo(MockProvider.EXTERNAL_TASK_ERROR_MESSAGE)).body("[0].errorMessage", equalTo(MockProvider.EXTERNAL_TASK_ERROR_MESSAGE)).body("[0].priority", equalTo(MockProvider.EXTERNAL_TASK_PRIORITY)).body("[0].variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME, notNullValue()).body("[0].variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".value", equalTo(MockProvider.EXAMPLE_PRIMITIVE_VARIABLE_VALUE.getValue())).body("[0].variables." + MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME + ".type", equalTo("String")).when().post(FETCH_EXTERNAL_TASK_URL_NAMED_ENGINE);
    InOrder inOrder = inOrder(fetchTopicBuilder, externalTaskService);
    inOrder.verify(externalTaskService).fetchAndLock(5, "aWorkerId", true);
    inOrder.verify(fetchTopicBuilder).topic("aTopicName", 12354L);
    inOrder.verify(fetchTopicBuilder).variables(Collections.singletonList(MockProvider.EXAMPLE_VARIABLE_INSTANCE_NAME));
    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 50 with LockedExternalTask

use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.

the class FetchAndLockHandlerImpl method executeFetchAndLock.

protected List<LockedExternalTaskDto> executeFetchAndLock(FetchExternalTasksExtendedDto fetchingDto, ProcessEngine processEngine) {
    ExternalTaskQueryBuilder fetchBuilder = fetchingDto.buildQuery(processEngine);
    List<LockedExternalTask> externalTasks = fetchBuilder.execute();
    return LockedExternalTaskDto.fromLockedExternalTasks(externalTasks);
}
Also used : ExternalTaskQueryBuilder(org.camunda.bpm.engine.externaltask.ExternalTaskQueryBuilder) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask)

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