use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class MTEntryPointsTest method initSession.
@Before
public void initSession() {
String str = "package org.jboss.brms\n" + "\n" + "import org.drools.compiler.integrationtests.MTEntryPointsTest.MessageEvent\n" + "\n" + "declare MessageEvent\n" + " @role( event )\n" + "end\n" + "\n" + "rule \"sum of last event from first entry point\"\n" + " when\n" + "\t accumulate (\n" + "\t MessageEvent ($value : value) over window:length(1) from entry-point \"FirstStream\",\n" + "\t $sum : sum($value)\n" + "\t )\n" + " then\n" + "end\n" + "\n" + "rule \"sum of last event from both entry points\"\n" + " when\n" + " accumulate (\n" + " MessageEvent ($value1 : value) over window:length(1) from entry-point \"FirstStream\",\n" + " $thirdSum1 : sum($value1)\n" + " )\n" + " accumulate (\n" + " MessageEvent ($value2 : value) over window:length(1) from entry-point \"SecondStream\",\n" + " $thirdSum2 : sum($value2)\n" + " )\n" + " then\n" + "end\n" + "\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
KieModuleModel kmoduleModel = ks.newKieModuleModel();
kmoduleModel.newKieBaseModel("defaultKieBase").addPackage("*").setEventProcessingMode(EventProcessingOption.STREAM).newKieSessionModel("defaultKieSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kmoduleModel.toXML());
KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, builder.getResults().getMessages().size());
ks.getRepository().addKieModule(builder.getKieModule());
this.kieSession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class DeclarativeAgendaTest method testFiredRuleDoNotRefireAfterUnblock.
@Test
public void testFiredRuleDoNotRefireAfterUnblock() {
// BZ-1038076
String drl = "package org.drools.compiler.integrationtests\n" + "\n" + "import org.kie.api.runtime.rule.Match\n" + "import java.util.List\n" + "\n" + "global List list\n" + "\n" + "rule startAgenda\n" + "salience 100\n" + "when\n" + " String( this == 'startAgenda' )\n" + "then\n" + " drools.getKnowledgeRuntime().getAgenda().getAgendaGroup(\"agenda\").setFocus();\n" + " list.add(kcontext.getRule().getName());\n" + "end\n" + "\n" + "rule sales @department('sales')\n" + "agenda-group \"agenda\"\n" + "when\n" + " $s : String( this == 'fireRules' )\n" + "then\n" + " list.add(kcontext.getRule().getName());\n" + "end\n" + "\n" + "rule salesBlocker salience 10\n" + "when\n" + " $s : String( this == 'fireBlockerRule' )\n" + " $i : Match( department == 'sales' )\n" + "then\n" + " kcontext.blockMatch( $i );\n" + " list.add(kcontext.getRule().getName());\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmodule = ks.newKieModuleModel();
KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true).setDeclarativeAgenda(DeclarativeAgendaOption.ENABLED);
baseModel.newKieSessionModel("defaultKSession").setDefault(true);
kfs.writeKModuleXML(kmodule.toXML());
kfs.write("src/main/resources/block_rule.drl", drl);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
List<String> list = new DebugList<String>();
ksession.setGlobal("list", list);
// first run
ksession.insert("startAgenda");
ksession.insert("fireRules");
FactHandle fireBlockerRule = ksession.insert("fireBlockerRule");
ksession.fireAllRules();
String[] expected = { "startAgenda", "sales", "salesBlocker" };
assertEquals(expected.length, list.size());
for (int i = 0; i < list.size(); i++) {
assertEquals(expected[i], list.get(i));
}
// second run
ksession.delete(fireBlockerRule);
list.clear();
ksession.fireAllRules();
assertEquals(0, list.size());
ksession.dispose();
list.clear();
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class CepJavaTypeTest method testJavaTypeAnnotatedWithRole_WindowTime.
@Test
public void testJavaTypeAnnotatedWithRole_WindowTime() {
String drl = "package org.drools.compiler.integrationtests\n" + "\n" + "import org.drools.compiler.integrationtests.CepJavaTypeTest.Event;\n" + "\n" + "rule \"CEP Window Time\"\n" + "when\n" + " Event() over window:time (1d)\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieModuleModel module = ks.newKieModuleModel();
KieBaseModel defaultBase = module.newKieBaseModel("defaultKBase").setDefault(true).addPackage("*");
defaultBase.newKieSessionModel("defaultKSession").setDefault(true);
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
kfs.writeKModuleXML(module.toXML());
KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
assertTrue(builder.getResults().getMessages().isEmpty());
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class CepFireUntilHaltTimerTest method init.
public void init() {
String drl = "package org.drools.compiler.integrationtests\n" + "\n" + "import org.drools.compiler.integrationtests.CepFireUntilHaltTimerTest.MetadataEvent;\n" + "import java.util.List;\n" + "\n" + "global List countResult;\n" + "\n" + "declare MetadataEvent\n" + " @role( event )\n" + " @timestamp( metadataTimestamp )\n" + " @duration( metadataDuration )\n" + " @expires (24h)\n" + "end\n" + "\n" + "rule \"Number of metadata events in the last 10 seconds\"\n" + "timer (int: 1s 10s)\n" + "//timer (int: 0s 10s) // this works\n" + "when\n" + " String( this == \"events_inserted\" )\n" + " $count: Number() from accumulate( $event: MetadataEvent() over window:time(10s), count( $event ) )\n" + "then\n" + " System.out.println(\"Events count: \" + $count);\n" + " countResult.add($count);\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieModuleModel module = ks.newKieModuleModel();
KieBaseModel defaultBase = module.newKieBaseModel("defaultKBase").setDefault(true).addPackage("*").setEventProcessingMode(EventProcessingOption.STREAM);
defaultBase.newKieSessionModel("defaultKSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
kfs.writeKModuleXML(module.toXML());
ks.newKieBuilder(kfs).buildAll();
ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
result = new ArrayList<Long>();
ksession.setGlobal("countResult", result);
clock = ksession.getSessionClock();
ksession.insert(clock);
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class BenchmarkUtil method getDefaultKieModuleModel.
public static KieModuleModel getDefaultKieModuleModel(final KieServices ks) {
final KieModuleModel kieModuleModel = ks.newKieModuleModel();
final KieBaseModel kieBaseModel1 = kieModuleModel.newKieBaseModel("kbase").setDefault(true);
kieBaseModel1.newKieSessionModel("ksession").setDefault(true);
return kieModuleModel;
}
Aggregations