use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method testUpdateWithDeclarationPresent.
@Test
public void testUpdateWithDeclarationPresent() throws Exception {
// DROOLS-560
String header = "package org.drools.compiler\n" + "import org.drools.compiler.integrationtests.incrementalcompilation.IncrementalCompilationTest.FooEvent\n";
String declaration = "declare FooEvent\n" + " @timestamp( mytime )\n" + " @role( event )\n" + "end\n";
String rule1 = "rule R1 when\n" + " $e : FooEvent( )\n" + "then\n" + " insert(new Message(\"Hello R1\"));\n" + "end\n";
String rule2 = "rule R1 when\n" + " $e : FooEvent( )\n" + "then\n" + " insert(new Message(\"Hello R2\"));\n" + "end\n";
String file1 = header + declaration + rule1;
String file2 = header + declaration + rule2;
KieServices ks = KieServices.Factory.get();
// Create an in-memory jar for version 1.0.0
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, file1);
// Create a session and fire rules
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
ksession.insert(new FooEvent(0));
assertEquals(1, ksession.fireAllRules());
// Create a new jar for version 1.1.0
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
km = createAndDeployJar(ks, releaseId2, file2);
// try to update the container to version 1.1.0
Results results = kc.updateToVersion(releaseId2);
assertFalse("Errors detected on updateToVersion: " + results.getMessages(org.kie.api.builder.Message.Level.ERROR), results.hasMessages(org.kie.api.builder.Message.Level.ERROR));
// continue working with the session
ksession.insert(new FooEvent(1));
assertEquals(2, ksession.fireAllRules());
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method testPropertyReactivityOfAKnownClass.
@Test
public void testPropertyReactivityOfAKnownClass() {
String drl1 = "import " + TypeA.class.getCanonicalName() + "\n" + "import " + TypeB.class.getCanonicalName() + "\n" + "rule \"RULE_1\"\n" + " when\n" + " TypeA()" + " TypeB()" + " then\n" + "end\n";
String drl2 = "import " + TypeB.class.getCanonicalName() + "\n" + "rule \"RULE_2\"\n" + " when\n" + " $b : TypeB() @watch(!*)" + " then\n" + " modify($b) { setValue(0) } \n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, drl1);
KieContainer kc = ks.newKieContainer(releaseId1);
KieSession ksession = kc.newKieSession();
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
createAndDeployJar(ks, releaseId2, drl2);
kc.updateToVersion(releaseId2);
ksession.insert(new TypeB(1));
int fired = ksession.fireAllRules(10);
assertEquals(1, fired);
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method testMultipleIncrementalCompilationWithExistentialRules.
@Test
public void testMultipleIncrementalCompilationWithExistentialRules() {
// DROOLS-988
List<String> drls = new ArrayList<String>();
drls.add(getExistenzialRule("R0", "> 10"));
// Create a session with the above rule
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId, drls.toArray(new String[drls.size()]));
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
AtomicInteger counter = new AtomicInteger(0);
ksession.setGlobal("counter", counter);
ksession.insert(3);
ksession.fireAllRules();
assertEquals(0, counter.get());
for (int i = 1; i < 11; i++) {
ReleaseId newReleaseId = ks.newReleaseId("org.kie", "test-upgrade", "1.1." + i);
drls.add(getExistenzialRule("R" + i, "< 10"));
km = createAndDeployJar(ks, newReleaseId, drls.toArray(new String[drls.size()]));
kc.updateToVersion(newReleaseId);
ksession.fireAllRules();
assertEquals(i, counter.get());
}
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method testKJarUpgradeWithDSL.
@Test
public void testKJarUpgradeWithDSL() throws Exception {
// DROOLS-718
String dsl = "[when][]There is a Message=Message()\n" + "[when][]-with message \"{factId}\"=message==\"{factId}\"\n" + "\n" + "[then][]Print \"{message}\"=System.out.println(\"{message}\");\n";
String drl2_1 = "package org.drools.compiler\n" + "rule \"bla\"\n" + "when\n" + "\tThere is a Message\t \n" + "\t-with message \"Hi Universe\"\n" + "then\n" + "\tPrint \"Found a Message Hi Universe.\"\n" + "end\n";
String drl2_2 = "package org.drools.compiler\n" + "rule \"bla\"\n" + "when\n" + "\tThere is a Message\t \n" + "\t-with message \"Hello World\"\n" + "then\n" + "\tPrint \"Found a Message Hello World.\"\n" + "end\n";
KieServices ks = KieServices.Factory.get();
// Create an in-memory jar for version 1.0.0
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJarWithDSL(ks, releaseId1, dsl, drl2_1);
// Create a session and fire rules
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(0, ksession.fireAllRules());
ksession.dispose();
// Create a new jar for version 1.1.0
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
km = createAndDeployJarWithDSL(ks, releaseId2, dsl, drl2_2);
// try to update the container to version 1.1.0
kc.updateToVersion(releaseId2);
// create and use a new session
ksession = kc.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
}
use of org.kie.api.builder.KieModule in project drools by kiegroup.
the class IncrementalCompilationTest method testSegmentSplitOnIncrementalCompilation.
@Test
public void testSegmentSplitOnIncrementalCompilation() throws Exception {
// DROOLS-930
String drl = "import " + Person.class.getCanonicalName() + "\n" + "global java.util.List list\n" + "rule R1 when\n" + " $s : String()" + " Person( name == $s ) \n" + "then\n" + " list.add(\"R1\");\n" + "end\n" + "rule R2 when\n" + " $s : String()" + " Person( name == $s ) \n" + "then\n" + " list.add(\"R2\");\n" + "end\n" + "rule R3 when\n" + " $s : String()" + " Person( name != $s ) \n" + "then\n" + " list.add(\"R3\");\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.1");
KieModule km = createAndDeployJar(ks, releaseId1);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
kc.updateToVersion(releaseId1);
ksession.insert(new Person("John", 26));
ksession.insert("John");
ksession.fireAllRules();
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
km = createAndDeployJar(ks, releaseId2, drl);
kc.updateToVersion(releaseId2);
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(2, list.size());
assertTrue(list.containsAll(asList("R1", "R2")));
}
Aggregations