KieScanner behavior for already existing KieBases and KieSessions

120 views
Skip to first unread message

Matteo Mortari

unread,
Nov 26, 2015, 1:34:52 PM11/26/15
to Drools Usage
Ciao, I think I've noticed behavior change in KieScanner automatic-update since 6.1 -> 6.2 etc. and I would like to expose my current question below, please.

Documentation[1] states:
If the KieScanner finds, in the Maven repository, an updated version of the Kie project used by that KieContainer it automatically downloads the new version and triggers an incremental build of the new project. From this moment all the new KieBases and KieSessions created from that KieContainer will use the new project version.

I think that current* behavior "From this moment on" actually is:
  1. already existing KieBase, generated with getKieBase() : it does get automatically updated. This is the use case of named KieBase or default KieBase referenced from kmodule.xml 
  2. already existing KieBase, generated with newKieBase() : NOT automatically updated. This is the use case of KieBase created with "custom" KieBaseConfiguration settings and NOT referencing kmodule.xml
  3. any KieBase generated after the KieScanner updated, with either getKieBase() or newKieBase() : directly the newer version, simple case, indeed as already mentioned in the documentation.
Behavior for already existing KieSession depends on the underlying KieBase, so it make reference to the cases described here-above. 
To be fully explicit, when already existing KieSession was generated directly from KieContainer.newKieSession() is case #1 because it implies the default KieBase from kmodule.xml.

My question is:
  • IF my statements are correct, which I checked earlier by JUnit test method below [2]: I think I will submit a PR with proposals for documentation clarifications: I think statement is missing to describe what happens to already existing KieSession and KieBase; from the current description I would have assumed only "new" stuff gets up-to-date, but (fortunately!) also some type of already-existing KieSession and KieBase gets automatically updated.
  • ELSE I'm wrong, meaning also case #2 should be automatically updated: I think I will submit via PR the JUnit test method below [2] with different assert values, because then case #2 we think actually demonstrate a bug.
Can you tell me if it's one or the other, please? =)

Thank you in advance for your feedback
Ciao
MM



* (tested against master @ 6fcacdf, version 6.4.0-SNAPSHOT)
@Test
public void testKJarUpgradeKieScannerDocumentationBehavior() throws Exception {
 
String drl1 = "package org.drools.compiler\n" +
             
"rule R1 when\n" +
             
"   $m : Message()\n" +
             
"then\n" +
             
"end\n";


     
String drl2_1 = "package org.drools.compiler\n" +
             
"rule R2_1 when\n" +
             
"   $m : Message( message == \"Hi Universe\" )\n" +
             
"then\n" +
             
"end\n";


     
String drl2_2 = "package org.drools.compiler\n" +
             
"rule R2_2 when\n" +
             
"   $m : Message( message == \"Hello World\" )\n" +
             
"then\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 = createAndDeployJar( ks, releaseId1, drl1, drl2_1 );


     
// Create a session and fire rules
     
KieContainer kc = ks.newKieContainer( km.getReleaseId() );
     
KieSession ksession = kc.newKieSession();
     
     org
.kie.api.KieBase kBaseGET = kc.getKieBase();
     
KieSession ksession_kBaseGET = kBaseGET.newKieSession();
     
     org
.kie.api.KieBaseConfiguration kConfig = ks.newKieBaseConfiguration();
     kConfig
.setOption(EventProcessingOption.STREAM);
     org
.kie.api.KieBase kBaseCREATENEW = kc.newKieBase(kConfig);
     
KieSession ksession_kBaseCREATENEW = kBaseCREATENEW.newKieSession();
     
     ksession
.insert( new Message( "Hello World" ) );
     assertEquals
( 1, ksession.fireAllRules() );
     
     ksession_kBaseGET
.insert( new Message( "Hello World" ) );
     assertEquals
( 1, ksession_kBaseGET.fireAllRules() );
     
     ksession_kBaseCREATENEW
.insert( new Message( "Hello World" ) );
     assertEquals
( 1, ksession_kBaseCREATENEW.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, drl1, drl2_2 );


     
// try to update the container to version 1.1.0
     kc
.updateToVersion( releaseId2 );


     
// continue working with the session
     ksession
.insert( new Message( "Hello World" ) );
     assertEquals
( 3, ksession.fireAllRules() );
     
     ksession_kBaseGET
.insert( new Message( "Hello World" ) );
     assertEquals
( 3, ksession_kBaseGET.fireAllRules() ); // This session use a KieBase generated with .getKieBase(), meaning default KieBase declared in kmodule.xml, automatic update OK. It is just an explicit case of the above.
     
     ksession_kBaseCREATENEW
.insert( new Message( "Hello World" ) );
     assertEquals
( 1, ksession_kBaseCREATENEW.fireAllRules() ); // expected: 1, NOT 3. This session use a KieBase generated with .newKieBase() from "custom" KieBaseConfiguration hence NOT automatically upgraded.
     
     
// generate and use a new session
     org
.kie.api.KieBase kBaseCREATENEW_afterUpgrade = kc.newKieBase(kConfig);
     
KieSession ksession_kBaseCREATENEW_afterUpgrade = kBaseCREATENEW_afterUpgrade.newKieSession();
     ksession_kBaseCREATENEW_afterUpgrade
.insert( new Message( "Hello World" ) );
     assertEquals
( 2, ksession_kBaseCREATENEW_afterUpgrade.fireAllRules() ); // expected: 2 (two). This session was created AFTER KieScanner upgrade, even if it's from "custom" KieBaseConfiguration is simply already up to date
}




Mario Fusco

unread,
Dec 1, 2015, 11:45:13 AM12/1/15
to Drools Usage
Hi Matteo,

and sorry for the delay in my reply.

Yes, what you described is correct. KieBases obtained with getKieBase() are under the control of the KieContainer and are updated together with it, while the ones created with newKieBase() are out of its control.

Feel free to send a PR to clarify our documentation.

Thanks a lot,
Mario

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/62af9722-8f1c-4630-87b2-1bd0e71a3586%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matteo Mortari

unread,
Dec 2, 2015, 4:34:18 PM12/2/15
to Drools Usage
Ciao Mario, no probs and thanks for the feedback. I've opened proposal for documentation clarification -> PR https://github.com/droolsjbpm/kie-docs/pull/21

Thanks again,
Ciao
MM
Reply all
Reply to author
Forward
0 new messages