Search in sources :

Example 41 with EntryPoint

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

the class NegativePatternsTest method testSingleEvent.

@Test
public void testSingleEvent() throws InterruptedException {
    EntryPoint entryPoint = ksession.getEntryPoint("EventStream");
    int count = 0;
    // no rules should be fired in the beginning
    advanceTime(LONG_SLEEP_TIME);
    assertEquals(count, firedRulesListener.ruleFiredCount("SingleAbsence"));
    // after firing the rule will wait for 18ms
    ksession.fireAllRules();
    assertEquals(count, firedRulesListener.ruleFiredCount("SingleAbsence"));
    count++;
    advanceTime(LONG_SLEEP_TIME);
    ksession.fireAllRules();
    assertEquals(count, firedRulesListener.ruleFiredCount("SingleAbsence"));
    FactHandle event = entryPoint.insert(new TestEvent(0, "EventA"));
    ksession.fireAllRules();
    advanceTime(LONG_SLEEP_TIME);
    ksession.fireAllRules();
    assertEquals(count, firedRulesListener.ruleFiredCount("SingleAbsence"));
    entryPoint.delete(event);
    ksession.fireAllRules();
    count++;
    advanceTime(LONG_SLEEP_TIME);
    ksession.fireAllRules();
    assertEquals(count, firedRulesListener.ruleFiredCount("SingleAbsence"));
    // rule was already fired and no changes were made to working memory
    ksession.fireAllRules();
    advanceTime(LONG_SLEEP_TIME);
    ksession.fireAllRules();
    assertEquals(count, firedRulesListener.ruleFiredCount("SingleAbsence"));
}
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 42 with EntryPoint

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

the class WindowTest method testDeclaredTimeWindowInRule.

@Test
public void testDeclaredTimeWindowInRule() throws InterruptedException {
    final long[] results = new long[] { 1, 2, 3, 4, 5, 5, 5, 5, 5, 5 };
    EntryPoint entryPoint = ksession.getEntryPoint("EventStream");
    List<Long> result = new ArrayList<Long>();
    ksession.setGlobal("result", result);
    TestEvent event;
    for (int i = 0; i < 10; i++) {
        event = new TestEvent(null, "timeDec", null);
        entryPoint.insert(event);
        ksession.fireAllRules();
        assertEquals(results[i], result.get(result.size() - 1).longValue());
        clock.advanceTime(10, TimeUnit.MILLISECONDS);
    }
}
Also used : ArrayList(java.util.ArrayList) EntryPoint(org.kie.api.runtime.rule.EntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) Test(org.junit.Test)

Example 43 with EntryPoint

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

the class WindowTest method testLengthWindow.

@Test
public void testLengthWindow() {
    EntryPoint entryPoint = ksession.getEntryPoint("EventStream");
    TestEvent event;
    for (int i = 1; i <= 20; i++) {
        event = new TestEvent(null, "length", null);
        entryPoint.insert(event);
        assertEquals((i < 10 ? i : 10), ((Long) ksession.getQueryResults("TestLengthWindow").iterator().next().get("$eventCount")).intValue());
    }
}
Also used : EntryPoint(org.kie.api.runtime.rule.EntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) Test(org.junit.Test)

Example 44 with EntryPoint

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

the class WindowTest method testDeclaredTimeWindowInQuery.

@Test
public void testDeclaredTimeWindowInQuery() throws InterruptedException {
    final long[] results = new long[] { 1, 2, 3, 4, 5, 5, 5, 5, 5, 5 };
    EntryPoint entryPoint = ksession.getEntryPoint("EventStream");
    TestEvent event;
    for (int i = 0; i < 10; i++) {
        event = new TestEvent(null, "timeDec", null);
        entryPoint.insert(event);
        assertEquals(results[i], ksession.getQueryResults("TestDeclaredTimeWindow").iterator().next().get("$eventCount"));
        clock.advanceTime(10, TimeUnit.MILLISECONDS);
    }
}
Also used : EntryPoint(org.kie.api.runtime.rule.EntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) Test(org.junit.Test)

Example 45 with EntryPoint

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

the class WindowTest method testDeclaredLengthWindowInRule.

@Test
public void testDeclaredLengthWindowInRule() {
    EntryPoint entryPoint = ksession.getEntryPoint("EventStream");
    List<Long> result = new ArrayList<Long>();
    ksession.setGlobal("result", result);
    TestEvent event;
    for (int i = 1; i <= 10; i++) {
        event = new TestEvent(null, "lengthDec", null);
        entryPoint.insert(event);
        ksession.fireAllRules();
        assertEquals((i < 5 ? i : 5), result.get(result.size() - 1).longValue());
    }
}
Also used : ArrayList(java.util.ArrayList) 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