use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class ExternalisedLambdaTest method testCep.
@Test
public void testCep() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + " $a : StockTick( company == \"DROO\" )\n" + " $b : StockTick( company == \"ACME\", timeFieldAsLong after[5,8] $a.timeFieldAsLong )\n" + "then\n" + " System.out.println(\"fired\");\n" + "end\n";
KieModuleModel kmodel = KieServices.get().newKieModuleModel();
kmodel.newKieBaseModel("kb").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM).newKieSessionModel("ks").setDefault(true).setClockType(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
KieSession ksession = null;
try {
ksession = getKieSession(kmodel, str);
} catch (NonExternalisedLambdaFoundException e) {
fail(e.getMessage());
}
SessionPseudoClock clock = ksession.getSessionClock();
ksession.insert(new StockTick("DROO").setTimeField(0));
ksession.insert(new StockTick("ACME").setTimeField(6));
assertEquals(1, ksession.fireAllRules());
ksession.insert(new StockTick("ACME").setTimeField(10));
assertEquals(0, ksession.fireAllRules());
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testNegatedAfter.
@Test
public void testNegatedAfter() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + " $a : StockTick( company == \"DROO\" )\n" + " $b : StockTick( company == \"ACME\", this not 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"));
assertEquals(0, ksession.fireAllRules());
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
assertEquals(1, ksession.fireAllRules());
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testBeforeOnLongFields.
@Test
public void testBeforeOnLongFields() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "declare StockTick @timestamp(timeFieldAsLong) end\n" + "rule R when\n" + " $a : StockTick( company == \"DROO\" )\n" + " $b : StockTick( company == \"ACME\", timeFieldAsLong before[5,8] $a.timeFieldAsLong )\n" + "then\n" + " System.out.println(\"fired\");\n" + "end\n";
KieSession ksession = getKieSession(getCepKieModuleModel(), str);
SessionPseudoClock clock = ksession.getSessionClock();
ksession.insert(new StockTick("ACME").setTimeField(0));
ksession.insert(new StockTick("DROO").setTimeField(6));
assertEquals(1, ksession.fireAllRules());
ksession.insert(new StockTick("DROO").setTimeField(10));
assertEquals(0, ksession.fireAllRules());
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testBefore.
@Test
public void testBefore() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + " $a : StockTick( company == \"DROO\" )\n" + " $b : StockTick( company == \"ACME\", this before[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("ACME"));
clock.advanceTime(6, TimeUnit.SECONDS);
ksession.insert(new StockTick("DROO"));
assertEquals(1, ksession.fireAllRules());
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.insert(new StockTick("DROO"));
assertEquals(0, ksession.fireAllRules());
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testDeclaredSlidingWindowWithEntryPoint.
@Test
public void testDeclaredSlidingWindowWithEntryPoint() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "declare window DeclaredWindow\n" + " StockTick( company == \"DROO\" ) over window:time( 5s ) from entry-point ticks\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();
EntryPoint ep = ksession.getEntryPoint("ticks");
clock.advanceTime(2, TimeUnit.SECONDS);
ep.insert(new StockTick("DROO"));
clock.advanceTime(2, TimeUnit.SECONDS);
ep.insert(new StockTick("DROO"));
clock.advanceTime(2, TimeUnit.SECONDS);
ep.insert(new StockTick("ACME"));
clock.advanceTime(2, TimeUnit.SECONDS);
ep.insert(new StockTick("DROO"));
assertEquals(2, ksession.fireAllRules());
}
Aggregations