Search in sources :

Example 61 with RuntimeEnvironment

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");
}
Also used : UserTransaction(javax.transaction.UserTransaction) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 62 with RuntimeEnvironment

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);
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 63 with RuntimeEnvironment

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();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 64 with RuntimeEnvironment

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();
}
Also used : EntityManager(javax.persistence.EntityManager) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) EntityManagerFactory(javax.persistence.EntityManagerFactory) SessionInfo(org.drools.persistence.info.SessionInfo) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 65 with RuntimeEnvironment

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();
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)177 Test (org.junit.Test)163 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)148 KieSession (org.kie.api.runtime.KieSession)127 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)107 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)101 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)51 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)49 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)48 HashMap (java.util.HashMap)47 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)42 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)38 ArrayList (java.util.ArrayList)21 TaskSummary (org.kie.api.task.model.TaskSummary)21 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)20 AuditService (org.kie.api.runtime.manager.audit.AuditService)20 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)19 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)19 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)19 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)17