use of org.kie.api.builder.KieModule 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.KieModule 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.KieModule 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.KieModule in project drools by kiegroup.
the class MBeansMonitoringTest method testLoadKjarFromClasspath.
/**
* Copied from KieRepositoryTest to test JMX monitoring
*/
@Test
public void testLoadKjarFromClasspath() {
// DROOLS-1335
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.getClass().getResource("/kie-project-simple-1.0.0.jar") });
Thread.currentThread().setContextClassLoader(urlClassLoader);
MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
try {
KieServices ks = KieServices.Factory.get();
KieRepository kieRepository = ks.getRepository();
ReleaseId releaseId = ks.newReleaseId("org.test", "kie-project-simple", "1.0.0");
KieModule kieModule = kieRepository.getKieModule(releaseId);
assertNotNull(kieModule);
assertEquals(releaseId, kieModule.getReleaseId());
ks.newKieContainer("myID", releaseId);
KieContainerMonitorMXBean c1Monitor = JMX.newMXBeanProxy(mbserver, DroolsManagementAgent.createObjectNameBy("myID"), KieContainerMonitorMXBean.class);
assertTrue(c1Monitor.getConfiguredReleaseId().sameGAVof(releaseId));
assertTrue(c1Monitor.getResolvedReleaseId().sameGAVof(releaseId));
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class DynamicRuleLoadTest method updateToVersion.
public void updateToVersion() {
KieServices ks = KieServices.Factory.get();
// Create a new jar for version 1.1.0
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
KieModule km = createAndDeployJar(ks, releaseId2, drl1, drl2_2);
// try to update the container to version 1.1.0
kieContainer.updateToVersion(releaseId2);
// create and use a new session
ksession.insert(new Message("Hello World"));
}
Aggregations