use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class IncrementalCompilationTest method testKeepBuilderConfAfterIncrementalUpdate.
@Test
public void testKeepBuilderConfAfterIncrementalUpdate() throws Exception {
// DROOLS-1282
String drl1 = "import " + DummyEvent.class.getCanonicalName() + "\n" + "rule R1 when\n" + " DummyEvent() @watch(id)\n" + "then end\n";
String drl2 = "import " + DummyEvent.class.getCanonicalName() + "\n" + "rule R1 when\n" + " DummyEvent() @watch(*)\n" + "then end\n";
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel().setConfigurationProperty(PropertySpecificOption.PROPERTY_NAME, PropertySpecificOption.ALWAYS.toString());
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-property-reactive-upgrade", "1");
KieModule km = deployJar(ks, createKJar(ks, kproj, releaseId1, null, drl1));
KieContainer container = ks.newKieContainer(releaseId1);
container.newKieSession();
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-property-reactive-upgrade", "2");
km = deployJar(ks, createKJar(ks, kproj, releaseId2, null, drl2));
Results results = container.updateToVersion(releaseId2);
assertEquals(0, results.getMessages().size());
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class IncrementalCompilationTest method testUpdateVersionWithKSessionLogger.
@Test
public void testUpdateVersionWithKSessionLogger() {
// DROOLS-790
String drl1 = "import java.util.List\n" + "import java.util.ArrayList\n" + "\n" + "rule \"Test1\"\n" + "\n" + "when\n" + " $a : Integer()\n" + "then\n" + " insert(new ArrayList());\n" + "end\n";
String drl2 = "rule \"Test2\"\n" + "when\n" + " $b : List()\n" + " then\n" + " $b.isEmpty();\n" + "end";
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(km.getReleaseId());
StatelessKieSession statelessKieSession = kc.newStatelessKieSession();
KieRuntimeLogger kieRuntimeLogger = ks.getLoggers().newConsoleLogger(statelessKieSession);
List<Command> cmds = new ArrayList<Command>();
cmds.add(CommandFactory.newInsertElements(new ArrayList()));
FireAllRulesCommand fireAllRulesCommand = (FireAllRulesCommand) CommandFactory.newFireAllRules();
cmds.add(fireAllRulesCommand);
cmds.add(CommandFactory.newGetObjects("returnedObjects"));
BatchExecutionCommand batchExecutionCommand = CommandFactory.newBatchExecution(cmds);
statelessKieSession.execute(batchExecutionCommand);
kieRuntimeLogger.close();
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
km = createAndDeployJar(ks, releaseId2, drl1 + drl2);
kc.updateToVersion(km.getReleaseId());
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class IncrementalCompilationTest method testAddFieldToDeclaredType.
@Test
public void testAddFieldToDeclaredType() throws Exception {
// DROOLS-2197
String declares1 = "declare Address\n" + " streetName : String\n" + " city : String\n" + "end";
String declares2 = "declare Address\n" + " streetName : String\n" + " city : String\n" + " flg: String\n" + "end";
String rules1 = "rule R when\n" + " a : Address( city == \"Antibes\" )\n" + "then\n" + " a.setStreetName(\"Av. Jean Medecin\");\n" + "end";
String rules2 = "rule R when\n" + " a : Address( city == \" Paris \", flg == \"yes\" )\n" + "then\n" + " a.setStreetName(\" Champs Elisees \");\n" + "end";
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");
createAndDeployJar(ks, releaseId1, declares1, rules1);
KieContainer kieContainer = ks.newKieContainer(releaseId1);
KieSession kieSession = kieContainer.newKieSession();
assertEquals(0, kieSession.fireAllRules());
createAndDeployJar(ks, releaseId2, declares2, rules2);
kieContainer.updateToVersion(releaseId2);
assertEquals(0, kieSession.fireAllRules());
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class IncrementalCompilationTest method testSplitAfterQuery.
@Test
public void testSplitAfterQuery() throws Exception {
String drl1 = "global java.util.List list; " + "query foo( Integer $i ) " + " $i := Integer( this < 10 ) " + "end\n" + "\n" + "rule r2 when " + " foo( $i; ) " + " Integer( this == 20 ) " + "then " + " System.out.println(\"20 \" + $i);" + " list.add( 20 + $i );\n" + "end\n" + "rule r3 when " + " $i : Integer( this == 1 ) " + "then " + " System.out.println($i);" + " update( kcontext.getKieRuntime().getFactHandle( $i ), $i + 1 );" + "end\n" + "\n";
String drl2 = "global java.util.List list; " + "query foo( Integer $i ) " + " $i := Integer( this < 10 ) " + "end\n" + "\n" + "rule r1 when " + " foo( $i ; ) " + " Integer( this == 10 ) " + "then " + " System.out.println(\"10 \" + $i);" + " list.add( 10 + $i );\n" + "end\n" + "rule r2 when " + " foo( $i; ) " + " Integer( this == 20 ) " + "then " + " System.out.println(\"20 \" + $i);" + " list.add( 20 + $i );\n" + "end\n" + "rule r3 when " + " $i : Integer( this == 1 ) " + "then " + " System.out.println($i);" + " update( kcontext.getKieRuntime().getFactHandle( $i ), $i + 1 );" + "end\n" + "\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.1");
KieModule km = createAndDeployJar(ks, releaseId1, drl1);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
List<Integer> list = new ArrayList<Integer>();
ksession.setGlobal("list", list);
ksession.insert(1);
ksession.insert(20);
ksession.fireAllRules();
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
km = createAndDeployJar(ks, releaseId2, drl2);
kc.updateToVersion(releaseId2);
ksession.fireAllRules();
assertEquals(2, list.size());
assertEquals(21, (int) list.get(0));
assertEquals(22, (int) list.get(1));
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class IncrementalCompilationTest method testRetractLogicalAssertedObjectOnRuleRemoval.
@Test
public void testRetractLogicalAssertedObjectOnRuleRemoval() throws Exception {
// DROOLS-951
String drl1 = "rule R1 when\n" + " exists( Integer() )\n" + "then\n" + " insertLogical( \"found1\" );" + "end\n";
String drl2 = "package org.drools.compiler\n" + "rule R2 when\n" + " exists( Integer() )\n" + "then\n" + " insertLogical( \"found2\" );" + "end\n";
String drl3 = "package org.drools.compiler\n" + "rule R3 when\n" + " exists( Integer() )\n" + "then\n" + " insertLogical( \"found3\");" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.1");
KieModule km = createAndDeployJar(ks, releaseId1, drl1, drl2, drl3);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
ksession.insert(4);
ksession.fireAllRules();
assertEquals(3, ksession.getObjects(new ClassObjectFilter(String.class)).size());
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
km = createAndDeployJar(ks, releaseId2, drl1, drl2);
kc.updateToVersion(releaseId2);
ksession.fireAllRules();
assertEquals(2, ksession.getObjects(new ClassObjectFilter(String.class)).size());
ReleaseId releaseId3 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.3");
km = createAndDeployJar(ks, releaseId3, drl1);
kc.updateToVersion(releaseId3);
ksession.fireAllRules();
assertEquals(1, ksession.getObjects(new ClassObjectFilter(String.class)).size());
ReleaseId releaseId4 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.4");
km = createAndDeployJar(ks, releaseId4);
kc.updateToVersion(releaseId4);
ksession.fireAllRules();
assertEquals(0, ksession.getObjects(new ClassObjectFilter(String.class)).size());
}
Aggregations