use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class CleanupExecutionErrorCommandWithProcessTest method testRunProcessWithAsyncHandlerDeleteUsingOlderThanPeriod.
@Test(timeout = 30000)
public void testRunProcessWithAsyncHandlerDeleteUsingOlderThanPeriod() 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);
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());
// advance time 1 second
Thread.sleep(1000);
// delete errors which happened 1s or more ago
scheduleLogCleanup(null, "1s", true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", 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);
// delete errors which happened 5s or more ago
scheduleLogCleanup(null, "5s", true, null, "ScriptTask", String.valueOf(processInstanceId), "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
countDownListener.reset(1);
countDownListener.waitTillCompleted();
// should not delete any errors as we wanted to delete errors from 5s ago
errors = errorStorage.list(0, 10);
assertEquals(1, errors.size());
// delete errors which happened 1s or more ago
scheduleLogCleanup(null, "0s", 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.api.runtime.manager.RuntimeEnvironment 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.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class CleanupLogCommandWithProcessTest method testRunProcessWithAsyncHandlerDontDeleteActive.
@Test
public void testRunProcessWithAsyncHandlerDontDeleteActive() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("async", new DoNothingWorkItemHandler());
return handlers;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
assertEquals(0, getProcessLogSize("ScriptTask"));
assertEquals(0, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
Date startDate = new Date();
ProcessInstance processInstance = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
scheduleLogCleanup(false, true, false, startDate, "ScriptTask", "yyyy-MM-dd", manager.getIdentifier());
countDownListener.waitTillCompleted();
System.out.println("Aborting process instance " + processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNotNull(processInstance);
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
runtime.getKieSession().abortProcessInstance(processInstance.getId());
processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
assertNull(processInstance);
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(6, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
// and start another one to keep it active while cleanup happens
processInstance = ksession.startProcess("ScriptTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
assertEquals(2, getProcessLogSize("ScriptTask"));
assertEquals(11, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
Thread.sleep(1000);
scheduleLogCleanup(false, false, false, new Date(), "ScriptTask", "yyyy-MM-dd HH:mm:ss", manager.getIdentifier());
countDownListener.reset(1);
countDownListener.waitTillCompleted();
assertEquals(1, getProcessLogSize("ScriptTask"));
assertEquals(5, getNodeInstanceLogSize("ScriptTask"));
assertEquals(0, getTaskLogSize("ScriptTask"));
assertEquals(0, getVariableLogSize("ScriptTask"));
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class SLATrackingCommandTest method testSLATrackingOnUserTaskSLAMet.
@Test
public void testSLATrackingOnUserTaskSLAMet() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithSLAOnTask.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("SLATimerMode", "false").get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("UserTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
List<TaskSummary> tasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
JPAAuditLogService logService = new JPAAuditLogService(emf);
assertNodeInstanceSLACompliance(logService, processInstance.getId(), "Hello", ProcessInstance.SLA_PENDING);
scheduleSLATracking(manager.getIdentifier());
countDownListener.waitTillCompleted();
assertNodeInstanceSLACompliance(logService, processInstance.getId(), "Hello", ProcessInstance.SLA_PENDING);
runtime.getTaskService().start(tasks.get(0).getId(), "john");
runtime.getTaskService().complete(tasks.get(0).getId(), "john", null);
assertNodeInstanceSLACompliance(logService, processInstance.getId(), "Hello", ProcessInstance.SLA_MET);
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class SLATrackingCommandTest method testSLATrackingOnProcessInstance.
@Test
public void testSLATrackingOnProcessInstance() throws Exception {
CountDownAsyncJobListener countDownListener = configureListener(1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithSLA.bpmn2"), ResourceType.BPMN2).addEnvironmentEntry("SLATimerMode", "false").get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance processInstance = ksession.startProcess("UserTask");
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
JPAAuditLogService logService = new JPAAuditLogService(emf);
assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_PENDING);
scheduleSLATracking(manager.getIdentifier());
countDownListener.waitTillCompleted();
assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_PENDING);
// wait for due date of SLA to pass
Thread.sleep(3000);
countDownListener.reset(1);
scheduleSLATracking(manager.getIdentifier());
countDownListener.waitTillCompleted();
assertProcessInstanceSLACompliance(logService, processInstance.getId(), ProcessInstance.SLA_VIOLATED);
}
Aggregations