use of org.kie.internal.runtime.error.ExecutionError in project jbpm by kiegroup.
the class CleanupExecutionErrorCommandWithProcessTest method testRunProcessWithAsyncHandlerDeleteUsingOlderThan.
@Test(timeout = 30000)
public void testRunProcessWithAsyncHandlerDeleteUsingOlderThan() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = configureEnvironment();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
ExecutionErrorStorage errorStorage = ((AbstractRuntimeManager) manager).getExecutionErrorManager().getStorage();
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
Date startDate = new Date();
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
long processInstanceId = processInstance.getId();
countDownListener.waitTillCompleted();
List<ExecutionError> errors = errorStorage.list(0, 10);
assertEquals(1, errors.size());
scheduleLogCleanup(startDate, null, true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd", manager.getIdentifier());
countDownListener.reset(1);
countDownListener.waitTillCompleted();
System.out.println("Aborting process instance " + processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
// should not delete any errors as the process instance is still active
errors = errorStorage.list(0, 10);
assertEquals(1, errors.size());
runtime.getKieSession().abortProcessInstance(processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
Thread.sleep(1000);
scheduleLogCleanup(new Date(), null, true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
countDownListener.reset(1);
countDownListener.waitTillCompleted();
errors = errorStorage.list(0, 10);
assertEquals(0, errors.size());
}
use of org.kie.internal.runtime.error.ExecutionError in project jbpm by kiegroup.
the class UserTaskAdminServiceImpl method acknowledgeError.
@Override
public void acknowledgeError(String... errorId) throws ExecutionErrorNotFoundException {
for (String error : errorId) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("errorId", error);
params.put("ack", new Short("0"));
List<ExecutionError> execErrors = commandService.execute(new QueryNameCommand<List<ExecutionError>>("getErrorById", params));
if (execErrors.isEmpty()) {
throw new ExecutionErrorNotFoundException("No execution error found for id " + errorId);
}
ExecutionError errorInstance = execErrors.get(0);
RuntimeManager runtimeManager = RuntimeManagerRegistry.get().getManager(errorInstance.getDeploymentId());
if (runtimeManager != null) {
((AbstractRuntimeManager) runtimeManager).getExecutionErrorManager().getStorage().acknowledge(identityProvider.getName(), errorInstance.getErrorId());
}
}
}
use of org.kie.internal.runtime.error.ExecutionError in project jbpm by kiegroup.
the class ExecutionErrorHandlingRuntimeManagerTest method testScriptFailureAfterUserTask.
@Test
public void testScriptFailureAfterUserTask() {
RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession1 = runtime1.getKieSession();
assertNotNull(ksession1);
ProcessInstance pi = ksession1.startProcess("UserTaskWithRollback");
manager.disposeRuntimeEngine(runtime1);
runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi.getId()));
ksession1 = runtime1.getKieSession();
TaskService taskService = runtime1.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
Map<String, Object> results = new HashMap<>();
results.put("output1", "rollback");
try {
taskService.complete(taskId, "john", results);
fail("Complete task should fail due to broken script");
} catch (Throwable e) {
// expected
}
manager.disposeRuntimeEngine(runtime1);
ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
ExecutionErrorStorage storage = errorManager.getStorage();
List<ExecutionError> errors = storage.list(0, 10);
assertNotNull(errors);
assertEquals(1, errors.size());
assertExecutionError(errors.get(0), "Process", "UserTaskWithRollback", "Script Task 1");
}
use of org.kie.internal.runtime.error.ExecutionError in project jbpm by kiegroup.
the class ExecutionErrorHandlingRuntimeManagerTest method testDataBaseFailureInMemoryStorage.
@Test
public void testDataBaseFailureInMemoryStorage() {
RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession1 = runtime1.getKieSession();
assertNotNull(ksession1);
ksession1.addEventListener(new DefaultProcessEventListener() {
@Override
public void afterProcessStarted(ProcessStartedEvent event) {
pds.close();
}
});
try {
ksession1.startProcess("UserTaskWithRollback");
fail("Start process should fail due to data base error");
} catch (Throwable e) {
// expected
}
int expectedErrors = 1;
try {
manager.disposeRuntimeEngine(runtime1);
} catch (Exception e) {
// expected to fail for some strategies due to data source being down
expectedErrors++;
}
ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
ExecutionErrorStorage storage = errorManager.getStorage();
List<ExecutionError> errors = storage.list(0, 10);
assertNotNull(errors);
assertEquals(expectedErrors, errors.size());
assertExecutionError(errors.get(0), "DB", "UserTaskWithRollback", "Hello");
}
use of org.kie.internal.runtime.error.ExecutionError in project jbpm by kiegroup.
the class ExecutionErrorHandlingRuntimeManagerTest method testUserTaskFailure.
@SuppressWarnings("unchecked")
@Test
public void testUserTaskFailure() {
RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession1 = runtime1.getKieSession();
assertNotNull(ksession1);
ksession1.startProcess("UserTaskWithRollback");
TaskService taskService = runtime1.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
try {
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new DefaultTaskEventListener() {
@Override
public void afterTaskStartedEvent(TaskEvent event) {
throw new TaskExecutionException("On purpose");
}
});
taskService.start(taskId, "john");
fail("Start task should fail due to broken script");
} catch (Throwable e) {
// expected
}
manager.disposeRuntimeEngine(runtime1);
ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
ExecutionErrorStorage storage = errorManager.getStorage();
List<ExecutionError> errors = storage.list(0, 10);
assertNotNull(errors);
assertEquals(1, errors.size());
assertExecutionError(errors.get(0), "Task", "UserTaskWithRollback", "Hello");
}
Aggregations