use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class ReteooWorkingMemoryTest method testDifferentEntryPointsOnSameFact.
@Test
public void testDifferentEntryPointsOnSameFact() {
// JBRULES-2971
InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
Rete rete = kBase.getRete();
NodeFactory nFacotry = kBase.getConfiguration().getComponentFactory().getNodeFactoryService();
EntryPointNode epn = nFacotry.buildEntryPointNode(kBase.getReteooBuilder().getIdGenerator().getNextId(), RuleBasePartitionId.MAIN_PARTITION, kBase.getConfiguration().isMultithreadEvaluation(), rete, new EntryPointId("xxx"));
kBase.getRete().addObjectSink(epn);
KieSession ksession = kBase.newKieSession();
FactHandle f1 = ksession.insert("f1");
EntryPoint ep = ksession.getEntryPoint("xxx");
try {
ep.update(f1, "s1");
fail("Should throw an exception");
} catch (IllegalArgumentException e) {
}
try {
ep.retract(f1);
fail("Should throw an exception");
} catch (IllegalArgumentException e) {
}
ksession.update(f1, "s1");
assertNotNull(ksession.getObject(f1));
ksession.retract(f1);
ksession.retract(f1);
assertNull(ksession.getObject(f1));
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class TraitHelper method lookupHandleForWrapper.
private <K> InternalFactHandle lookupHandleForWrapper(K core) {
for (EntryPoint ep : workingMemory.getEntryPoints()) {
ObjectStore store = ((WorkingMemoryEntryPoint) ep).getObjectStore();
Iterator<InternalFactHandle> iter = store.iterateFactHandles();
while (iter.hasNext()) {
InternalFactHandle handle = iter.next();
if (handle.isTraitable() && handle.getObject() instanceof CoreWrapper && ((CoreWrapper) handle.getObject()).getCore() == core) {
return handle;
}
}
}
return null;
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class DescrBuilderTest method testFromEntryPoint.
@Test
public void testFromEntryPoint() throws InstantiationException, IllegalAccessException {
PackageDescr pkg = DescrFactory.newPackage().name("org.drools").newRule().name("from rule").lhs().pattern("String").id("s", false).from().entryPoint("EventStream").end().end().rhs("//System.out.println(s);").end().getDescr();
KiePackage kpkg = compilePkgDescr(pkg, "org.drools");
assertEquals("org.drools", kpkg.getName());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Collections.singletonList(kpkg));
KieSession ksession = createKnowledgeSession(kbase);
EntryPoint ep = ksession.getEntryPoint("EventStream");
ep.insert("Hello World!");
int rules = ksession.fireAllRules();
assertEquals(1, rules);
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class MarshallingTest method testMarshallEntryPointsWithSlidingTimeWindow.
@Test
@Ignore("beta4 phreak")
public void testMarshallEntryPointsWithSlidingTimeWindow() throws Exception {
String str = "package org.domain.test \n" + "import " + getClass().getCanonicalName() + ".*\n" + "import java.util.List\n" + "global java.util.List list\n" + "declare A\n" + " @role( event )\n" + " @expires( 10m )\n" + "end\n" + "declare B\n" + "" + " @role( event )\n" + " @expires( 10m )\n" + "end\n" + "" + "rule a1\n" + "when\n" + " $l : List() from collect( A() over window:time(30s) from entry-point 'a-ep') \n" + "then\n" + " list.add( $l );" + "end\n";
KieBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
conf.setOption(EventProcessingOption.STREAM);
final KieBase kbase = loadKnowledgeBaseFromString(conf, str);
KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.get("pseudo"));
ksconf.setOption(TimerJobFactoryOption.get("trackable"));
KieSession ksession = createKnowledgeSession(kbase, ksconf);
List list = new ArrayList();
ksession.setGlobal("list", list);
EntryPoint aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
list.clear();
ksession.fireAllRules();
ksession = marsallStatefulKnowledgeSession(ksession);
assertEquals(2, ((List) list.get(0)).size());
PseudoClockScheduler timeService = (PseudoClockScheduler) ksession.<SessionClock>getSessionClock();
timeService.advanceTime(15, TimeUnit.SECONDS);
ksession = marsallStatefulKnowledgeSession(ksession);
aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
aep = ksession.getEntryPoint("a-ep");
aep.insert(new A());
ksession = marsallStatefulKnowledgeSession(ksession);
list.clear();
ksession.fireAllRules();
ksession = marsallStatefulKnowledgeSession(ksession);
assertEquals(4, ((List) list.get(0)).size());
timeService = (PseudoClockScheduler) ksession.<SessionClock>getSessionClock();
timeService.advanceTime(20, TimeUnit.SECONDS);
ksession = marsallStatefulKnowledgeSession(ksession);
list.clear();
ksession.fireAllRules();
assertEquals(2, ((List) list.get(0)).size());
}
use of org.kie.api.runtime.rule.EntryPoint in project drools by kiegroup.
the class FromTest method testNetworkBuildErrorAcrossEntryPointsAndFroms.
@Test
public void testNetworkBuildErrorAcrossEntryPointsAndFroms() throws Exception {
String rule1 = "package org.drools.compiler\n";
rule1 += "global java.util.List list\n";
rule1 += "rule rule1\n";
rule1 += "when\n";
rule1 += " Cheese() from entry-point \"testep\"\n";
rule1 += " $p : Person() from list\n";
rule1 += "then \n";
rule1 += " list.add( \"rule1\" ) ;\n";
rule1 += " insert( $p );\n";
rule1 += "end\n";
rule1 += "rule rule2\n";
rule1 += "when\n";
rule1 += " $p : Person() \n";
rule1 += "then \n";
rule1 += " list.add( \"rule2\" ) ;\n";
rule1 += "end\n";
final KieBase kbase = loadKnowledgeBaseFromString(rule1);
final KieSession ksession = createKnowledgeSession(kbase);
final EntryPoint ep = ksession.getEntryPoint("testep");
final List list = new ArrayList();
ksession.setGlobal("list", list);
list.add(new Person("darth"));
ep.insert(new Cheese("cheddar"));
ksession.fireAllRules();
assertEquals(3, list.size());
}
Aggregations