use of org.kie.internal.runtime.error.ExecutionErrorStorage 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.ExecutionErrorStorage 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.ExecutionErrorStorage 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.ExecutionErrorStorage 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");
}
use of org.kie.internal.runtime.error.ExecutionErrorStorage in project jbpm by kiegroup.
the class ExecutionErrorHandlingRuntimeManagerTest method createEnvironment.
private RuntimeEnvironment createEnvironment() {
ExecutionErrorStorage storage = new ExecutionErrorStorage() {
private List<ExecutionError> errors = new ArrayList<>();
@Override
public ExecutionError store(ExecutionError error) {
this.errors.add(error);
return error;
}
@Override
public List<ExecutionError> listByProcessInstance(Long processInstanceId, Integer page, Integer pageSize) {
return errors;
}
@Override
public List<ExecutionError> listByDeployment(String deploymentId, Integer page, Integer pageSize) {
return errors;
}
@Override
public List<ExecutionError> listByActivity(String activityName, Integer page, Integer pageSize) {
return errors;
}
@Override
public List<ExecutionError> list(Integer page, Integer pageSize) {
return errors;
}
@Override
public ExecutionError get(String errorId) {
return errors.stream().filter(err -> err.getErrorId().equals(errorId)).findFirst().get();
}
@Override
public void acknowledge(String user, String... errorIds) {
for (String errorId : errorIds) {
ExecutionError error = get(errorId);
error.setAcknowledged(true);
error.setAcknowledgedBy(user);
error.setAcknowledgedAt(new Date());
}
}
};
RuntimeEnvironmentBuilder environmentBuilder = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-BrokenScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithRollback.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskCustomTask.bpmn2"), ResourceType.BPMN2);
if (testName.getMethodName().contains("InMemoryStorage")) {
environmentBuilder.addEnvironmentEntry("ExecutionErrorStorage", storage);
}
return environmentBuilder.get();
}
Aggregations