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 = RuleBaseFactory.newKnowledgeBaseConfiguration(null, cl);
kbConf.setOption(kBaseModel.getEqualsBehavior());
kbConf.setOption(kBaseModel.getEventProcessingMode());
kbConf.setOption(kBaseModel.getDeclarativeAgenda());
kbConf.setOption(kBaseModel.getSequential());
kbConf.setOption(kBaseModel.getSessionsPool());
return kbConf;
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class RangeIndexANCTest method createKieBaseWithRangeIndexThresholdValue.
private KieBase createKieBaseWithRangeIndexThresholdValue(String drl, int rangeIndexThresholdValue) {
final KieContainer kieContainer = getKieContainer(drl);
final KieBaseConfiguration kieBaseConfiguration = KieServices.get().newKieBaseConfiguration();
// for test convenience. Default value is AlphaRangeIndexThresholdOption.DEFAULT_VALUE
kieBaseConfiguration.setOption(AlphaRangeIndexThresholdOption.get(rangeIndexThresholdValue));
return kieContainer.newKieBase(kieBaseConfiguration);
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class AccumulateTest method testAccumulatesExpireVsCancel.
@Test
public void testAccumulatesExpireVsCancel() throws Exception {
// JBRULES-3201
String drl = "package com.sample;\n" + "\n" + "global java.util.List list; \n" + "" + "declare FactTest\n" + " @role( event ) \n" + "end\n" + " \n" + "rule \"A500 test\"\n" + "when\n" + " accumulate (\n" + " $d : FactTest() over window:time(1m), $tot : count($d); $tot > 0 )\n" + "then\n" + " System.out.println( $tot ); \n" + " list.add( $tot.intValue() ); \n " + "end\n" + "\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DRL);
assertFalse(kbuilder.hasErrors());
KieBaseConfiguration kbConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbConf.setOption(EventProcessingOption.STREAM);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConf);
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksConf.setOption(ClockTypeOption.get("pseudo"));
KieSession ksession = kbase.newKieSession(ksConf, null);
ArrayList list = new ArrayList();
ksession.setGlobal("list", list);
FactType ft = kbase.getFactType("com.sample", "FactTest");
ksession.insert(ft.newInstance());
ksession.fireAllRules();
ksession.insert(ft.newInstance());
ksession.fireAllRules();
ksession.insert(ft.newInstance());
ksession.fireAllRules();
SessionPseudoClock clock = ksession.getSessionClock();
clock.advanceTime(1, TimeUnit.MINUTES);
ksession.fireAllRules();
assertFalse(list.contains(0));
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class FailureOnRemovalTest method createKnowledgeBaseConfiguration.
private KieBaseConfiguration createKnowledgeBaseConfiguration(boolean shareBetaNodes) {
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kconf.setOption(SequentialOption.NO);
kconf.setOption(ShareAlphaNodesOption.YES);
kconf.setOption(shareBetaNodes ? ShareBetaNodesOption.YES : ShareBetaNodesOption.NO);
return kconf;
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class MVELTest method testMVELTypeCoercion.
@Test
public void testMVELTypeCoercion() {
final String str = "package org.drools.compiler.test; \n" + "\n" + "global java.util.List list;" + "\n" + "declare Bean\n" + // NOTICE: THIS WORKS WHEN THE FIELD IS "LIST", BUT USED TO WORK WITH ARRAYLIST TOO
" field : java.util.ArrayList\n" + "end\n" + "\n" + "\n" + "rule \"Init\"\n" + "when \n" + "then\n" + " insert( new Bean( new java.util.ArrayList( java.util.Arrays.asList( \"x\" ) ) ) );\n" + "end\n" + "\n" + "rule \"Check\"\n" + "when\n" + " $b : Bean( $fld : field == [\"x\"] )\n" + "then\n" + " System.out.println( $fld );\n" + " list.add( \"OK\" ); \n" + "end";
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
final KieBaseConfiguration kbConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbConf.setOption(EqualityBehaviorOption.EQUALITY);
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConf);
kbase.addPackages(kbuilder.getKnowledgePackages());
final KieSession ksession = kbase.newKieSession();
final List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertTrue(list.contains("OK"));
ksession.dispose();
}
Aggregations