use of org.kie.api.builder.model.KieBaseModel 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.KieBaseModel 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.KieBaseModel 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.KieBaseModel 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;
}
use of org.kie.api.builder.model.KieBaseModel in project drools by kiegroup.
the class KieUtil method getDefaultKieModuleModel.
public static KieModuleModel getDefaultKieModuleModel(KieServices ks) {
final KieModuleModel kproj = KieServices.get().newKieModuleModel();
final KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("kbase").setDefault(true);
final KieSessionModel ksession1 = kieBaseModel1.newKieSessionModel("ksession").setDefault(true);
return kproj;
}
Aggregations