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"));
}
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);
}
}
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());
}
}
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);
}
}
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());
}
}
Aggregations