use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieHelloWorldTest method createKieProjectWithPackagesAnd2KieBases.
private KieModuleModel createKieProjectWithPackagesAnd2KieBases(KieServices ks) {
KieModuleModel kproj = ks.newKieModuleModel();
kproj.newKieBaseModel().setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM).addPackage("org.pkg1").newKieSessionModel("KSession1");
kproj.newKieBaseModel().setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM).addPackage("org.pkg2").newKieSessionModel("KSession2");
return kproj;
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieLoggersTest method testDeclarativeKieFileLogger.
@Test
public void testDeclarativeKieFileLogger() throws Exception {
String drl = "package org.drools.integrationtests\n" + "import org.drools.compiler.Message;\n" + "rule \"Hello World\"\n" + " when\n" + " m : Message( myMessage : message )\n" + " then\n" + "end";
String fileName = "target/testKieFileLogger";
File file = new File(fileName + ".log");
if (file.exists()) {
file.delete();
}
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setFileLogger(fileName);
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML());
kfs.write("src/main/resources/KBase1/rule.drl", drl);
KieModule kieModule = ks.newKieBuilder(kfs).buildAll().getKieModule();
KieContainer kieContainer = ks.newKieContainer(kieModule.getReleaseId());
KieSession ksession = kieContainer.newKieSession("KSession1");
ksession.insert(new Message("Hello World"));
int fired = ksession.fireAllRules();
assertEquals(1, fired);
// disposing the ksession also flushes and closes the logger
ksession.dispose();
file = new File(fileName + ".log");
assertTrue(file.exists());
file.delete();
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieLoggersTest method testDeclarativeKieConsoleLogger.
@Test
public void testDeclarativeKieConsoleLogger() throws Exception {
String drl = "package org.drools.integrationtests\n" + "import org.drools.compiler.Message;\n" + "rule \"Hello World\"\n" + " when\n" + " m : Message( myMessage : message )\n" + " then\n" + "end";
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setConsoleLogger("logger");
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML());
kfs.write("src/main/resources/KBase1/rule.drl", drl);
KieModule kieModule = ks.newKieBuilder(kfs).buildAll().getKieModule();
KieContainer kieContainer = ks.newKieContainer(kieModule.getReleaseId());
KieSession ksession = kieContainer.newKieSession("KSession1");
ksession.insert(new Message("Hello World"));
int fired = ksession.fireAllRules();
assertEquals(1, fired);
KieRuntimeLogger logger = ksession.getLogger();
assertNotNull(logger);
logger.close();
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieLoggersTest method testDeclarativeKieConsoleLoggerStateless.
@Test
public void testDeclarativeKieConsoleLoggerStateless() throws Exception {
String drl = "package org.drools.integrationtests\n" + "import org.drools.compiler.Message;\n" + "rule \"Hello World\"\n" + " when\n" + " m : Message( myMessage : message )\n" + " then\n" + "end";
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setType(KieSessionModel.KieSessionType.STATELESS).setConsoleLogger("logger");
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML());
kfs.write("src/main/resources/KBase1/rule.drl", drl);
KieModule kieModule = ks.newKieBuilder(kfs).buildAll().getKieModule();
KieContainer kieContainer = ks.newKieContainer(kieModule.getReleaseId());
StatelessKieSession ksession = kieContainer.newStatelessKieSession("KSession1");
ksession.execute(new Message("Hello World"));
KieRuntimeLogger logger = ksession.getLogger();
assertNotNull(logger);
logger.close();
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class MBeansMonitoringTest method testContainerMBeans.
@Test
public void testContainerMBeans() throws Exception {
String drl = "package org.drools.compiler.test\n" + "import org.drools.compiler.StockTick\n" + "declare StockTick\n" + " @role(event)\n" + " @expires(10s)\n" + "end\n" + "rule X\n" + "when\n" + " StockTick()\n" + "then\n" + "end";
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel(KBASE1).setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
KieSessionModel ksessionModel1 = kieBaseModel1.newKieSessionModel(KSESSION1).setDefault(true).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
ReleaseId releaseId1 = ks.newReleaseId("org.kie.test", "mbeans", "1.0.0");
createKJar(ks, kproj, releaseId1, null, drl);
KieContainer kc = ks.newKieContainer(releaseId1);
KieBase kiebase = kc.getKieBase(KBASE1);
kc.newKieSession(KSESSION1);
kiebase.newKieSession();
String kc1ID = ((InternalKieContainer) kc).getContainerId();
MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
LOG.debug("{}", mbserver.queryNames(new ObjectName("org.kie:kcontainerId=" + ObjectName.quote(kc1ID) + ",*"), null));
ReleaseId verRelease = ks.newReleaseId("org.kie.test", "mbeans", "RELEASE");
KieContainer kc2 = ks.newKieContainer("Matteo", verRelease);
kc2.newKieSession(KSESSION1);
KieContainerMonitorMXBean c1Monitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy(kc1ID), KieContainerMonitorMXBean.class);
assertEquals(releaseId1.toExternalForm(), c1Monitor.getConfiguredReleaseIdStr());
assertEquals(releaseId1.toExternalForm(), c1Monitor.getResolvedReleaseIdStr());
assertTrue(c1Monitor.getConfiguredReleaseId().sameGAVof(releaseId1));
assertTrue(c1Monitor.getResolvedReleaseId().sameGAVof(releaseId1));
assertEquals(releaseId1.getVersion(), c1Monitor.getConfiguredReleaseId().getVersion());
assertEquals(releaseId1.getVersion(), c1Monitor.getResolvedReleaseId().getVersion());
KieContainerMonitorMXBean c2Monitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy("Matteo"), KieContainerMonitorMXBean.class);
assertEquals(verRelease.toExternalForm(), c2Monitor.getConfiguredReleaseIdStr());
assertEquals(releaseId1.toExternalForm(), c2Monitor.getResolvedReleaseIdStr());
assertTrue(c2Monitor.getConfiguredReleaseId().sameGAVof(verRelease));
assertTrue(c2Monitor.getResolvedReleaseId().sameGAVof(releaseId1));
assertEquals(verRelease.getVersion(), c2Monitor.getConfiguredReleaseId().getVersion());
assertEquals(releaseId1.getVersion(), c2Monitor.getResolvedReleaseId().getVersion());
// MBean are supported only via KieContainer public API.
assertEquals(3, mbserver.queryNames(new ObjectName("org.kie:kcontainerId=" + ObjectName.quote(kc1ID) + ",*"), null).size());
kc.dispose();
assertEquals(0, mbserver.queryNames(new ObjectName("org.kie:kcontainerId=" + ObjectName.quote(kc1ID) + ",*"), null).size());
assertEquals(3, mbserver.queryNames(new ObjectName("org.kie:kcontainerId=" + ObjectName.quote("Matteo") + ",*"), null).size());
}
Aggregations