use of org.kie.api.runtime.manager.audit.AuditService in project jbpm by kiegroup.
the class ConcurrentGlobalTimerServiceTest method testSessionPerProcessInstance.
@Test
public void testSessionPerProcessInstance() throws Exception {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).get();
long startTimeStamp = System.currentTimeMillis();
long maxEndTime = startTimeStamp + maxWaitTime;
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
// prepare task service with users and groups
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
TaskService taskService = engine.getTaskService();
Group grouphr = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) grouphr).setId("HR");
User mary = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) mary).setId("mary");
User john = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) john).setId("john");
((InternalTaskService) taskService).addGroup(grouphr);
((InternalTaskService) taskService).addUser(mary);
((InternalTaskService) taskService).addUser(john);
manager.disposeRuntimeEngine(engine);
completedStart = 0;
for (int i = 0; i < nbThreadsProcess; i++) {
new StartProcessPerProcessInstanceRunnable(manager, i).run();
}
completedTask = 0;
for (int i = 0; i < nbThreadsTask; i++) {
new Thread(new CompleteTaskPerProcessInstanceRunnable(manager, i)).start();
}
while (completedStart < nbThreadsProcess || completedTask < nbThreadsTask) {
Thread.sleep(100);
if (System.currentTimeMillis() > maxEndTime) {
fail("Failure, did not finish in time most likely hanging");
}
}
// make sure all process instance were completed
engine = manager.getRuntimeEngine(EmptyContext.get());
AuditService logService = engine.getAuditService();
// active
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
assertNotNull(logs);
for (ProcessInstanceLog log : logs) {
logger.debug("Left over {}", log.getProcessInstanceId());
}
assertEquals(0, logs.size());
// completed
logs = logService.findProcessInstances("IntermediateCatchEvent");
assertNotNull(logs);
assertEquals(nbThreadsProcess, logs.size());
manager.disposeRuntimeEngine(engine);
logger.debug("Done");
}
use of org.kie.api.runtime.manager.audit.AuditService in project jbpm by kiegroup.
the class GlobalTimerServiceVolumeTest method testRuntimeManagerStrategyWithTimerService.
@Test(timeout = 30000)
public void testRuntimeManagerStrategyWithTimerService() throws Exception {
// prepare task service with users and groups
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
TaskService taskService = engine.getTaskService();
Group grouphr = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) grouphr).setId("HR");
Group groupadmins = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) groupadmins).setId("Administrators");
User mary = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) mary).setId("mary");
User john = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) john).setId("john");
User admin = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) admin).setId("Administrator");
((InternalTaskService) taskService).addGroup(grouphr);
((InternalTaskService) taskService).addGroup(groupadmins);
((InternalTaskService) taskService).addUser(mary);
((InternalTaskService) taskService).addUser(john);
((InternalTaskService) taskService).addUser(admin);
manager.disposeRuntimeEngine(engine);
int counter = numberOfProcesses;
// start processes until oom
while (counter > 0) {
new GlobalTimerServiceVolumeTest.StartProcessPerProcessInstanceRunnable(manager).run();
counter--;
}
Collection<TimerJobInstance> timers = null;
Map<Long, List<GlobalJobHandle>> jobs = null;
TimerService timerService = TimerServiceRegistry.getInstance().get(manager.getIdentifier() + TimerServiceRegistry.TIMER_SERVICE_SUFFIX);
if (timerService != null) {
if (timerService instanceof GlobalTimerService) {
jobs = ((GlobalTimerService) timerService).getTimerJobsPerSession();
timers = ((GlobalTimerService) timerService).getTimerJobFactoryManager().getTimerJobInstances();
}
}
assertNotNull("Jobs should not be null as number of timers have been created", jobs);
assertEquals("There should be no jobs in the global timer service", 0, jobs.size());
assertNotNull("Timer instances should not be null as number of timers have been created", timers);
assertEquals("There should be no timer instances in the global timer service manager", 0, timers.size());
RuntimeEngine empty = manager.getRuntimeEngine(EmptyContext.get());
AuditService logService = empty.getAuditService();
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
assertEquals("Active process instances should be " + numberOfProcesses, numberOfProcesses, logs.size());
countDownListener.waitTillCompleted();
List<TaskSummary> tasks = empty.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals("Number of John's tasks should be " + numberOfProcesses, numberOfProcesses, tasks.size());
for (TaskSummary task : tasks) {
RuntimeEngine piEngine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(task.getProcessInstanceId()));
piEngine.getTaskService().start(task.getId(), "john");
piEngine.getTaskService().complete(task.getId(), "john", null);
manager.disposeRuntimeEngine(piEngine);
}
logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
assertEquals("Active process instances should be 0", 0, logs.size());
logService.dispose();
manager.disposeRuntimeEngine(empty);
}
use of org.kie.api.runtime.manager.audit.AuditService in project jbpm by kiegroup.
the class WorkitemAssignmentTest method testWorkitemAssignment.
@Test
public void testWorkitemAssignment() {
manager = createRuntimeManager("org/jbpm/test/functional/workitem/workitemAssignmentTest.bpmn2");
RuntimeEngine runtimeEngine = getRuntimeEngine(EmptyContext.get());
KieSession kieSession = runtimeEngine.getKieSession();
WorkItemManager workItemManager = (org.drools.core.process.instance.WorkItemManager) kieSession.getWorkItemManager();
workItemManager.registerWorkItemHandler("SampleUserWorkitem", new UserAssignmentWorkitemHandler());
Map<String, Object> initEmptyVars = new HashMap<String, Object>();
initEmptyVars.put("firstName", "initValue");
initEmptyVars.put("lastName", "initValue");
ProcessInstance pi = kieSession.startProcess("workitemassignmenttest", initEmptyVars);
// values should be from initial state when process instance started -- "initValue", "initValue"
String varFirstNameOrig = (String) ((WorkflowProcessInstance) pi).getVariable("firstName");
String varLasttNameOrig = (String) ((WorkflowProcessInstance) pi).getVariable("lastName");
assertEquals("initValue", varFirstNameOrig);
assertEquals("initValue", varLasttNameOrig);
// advance process execution past first user task
// it will then go through the custom workitem and
// get into the second user task
TaskService taskService = runtimeEngine.getTaskService();
assertProcessInstanceActive(pi.getId());
assertNodeTriggered(pi.getId(), "myFirstUserTask");
assertNodeActive(pi.getId(), kieSession, "myFirstUserTask");
List<TaskSummary> firstTasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, firstTasks.size());
TaskSummary firstTaskSummary = firstTasks.get(0);
taskService.start(firstTaskSummary.getId(), "john");
taskService.complete(firstTaskSummary.getId(), "john", null);
// get process instance again to get updated process var values which were set
// by the assignments in custom workitem handler
ProcessInstance processInstance = kieSession.getProcessInstance(pi.getId());
String varFirstName = (String) ((WorkflowProcessInstance) processInstance).getVariable("firstName");
String varLasttName = (String) ((WorkflowProcessInstance) processInstance).getVariable("lastName");
assertNotNull(varFirstName);
assertNotNull(varLasttName);
assertEquals(UserAssignmentWorkitemHandler.fnameStr, varFirstName);
assertEquals(UserAssignmentWorkitemHandler.lnameStr, varLasttName);
// make sure we passed the custom workitem
assertNodeTriggered(pi.getId(), "SampleUserWorkitem");
assertNodeActive(pi.getId(), kieSession, "mySecondUserTask");
List<TaskSummary> secondTasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, secondTasks.size());
// advance paste the second user task to complete the process instance
TaskSummary secondTaskSummary = secondTasks.get(0);
taskService.start(secondTaskSummary.getId(), "john");
taskService.complete(secondTaskSummary.getId(), "john", null);
assertProcessInstanceCompleted(processInstance.getId());
// now we can check audit service to see process vars
// and how they chaged throughout process execution
AuditService auditService = runtimeEngine.getAuditService();
List<? extends VariableInstanceLog> firstNameVars = auditService.findVariableInstances(processInstance.getId(), "firstName");
List<? extends VariableInstanceLog> lastNameVars = auditService.findVariableInstances(processInstance.getId(), "lastName");
assertNotNull(firstNameVars);
assertNotNull(lastNameVars);
assertEquals(2, firstNameVars.size());
assertEquals("initValue", firstNameVars.get(0).getValue());
assertEquals(UserAssignmentWorkitemHandler.fnameStr, firstNameVars.get(1).getValue());
assertEquals(2, lastNameVars.size());
assertEquals("initValue", lastNameVars.get(0).getValue());
assertEquals(UserAssignmentWorkitemHandler.lnameStr, lastNameVars.get(1).getValue());
}
use of org.kie.api.runtime.manager.audit.AuditService in project jbpm by kiegroup.
the class TimerEventTest method testStartTimerCycle.
@Test
@BZ("1104563")
public void testStartTimerCycle() throws InterruptedException {
KieSession ksession = createKSession(START_TIMER_CYCLE);
AuditService auditService = getLogService();
ksession.startProcess(START_TIMER_CYCLE_ID);
Assertions.assertThat(auditService.findProcessInstances()).hasSize(1);
Thread.sleep(5000);
Assertions.assertThat(auditService.findProcessInstances()).hasSize(2);
Thread.sleep(5000);
Assertions.assertThat(auditService.findProcessInstances()).hasSize(3);
}
use of org.kie.api.runtime.manager.audit.AuditService in project jbpm by kiegroup.
the class ReusableSubprocessTest method testDependentSubprocessAbort.
@Test
@BZ("1128597")
public void testDependentSubprocessAbort() {
RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "myPpiManager", DEPENDENT_SUBPROCESS_ABORT_PARENT, DEPENDENT_SUBPROCESS_ABORT_SUBPROCESS);
Assertions.assertThat(manager).isNotNull();
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
Assertions.assertThat(ksession).isNotNull();
Assertions.assertThat(ksession.getId()).isEqualTo(2);
ProcessInstance pi1 = ksession.startProcess(DEPENDENT_SUBPROCESS_ABORT_PARENT_ID);
assertProcessInstanceActive(pi1.getId());
// Aborting the parent process
ksession.abortProcessInstance(pi1.getId());
AuditService logService = getLogService();
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances(DEPENDENT_SUBPROCESS_ABORT_PARENT_ID);
Assertions.assertThat(logs).isNotNull();
Assertions.assertThat(logs).hasSize(0);
logs = logService.findActiveProcessInstances(DEPENDENT_SUBPROCESS_ABORT_SUBPROCESS_ID);
Assertions.assertThat(logs).isNotNull();
Assertions.assertThat(logs).hasSize(0);
logs = logService.findProcessInstances(DEPENDENT_SUBPROCESS_ABORT_PARENT_ID);
Assertions.assertThat(logs).isNotNull();
Assertions.assertThat(logs).hasSize(1);
assertProcessInstanceAborted(logs.get(0).getProcessInstanceId());
logs = logService.findProcessInstances(DEPENDENT_SUBPROCESS_ABORT_SUBPROCESS_ID);
Assertions.assertThat(logs).isNotNull();
Assertions.assertThat(logs).hasSize(1);
assertProcessInstanceAborted(logs.get(0).getProcessInstanceId());
manager.close();
}
Aggregations