Search in sources :

Example 16 with CommandBasedStatefulKnowledgeSession

use of org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession in project jbpm by kiegroup.

the class TimerCycleOnBinaryPackageTest method testStartTimerCycleFromDiscDRL.

@Test
@Ignore("beta4 phreak")
public void testStartTimerCycleFromDiscDRL() throws Exception {
    KieBase kbase = createKnowledgeBaseFromDisc("rules-timer.drl");
    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
    long sessionId = ksession.getIdentifier();
    Environment env = ksession.getEnvironment();
    final List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
    ksession.fireAllRules();
    Thread.sleep(5000);
    assertEquals(2, list.size());
    logger.info("dispose");
    ksession.dispose();
    ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
    AuditLoggerFactory.newInstance(Type.JPA, ksession, null);
    final List<String> list2 = new ArrayList<String>();
    ksession.setGlobal("list", list2);
    ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
    ksession.fireAllRules();
    Thread.sleep(6000);
    assertEquals(3, list2.size());
}
Also used : KieBase(org.kie.api.KieBase) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) StatefulKnowledgeSession(org.kie.internal.runtime.StatefulKnowledgeSession) ArrayList(java.util.ArrayList) Environment(org.kie.api.runtime.Environment) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) TriggerRulesEventListener(org.jbpm.process.instance.event.listeners.TriggerRulesEventListener) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with CommandBasedStatefulKnowledgeSession

use of org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession in project jbpm by kiegroup.

the class ActivityTest method testRuleTaskWithFactsWithPersistence.

@Test
@RequirePersistence
public void testRuleTaskWithFactsWithPersistence() throws Exception {
    KieBase kbase = createKnowledgeBaseWithoutDumper("BPMN2-RuleTaskWithFact.bpmn2", "BPMN2-RuleTask3.drl");
    ksession = createKnowledgeSession(kbase);
    ((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
    ksession.addEventListener(new DebugAgendaEventListener());
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "SomeString");
    ProcessInstance processInstance = ksession.startProcess("RuleTask", params);
    assertProcessInstanceFinished(processInstance, ksession);
    params = new HashMap<String, Object>();
    try {
        processInstance = ksession.startProcess("RuleTask", params);
        fail("Should fail");
    } catch (Exception e) {
        e.printStackTrace();
    }
    params = new HashMap<String, Object>();
    params.put("x", "SomeString");
    processInstance = ksession.startProcess("RuleTask", params);
    assertProcessInstanceFinished(processInstance, ksession);
}
Also used : DebugAgendaEventListener(org.kie.api.event.rule.DebugAgendaEventListener) HashMap(java.util.HashMap) KieBase(org.kie.api.KieBase) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession) TriggerRulesEventListener(org.jbpm.process.instance.event.listeners.TriggerRulesEventListener) FeelReturnValueEvaluatorException(org.jbpm.process.instance.impl.FeelReturnValueEvaluatorException) WorkflowRuntimeException(org.jbpm.workflow.instance.WorkflowRuntimeException) ConsequenceException(org.kie.api.runtime.rule.ConsequenceException) Test(org.junit.Test) RequirePersistence(org.jbpm.bpmn2.test.RequirePersistence)

Example 18 with CommandBasedStatefulKnowledgeSession

use of org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession in project jahia by Jahia.

the class JBPM6WorkflowProvider method executeCommand.

private <T> T executeCommand(BaseCommand<T> t) {
    t.setRuntimeEngine(runtimeEngine);
    t.setEm(sharedEm);
    t.setPersistenceManager(jbpmServicesPersistenceManager);
    t.setGroupManager(groupManager);
    t.setUserManager(userManager);
    t.setWorkflowService(workflowService);
    t.setKey(key);
    CommandBasedStatefulKnowledgeSession s = (CommandBasedStatefulKnowledgeSession) runtimeEngine.getKieSession();
    return s.execute(t);
}
Also used : CommandBasedStatefulKnowledgeSession(org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)

Aggregations

CommandBasedStatefulKnowledgeSession (org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession)18 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)10 StatefulKnowledgeSession (org.kie.internal.runtime.StatefulKnowledgeSession)8 KieBase (org.kie.api.KieBase)7 Environment (org.kie.api.runtime.Environment)7 TriggerRulesEventListener (org.jbpm.process.instance.event.listeners.TriggerRulesEventListener)5 Context (org.kie.api.runtime.Context)4 RegistryContext (org.kie.internal.command.RegistryContext)4 InternalAgenda (org.drools.core.common.InternalAgenda)3 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)3 ExecutableCommand (org.kie.api.command.ExecutableCommand)3 HashMap (java.util.HashMap)2 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)2 ClassPathResource (org.drools.core.io.impl.ClassPathResource)2 PersistableRunner (org.drools.persistence.PersistableRunner)2 OptimisticLockRetryInterceptor (org.drools.persistence.jpa.OptimisticLockRetryInterceptor)2 DroolsPersistenceUtil.createEnvironment (org.drools.persistence.util.DroolsPersistenceUtil.createEnvironment)2 RequirePersistence (org.jbpm.bpmn2.test.RequirePersistence)2 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.process.NodeLeftCountDownProcessEventListener)2