use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class MBeansMonitoringTest method testEventOffset.
@Test
public void testEventOffset() 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 ksession1 = 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);
MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
ObjectName kbOn = DroolsManagementAgent.createObjectNameFor((InternalKnowledgeBase) kiebase);
mbserver.invoke(kbOn, "startInternalMBeans", new Object[0], new String[0]);
Object expOffset = mbserver.getAttribute(new ObjectName(kbOn + ",group=EntryPoints,EntryPoint=DEFAULT,ObjectType=org.drools.compiler.StockTick"), "ExpirationOffset");
assertEquals(10001, ((Number) expOffset).longValue());
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieBuilderTest method testNotExistingInclude.
@Test
public void testNotExistingInclude() throws Exception {
String drl = "package org.drools.compiler.integrationtests\n" + "declare CancelFact\n" + " cancel : boolean = true\n" + "end\n" + "rule R1 when\n" + " $m : CancelFact( cancel == true )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
KieModuleModel module = ks.newKieModuleModel();
final String defaultBaseName = "defaultKBase";
KieBaseModel defaultBase = module.newKieBaseModel(defaultBaseName).addInclude("notExistingKB1").addInclude("notExistingKB2");
defaultBase.setDefault(true);
defaultBase.addPackage("*");
defaultBase.newKieSessionModel("defaultKSession").setDefault(true);
kfs.writeKModuleXML(module.toXML());
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
assertEquals(2, kb.getResults().getMessages().size());
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieBuilderTest method testNoPomXml.
@Test
public void testNoPomXml() throws ClassNotFoundException, InterruptedException, IOException {
String namespace = "org.kie.test";
KieModuleModel kProj = createKieProject(namespace);
ReleaseId releaseId = KieServices.Factory.get().getRepository().getDefaultReleaseId();
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
generateKProjectXML(kfs, namespace, kProj);
generateMessageClass(kfs, namespace);
generateRule(kfs, namespace);
MemoryFileSystem mfs = ((KieFileSystemImpl) kfs).asMemoryFileSystem();
createAndTestKieContainer(releaseId, createKieBuilder(kfs), namespace);
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieBuilderTest method testInvalidProjectXml.
@Test
public void testInvalidProjectXml() throws ClassNotFoundException, InterruptedException, IOException {
String namespace = "org.kie.test";
KieModuleModel kProj = createKieProject(namespace);
ReleaseId releaseId = KieServices.Factory.get().newReleaseId(namespace, "memory", "1.0-SNAPSHOT");
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
generatePomXML(kfs, releaseId);
kfs.writeKModuleXML("xxxx");
generateMessageClass(kfs, namespace);
generateRule(kfs, namespace);
KieBuilder kieBuilder = createKieBuilder(kfs);
kieBuilder.buildAll();
assertTrue(kieBuilder.getResults().hasMessages(Level.ERROR));
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class CepEspTest method testThrowsWhenCreatingKieBaseUsingWindowsInCloudMode.
@Test
public void testThrowsWhenCreatingKieBaseUsingWindowsInCloudMode() {
String drl = "declare TestEvent\n" + " @role( event )\n" + " name : String\n" + "end\n" + "\n" + "rule R when\n" + " TestEvent ( name == \"EventA\" ) over window:time( 1s ) from entry-point EventStream\n" + " then\n" + " // consequence\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieModuleModel kieModule = ks.newKieModuleModel();
KieBaseModel defaultBase = kieModule.newKieBaseModel("KBase").setDefault(true).addPackage("*").setEventProcessingMode(EventProcessingOption.CLOUD);
defaultBase.newKieSessionModel("KSession").setClockType(ClockTypeOption.get("pseudo")).setDefault(true);
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
kfs.writeKModuleXML(kieModule.toXML());
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
try {
kieContainer.getKieBase("KBase");
fail("Should throw a RuntimeException because the CLOUD kbase is trying to use features only available in STREAM mode");
} catch (Exception e) {
}
}
Aggregations