Search in sources :

Example 36 with EntryPoint

use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.

the class AggregateFieldsTest method testAggregate.

@Test
@Ignore
public // FIXME I used to keep all null-context fields... but then memory would blow up. Now I keep only the last one, but then I must override that for accumulates...
void testAggregate() throws Exception {
    getKSession().getEntryPoint("in_Limit").insert(18);
    EntryPoint ep = getKSession().getEntryPoint("in_Age");
    ep.insert(10);
    ep.insert(20);
    ep.insert(30);
    ep.insert(40);
    getKSession().fireAllRules();
    checkFirstDataFieldOfTypeStatus(getKbase().getFactType(packageName, "Summa"), true, false, null, 90.0);
    checkGeneratedRules();
}
Also used : EntryPoint(org.kie.api.runtime.rule.EntryPoint) Ignore(org.junit.Ignore) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 37 with EntryPoint

use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.

the class SerializableGeneratedTypesTest method testSerializability.

@Test
public void testSerializability() throws Exception {
    final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("serializableGeneratedTypesTest.drl", getClass());
    final KieBase kieBase = KieBaseUtil.getKieBaseAndBuildInstallModule(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, drlResource);
    final KieSession session = kieBase.newKieSession();
    final FactType testEventType = session.getKieBase().getFactType(TestConstants.PACKAGE_REGRESSION, "TestEvent");
    for (int i = 0; i < 10; i++) {
        final Object testEvent = testEventType.newInstance();
        testEventType.set(testEvent, "id", "id" + i);
        final EntryPoint mainStream = session.getEntryPoint("test");
        mainStream.insert(testEvent);
        session.fireAllRules();
    }
}
Also used : KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) EntryPoint(org.kie.api.runtime.rule.EntryPoint) KieSession(org.kie.api.runtime.KieSession) EntryPoint(org.kie.api.runtime.rule.EntryPoint) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test)

Example 38 with EntryPoint

use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.

the class MarshallingTest method testMarshallEntryPointsWithExpires.

@Test
public void testMarshallEntryPointsWithExpires() throws Exception {
    String str = "package org.domain.test \n" + "import " + getClass().getCanonicalName() + ".*\n" + "global java.util.List list\n" + "declare A\n" + " @role( event )\n" + " @expires( 10s )\n" + "end\n" + "declare B\n" + "" + " @role( event )\n" + " @expires( 10s )\n" + "end\n" + "" + "declare C\n" + " @role( event )\n" + " @expires( 15s )\n" + "end\n" + "" + "rule a1\n" + "when\n" + "   $a : A() from entry-point 'a-ep'\n" + "then\n" + "list.add( $a );" + "end\n" + "" + "rule b1\n" + "when\n" + "   $b : B() from entry-point 'b-ep'\n" + "then\n" + "list.add( $b );" + "end\n" + "" + "rule c1\n" + "when\n" + "   $c : C() from entry-point 'c-ep'\n" + "then\n" + "list.add( $c );" + "end\n";
    KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    config.setOption(EventProcessingOption.STREAM);
    KieBase kBase = loadKnowledgeBaseFromString(config, str);
    KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    ksconf.setOption(ClockTypeOption.get("pseudo"));
    ksconf.setOption(TimerJobFactoryOption.get("trackable"));
    KieSession ksession = kBase.newKieSession(ksconf, null);
    List list = new ArrayList();
    ksession.setGlobal("list", list);
    EntryPoint aep = ksession.getEntryPoint("a-ep");
    aep.insert(new A());
    ksession = marsallStatefulKnowledgeSession(ksession);
    EntryPoint bep = ksession.getEntryPoint("b-ep");
    bep.insert(new B());
    ksession = marsallStatefulKnowledgeSession(ksession);
    EntryPoint cep = ksession.getEntryPoint("c-ep");
    cep.insert(new C());
    ksession = marsallStatefulKnowledgeSession(ksession);
    ksession.fireAllRules();
    ksession = marsallStatefulKnowledgeSession(ksession);
    assertEquals(3, list.size());
    aep = ksession.getEntryPoint("a-ep");
    assertEquals(1, aep.getFactHandles().size());
    bep = ksession.getEntryPoint("b-ep");
    assertEquals(1, bep.getFactHandles().size());
    cep = ksession.getEntryPoint("c-ep");
    assertEquals(1, cep.getFactHandles().size());
    PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock>getSessionClock();
    timeService.advanceTime(11, TimeUnit.SECONDS);
    ksession = marsallStatefulKnowledgeSession(ksession);
    ksession.fireAllRules();
    ksession = marsallStatefulKnowledgeSession(ksession);
    aep = ksession.getEntryPoint("a-ep");
    assertEquals(0, aep.getFactHandles().size());
    bep = ksession.getEntryPoint("b-ep");
    assertEquals(0, bep.getFactHandles().size());
    cep = ksession.getEntryPoint("c-ep");
    assertEquals(1, cep.getFactHandles().size());
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) FactA(org.drools.compiler.FactA) FactB(org.drools.compiler.FactB) FactC(org.drools.compiler.FactC) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) EntryPoint(org.kie.api.runtime.rule.EntryPoint) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) IteratorToList(org.drools.compiler.integrationtests.IteratorToList) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) PseudoClockScheduler(org.drools.core.time.impl.PseudoClockScheduler) Test(org.junit.Test)

Example 39 with EntryPoint

use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.

the class NegativePatternsTest method testConstrainedAbsence.

@Test
public void testConstrainedAbsence() throws InterruptedException {
    EntryPoint entryPoint = ksession.getEntryPoint("EventStream");
    int count = 0;
    count++;
    for (int i = 0; i < LOOPS; i++) {
        entryPoint.insert(new TestEvent(count, "EventB"));
        ksession.fireAllRules();
        advanceTime(LONG_SLEEP_TIME);
    }
    FactHandle handle;
    for (int i = 0; i < LOOPS; i++) {
        handle = entryPoint.insert(new TestEvent(i, "EventA"));
        advanceTime(LONG_SLEEP_TIME);
        ksession.fireAllRules();
        entryPoint.delete(handle);
        count++;
        advanceTime(LONG_SLEEP_TIME);
        ksession.fireAllRules();
    }
    ksession.fireAllRules();
    assertEquals(count, firedRulesListener.ruleFiredCount("SingleConstrained"));
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) EntryPoint(org.kie.api.runtime.rule.EntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) Test(org.junit.Test)

Example 40 with EntryPoint

use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.

the class NegativePatternsTest method testMultipleEvents.

@Test
public void testMultipleEvents() throws InterruptedException {
    EntryPoint entryPoint = ksession.getEntryPoint("EventStream");
    int count = 0;
    for (; count < LOOPS / 2; ) {
        entryPoint.insert(new TestEvent(count, "EventA"));
        ksession.fireAllRules();
        count++;
        advanceTime(SHORT_SLEEP_TIME);
        ksession.fireAllRules();
    }
    assertEquals(count, firedRulesListener.ruleFiredCount("MultipleEvents"));
    entryPoint.insert(new TestEvent(count, "EventA"));
    FactHandle handle = entryPoint.insert(new TestEvent(-1, "EventB"));
    advanceTime(SHORT_SLEEP_TIME);
    ksession.fireAllRules();
    entryPoint.delete(handle);
    ksession.fireAllRules();
    // it shouldn't fire because of the duration
    advanceTime(SHORT_SLEEP_TIME);
    ksession.fireAllRules();
    for (; count < LOOPS; ) {
        entryPoint.insert(new TestEvent(count, "EventA"));
        ksession.fireAllRules();
        count++;
        advanceTime(SHORT_SLEEP_TIME);
        ksession.fireAllRules();
    }
    ksession.fireAllRules();
    assertEquals(count, firedRulesListener.ruleFiredCount("MultipleEvents"));
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) EntryPoint(org.kie.api.runtime.rule.EntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) Test(org.junit.Test)

Aggregations

EntryPoint (org.kie.api.runtime.rule.EntryPoint)70 Test (org.junit.Test)50 KieSession (org.kie.api.runtime.KieSession)46 ArrayList (java.util.ArrayList)26 KieBase (org.kie.api.KieBase)26 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)19 StockTick (org.drools.compiler.StockTick)18 KieBaseConfiguration (org.kie.api.KieBaseConfiguration)16 FactHandle (org.kie.api.runtime.rule.FactHandle)15 List (java.util.List)13 InternalFactHandle (org.drools.core.common.InternalFactHandle)13 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)13 RegistryContext (org.drools.core.command.impl.RegistryContext)12 SessionPseudoClock (org.kie.api.time.SessionPseudoClock)8 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)7 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)7 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)6 EventFactHandle (org.drools.core.common.EventFactHandle)6 AfterMatchFiredEvent (org.kie.api.event.rule.AfterMatchFiredEvent)6 AgendaEventListener (org.kie.api.event.rule.AgendaEventListener)6