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