use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class IncrementalCompilationTest method testRemoveAndReaddJavaClass.
@Test
public void testRemoveAndReaddJavaClass() {
// DROOLS-1704
String javaSource = "package org.drools.test;\n" + "public class Person { }\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
ReleaseId releaseId3 = ks.newReleaseId("org.kie", "test-upgrade", "1.2.0");
KieFileSystem kfs = ks.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId1);
KieModuleModel kModuleModel = ks.newKieModuleModel();
kfs.writeKModuleXML(kModuleModel.toXML());
kfs.write("src/main/java/org/drools/test/Person.java", javaSource);
ks.newKieBuilder(kfs).buildAll();
KieContainer kContainer = ks.newKieContainer(releaseId1);
try {
Class.forName("org.drools.test.Person", true, kContainer.getClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
kContainer.getKieBase();
kfs = ks.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId2);
kModuleModel = ks.newKieModuleModel();
kfs.writeKModuleXML(kModuleModel.toXML());
ks.newKieBuilder(kfs).buildAll();
kContainer.updateToVersion(releaseId2);
kContainer.getKieBase();
kfs = ks.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId3);
kModuleModel = ks.newKieModuleModel();
kfs.writeKModuleXML(kModuleModel.toXML());
kfs.write("src/main/java/org/drools/test/Person.java", javaSource);
ks.newKieBuilder(kfs).buildAll();
kContainer.updateToVersion(releaseId3);
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class IncrementalCompilationTest method testAddRuleWithSlidingWindows.
@Test
public void testAddRuleWithSlidingWindows() throws Exception {
// DROOLS-2292
String drl1 = "package org.drools.compiler\n" + "import " + List.class.getCanonicalName() + "\n" + "import " + BooleanEvent.class.getCanonicalName() + "\n" + "rule R1 when\n" + " $e : BooleanEvent(!enabled)\n" + " List(size >= 1) from collect ( BooleanEvent(!enabled) over window:time(1) )\n" + " $toEdit : List() from collect( BooleanEvent(!enabled) over window:time(2) )\n" + "then\n" + " modify( (BooleanEvent)$toEdit.get(0) ){ setEnabled( true ) }\n" + "end\n";
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-upgrade", "1.0.0");
deployJar(ks, createKJar(ks, kproj, releaseId1, null));
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "2.0.0");
deployJar(ks, createKJar(ks, kproj, releaseId2, null, drl1));
KieContainer kc = ks.newKieContainer(releaseId1);
KieSession kieSession = kc.newKieSession();
kieSession.insert(new BooleanEvent());
kieSession.fireAllRules();
kc.updateToVersion(releaseId2);
kieSession.fireAllRules();
KieMarshallers marshallers = ks.getMarshallers();
Marshaller marshaller = marshallers.newMarshaller(kieSession.getKieBase());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
marshaller.marshall(outputStream, kieSession);
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class IncrementalCompilationTest method testDrlRenamingWithEvents.
@Test
public void testDrlRenamingWithEvents() throws Exception {
// DROOLS-965
String drl1 = "import " + SimpleEvent.class.getCanonicalName() + ";\n" + "\n" + "global java.util.concurrent.atomic.AtomicInteger counter1;\n" + "global java.util.concurrent.atomic.AtomicInteger counter2;\n" + "\n" + "declare SimpleEvent\n" + " @role( event )\n" + " @timestamp( timestamp )\n" + " @expires( 2d )\n" + "end\n" + "\n" + "rule R1 when\n" + " $s:SimpleEvent(code==\"MY_CODE\")\n" + "then\n" + " counter1.incrementAndGet();\n" + "end\n" + "\n" + "rule R2 when\n" + " $s:SimpleEvent(code==\"MY_CODE\")\n" + " not SimpleEvent(this != $s, this after [0,10s] $s)\n" + "then\n" + " counter2.incrementAndGet();\n" + "end\n";
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-upgrade", "1.1.1");
KieModule km = deployJar(ks, createKJar(ks, kproj, releaseId1, null, drl1));
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
PseudoClockScheduler clock = ksession.getSessionClock();
AtomicInteger counter1 = new AtomicInteger(0);
AtomicInteger counter2 = new AtomicInteger(0);
ksession.setGlobal("counter1", counter1);
ksession.setGlobal("counter2", counter2);
ksession.insert(new SimpleEvent("1", "MY_CODE", 0));
ksession.fireAllRules();
clock.advanceTime(5, TimeUnit.SECONDS);
ksession.insert(new SimpleEvent("2", "MY_CODE", 5));
ksession.fireAllRules();
assertEquals(2, counter1.get());
assertEquals(0, counter2.get());
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
// the null drl placeholder is used to have the same drl with a different file name
// this causes the removal and readdition of both rules
km = deployJar(ks, createKJar(ks, kproj, releaseId2, null, (String) null, drl1));
kc.updateToVersion(releaseId2);
clock = ksession.getSessionClock();
clock.advanceTime(16, TimeUnit.SECONDS);
ksession.insert(new SimpleEvent("3", "MY_CODE", 21));
ksession.fireAllRules();
assertEquals(5, counter1.get());
assertEquals(1, counter2.get());
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class DslExpansionTest method testDSLExpansion_MessageImplNPE.
@Test
public void testDSLExpansion_MessageImplNPE() throws Exception {
final KieServices ks = KieServices.Factory.get();
final ReleaseId releaseId = ks.newReleaseId("org.kie", "dsl-test", "1.0-SNAPSHOT");
final KieModuleModel kproj = ks.newKieModuleModel();
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML()).writePomXML(generatePomXml(releaseId)).write("src/main/resources/KBase1/test-dsl.dsl", createDSL()).write("src/main/resources/KBase1/test-rule.dslr", createDRL());
final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
if (!messages.isEmpty()) {
for (final Message m : messages) {
System.out.println(m.getText());
}
}
assertTrue(messages.isEmpty());
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class WireChannelTest method build.
private void build(KieServices ks, ReleaseId releaseId) throws IOException {
KieModuleModel kproj = ks.newKieModuleModel();
KieSessionModel ksession1 = kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setDefault(true);
ksession1.newChannelModel("testChannel", RecordingChannel.class.getName());
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML()).writePomXML(generatePomXml(releaseId)).write("src/main/resources/KBase1/rules.drl", createDRL());
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
}
Aggregations