[
https://issues.jboss.org/browse/DROOLS-953?page=com.atlassian.jira.plugin...
]
Mario Fusco commented on DROOLS-953:
------------------------------------
Reproduced with the following test case:
{code}
@Test(timeout=10000)
public void testSerializationWithWindowLength() throws Exception {
// DROOLS-953
String drl =
"import " + StockTick.class.getCanonicalName() + "\n"
+
"declare StockTick\n" +
" @role( event )\n" +
"end\n" +
"\n" +
"rule ReportLastEvent when\n" +
" $e : StockTick() over window:length(1)\n" +
"then\n" +
" System.out.println(\"Reporting Last Event: \" +
$e);\n" +
"end\n" +
"\n" +
"rule ReportEventInserted when\n" +
" $e : StockTick()\n" +
"then\n" +
" System.out.println(\"Event Insert : \" + $e);\n"
+
"end";
KieSessionConfiguration sessionConfig =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sessionConfig.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) );
KieHelper helper = new KieHelper();
helper.addContent( drl, ResourceType.DRL );
KieBase kbase = helper.build( EventProcessingOption.STREAM );
KieSession ksession = kbase.newKieSession( sessionConfig, null );
PseudoClockScheduler clock = ksession.getSessionClock();
ksession.insert( new StockTick( 1, "ACME", 50 ) );
ksession.insert( new StockTick( 2, "DROO", 50 ) );
ksession.insert( new StockTick( 3, "JBPM", 50 ) );
ksession.fireAllRules();
try {
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(
ksession, true, false );
} catch ( Exception e ) {
e.printStackTrace();
fail( e.getMessage() );
}
ksession.fireAllRules();
}
{code}
Rules from declare window refire after deserialization
------------------------------------------------------
Key: DROOLS-953
URL:
https://issues.jboss.org/browse/DROOLS-953
Project: Drools
Issue Type: Bug
Components: core engine
Affects Versions: 6.3.0.Final
Environment: java se 8
Reporter: Kevin Prendergast
Assignee: Mario Fusco
Priority: Minor
Attachments: WindowDemo.zip
Rules using 'from window length' refire incorrectly after session
deserialization.
Full story on usage forum.
https://groups.google.com/forum/#!topic/drools-usage/kTHTVXZznxw
In summary...
Insert facts Event#1, Event#2, Event#3 into a stateful, psuedo clock stream session
with...
declare window lastEvent
Event() over window:length(1)
end
rule "Reporting Last Event 1001"
when
$e : Event($eventCode : eventCode == "1001") from window lastEvent
then
log.info("Reporting Last Event 1001 : " + $e);
end
The rule "Reporting Last Event" will refire after deserialization from disk for
Events #1+#2
Demonstrated with the attached reproducer window-demo. Run the JUnit test to get this
console output...
INFO 17:25:40 [org.kev.KnowledgeSession] creating kcontainer
INFO 17:25:40 [org.drools.compiler.kie.builder.impl.ClasspathKieProject] Found kmodule:
file:/C:/Users/Kevin/workspace_luna/window-demo/target/classes/META-INF/kmodule.xml
INFO 17:25:40 [org.drools.compiler.kie.builder.impl.KieRepositoryImpl] KieModule was
added:
FileKieModule[releaseId=org.kev:window-demo:0.0.1-SNAPSHOT,file=C:\Users\Kevin\workspace_luna\window-demo\target\classes]
INFO 17:25:42 [org.kev.KnowledgeSession] no messages from kContainer
INFO 17:25:42 [org.kev.KnowledgeSession] KieSession sessionDefault is OK
{color:#59afe1}INSERTING Event OBJECTS CAUSES RULES TO FIRE NICELY{color}....
INFO 17:25:42 [org.kev.KnowledgeSession] Reporting Last Event 1001 : Event
[eventCode=1001, recordedTime=13-10-15 17:25:39.904]
INFO 17:25:42 [org.kev.KnowledgeSession] Event Insert : Event [eventCode=1001,
recordedTime=13-10-15 17:25:39.904]
INFO 17:25:42 [org.kev.KnowledgeSession] Rules Fired : 2
INFO 17:25:42 [org.kev.KnowledgeSession] Reporting Last Event 1001 : Event
[eventCode=1001, recordedTime=13-10-15 17:25:40.904]
INFO 17:25:42 [org.kev.KnowledgeSession] Event Insert : Event [eventCode=1001,
recordedTime=13-10-15 17:25:40.904]
INFO 17:25:42 [org.kev.KnowledgeSession] Rules Fired : 2
INFO 17:25:42 [org.kev.KnowledgeSession] Reporting Last Event 1001 : Event
[eventCode=1001, recordedTime=13-10-15 17:25:41.904]
INFO 17:25:42 [org.kev.KnowledgeSession] Event Insert : Event [eventCode=1001,
recordedTime=13-10-15 17:25:41.904]
INFO 17:25:42 [org.kev.KnowledgeSession] Rules Fired : 2
INFO 17:25:42 [org.kev.ReplayTests] Fire All Rules Before Save............
{color:#59afe1}NO MESSAGES HERE. SHOWS NO OUTSTANDING RULES TO FIRE IN SESSION.{color}
INFO 17:25:42 [org.kev.ReplayTests] Saving Session............ {color:#59afe1}NOW WE
SAVE TO DISK{color}
INFO 17:25:42 [org.kev.KnowledgeSession] Marshalling ksession to disk :
C:\Users\Kevin\workspace_luna\window-demo\demo.ks
INFO 17:25:43 [org.kev.ReplayTests] Restoring Session............ {color:#59afe1}AND
HERE'S THE RESTORE OF A NEW SESSION FROM DISK{color}
INFO 17:25:43 [org.kev.KnowledgeSession] no messages from kContainer
INFO 17:25:43 [org.kev.KnowledgeSession] KieSession sessionDefault is OK
INFO 17:25:43 [org.kev.KnowledgeSession] Marshall ksession from disk :
C:\Users\Kevin\workspace_luna\window-demo\demo.ks
INFO 17:25:43 [org.kev.KnowledgeSession] pseudoClock is recovered to :13-10-15
17:25:41.904 ...{color:#59afe1}ALL GOOD SO FAR, BUT NOW I FIRE ALL RULES{color}
INFO 17:25:43 [org.kev.ReplayTests] Fire All Rules After Restore
(1)............{color:#d04437}THESE NEXT MESSAGES ARE UNEXPECTED. IT'S THE FIRST 2
EVENTS THAT I'D ORIGINALLY INSERTED. But, nothing has been inserted since the
restore.{color}
INFO 17:25:43 [org.kev.KnowledgeSession] Reporting Last Event 1001 : Event
[eventCode=1001, recordedTime=13-10-15 17:25:39.904]
INFO 17:25:43 [org.kev.KnowledgeSession] Reporting Last Event 1001 : Event
[eventCode=1001, recordedTime=13-10-15 17:25:40.904]
INFO 17:25:43 [org.kev.ReplayTests] Fire All Rules After Restore
(2)............{color:#59afe1}ANOTHER FIRE ALL RULES AND NORMAL BEHAVIOUR RETURNS{color}
Consequence is that RHS fires unexpectedly for facts that have already been handled
before serialization.
KP
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)