Hi, everyone,
I just find that, insert an event into a entry point or insert it directly into session will cause different behaviour, is this expected?
Here is the details:
1. drools run in stream mode and use pseudo clock
2. insert a MyEvent into entry-point "stream" and a MyEvent into session directly every 1 seconds, start at 500ms.
3. call fireAllRules every 1seconds, at second 1, second 2, etc
4. drools version 5.5.0.Final
Below is the rule:
package me.ycy.drools.test1.data
import java.util.List
declare MyEvent
@role(event)
@timestamp(timestamp)
end
rule "over 0.3s"
when
$list: List() from collect(MyEvent() over window:time(300ms))
then
System.out.println("Rule: with in 0.3s --> " + $list);
end
rule "over 1s"
when
$list: List() from collect(MyEvent() over window:time(1s))
then
System.out.println("Rule: with in 1s --> " + $list);
end
rule "over 3s"
when
$list: List() from collect(MyEvent() over window:time(3s))
then
System.out.println("Rule: with in 3s --> " + $list);
end
rule "over 0.3s ep"
when
$list: List() from collect(MyEvent() over window:time(300ms) from entry-point "stream")
then
System.out.println("Rule: with in 0.3s use ep --> " + $list);
end
rule "over 1s ep"
when
$list: List() from collect(MyEvent() over window:time(1s) from entry-point "stream")
then
System.out.println("Rule: with in 1s use ep --> " + $list);
end
rule "over 3s ep"
when
$list: List() from collect(MyEvent() over window:time(3s) from entry-point "stream")
then
System.out.println("Rule: with in 3s use ep --> " + $list);
end
// ------- end of rule
Finally, the output(just run 5 seconds)
-------------- fire at 1000 ---------------
Rule: with in 3s use ep --> [MyEvent(event 0,500)]
Rule: with in 1s use ep --> [MyEvent(event 0,500)]
Rule: with in 0.3s use ep --> [MyEvent(event 0,500)]
Rule: with in 3s --> [MyEvent(event 0,500)]
Rule: with in 1s --> [MyEvent(event 0,500)]
Rule: with in 0.3s --> []
-------------- fire at 2000 ---------------
Rule: with in 3s use ep --> [MyEvent(event 0,500), MyEvent(event 1,1500)]
Rule: with in 1s use ep --> [MyEvent(event 0,500), MyEvent(event 1,1500)]
Rule: with in 0.3s use ep --> [MyEvent(event 0,500), MyEvent(event 1,1500)]
Rule: with in 3s --> [MyEvent(event 0,500), MyEvent(event 1,1500)]
Rule: with in 1s --> [MyEvent(event 1,1500)]
Rule: with in 0.3s --> []
-------------- fire at 3000 ---------------
Rule: with in 3s use ep --> [MyEvent(event 0,500), MyEvent(event 1,1500), MyEvent(event 2,2500)]
Rule: with in 1s use ep --> [MyEvent(event 0,500), MyEvent(event 1,1500), MyEvent(event 2,2500)]
Rule: with in 0.3s use ep --> [MyEvent(event 0,500), MyEvent(event 1,1500), MyEvent(event 2,2500)]
Rule: with in 3s --> [MyEvent(event 0,500), MyEvent(event 1,1500), MyEvent(event 2,2500)]
Rule: with in 1s --> [MyEvent(event 2,2500)]
Rule: with in 0.3s --> []
-------------- fire at 4000 ---------------
Rule: with in 3s use ep --> [MyEvent(event 1,1500), MyEvent(event 2,2500), MyEvent(event 3,3500)]
Rule: with in 1s use ep --> [MyEvent(event 1,1500), MyEvent(event 2,2500), MyEvent(event 3,3500)]
Rule: with in 0.3s use ep --> [MyEvent(event 1,1500), MyEvent(event 2,2500), MyEvent(event 3,3500)]
Rule: with in 3s --> [MyEvent(event 1,1500), MyEvent(event 2,2500), MyEvent(event 3,3500)]
Rule: with in 1s --> [MyEvent(event 3,3500)]
Rule: with in 0.3s --> []
-------------- fire at 5000 ---------------
Rule: with in 3s use ep --> [MyEvent(event 2,2500), MyEvent(event 3,3500), MyEvent(event 4,4500)]
Rule: with in 1s use ep --> [MyEvent(event 2,2500), MyEvent(event 3,3500), MyEvent(event 4,4500)]
Rule: with in 0.3s use ep --> [MyEvent(event 2,2500), MyEvent(event 3,3500), MyEvent(event 4,4500)]
Rule: with in 3s --> [MyEvent(event 2,2500), MyEvent(event 3,3500), MyEvent(event 4,4500)]
Rule: with in 1s --> [MyEvent(event 4,4500)]
Rule: with in 0.3s --> []
--
Best regards,
Changyuan