use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class MarshallingTest method testMarshallEntryPointsWithSlidingLengthWindow.
@Test
public void testMarshallEntryPointsWithSlidingLengthWindow() 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:length(3) 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());
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(3, ((List) list.get(0)).size());
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class PatternTest method testDeclaringAndUsingBindsInSamePattern.
@Test
public void testDeclaringAndUsingBindsInSamePattern() throws IOException, ClassNotFoundException {
final KieBaseConfiguration kbc = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbc.setOption(RemoveIdentitiesOption.YES);
final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase(kbc, "test_DeclaringAndUsingBindsInSamePattern.drl"));
final KieSession ksession = createKnowledgeSession(kbase);
final List sensors = new ArrayList();
ksession.setGlobal("sensors", sensors);
final Sensor sensor1 = new Sensor(100, 150);
ksession.insert(sensor1);
ksession.fireAllRules();
assertEquals(0, sensors.size());
final Sensor sensor2 = new Sensor(200, 150);
ksession.insert(sensor2);
ksession.fireAllRules();
assertEquals(3, sensors.size());
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class AbstractKieModule method getKnowledgeBaseConfiguration.
private KieBaseConfiguration getKnowledgeBaseConfiguration(KieBaseModelImpl kBaseModel, ClassLoader cl) {
KieBaseConfiguration kbConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null, cl);
kbConf.setOption(kBaseModel.getEqualsBehavior());
kbConf.setOption(kBaseModel.getEventProcessingMode());
kbConf.setOption(kBaseModel.getDeclarativeAgenda());
return kbConf;
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class FireUntilHaltAccumulateTest method setUp.
@Before
public void setUp() {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
System.err.println(kbuilder.getErrors().toString());
}
final KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);
kbase.addPackages(kbuilder.getKnowledgePackages());
final KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sessionConfig.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
this.statefulSession = kbase.newKieSession(sessionConfig, null);
this.stockFactory = new StockFactory(kbase);
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class FirstOrderLogicTest method testRemoveIdentitiesSubNetwork.
@Test
public void testRemoveIdentitiesSubNetwork() throws Exception {
KieBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
conf.setOption(RemoveIdentitiesOption.YES);
KieBase kbase = loadKnowledgeBase(conf, "test_removeIdentitiesSubNetwork.drl");
KieSession workingMemory = createKnowledgeSession(kbase);
final List list = new ArrayList();
workingMemory.setGlobal("results", list);
final Person bob = new Person("bob", "stilton");
workingMemory.insert(bob);
final Person mark = new Person("mark", "stilton");
workingMemory.insert(mark);
final Cheese stilton1 = new Cheese("stilton", 6);
final FactHandle stilton1Handle = (FactHandle) workingMemory.insert(stilton1);
final Cheese stilton2 = new Cheese("stilton", 7);
final FactHandle stilton2Handle = (FactHandle) workingMemory.insert(stilton2);
workingMemory.fireAllRules();
assertEquals(0, list.size());
workingMemory.retract(stilton1Handle);
workingMemory.fireAllRules();
assertEquals(1, list.size());
assertEquals(mark, list.get(0));
workingMemory.retract(stilton2Handle);
workingMemory.fireAllRules();
assertEquals(2, list.size());
assertEquals(bob, list.get(1));
}
Aggregations