use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerRequestRuntimeManagerTest method testCreationOfSessionWithinTransaction.
@Test
public void testCreationOfSessionWithinTransaction() throws Exception {
System.setProperty("jbpm.tm.jndi.lookup", "java:comp/UserTransaction");
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long sessionId = ksession.getIdentifier();
assertTrue(sessionId == 1);
ut.commit();
// so now session should already be disposed
try {
ksession.getIdentifier();
fail("Should fail as session manager was closed and with that it's session");
} catch (IllegalStateException e) {
} catch (UndeclaredThrowableException e) {
TestUtil.checkDisposedSessionException(e);
}
System.clearProperty("jbpm.tm.jndi.lookup");
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerRequestRuntimeManagerTest method testCreationOfSessionWithPeristence.
@Test
public void testCreationOfSessionWithPeristence() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long sessionId = ksession.getIdentifier();
assertTrue(sessionId == 1);
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(EmptyContext.get());
ksession = runtime.getKieSession();
// session id should be 1+ previous session id
assertEquals(sessionId + 1, ksession.getIdentifier());
sessionId = ksession.getIdentifier();
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(EmptyContext.get());
ksession = runtime.getKieSession();
// session id should be 1+ previous session id
assertEquals(sessionId + 1, ksession.getIdentifier());
manager.disposeRuntimeEngine(runtime);
// when trying to access session after dispose
try {
ksession.getIdentifier();
fail("Should fail as session manager was closed and with that it's session");
} catch (IllegalStateException e) {
} catch (UndeclaredThrowableException e) {
TestUtil.checkDisposedSessionException(e);
}
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PerRequestRuntimeManagerTest method testCreationOfSessionTaskServiceNotConfigured.
@Test
public void testCreationOfSessionTaskServiceNotConfigured() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newEmptyBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).get();
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
try {
runtime.getTaskService();
fail("Should fail as task service is not configured");
} catch (UnsupportedOperationException e) {
assertEquals("TaskService was not configured", e.getMessage());
}
manager.disposeRuntimeEngine(runtime);
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class PersistenceRuntimeManagerTest method testPerRequestManagerDestorySession.
@SuppressWarnings("unchecked")
@Test
public void testPerRequestManagerDestorySession() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
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).get();
EntityManager em = emf.createEntityManager();
List<SessionInfo> sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
assertNotNull(manager);
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
// ksession for process instance #1
// since there is no process instance yet we need to get new session
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
runtime.getKieSession();
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(1, sessions.size());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
ProcessInstance pi1 = ksession.startProcess("UserTask");
// both processes started
assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
manager.disposeRuntimeEngine(runtime);
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
runtime = manager.getRuntimeEngine(EmptyContext.get());
ksession = runtime.getKieSession();
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(1, sessions.size());
ksession.getWorkItemManager().completeWorkItem(1, null);
manager.disposeRuntimeEngine(runtime);
sessions = em.createQuery("from SessionInfo").getResultList();
assertEquals(0, sessions.size());
manager.close();
emf.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class SignalScopedToRuntimeManagerTest method testSingletonRuntimeManagerCompleteTaskViaWrongRuntimeManager.
@Test
public void testSingletonRuntimeManagerCompleteTaskViaWrongRuntimeManager() {
RuntimeEnvironment environment = createEnvironment();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment, "first");
assertNotNull(manager);
RuntimeEnvironment environment2 = createEnvironment();
manager2 = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment2, "second");
assertNotNull(manager2);
testCompleteTaskViaWrongRuntimeManager();
}
Aggregations