use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class ConcurrentOperationsTest method testExecuteProcessWithAsyncHandler.
@Test(timeout = 10000)
public void testExecuteProcessWithAsyncHandler() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Log", 1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addEnvironmentEntry("TRANSACTION_LOCK_ENABLED", true).registerableItemsFactory(new DefaultRegisterableItemsFactory() {
@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
Map<String, WorkItemHandler> handlers = super.getWorkItemHandlers(runtime);
handlers.put("Log", new AsyncWorkItemHandler(((RuntimeEngineImpl) runtime).getManager()));
return handlers;
}
@Override
public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
listeners.add(countDownListener);
return listeners;
}
}).addAsset(ResourceFactory.newClassPathResource("BPMN2-CustomTask.bpmn2"), ResourceType.BPMN2).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());
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
ProcessInstance processInstance = ksession.startProcess("customtask");
logger.debug("Started process, committing...");
ut.commit();
countDownListener.waitTillCompleted();
processInstance = ksession.getProcessInstance(processInstance.getId());
assertNull(processInstance);
// 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 AdHocSubprocessAbortRuntimeManagerTest method testPerCaseRuntimeManagerScopeSignal.
@Test
public void testPerCaseRuntimeManagerScopeSignal() {
RuntimeEnvironment environment = createEnvironment();
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment, "first");
assertNotNull(manager);
testAdHocSubprocess();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class InMemorySingletonRuntimeManagerTest method testCreationOfSessionInMemory.
@Test
public void testCreationOfSessionInMemory() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().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);
long sessionId = ksession.getIdentifier();
assertTrue(sessionId == 0);
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();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class FireRulesWithListeneronRMTest method testCreationOfSessionWithPersistence.
@Test
public void testCreationOfSessionWithPersistence() throws ParseException {
String accountRule = "";
accountRule += "package org.kie.test\n";
accountRule += "import org.jbpm.runtime.manager.rule.Account\n";
accountRule += "rule \"Account Eligibility\"\n";
accountRule += "dialect \"java\" \n";
accountRule += "when\n";
accountRule += "$account:Account( getAccountStatus().equals(\"O\"))\n";
accountRule += "then\n";
accountRule += "$account.setAccountEligible(true);\n";
accountRule += "System.out.println(\" Account Eligibility Rule called - then part after changing value \"+$account);\n";
accountRule += "end\n";
accountRule += "\n";
String customerRule = "";
customerRule += "package org.kie.test\n";
customerRule += "import org.jbpm.runtime.manager.rule.OrderEligibility\n";
customerRule += "import function org.jbpm.runtime.manager.rule.OrderEligibilityCheck.dateDifference\n";
customerRule += "rule \"Customer Eligibility\"\n";
customerRule += "dialect \"java\" \n";
customerRule += "when\n";
customerRule += " $orderEligibility: OrderEligibility(dateDifference(getOrderDetails().getEndDate(), getOrderDetails().getStartDate()))\n";
customerRule += "then\n";
customerRule += " $orderEligibility.setOrderEligibile(true);\n";
customerRule += "System.out.println(\" Order Eligibility Rule called - then part after changing value \"+ $orderEligibility);\n";
customerRule += "end\n";
customerRule += "\n";
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().addAsset(ResourceFactory.newByteArrayResource(accountRule.getBytes()), ResourceType.DRL).addAsset(ResourceFactory.newByteArrayResource(customerRule.getBytes()), ResourceType.DRL).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();
Account accountOpen = new Account("O");
Account accountClosed = new Account("C");
FactHandle accountOpen_FH = ksession.insert(accountOpen);
FactHandle accountClosed_FH = ksession.insert(accountClosed);
SimpleDateFormat stdDateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date today = stdDateFormat.parse("2014/03/10");
Date yesterday = stdDateFormat.parse("2014/03/09");
Date lastYear = stdDateFormat.parse("2013/03/10");
OrderDetails lastYearOrder = new OrderDetails(lastYear, today);
OrderDetails thisYearOrder = new OrderDetails(yesterday, today);
OrderEligibility lastYearEligibility = new OrderEligibility(lastYearOrder);
OrderEligibility thisYearEligibility = new OrderEligibility(thisYearOrder);
FactHandle lye_FH = ksession.insert(lastYearEligibility);
FactHandle tye_FH = ksession.insert(thisYearEligibility);
ksession.fireAllRules();
assertTrue(accountOpen.getAccountEligible());
assertTrue(!accountClosed.getAccountEligible());
ksession.delete(accountOpen_FH);
ksession.delete(accountClosed_FH);
assertTrue(lastYearEligibility.getOrderEligibile());
assertTrue(!thisYearEligibility.getOrderEligibile());
ksession.delete(lye_FH);
ksession.delete(tye_FH);
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class ConcurrentGlobalTimerServiceTest method testSessionPerProcessInstance.
@Test
public void testSessionPerProcessInstance() throws Exception {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/IntermediateCatchEventTimerCycleWithHT.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).get();
long startTimeStamp = System.currentTimeMillis();
long maxEndTime = startTimeStamp + maxWaitTime;
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
// prepare task service with users and groups
RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
TaskService taskService = engine.getTaskService();
Group grouphr = TaskModelProvider.getFactory().newGroup();
((InternalOrganizationalEntity) grouphr).setId("HR");
User mary = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) mary).setId("mary");
User john = TaskModelProvider.getFactory().newUser();
((InternalOrganizationalEntity) john).setId("john");
((InternalTaskService) taskService).addGroup(grouphr);
((InternalTaskService) taskService).addUser(mary);
((InternalTaskService) taskService).addUser(john);
manager.disposeRuntimeEngine(engine);
completedStart = 0;
for (int i = 0; i < nbThreadsProcess; i++) {
new StartProcessPerProcessInstanceRunnable(manager, i).run();
}
completedTask = 0;
for (int i = 0; i < nbThreadsTask; i++) {
new Thread(new CompleteTaskPerProcessInstanceRunnable(manager, i)).start();
}
while (completedStart < nbThreadsProcess || completedTask < nbThreadsTask) {
Thread.sleep(100);
if (System.currentTimeMillis() > maxEndTime) {
fail("Failure, did not finish in time most likely hanging");
}
}
// make sure all process instance were completed
engine = manager.getRuntimeEngine(EmptyContext.get());
AuditService logService = engine.getAuditService();
// active
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("IntermediateCatchEvent");
assertNotNull(logs);
for (ProcessInstanceLog log : logs) {
logger.debug("Left over {}", log.getProcessInstanceId());
}
assertEquals(0, logs.size());
// completed
logs = logService.findProcessInstances("IntermediateCatchEvent");
assertNotNull(logs);
assertEquals(nbThreadsProcess, logs.size());
manager.disposeRuntimeEngine(engine);
logger.debug("Done");
}
Aggregations