Search in sources :

Example 81 with RuntimeEngine

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

Example 82 with RuntimeEngine

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();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 83 with RuntimeEngine

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

Example 84 with RuntimeEngine

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

Example 85 with RuntimeEngine

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

Aggregations

RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)388 Test (org.junit.Test)269 KieSession (org.kie.api.runtime.KieSession)265 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)229 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)149 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)116 TaskService (org.kie.api.task.TaskService)111 HashMap (java.util.HashMap)110 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)105 TaskSummary (org.kie.api.task.model.TaskSummary)86 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)82 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)67 ArrayList (java.util.ArrayList)59 InternalTaskService (org.kie.internal.task.api.InternalTaskService)59 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)58 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)49 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)43 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)40 UserTaskService (org.jbpm.services.api.UserTaskService)36 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)34