Search in sources :

Example 1 with TrackingAgendaEventListener

use of org.jbpm.test.container.listeners.TrackingAgendaEventListener 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 2 with TrackingAgendaEventListener

use of org.jbpm.test.container.listeners.TrackingAgendaEventListener in project jbpm by kiegroup.

the class TransactionsTest method testRuleflowGroup.

@Test
public void testRuleflowGroup() throws Exception {
    TrackingProcessEventListener process = new TrackingProcessEventListener();
    TrackingAgendaEventListener agenda = new TrackingAgendaEventListener();
    KieSession ksession = createJPASession(getKnowledgeBase());
    ksession.addEventListener(process);
    ksession.addEventListener(agenda);
    long processId = ksession.startProcess(LocalTransactions.PROCESS_TRANSACTIONS).getId();
    UserTransaction ut = getUserTransaction();
    ut.begin();
    ksession.signalEvent("start", "rfg", processId);
    Assertions.assertThat(process.wasNodeLeft("rfg")).isTrue();
    ut.rollback();
    Thread.sleep(600);
    process.clear();
    agenda.clear();
    ksession = reloadSession(ksession);
    ksession.addEventListener(process);
    ksession.addEventListener(agenda);
    ksession.fireAllRules();
    Assertions.assertThat(agenda.isRuleFired("dummyRule")).isFalse();
    agenda.clear();
    process.clear();
    ut = getUserTransaction();
    ut.begin();
    ksession.signalEvent("start", "rfg", processId);
    Thread.sleep(1000);
    ut.commit();
    Assertions.assertThat(process.wasNodeLeft("rfg")).isTrue();
    ksession.fireAllRules();
    ksession.signalEvent("finish", null, processId);
    Thread.sleep(1000);
    Assertions.assertThat(agenda.isRuleFired("dummyRule")).isTrue();
    Assertions.assertThat(process.wasProcessCompleted(LocalTransactions.PROCESS_TRANSACTIONS)).isTrue();
}
Also used : UserTransaction(javax.transaction.UserTransaction) TrackingAgendaEventListener(org.jbpm.test.container.listeners.TrackingAgendaEventListener) TrackingProcessEventListener(org.jbpm.test.container.listeners.TrackingProcessEventListener) KieSession(org.kie.api.runtime.KieSession) JbpmContainerTest(org.jbpm.test.container.JbpmContainerTest) Test(org.junit.Test)

Aggregations

UserTransaction (javax.transaction.UserTransaction)2 TrackingAgendaEventListener (org.jbpm.test.container.listeners.TrackingAgendaEventListener)2 Test (org.junit.Test)2 FireAllRulesCommand (org.drools.core.command.runtime.rule.FireAllRulesCommand)1 AbstractRuntimeEJBServicesTest (org.jbpm.test.container.AbstractRuntimeEJBServicesTest)1 JbpmContainerTest (org.jbpm.test.container.JbpmContainerTest)1 TrackingProcessEventListener (org.jbpm.test.container.listeners.TrackingProcessEventListener)1 KieSession (org.kie.api.runtime.KieSession)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1