use of org.kie.api.time.SessionPseudoClock in project drools by kiegroup.
the class CepTest method testSlidingWindow.
@Test
public void testSlidingWindow() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "rule R when\n" + " $a : StockTick( company == \"DROO\" ) over window:length( 2 )\n" + "then\n" + " System.out.println(\"fired\");\n" + "end\n";
KieSession ksession = getKieSession(getCepKieModuleModel(), str);
SessionPseudoClock clock = ksession.getSessionClock();
clock.advanceTime(1, TimeUnit.SECONDS);
ksession.insert(new StockTick("DROO"));
clock.advanceTime(1, TimeUnit.SECONDS);
ksession.insert(new StockTick("DROO"));
clock.advanceTime(1, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
clock.advanceTime(1, TimeUnit.SECONDS);
ksession.insert(new StockTick("DROO"));
assertEquals(2, ksession.fireAllRules());
}
use of org.kie.api.time.SessionPseudoClock in project drools by kiegroup.
the class CepTest method testWithDeclaredEvent.
@Test
public void testWithDeclaredEvent() throws Exception {
String str = "import " + StockFact.class.getCanonicalName() + ";\n" + "declare StockFact @role( event ) end;\n" + "rule R when\n" + " $a : StockFact( company == \"DROO\" )\n" + " $b : StockFact( company == \"ACME\", this after[5s,8s] $a )\n" + "then\n" + " System.out.println(\"fired\");\n" + "end\n";
KieSession ksession = getKieSession(getCepKieModuleModel(), str);
SessionPseudoClock clock = ksession.getSessionClock();
ksession.insert(new StockFact("DROO"));
clock.advanceTime(6, TimeUnit.SECONDS);
ksession.insert(new StockFact("ACME"));
assertEquals(1, ksession.fireAllRules());
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.insert(new StockFact("ACME"));
assertEquals(0, ksession.fireAllRules());
}
use of org.kie.api.time.SessionPseudoClock in project drools by kiegroup.
the class CepTest method testDeclaredSlidingWindowWith2Arguments.
@Test
public void testDeclaredSlidingWindowWith2Arguments() throws Exception {
String str = "declare String\n" + " @role( event )\n" + "end\n" + "declare window DeclaredWindow\n" + " String( length == 4, this.startsWith(\"D\") ) over window:time( 5s )\n" + "end\n" + "rule R when\n" + " $a : String() from window DeclaredWindow\n" + "then\n" + " System.out.println($a);\n" + "end\n";
KieSession ksession = getKieSession(getCepKieModuleModel(), str);
SessionPseudoClock clock = ksession.getSessionClock();
ksession.insert("ACME");
ksession.insert("DROO");
assertEquals(1, ksession.fireAllRules());
}
use of org.kie.api.time.SessionPseudoClock in project drools by kiegroup.
the class CepTest method testDeclaredSlidingWindow.
@Test
public void testDeclaredSlidingWindow() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "declare window DeclaredWindow\n" + " StockTick( company == \"DROO\" ) over window:time( 5s )\n" + "end\n" + "rule R when\n" + " $a : StockTick() from window DeclaredWindow\n" + "then\n" + " System.out.println($a.getCompany());\n" + "end\n";
KieSession ksession = getKieSession(getCepKieModuleModel(), str);
SessionPseudoClock clock = ksession.getSessionClock();
clock.advanceTime(2, TimeUnit.SECONDS);
ksession.insert(new StockTick("DROO"));
clock.advanceTime(2, TimeUnit.SECONDS);
ksession.insert(new StockTick("DROO"));
clock.advanceTime(2, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
clock.advanceTime(2, TimeUnit.SECONDS);
ksession.insert(new StockTick("DROO"));
assertEquals(2, ksession.fireAllRules());
}
Aggregations