I am using Drool Fusion to execute windowing rules. The following is my Test class:
public class Test {
int count;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public Test(int count) {
this.count = count;
}
}
When i am trying to execute the following rule i am getting unexpected result:
declare Test
@role(event)
@timestamp(time)
@expires(10m)
end
rule "Sliding window test1"
agenda-group "g0"
when
$number: Number() from accumulate(Test($t:count <10) over window:time(10s) , average($t))
then
System.out.println("Test Rule 1 " + $number );
end
rule "Sliding window test2"
agenda-group "g0"
when
$number: Number() from accumulate(Test($t:count >10 ) over window:time(10s) , average($t))
then
System.out.println("Test Rule 2 " + $number );
end
Response : After the end of window rule i.e
10 seconds
both the rules is getting fired.
My Implementer is :
public static void main(String[] args) throws InterruptedException {
KieServices kieServices = KieServices.Factory.get();
KieContainer kieContainer = kieServices.getKieClasspathContainer();
KieSession kieSession = kieContainer.newKieSession("window-session");
SessionPseudoClock clock = kieSession.getSessionClock();
long curr = System.currentTimeMillis();
while(true) {
long time = System.currentTimeMillis();
for(int i=0;i<20;i++) {
Test test = new Test(i);
kieSession.insert(test);
kieSession.getAgenda().getAgendaGroup("g0").setFocus();
clock.advanceTime(time - clock.getCurrentTime(), TimeUnit.MILLISECONDS);
kieSession.fireAllRules();
System.out.println(System.currentTimeMillis() - curr);
Thread.sleep(10); //historical event test
}
}
}
I am getting unexpected output i.e after 10 seconds both the rules is firing after 1 second it is repeating the same. This behaviour is only happening when i am using Pseudo clock
.
Kindly Help