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