use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testNotAfter.
@Test
public void testNotAfter() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + " $a : StockTick( company == \"DROO\" )\n" + " not( StockTick( 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 StockTick("DROO"));
clock.advanceTime(6, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
clock.advanceTime(10, TimeUnit.SECONDS);
assertEquals(0, ksession.fireAllRules());
ksession.insert(new StockTick("DROO"));
clock.advanceTime(3, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
clock.advanceTime(10, TimeUnit.SECONDS);
assertEquals(1, ksession.fireAllRules());
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testExpireEventOnEndTimestampWithDeclaredEvent.
@Test
public void testExpireEventOnEndTimestampWithDeclaredEvent() throws Exception {
String str = "package org.drools.compiler;\n" + "import " + StockFact.class.getCanonicalName() + ";\n" + "global java.util.List resultsAfter;\n" + "\n" + "declare StockFact\n" + " @role( event )\n" + " @duration( duration )\n" + "end\n" + "\n" + "rule \"after[60,80]\"\n" + "when\n" + "$a : StockFact( company == \"DROO\" )\n" + "$b : StockFact( company == \"ACME\", this after[60,80] $a )\n" + "then\n" + " resultsAfter.add( $b );\n" + "end";
KieSession ksession = getKieSession(getCepKieModuleModel(), str);
SessionPseudoClock clock = ksession.getSessionClock();
List<StockTick> resultsAfter = new ArrayList<StockTick>();
ksession.setGlobal("resultsAfter", resultsAfter);
// inserting new StockTick with duration 30 at time 0 => rule
// after[60,80] should fire when ACME lasts at 100-120
ksession.insert(new StockFact("DROO", 30));
clock.advanceTime(100, TimeUnit.MILLISECONDS);
ksession.insert(new StockFact("ACME", 20));
ksession.fireAllRules();
assertEquals(1, resultsAfter.size());
}
use of org.drools.modelcompiler.domain.StockTick 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());
}
use of org.drools.modelcompiler.domain.StockTick 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.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class AccumulateTest method testAccumulateWithMaxCalendarAndConstraint.
@Test
public void testAccumulateWithMaxCalendarAndConstraint() {
String str = "import " + Customer.class.getCanonicalName() + ";\n" + "import " + StockTick.class.getCanonicalName() + ";\n" + "rule AccumulateMaxDate\n" + " dialect \"java\"\n" + " when\n" + " $customer : Customer( code == \"RHT\" )\n" + " $max1 : Number() from accumulate(\n" + " StockTick( company == $customer.code\n" + " , $time : dueDate);\n" + " max($time.getTime().getTime()))\n" + "then\n" + "end\n";
KieSession ksession = getKieSession(str);
StockTick st = new StockTick("RHT");
st.setDueDate(Calendar.getInstance());
Customer c = new Customer();
c.setCode("RHT");
ksession.insert(st);
ksession.insert(c);
Assertions.assertThat(ksession.fireAllRules()).isEqualTo(1);
}
Aggregations