use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testHandleBpmnErrorSuspendedTask.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleBpmnErrorSuspendedTask() {
// given
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(5, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
LockedExternalTask task = externalTasks.get(0);
// when suspending the process instance
runtimeService.suspendProcessInstanceById(processInstance.getId());
// then the external task cannot be completed
try {
externalTaskService.handleBpmnError(task.getId(), WORKER_ID, "ERROR-OCCURED");
fail("expected exception");
} catch (ProcessEngineException e) {
assertTextPresent("ExternalTask with id '" + task.getId() + "' is suspended", e.getMessage());
}
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testCompleteWithNonLocalVariables.
public void testCompleteWithNonLocalVariables() {
// given
BpmnModelInstance instance = Bpmn.createExecutableProcess("Process").startEvent().serviceTask("externalTask").camundaType("external").camundaTopic("foo").camundaTaskPriority("100").camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ReadLocalVariableListenerImpl.class).userTask("user").endEvent().done();
deployment(instance);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Process");
List<LockedExternalTask> lockedTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic("foo", 1L).execute();
// when
externalTaskService.complete(lockedTasks.get(0).getId(), WORKER_ID, Variables.createVariables().putValue("abc", "bar"), null);
// then
VariableInstance variableInstance = runtimeService.createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()).singleResult();
assertNotNull(variableInstance);
assertEquals("bar", variableInstance.getValue());
assertEquals("abc", variableInstance.getName());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testHandleFailureNullErrorMessage.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testHandleFailureNullErrorMessage() {
// given
runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
// when
externalTaskService.handleFailure(externalTasks.get(0).getId(), WORKER_ID, null, 5, LOCK_TIME);
// then the failure was reported successfully and the error message is null
ExternalTask task = externalTaskService.createExternalTaskQuery().singleResult();
assertEquals(5, (int) task.getRetries());
assertNull(task.getErrorMessage());
assertNull(externalTaskService.getExternalTaskErrorDetails(task.getId()));
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask in project camunda-bpm-platform by camunda.
the class ExternalTaskServiceTest method testLocking.
@Deployment(resources = "org/camunda/bpm/engine/test/api/externaltask/oneExternalTaskProcess.bpmn20.xml")
public void testLocking() {
// given
runtimeService.startProcessInstanceByKey("oneExternalTaskProcess");
// when
List<LockedExternalTask> externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
// then the task is locked
assertEquals(1, externalTasks.size());
LockedExternalTask task = externalTasks.get(0);
AssertUtil.assertEqualsSecondPrecision(nowPlus(LOCK_TIME), task.getLockExpirationTime());
// and cannot be retrieved by another query
externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(0, externalTasks.size());
// unless the expiration time expires
ClockUtil.setCurrentTime(new DateTime(ClockUtil.getCurrentTime()).plus(LOCK_TIME * 2).toDate());
externalTasks = externalTaskService.fetchAndLock(1, WORKER_ID).topic(TOPIC_NAME, LOCK_TIME).execute();
assertEquals(1, externalTasks.size());
}
use of org.camunda.bpm.engine.externaltask.LockedExternalTask 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));
}
Aggregations