Search in sources :

Example 71 with ProcessEngineException

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

the class FetchAndLockHandlerImpl method addPendingRequest.

@Override
public void addPendingRequest(FetchExternalTasksExtendedDto dto, AsyncResponse asyncResponse, ProcessEngine processEngine) {
    Long asyncResponseTimeout = dto.getAsyncResponseTimeout();
    if (asyncResponseTimeout != null && asyncResponseTimeout > MAX_TIMEOUT) {
        invalidRequest(asyncResponse, "The asynchronous response timeout cannot be set to a value greater than " + MAX_TIMEOUT + " milliseconds");
        return;
    }
    IdentityService identityService = processEngine.getIdentityService();
    Authentication authentication = identityService.getCurrentAuthentication();
    FetchAndLockRequest incomingRequest = new FetchAndLockRequest().setProcessEngine(processEngine).setAsyncResponse(asyncResponse).setAuthentication(authentication).setDto(dto);
    FetchAndLockResult result = tryFetchAndLock(incomingRequest);
    if (result.wasSuccessful()) {
        List<LockedExternalTaskDto> lockedTasks = result.getTasks();
        if (!lockedTasks.isEmpty() || dto.getAsyncResponseTimeout() == null) {
            // response immediately if tasks available
            asyncResponse.resume(lockedTasks);
        } else {
            addRequest(incomingRequest);
        }
    } else {
        ProcessEngineException processEngineException = result.getProcessEngineException();
        asyncResponse.resume(processEngineException);
    }
}
Also used : IdentityService(org.camunda.bpm.engine.IdentityService) Authentication(org.camunda.bpm.engine.impl.identity.Authentication) LockedExternalTaskDto(org.camunda.bpm.engine.rest.dto.externaltask.LockedExternalTaskDto) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 72 with ProcessEngineException

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

the class FetchAndLockHandlerImpl method acquire.

protected void acquire() {
    queue.drainTo(pendingRequests);
    // timestamp
    long backoffTime = MAX_BACK_OFF_TIME;
    Iterator<FetchAndLockRequest> iterator = pendingRequests.iterator();
    while (iterator.hasNext()) {
        FetchAndLockRequest pendingRequest = iterator.next();
        long currentTime = ClockUtil.getCurrentTime().getTime();
        FetchAndLockResult result = tryFetchAndLock(pendingRequest);
        if (result.wasSuccessful()) {
            List<LockedExternalTaskDto> lockedTasks = result.getTasks();
            long timeout = pendingRequest.getTimeoutTimestamp();
            if (!lockedTasks.isEmpty() || timeout <= currentTime) {
                AsyncResponse asyncResponse = pendingRequest.getAsyncResponse();
                iterator.remove();
                asyncResponse.resume(lockedTasks);
            } else {
                if (timeout < backoffTime) {
                    backoffTime = timeout;
                }
            }
        } else {
            AsyncResponse asyncResponse = pendingRequest.getAsyncResponse();
            iterator.remove();
            ProcessEngineException processEngineException = result.getProcessEngineException();
            asyncResponse.resume(processEngineException);
        }
    }
    suspend(Math.max(0, backoffTime - ClockUtil.getCurrentTime().getTime()));
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) LockedExternalTaskDto(org.camunda.bpm.engine.rest.dto.externaltask.LockedExternalTaskDto) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 73 with ProcessEngineException

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

the class FetchAndLockHandlerTest method shouldResumeAsyncResponseAfterBackoffDueToProcessEngineException.

@Test
public void shouldResumeAsyncResponseAfterBackoffDueToProcessEngineException() {
    // 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);
    // when
    doThrow(new ProcessEngineException()).when(fetchTopicBuilder).execute();
    handler.acquire();
    // then
    assertThat(handler.getPendingRequests().size(), is(0));
    verify(handler).suspend(Long.MAX_VALUE - ClockUtil.getCurrentTime().getTime());
    verify(asyncResponse).resume(any(ProcessEngineException.class));
}
Also used : AsyncResponse(javax.ws.rs.container.AsyncResponse) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test)

Example 74 with ProcessEngineException

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

the class FetchAndLockRestServiceInteractionTest method shouldThrowProcessEngineExceptionNotDuringTimeout.

@Test
public void shouldThrowProcessEngineExceptionNotDuringTimeout() {
    FetchExternalTasksExtendedDto fetchExternalTasksDto = createDto(500L);
    when(fetchTopicBuilder.execute()).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, times(1)).execute();
}
Also used : 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 75 with ProcessEngineException

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

the class FallbackSerializationTest method testSerializationOfUnknownFormat.

@Deployment(resources = ONE_TASK_PROCESS)
public void testSerializationOfUnknownFormat() {
    // given
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    // when
    ObjectValue objectValue = Variables.serializedObjectValue("foo").serializationDataFormat("application/foo").objectTypeName("org.camunda.Foo").create();
    runtimeService.setVariable(instance.getId(), "var", objectValue);
    // then
    try {
        runtimeService.getVariable(instance.getId(), "var");
        fail();
    } catch (ProcessEngineException e) {
        assertTextPresent("Fallback serializer cannot handle deserialized objects", e.getMessage());
    }
    ObjectValue returnedValue = runtimeService.getVariableTyped(instance.getId(), "var", false);
    assertFalse(returnedValue.isDeserialized());
    assertEquals("application/foo", returnedValue.getSerializationDataFormat());
    assertEquals("foo", returnedValue.getValueSerialized());
    assertEquals("org.camunda.Foo", returnedValue.getObjectTypeName());
}
Also used : ObjectValue(org.camunda.bpm.engine.variable.value.ObjectValue) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)611 Test (org.junit.Test)185 Deployment (org.camunda.bpm.engine.test.Deployment)138 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)79 HashMap (java.util.HashMap)62 RestException (org.camunda.bpm.engine.rest.exception.RestException)62 Matchers.anyString (org.mockito.Matchers.anyString)60 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)57 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)47 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)41 Task (org.camunda.bpm.engine.task.Task)40 ArrayList (java.util.ArrayList)39 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)36 Matchers.containsString (org.hamcrest.Matchers.containsString)35 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)24 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)22 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)21 CaseInstanceQuery (org.camunda.bpm.engine.runtime.CaseInstanceQuery)21 NotValidException (org.camunda.bpm.engine.exception.NotValidException)19 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)18