use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testSignalEventWithDeactivate.
@Test
public void testSignalEventWithDeactivate() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime1 = manager.getRuntimeEngine(CaseContext.get("Case-1"));
KieSession ksession1 = runtime1.getKieSession();
ksession1.signalEvent("SampleEvent", null);
List<? extends ProcessInstanceLog> logs = runtime1.getAuditService().findProcessInstances();
assertEquals(1, logs.size());
manager.disposeRuntimeEngine(runtime1);
((InternalRuntimeManager) manager).deactivate();
runtime1 = manager.getRuntimeEngine(CaseContext.get("Case-1"));
ksession1 = runtime1.getKieSession();
ksession1.signalEvent("SampleEvent", null);
logs = runtime1.getAuditService().findProcessInstances();
assertEquals(1, logs.size());
manager.disposeRuntimeEngine(runtime1);
((InternalRuntimeManager) manager).activate();
runtime1 = manager.getRuntimeEngine(CaseContext.get("Case-1"));
ksession1 = runtime1.getKieSession();
ksession1.signalEvent("SampleEvent", null);
logs = runtime1.getAuditService().findProcessInstances();
assertEquals(2, logs.size());
manager.disposeRuntimeEngine(runtime1);
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerCaseRuntimeManagerTest method testCreationOfSession.
@Test
public void testCreationOfSession() {
final Set<Long> ksessionUsed = new HashSet<Long>();
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(new DefaultProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
}
});
return listeners;
}
}).get();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id > 0);
// ksession for process instance #2
// since there is no process instance yet we need to get new session
RuntimeEngine runtime2 = manager.getRuntimeEngine(CaseContext.get("Case-2"));
KieSession ksession2 = runtime2.getKieSession();
assertNotNull(ksession2);
long ksession2Id = ksession2.getIdentifier();
assertTrue(ksession2Id > ksession1Id);
ProcessInstance pi1 = ksession.startProcess("UserTask");
ProcessInstance pi2 = ksession2.startProcess("UserTask");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
manager.disposeRuntimeEngine(runtime);
manager.disposeRuntimeEngine(runtime2);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
ksession = runtime.getKieSession();
assertEquals(ksession1Id, ksession.getIdentifier());
runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId()));
ksession2 = runtime2.getKieSession();
assertEquals(ksession2Id, ksession2.getIdentifier());
manager.disposeRuntimeEngine(runtime);
manager.disposeRuntimeEngine(runtime2);
// now let's check by case context
runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
ksession = runtime.getKieSession();
assertEquals(ksession1Id, ksession.getIdentifier());
runtime2 = manager.getRuntimeEngine(CaseContext.get("Case-2"));
ksession2 = runtime2.getKieSession();
assertEquals(ksession2Id, ksession2.getIdentifier());
assertEquals(2, ksessionUsed.size());
assertTrue(ksessionUsed.contains(ksession1Id));
assertTrue(ksessionUsed.contains(ksession2Id));
manager.disposeRuntimeEngine(runtime);
manager.disposeRuntimeEngine(runtime2);
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionWithPersistence.
@Test
public void testCreationOfSessionWithPersistence() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 2);
// ksession for process instance #2
// since there is no process instance yet we need to get new session
RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession2 = runtime2.getKieSession();
assertNotNull(ksession2);
long ksession2Id = ksession2.getIdentifier();
assertTrue(ksession2Id == 3);
ProcessInstance pi1 = ksession.startProcess("UserTask");
ProcessInstance pi2 = ksession2.startProcess("UserTask");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
ksession = runtime.getKieSession();
assertEquals(ksession1Id, ksession.getIdentifier());
ksession.getWorkItemManager().completeWorkItem(1, null);
manager.disposeRuntimeEngine(runtime);
// since process is completed now session should not be there any more
try {
manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId())).getKieSession();
fail("Session for this (" + pi1.getId() + ") process instance is no more accessible");
} catch (RuntimeException e) {
}
runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId()));
;
ksession2 = runtime2.getKieSession();
assertEquals(ksession2Id, ksession2.getIdentifier());
ksession2.getWorkItemManager().completeWorkItem(2, null);
manager.disposeRuntimeEngine(runtime2);
// since process is completed now session should not be there any more
try {
manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId())).getKieSession();
fail("Session for this (" + pi2.getId() + ") process instance is no more accessible");
} catch (RuntimeException e) {
}
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionWithPersistenceAndAuditService.
@Test
public void testCreationOfSessionWithPersistenceAndAuditService() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 2);
AuditService auditService = runtime.getAuditService();
assertNotNull(auditService);
List<? extends ProcessInstanceLog> logs = auditService.findProcessInstances();
assertNotNull(logs);
assertEquals(0, logs.size());
// ksession for process instance #2
// since there is no process instance yet we need to get new session
RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession2 = runtime2.getKieSession();
assertNotNull(ksession2);
long ksession2Id = ksession2.getIdentifier();
assertTrue(ksession2Id == 3);
ProcessInstance pi1 = ksession.startProcess("UserTask");
logs = auditService.findProcessInstances();
assertNotNull(logs);
assertEquals(1, logs.size());
ProcessInstance pi2 = ksession2.startProcess("UserTask");
logs = auditService.findProcessInstances();
assertNotNull(logs);
assertEquals(2, logs.size());
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
ksession = runtime.getKieSession();
assertEquals(ksession1Id, ksession.getIdentifier());
ksession.getWorkItemManager().completeWorkItem(1, null);
manager.disposeRuntimeEngine(runtime);
// since process is completed now session should not be there any more
try {
manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId())).getKieSession();
fail("Session for this (" + pi1.getId() + ") process instance is no more accessible");
} catch (RuntimeException e) {
}
runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId()));
;
ksession2 = runtime2.getKieSession();
assertEquals(ksession2Id, ksession2.getIdentifier());
ksession2.getWorkItemManager().completeWorkItem(2, null);
auditService = runtime2.getAuditService();
logs = auditService.findProcessInstances();
assertNotNull(logs);
assertEquals(2, logs.size());
manager.disposeRuntimeEngine(runtime2);
// since process is completed now session should not be there any more
try {
manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId())).getKieSession();
fail("Session for this (" + pi2.getId() + ") process instance is no more accessible");
} catch (RuntimeException e) {
}
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.
the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionWithPersistenceByCorrelationKey.
@Test
public void testCreationOfSessionWithPersistenceByCorrelationKey() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
CorrelationKeyFactory keyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
// ksession for process instance #1
// since there is no process instance yet we need to get new session
CorrelationKey key = keyFactory.newCorrelationKey("first");
RuntimeEngine runtime = manager.getRuntimeEngine(CorrelationKeyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long ksession1Id = ksession.getIdentifier();
assertTrue(ksession1Id == 2);
// ksession for process instance #2
// since there is no process instance yet we need to get new session
CorrelationKey key2 = keyFactory.newCorrelationKey("second");
RuntimeEngine runtime2 = manager.getRuntimeEngine(CorrelationKeyContext.get());
KieSession ksession2 = runtime2.getKieSession();
assertNotNull(ksession2);
long ksession2Id = ksession2.getIdentifier();
assertTrue(ksession2Id == 3);
ProcessInstance pi1 = ((CorrelationAwareProcessRuntime) ksession).startProcess("UserTask", key, null);
ProcessInstance pi2 = ((CorrelationAwareProcessRuntime) ksession2).startProcess("UserTask", key2, null);
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
runtime = manager.getRuntimeEngine(CorrelationKeyContext.get(key));
ksession = runtime.getKieSession();
assertEquals(ksession1Id, ksession.getIdentifier());
ksession.getWorkItemManager().completeWorkItem(1, null);
// since process is completed now session should not be there any more
try {
manager.getRuntimeEngine(CorrelationKeyContext.get(key)).getKieSession();
fail("Session for this (" + pi1.getId() + ") process instance is no more accessible");
} catch (RuntimeException e) {
}
runtime2 = manager.getRuntimeEngine(CorrelationKeyContext.get(key2));
ksession2 = runtime2.getKieSession();
assertEquals(ksession2Id, ksession2.getIdentifier());
ksession2.getWorkItemManager().completeWorkItem(2, null);
// since process is completed now session should not be there any more
try {
manager.getRuntimeEngine(CorrelationKeyContext.get(key2)).getKieSession();
fail("Session for this (" + pi2.getId() + ") process instance is no more accessible");
} catch (RuntimeException e) {
}
manager.close();
}
Aggregations