use of org.drools.core.command.SingleSessionCommandService in project jbpm by kiegroup.
the class IntermediateEventTest method testEventTypesLifeCycle.
@Test
@RequirePersistence
public void testEventTypesLifeCycle() throws Exception {
// JBPM-4246
KieBase kbase = createKnowledgeBase("BPMN2-IntermediateCatchSignalBetweenUserTasks.bpmn2");
EntityManagerFactory separateEmf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");
Environment env = createEnvironment(separateEmf);
ksession = createKnowledgeSession(kbase, null, env);
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new DoNothingWorkItemHandler());
ksession.startProcess("BPMN2-IntermediateCatchSignalBetweenUserTasks");
int signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
return processInstancesToSignalList.size();
}
});
// Process instance is not waiting for signal
assertThat(signalListSize).isEqualTo(0);
ksession.getWorkItemManager().completeWorkItem(1, null);
signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
return processInstancesToSignalList.size();
}
});
// Process instance is waiting for signal now
assertThat(signalListSize).isEqualTo(1);
ksession.signalEvent("MySignal", null);
signalListSize = ksession.execute(new ExecutableCommand<Integer>() {
public Integer execute(Context context) {
SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
InternalKnowledgeRuntime kruntime = (InternalKnowledgeRuntime) commandService.getKieSession();
ProcessPersistenceContextManager contextManager = (ProcessPersistenceContextManager) kruntime.getEnvironment().get(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER);
ProcessPersistenceContext pcontext = contextManager.getProcessPersistenceContext();
List<Long> processInstancesToSignalList = pcontext.getProcessInstancesWaitingForEvent("MySignal");
return processInstancesToSignalList.size();
}
});
// Process instance is not waiting for signal
assertThat(signalListSize).isEqualTo(0);
ksession.getWorkItemManager().completeWorkItem(2, null);
ksession.dispose();
ksession = null;
separateEmf.close();
}
use of org.drools.core.command.SingleSessionCommandService in project jbpm by kiegroup.
the class ConcurrentGlobalTimerServiceTest method testStartProcess.
private void testStartProcess(RuntimeEngine runtime) throws Exception {
synchronized ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) runtime.getKieSession()).getRunner()) {
UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
try {
ut.begin();
logger.debug("Starting process on ksession {}", runtime.getKieSession().getIdentifier());
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "R2/PT1S");
ProcessInstance processInstance = runtime.getKieSession().startProcess("IntermediateCatchEvent", params);
logger.debug("Started process instance {} on ksession {}", processInstance.getId(), runtime.getKieSession().getIdentifier());
ut.commit();
} catch (Exception ex) {
ut.rollback();
throw ex;
}
}
}
use of org.drools.core.command.SingleSessionCommandService in project jbpm by kiegroup.
the class GlobalTimerServiceVolumeTest method testStartProcess.
private void testStartProcess(RuntimeEngine runtime) throws Exception {
synchronized ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) runtime.getKieSession()).getRunner()) {
UserTransaction ut = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
try {
ut.begin();
logger.debug("Starting process on ksession {}", runtime.getKieSession().getIdentifier());
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "5s");
ProcessInstance processInstance = runtime.getKieSession().startProcess("IntermediateCatchEvent", params);
logger.debug("Started process instance {} on ksession {}", processInstance.getId(), runtime.getKieSession().getIdentifier());
ut.commit();
} catch (Exception ex) {
ut.rollback();
throw ex;
}
}
}
Aggregations