use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class AsyncIntermediateCatchSignalTest method testCorrectProcessStateAfterExceptionSignalCommand.
@Test(timeout = 10000)
public void testCorrectProcessStateAfterExceptionSignalCommand() throws InterruptedException {
latch = new CountDownLatch(1);
RuntimeManager runtimeManager = createRuntimeManager(BPMN_AICS);
KieSession ksession = getRuntimeEngine().getKieSession();
ProcessInstance pi = ksession.startProcess(PROCESS_AICS, null);
long pid = pi.getId();
CommandContext ctx = new CommandContext();
ctx.setData("DeploymentId", runtimeManager.getIdentifier());
ctx.setData("ProcessInstanceId", pid);
ctx.setData("Signal", "MySignal");
ctx.setData("Event", null);
executorService.scheduleRequest(AsyncSignalEventCommand.class.getName(), ctx);
latch.await();
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class EThreadInfoTest method deployKieJar.
@Before
@Override
public void deployKieJar() {
if (kieJar == null) {
kieJar = archive.deployEJBComplianceKieJar().getIdentifier();
}
RuntimeManager manager = deploymentService.getRuntimeManager(kieJar);
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
engine.getKieSession().addEventListener(listener);
listener.reset(1);
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class ETransactionTest method testTimer.
@Test
public void testTimer() throws Exception {
DefaultCountDownProcessEventListener listener = new DefaultCountDownProcessEventListener(0) {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
if ("Timer".equals(event.getNodeInstance().getNodeName())) {
countDown();
}
}
};
RuntimeManager manager = deploymentService.getRuntimeManager(kieJar);
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
engine.getKieSession().addEventListener(listener);
Long processInstanceId = startProcessInstance(PROCESS_ID);
UserTransaction ut = InitialContext.doLookup(USER_TRANSACTION_NAME);
ut.begin();
try {
processService.signalProcessInstance(processInstanceId, "start", "timer");
Assertions.assertThat(hasNodeLeft(processInstanceId, "timer")).isTrue();
} catch (Exception e) {
ut.rollback();
throw e;
}
ut.rollback();
ut = InitialContext.doLookup(USER_TRANSACTION_NAME);
ut.begin();
try {
processService.signalProcessInstance(processInstanceId, "start", "timer");
} catch (Exception e) {
ut.rollback();
throw e;
}
ut.commit();
listener.reset(1);
listener.waitTillCompleted();
Assertions.assertThat(hasNodeLeft(processInstanceId, "timer")).isTrue();
Assertions.assertThat(hasNodeLeft(processInstanceId, "Timer")).isTrue();
processService.signalProcessInstance(processInstanceId, "finish", null);
Assertions.assertThat(hasProcessInstanceCompleted(processInstanceId)).isTrue();
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class ETransactionTest method testRuleFlowGroup.
@Test
public void testRuleFlowGroup() throws Exception {
TrackingAgendaEventListener agenda = new TrackingAgendaEventListener();
RuntimeManager manager = deploymentService.getRuntimeManager(kieJar);
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
engine.getKieSession().addEventListener(agenda);
Long processInstanceId = startProcessInstance(PROCESS_ID);
UserTransaction ut = InitialContext.doLookup(USER_TRANSACTION_NAME);
ut.begin();
processService.signalProcessInstance(processInstanceId, "start", "rfg");
Assertions.assertThat(hasNodeLeft(processInstanceId, "rfg")).isTrue();
ut.rollback();
agenda.clear();
processService.execute(kieJar, new FireAllRulesCommand());
Assertions.assertThat(agenda.isRuleFired("dummyRule")).isFalse();
agenda.clear();
ut = InitialContext.doLookup(USER_TRANSACTION_NAME);
ut.begin();
processService.signalProcessInstance(processInstanceId, "start", "rfg");
ut.commit();
Assertions.assertThat(hasNodeLeft(processInstanceId, "rfg")).isTrue();
processService.execute(kieJar, new FireAllRulesCommand());
processService.signalProcessInstance(processInstanceId, "finish", null);
Assertions.assertThat(agenda.isRuleFired("dummyRule")).isTrue();
Assertions.assertThat(hasProcessInstanceCompleted(processInstanceId)).isTrue();
}
use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.
the class SubProcessNodeInstance method cancel.
public void cancel() {
super.cancel();
if (getSubProcessNode() == null || !getSubProcessNode().isIndependent()) {
ProcessInstance processInstance = null;
InternalKnowledgeRuntime kruntime = ((ProcessInstance) getProcessInstance()).getKnowledgeRuntime();
RuntimeManager manager = (RuntimeManager) kruntime.getEnvironment().get(EnvironmentName.RUNTIME_MANAGER);
if (manager != null) {
try {
org.kie.api.runtime.manager.Context<?> context = ProcessInstanceIdContext.get(processInstanceId);
String caseId = (String) kruntime.getEnvironment().get(EnvironmentName.CASE_ID);
if (caseId != null) {
context = CaseContext.get(caseId);
}
RuntimeEngine runtime = manager.getRuntimeEngine(context);
KieRuntime managedkruntime = (KieRuntime) runtime.getKieSession();
processInstance = (ProcessInstance) managedkruntime.getProcessInstance(processInstanceId);
} catch (SessionNotFoundException e) {
// in case no session is found for parent process let's skip signal for process instance completion
}
} else {
processInstance = (ProcessInstance) kruntime.getProcessInstance(processInstanceId);
}
if (processInstance != null) {
processInstance.setState(ProcessInstance.STATE_ABORTED);
}
}
}
Aggregations