Search in sources :

Example 6 with ExecutionErrorStorage

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());
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Date(java.util.Date) Test(org.junit.Test) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest)

Example 7 with ExecutionErrorStorage

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");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) TaskSummary(org.kie.api.task.model.TaskSummary) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 8 with ExecutionErrorStorage

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");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) TaskExecutionException(org.jbpm.services.task.exception.TaskExecutionException) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 9 with ExecutionErrorStorage

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");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) TaskService(org.kie.api.task.TaskService) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) EventService(org.kie.internal.task.api.EventService) DefaultTaskEventListener(org.jbpm.services.task.events.DefaultTaskEventListener) TaskExecutionException(org.jbpm.services.task.exception.TaskExecutionException) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) TaskSummary(org.kie.api.task.model.TaskSummary) TaskEvent(org.kie.api.task.TaskEvent) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 10 with ExecutionErrorStorage

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();
}
Also used : ExecutionError(org.kie.internal.runtime.error.ExecutionError) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) List(java.util.List) ArrayList(java.util.ArrayList) Date(java.util.Date) RuntimeEnvironmentBuilder(org.kie.api.runtime.manager.RuntimeEnvironmentBuilder)

Aggregations

ExecutionError (org.kie.internal.runtime.error.ExecutionError)14 ExecutionErrorStorage (org.kie.internal.runtime.error.ExecutionErrorStorage)14 Test (org.junit.Test)13 KieSession (org.kie.api.runtime.KieSession)13 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)13 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)10 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)10 ExecutionErrorManager (org.kie.internal.runtime.error.ExecutionErrorManager)10 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)8 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)8 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)7 HashMap (java.util.HashMap)5 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)5 TaskService (org.kie.api.task.TaskService)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)3 TaskExecutionException (org.jbpm.services.task.exception.TaskExecutionException)3 CommandContext (org.kie.api.executor.CommandContext)3 RequestInfo (org.kie.api.executor.RequestInfo)3