Search in sources :

Example 1 with ForceEagerActivationFilter

use of org.kie.internal.runtime.conf.ForceEagerActivationFilter in project drools by kiegroup.

the class ActivationIteratorTest method testFilteredEagerEvaluation.

@Test(timeout = 10000)
public void testFilteredEagerEvaluation() throws Exception {
    String str = "package org.simple \n" + "rule xxx @Propagation(EAGER) \n" + "when \n" + "  $s : String()\n" + "then \n" + "end  \n" + "rule yyy @Propagation(EAGER) \n" + "when \n" + "  $s : String()\n" + "then \n" + "end  \n";
    KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    conf.setOption(new ForceEagerActivationOption.FILTERED(new ForceEagerActivationFilter() {

        @Override
        public boolean accept(Rule rule) {
            return rule.getName().equals("xxx");
        }
    }));
    KieBase kbase = loadKnowledgeBaseFromString(str);
    KieSession ksession = createKnowledgeSession(kbase, conf);
    final List list = new ArrayList();
    AgendaEventListener agendaEventListener = new DefaultAgendaEventListener() {

        public void matchCreated(org.kie.api.event.rule.MatchCreatedEvent event) {
            list.add("activated");
        }
    };
    ksession.addEventListener(agendaEventListener);
    ksession.insert("test");
    ((InternalWorkingMemory) ksession).flushPropagations();
    assertEquals(1, list.size());
}
Also used : ForceEagerActivationOption(org.kie.internal.runtime.conf.ForceEagerActivationOption) ArrayList(java.util.ArrayList) DefaultAgendaEventListener(org.kie.api.event.rule.DefaultAgendaEventListener) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) ForceEagerActivationFilter(org.kie.internal.runtime.conf.ForceEagerActivationFilter) KieBase(org.kie.api.KieBase) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) DefaultAgendaEventListener(org.kie.api.event.rule.DefaultAgendaEventListener) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Rule(org.kie.api.definition.rule.Rule) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) Test(org.junit.Test)

Example 2 with ForceEagerActivationFilter

use of org.kie.internal.runtime.conf.ForceEagerActivationFilter in project drools by kiegroup.

the class ActivateAndDeleteOnListenerTest method testOneLazyAndOneImmediateSubPath.

@Test
public void testOneLazyAndOneImmediateSubPath() throws Exception {
    String str = "package org.simple \n" + "rule xxx \n" + "when \n" + "  $s : String()\n" + "  exists( Integer() or Long() )\n" + "then \n" + "end  \n" + "rule yyy \n" + "when \n" + "  $s : String()\n" + "  exists( Integer() or Long() )\n" + "then \n" + "end  \n";
    KieServices ks = KieServices.Factory.get();
    KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    conf.setOption(new ForceEagerActivationOption.FILTERED(new ForceEagerActivationFilter() {

        @Override
        public boolean accept(Rule rule) {
            return rule.getName().equals("yyy");
        }
    }));
    KieSession ksession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession(conf, null);
    final List list = new ArrayList();
    AgendaEventListener agendaEventListener = new org.kie.api.event.rule.DefaultAgendaEventListener() {

        public void matchCreated(org.kie.api.event.rule.MatchCreatedEvent event) {
            list.add(event.getMatch().getRule().getName());
        }
    };
    ksession.addEventListener(agendaEventListener);
    ksession.insert("test");
    assertEquals(0, list.size());
    ksession.insert(1);
    assertEquals(1, list.size());
    assertEquals("yyy", list.get(0));
}
Also used : ForceEagerActivationOption(org.kie.internal.runtime.conf.ForceEagerActivationOption) ArrayList(java.util.ArrayList) KieHelper(org.kie.internal.utils.KieHelper) DefaultAgendaEventListener(org.drools.core.event.DefaultAgendaEventListener) KieServices(org.kie.api.KieServices) ForceEagerActivationFilter(org.kie.internal.runtime.conf.ForceEagerActivationFilter) DefaultAgendaEventListener(org.drools.core.event.DefaultAgendaEventListener) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Rule(org.kie.api.definition.rule.Rule) MatchCreatedEvent(org.kie.api.event.rule.MatchCreatedEvent) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) Test(org.junit.Test)

Example 3 with ForceEagerActivationFilter

use of org.kie.internal.runtime.conf.ForceEagerActivationFilter in project drools by kiegroup.

the class ActivationIteratorTest method testFilteredEagerEvaluation.

@Test(timeout = 10000)
public void testFilteredEagerEvaluation() throws Exception {
    String str = "package org.simple \n" + "rule xxx @Propagation(EAGER) \n" + "when \n" + "  $s : String()\n" + "then \n" + "end  \n" + "rule yyy @Propagation(EAGER) \n" + "when \n" + "  $s : String()\n" + "then \n" + "end  \n";
    KieSessionConfiguration conf = RuleBaseFactory.newKnowledgeSessionConfiguration();
    conf.setOption(new ForceEagerActivationOption.FILTERED(new ForceEagerActivationFilter() {

        @Override
        public boolean accept(Rule rule) {
            return rule.getName().equals("xxx");
        }
    }));
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession ksession = kbase.newKieSession(conf, null);
    final List list = new ArrayList();
    AgendaEventListener agendaEventListener = new DefaultAgendaEventListener() {

        public void matchCreated(org.kie.api.event.rule.MatchCreatedEvent event) {
            list.add("activated");
        }
    };
    ksession.addEventListener(agendaEventListener);
    ksession.insert("test");
    ((InternalWorkingMemory) ksession).flushPropagations();
    assertEquals(1, list.size());
}
Also used : ForceEagerActivationOption(org.kie.internal.runtime.conf.ForceEagerActivationOption) ArrayList(java.util.ArrayList) DefaultAgendaEventListener(org.kie.api.event.rule.DefaultAgendaEventListener) InternalWorkingMemory(org.drools.core.common.InternalWorkingMemory) ForceEagerActivationFilter(org.kie.internal.runtime.conf.ForceEagerActivationFilter) KieBase(org.kie.api.KieBase) DefaultAgendaEventListener(org.kie.api.event.rule.DefaultAgendaEventListener) AgendaEventListener(org.kie.api.event.rule.AgendaEventListener) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Rule(org.kie.api.definition.rule.Rule) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 Test (org.junit.Test)3 Rule (org.kie.api.definition.rule.Rule)3 AgendaEventListener (org.kie.api.event.rule.AgendaEventListener)3 KieSession (org.kie.api.runtime.KieSession)3 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)3 ForceEagerActivationFilter (org.kie.internal.runtime.conf.ForceEagerActivationFilter)3 ForceEagerActivationOption (org.kie.internal.runtime.conf.ForceEagerActivationOption)3 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)2 KieBase (org.kie.api.KieBase)2 DefaultAgendaEventListener (org.kie.api.event.rule.DefaultAgendaEventListener)2 Arrays.asList (java.util.Arrays.asList)1 DefaultAgendaEventListener (org.drools.core.event.DefaultAgendaEventListener)1 KieServices (org.kie.api.KieServices)1 MatchCreatedEvent (org.kie.api.event.rule.MatchCreatedEvent)1 KieHelper (org.kie.internal.utils.KieHelper)1