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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations