use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.
the class MultipleTimerServicesTest method testGlobalTimerServiceOnIndependentManager.
public void testGlobalTimerServiceOnIndependentManager() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
NodeLeftCountDownProcessEventListener countDownListener2 = new NodeLeftCountDownProcessEventListener("timer", 3);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listenerM1 = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
logger.debug("On manager 1");
timerExporations.add(event.getProcessInstance().getId());
}
}
};
final List<Long> timerExporations2 = new ArrayList<Long>();
ProcessEventListener listenerM2 = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
logger.debug("On manager 2");
timerExporations2.add(event.getProcessInstance().getId());
}
}
};
environmentM1 = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listenerM1, countDownListener)).schedulerService(globalScheduler1).get();
environmentM2 = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf2).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new TestRegisterableItemsFactory(listenerM2, countDownListener2)).schedulerService(globalScheduler2).get();
managerM1 = getManager(environmentM1, "one");
RuntimeEngine runtimeM1 = managerM1.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksessionM1 = runtimeM1.getKieSession();
managerM2 = getManager(environmentM2, "two");
RuntimeEngine runtimeM2 = managerM2.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksessionM2 = runtimeM2.getKieSession();
ProcessInstance processInstanceM1 = ksessionM1.startProcess("IntermediateCatchEvent");
assertTrue(processInstanceM1.getState() == ProcessInstance.STATE_ACTIVE);
ProcessInstance processInstanceM2 = ksessionM2.startProcess("IntermediateCatchEvent");
assertTrue(processInstanceM2.getState() == ProcessInstance.STATE_ACTIVE);
// now wait for 1 second for first timer to trigger
countDownListener.waitTillCompleted(2000);
countDownListener2.waitTillCompleted(2000);
// dispose session to force session to be reloaded on timer expiration
managerM1.disposeRuntimeEngine(runtimeM1);
managerM2.disposeRuntimeEngine(runtimeM2);
countDownListener.waitTillCompleted();
countDownListener2.waitTillCompleted();
countDownListener.reset(1);
countDownListener2.reset(1);
try {
runtimeM1 = managerM1.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceM1.getId()));
ksessionM1 = runtimeM1.getKieSession();
processInstanceM1 = ksessionM1.getProcessInstance(processInstanceM1.getId());
assertNull(processInstanceM1);
} catch (SessionNotFoundException e) {
// expected in PerProcessInstance manager
}
try {
runtimeM2 = managerM2.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceM2.getId()));
ksessionM2 = runtimeM2.getKieSession();
processInstanceM2 = ksessionM2.getProcessInstance(processInstanceM2.getId());
assertNull(processInstanceM2);
} catch (SessionNotFoundException e) {
// expected in PerProcessInstance manager
}
// let's wait to ensure no more timers are expired and triggered
countDownListener.waitTillCompleted(3000);
countDownListener2.waitTillCompleted(3000);
managerM1.disposeRuntimeEngine(runtimeM1);
managerM2.disposeRuntimeEngine(runtimeM2);
assertEquals(3, timerExporations.size());
assertEquals(3, timerExporations2.size());
}
use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.
the class WorkflowProcessInstanceImpl method setState.
public void setState(final int state, String outcome) {
super.setState(state, outcome);
// TODO move most of this to ProcessInstanceImpl
if (state == ProcessInstance.STATE_COMPLETED || state == ProcessInstance.STATE_ABORTED) {
if (this.slaCompliance == SLA_PENDING) {
if (System.currentTimeMillis() > slaDueDate.getTime()) {
// completion of the process instance is after expected SLA due date, mark it accordingly
this.slaCompliance = SLA_VIOLATED;
} else {
this.slaCompliance = state == ProcessInstance.STATE_COMPLETED ? SLA_MET : SLA_ABORTED;
}
}
InternalKnowledgeRuntime kruntime = getKnowledgeRuntime();
InternalProcessRuntime processRuntime = (InternalProcessRuntime) kruntime.getProcessRuntime();
processRuntime.getProcessEventSupport().fireBeforeProcessCompleted(this, kruntime);
// deactivate all node instances of this process instance
while (!nodeInstances.isEmpty()) {
NodeInstance nodeInstance = nodeInstances.get(0);
((org.jbpm.workflow.instance.NodeInstance) nodeInstance).cancel();
}
if (this.slaTimerId > -1) {
processRuntime.getTimerManager().cancelTimer(this.slaTimerId);
logger.debug("SLA Timer {} has been canceled", this.slaTimerId);
}
removeEventListeners();
processRuntime.getProcessInstanceManager().removeProcessInstance(this);
processRuntime.getProcessEventSupport().fireAfterProcessCompleted(this, kruntime);
if (isSignalCompletion()) {
RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER);
if (getParentProcessInstanceId() > 0 && manager != null) {
try {
org.kie.api.runtime.manager.Context<?> context = ProcessInstanceIdContext.get(getParentProcessInstanceId());
String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID);
if (caseId != null) {
context = CaseContext.get(caseId);
}
RuntimeEngine runtime = manager.getRuntimeEngine(context);
KieRuntime managedkruntime = (KieRuntime) runtime.getKieSession();
managedkruntime.signalEvent("processInstanceCompleted:" + getId(), this);
} catch (SessionNotFoundException e) {
// in case no session is found for parent process let's skip signal for process instance completion
}
} else {
processRuntime.getSignalManager().signalEvent("processInstanceCompleted:" + getId(), this);
}
}
}
}
use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.
the class GlobalThreadPoolTimerServiceTest method testInterediateTimerWithGlobalTestServiceWithinTransaction.
@Test(timeout = 20000)
public void testInterediateTimerWithGlobalTestServiceWithinTransaction() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
globalScheduler = new TransactionalThreadPoolSchedulerService(3);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
timerExporations.add(event.getProcessInstance().getId());
}
}
};
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
// now wait for 1 second for first timer to trigger
countDownListener.waitTillCompleted(2000);
// dispose session to force session to be reloaded on timer expiration
manager.disposeRuntimeEngine(runtime);
countDownListener.waitTillCompleted();
countDownListener.reset(1);
try {
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtime.getKieSession();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
// expected for PerProcessInstanceManagers since process instance is completed
}
// let's wait to ensure no more timers are expired and triggered
countDownListener.waitTillCompleted(3000);
assertEquals(3, timerExporations.size());
manager.disposeRuntimeEngine(runtime);
}
use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testInterediateTimerWithGlobalTestService.
@Test(timeout = 20000)
public void testInterediateTimerWithGlobalTestService() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("timer", 3);
// prepare listener to assert results
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if (event.getNodeInstance().getNodeName().equals("timer")) {
timerExporations.add(event.getProcessInstance().getId());
}
}
};
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycle3.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
ProcessInstance processInstance = ksession.startProcess("IntermediateCatchEvent");
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
// now wait for 1 second for first timer to trigger
Thread.sleep(1500);
// dispose session to force session to be reloaded on timer expiration
manager.disposeRuntimeEngine(runtime);
Thread.sleep(2000);
try {
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtime.getKieSession();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
// expected for PerProcessInstanceManagers since process instance is completed
}
// let's wait to ensure no more timers are expired and triggered
countDownListener.waitTillCompleted();
assertEquals(3, timerExporations.size());
manager.disposeRuntimeEngine(runtime);
}
use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testHumanTaskDeadlineWithGlobalTimerServiceMultipleInstances.
@Test
public void testHumanTaskDeadlineWithGlobalTimerServiceMultipleInstances() throws Exception {
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/HumanTaskWithDeadlines.bpmn"), ResourceType.BPMN2).schedulerService(globalScheduler).get();
manager = getManager(environment, true);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
ProcessInstance processInstance = ksession.startProcess("htdeadlinetest");
manager.disposeRuntimeEngine(runtime);
RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession2 = runtime2.getKieSession();
ProcessInstance processInstance2 = ksession2.startProcess("htdeadlinetest");
// abort second instance to trigger unschedule of deadlines
ksession2.abortProcessInstance(processInstance2.getId());
manager.disposeRuntimeEngine(runtime2);
assertTrue(processInstance.getState() == ProcessInstance.STATE_ACTIVE);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
List<TaskSummary> krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
assertEquals(1, krisTasks.size());
List<TaskSummary> johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(0, johnTasks.size());
List<TaskSummary> maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(0, maryTasks.size());
manager.disposeRuntimeEngine(runtime);
// now wait for 2 seconds for first reassignment
Thread.sleep(3000);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
assertEquals(0, krisTasks.size());
johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, johnTasks.size());
maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(0, maryTasks.size());
runtime.getTaskService().start(johnTasks.get(0).getId(), "john");
manager.disposeRuntimeEngine(runtime);
// now wait for 2 more seconds for second reassignment
Thread.sleep(2000);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
assertEquals(0, krisTasks.size());
johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, johnTasks.size());
maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(0, maryTasks.size());
manager.disposeRuntimeEngine(runtime);
// now wait for 1 seconds to make sure that reassignment did not happen any more since task was already started
Thread.sleep(3000);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
krisTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("krisv", "en-UK");
assertEquals(0, krisTasks.size());
johnTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(0, johnTasks.size());
maryTasks = runtime.getTaskService().getTasksAssignedAsPotentialOwner("mary", "en-UK");
assertEquals(1, maryTasks.size());
runtime.getTaskService().start(maryTasks.get(0).getId(), "mary");
runtime.getTaskService().complete(maryTasks.get(0).getId(), "mary", null);
manager.disposeRuntimeEngine(runtime);
// now wait for 2 seconds to make sure that reassignment did not happen any more since task was completed
Thread.sleep(2000);
try {
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
ksession = runtime.getKieSession();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
} catch (SessionNotFoundException e) {
// this can be thrown for per process instance strategy as instance has already been completed
}
manager.disposeRuntimeEngine(runtime);
}
Aggregations