Example usage for org.apache.ibatis.jdbc RuntimeSqlException RuntimeSqlException

List of usage examples for org.apache.ibatis.jdbc RuntimeSqlException RuntimeSqlException

Introduction

In this page you can find the example usage for org.apache.ibatis.jdbc RuntimeSqlException RuntimeSqlException.

Prototype

public RuntimeSqlException(Throwable cause) 

Source Link

Usage

From source file:org.camunda.bpm.engine.test.api.externaltask.ExternalTaskServiceTest.java

License:Apache License

@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleFailureWithErrorDetails() {
    // given// w  ww . j a  va2 s .  c  om
    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));
}