Search in sources :

Example 1 with RuntimeSqlException

use of org.apache.ibatis.jdbc.RuntimeSqlException in project camunda-bpm-platform by camunda.

the class ExternalTaskServiceTest method testHandleFailureWithErrorDetails.

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleFailureWithErrorDetails() {
    // given
    runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
    List<LockedExternalTask> tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    LockedExternalTask task = tasks.get(0);
    // when submitting a failure (after a simulated processing time of three seconds)
    ClockUtil.setCurrentTime(nowPlus(3000L));
    String errorMessage;
    String exceptionStackTrace;
    try {
        RuntimeSqlException cause = new RuntimeSqlException("test cause");
        for (int i = 0; i < 10; i++) {
            cause = new RuntimeSqlException(cause);
        }
        throw cause;
    } catch (RuntimeException e) {
        exceptionStackTrace = ExceptionUtils.getStackTrace(e);
        errorMessage = e.getMessage();
        while (errorMessage.length() < 1000) {
            errorMessage = errorMessage + ":" + e.getMessage();
        }
    }
    Assert.assertThat(exceptionStackTrace, is(notNullValue()));
    // make sure that stack trace is longer then errorMessage DB field length
    Assert.assertThat(exceptionStackTrace.length(), is(greaterThan(4000)));
    externalTaskService.handleFailure(task.getId(), WORKER_ID, errorMessage, exceptionStackTrace, 5, 3000L);
    ClockUtil.setCurrentTime(nowPlus(4000L));
    tasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
    Assert.assertThat(tasks.size(), is(1));
    // verify that exception is accessible properly
    task = tasks.get(0);
    Assert.assertThat(task.getErrorMessage(), is(errorMessage.substring(0, 666)));
    Assert.assertThat(task.getRetries(), is(5));
    Assert.assertThat(externalTaskService.getExternalTaskErrorDetails(task.getId()), is(exceptionStackTrace));
    Assert.assertThat(task.getErrorDetails(), is(exceptionStackTrace));
}
Also used : RuntimeSqlException(org.apache.ibatis.jdbc.RuntimeSqlException) LockedExternalTask(org.camunda.bpm.engine.externaltask.LockedExternalTask) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

RuntimeSqlException (org.apache.ibatis.jdbc.RuntimeSqlException)1 LockedExternalTask (org.camunda.bpm.engine.externaltask.LockedExternalTask)1 Deployment (org.camunda.bpm.engine.test.Deployment)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1