Search in sources :

Example 71 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class SingletonRuntimeManagerTest method testExecuteReusableSubprocess.

@Test
public void testExecuteReusableSubprocess() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivity.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivitySubProcess.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    // 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 == 1);
    ProcessInstance pi1 = ksession.startProcess("ParentProcess");
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    ksession.getWorkItemManager().completeWorkItem(1, null);
    AuditService logService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("ParentProcess");
    assertNotNull(logs);
    assertEquals(0, logs.size());
    logs = logService.findActiveProcessInstances("SubProcess");
    assertNotNull(logs);
    assertEquals(0, logs.size());
    logs = logService.findProcessInstances("ParentProcess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    logs = logService.findProcessInstances("SubProcess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    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) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 72 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class SingletonRuntimeManagerTest method testInterceptorAfterRollback.

@Test
public void testInterceptorAfterRollback() throws Exception {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithRollback.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    ProcessInstance processInstance = ksession.startProcess("UserTaskWithRollback");
    ExecutableRunner commandService = ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
    assertEquals(PersistableRunner.class, commandService.getClass());
    ChainableRunner internalCommandService = ((PersistableRunner) commandService).getChainableRunner();
    assertEquals(ExecutionErrorHandlerInterceptor.class, internalCommandService.getClass());
    internalCommandService = (ChainableRunner) ((ExecutionErrorHandlerInterceptor) internalCommandService).getNext();
    assertEquals(TransactionLockInterceptor.class, internalCommandService.getClass());
    TaskService taskService = runtime.getTaskService();
    List<Long> taskIds = taskService.getTasksByProcessInstanceId(processInstance.getId());
    taskService.start(taskIds.get(0), "john");
    HashMap<String, Object> result = new HashMap<String, Object>();
    result.put("output1", "rollback");
    try {
        // rollback transaction
        taskService.complete(taskIds.get(0), "john", result);
    } catch (WorkflowRuntimeException e) {
    // ignore
    }
    result = new HashMap<String, Object>();
    result.put("output1", "ok");
    // this time, execute normally
    taskService.complete(taskIds.get(0), "john", result);
    internalCommandService = ((PersistableRunner) commandService).getChainableRunner();
    assertEquals(ExecutionErrorHandlerInterceptor.class, internalCommandService.getClass());
    internalCommandService = (ChainableRunner) ((ExecutionErrorHandlerInterceptor) internalCommandService).getNext();
    assertEquals(TransactionLockInterceptor.class, internalCommandService.getClass());
    internalCommandService = (ChainableRunner) ((TransactionLockInterceptor) internalCommandService).getNext();
    assertEquals(OptimisticLockRetryInterceptor.class, internalCommandService.getClass());
    internalCommandService = (ChainableRunner) ((OptimisticLockRetryInterceptor) internalCommandService).getNext();
    assertEquals("org.drools.persistence.PersistableRunner$TransactionInterceptor", internalCommandService.getClass().getName());
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) ExecutableRunner(org.kie.api.runtime.ExecutableRunner) PersistableRunner(org.drools.persistence.PersistableRunner) ChainableRunner(org.drools.core.runtime.ChainableRunner) ExecutionErrorHandlerInterceptor(org.jbpm.runtime.manager.impl.error.ExecutionErrorHandlerInterceptor) OptimisticLockRetryInterceptor(org.drools.persistence.jpa.OptimisticLockRetryInterceptor) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) TransactionLockInterceptor(org.drools.persistence.jta.TransactionLockInterceptor) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 73 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class SingletonRuntimeManagerTest method testCreationOfMultipleSingletonManagerWithPersistence.

@Test
public void testCreationOfMultipleSingletonManagerWithPersistence() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).get();
    // create first manager
    // -----------------------------------------
    RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment, "manager1");
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long sessionId = ksession.getIdentifier();
    assertTrue(sessionId == 1);
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime);
    ksession = manager.getRuntimeEngine(EmptyContext.get()).getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    // close manager which will close session maintained by the manager
    manager.close();
    // create another manager
    // -----------------------------------------
    RuntimeManager manager2 = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment, "manager2");
    assertNotNull(manager2);
    runtime = manager2.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertNotNull(ksession);
    sessionId = ksession.getIdentifier();
    assertTrue(sessionId == 2);
    runtime = manager2.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    // dispose session that should not have affect on the session at all
    manager2.disposeRuntimeEngine(runtime);
    ksession = manager2.getRuntimeEngine(EmptyContext.get()).getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    // close manager which will close session maintained by the manager
    manager2.close();
    // recreate first manager
    // -----------------------------------------
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment, "manager1");
    assertNotNull(manager);
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertNotNull(ksession);
    sessionId = ksession.getIdentifier();
    assertTrue(sessionId == 1);
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime);
    ksession = manager.getRuntimeEngine(EmptyContext.get()).getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    // close manager which will close session maintained by the manager
    manager.close();
    // create another manager
    // -----------------------------------------
    manager2 = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment, "manager2");
    assertNotNull(manager2);
    runtime = manager2.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertNotNull(ksession);
    sessionId = ksession.getIdentifier();
    assertTrue(sessionId == 2);
    runtime = manager2.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    // dispose session that should not have affect on the session at all
    manager2.disposeRuntimeEngine(runtime);
    ksession = manager2.getRuntimeEngine(EmptyContext.get()).getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    // close manager which will close session maintained by the manager
    manager2.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 74 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class SingletonRuntimeManagerTest method testBusinessRuleTaskWithGlobal.

@Test
public void testBusinessRuleTaskWithGlobal() {
    final List<String> list = new ArrayList<String>();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().addAsset(ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTaskWithGlobal.drl"), ResourceType.DRL).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public Map<String, Object> getGlobals(RuntimeEngine runtime) {
            Map<String, Object> globals = super.getGlobals(runtime);
            globals.put("list", list);
            return globals;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long sessionId = ksession.getIdentifier();
    assertTrue(sessionId == 1);
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    ksession = runtime.getKieSession();
    assertEquals(sessionId, ksession.getIdentifier());
    // start process
    ProcessInstance pi = ksession.createProcessInstance("BPMN2-BusinessRuleTask", null);
    ksession.insert(pi);
    ksession.startProcessInstance(pi.getId());
    assertNull(ksession.getProcessInstance(pi.getId()));
    assertEquals(1, list.size());
    AuditService logService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("BPMN2-BusinessRuleTask");
    assertNotNull(logs);
    assertEquals(0, logs.size());
    logs = logService.findProcessInstances("BPMN2-BusinessRuleTask");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime);
    // close manager which will close session maintained by the manager
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 75 with RuntimeEnvironment

use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.

the class SingletonRuntimeManagerTest 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().newSingletonRuntimeManager(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());
    }
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime);
    // close manager which will close session maintained by the manager
    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)

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