Search in sources :

Example 56 with RuntimeManager

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();
}
Also used : CommandContext(org.kie.api.executor.CommandContext) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) CountDownLatch(java.util.concurrent.CountDownLatch) AsyncSignalEventCommand(org.jbpm.process.core.async.AsyncSignalEventCommand) Test(org.junit.Test)

Example 57 with RuntimeManager

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);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) Before(org.junit.Before)

Example 58 with RuntimeManager

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();
}
Also used : UserTransaction(javax.transaction.UserTransaction) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DefaultCountDownProcessEventListener(org.jbpm.test.listener.DefaultCountDownProcessEventListener) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) ProcessNodeLeftEvent(org.kie.api.event.process.ProcessNodeLeftEvent) AbstractRuntimeEJBServicesTest(org.jbpm.test.container.AbstractRuntimeEJBServicesTest) Test(org.junit.Test)

Example 59 with RuntimeManager

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();
}
Also used : UserTransaction(javax.transaction.UserTransaction) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) TrackingAgendaEventListener(org.jbpm.test.container.listeners.TrackingAgendaEventListener) FireAllRulesCommand(org.drools.core.command.runtime.rule.FireAllRulesCommand) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) AbstractRuntimeEJBServicesTest(org.jbpm.test.container.AbstractRuntimeEJBServicesTest) Test(org.junit.Test)

Example 60 with RuntimeManager

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);
        }
    }
}
Also used : InternalKnowledgeRuntime(org.drools.core.common.InternalKnowledgeRuntime) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) KieRuntime(org.kie.api.runtime.KieRuntime) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) ProcessInstance(org.jbpm.process.instance.ProcessInstance) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Aggregations

RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)150 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)116 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)79 KieSession (org.kie.api.runtime.KieSession)55 TaskService (org.kie.api.task.TaskService)53 Test (org.junit.Test)51 HashMap (java.util.HashMap)49 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)46 InternalTaskService (org.kie.internal.task.api.InternalTaskService)44 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)38 UserTaskService (org.jbpm.services.api.UserTaskService)36 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)35 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)23 TaskSummary (org.kie.api.task.model.TaskSummary)21 ArrayList (java.util.ArrayList)19 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)19 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)18 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)15 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)15