use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testBeforeBindingFirst.
@Test
public void testBeforeBindingFirst() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + " $a : StockTick( company == \"DROO\" )\n" + " $b : StockTick( company == \"ACME\", $a before[5s,8s] this )\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(1, ksession.fireAllRules());
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
assertEquals(0, ksession.fireAllRules());
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testAfterWithEntryPoints.
@Test
public void testAfterWithEntryPoints() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + " $a : StockTick( company == \"DROO\" ) from entry-point ep1\n" + " $b : StockTick( company == \"ACME\", this after[5s,8s] $a ) from entry-point ep2\n" + "then\n" + " System.out.println(\"fired\");\n" + "end\n";
KieSession ksession = getKieSession(getCepKieModuleModel(), str);
SessionPseudoClock clock = ksession.getSessionClock();
ksession.getEntryPoint("ep1").insert(new StockTick("DROO"));
clock.advanceTime(6, TimeUnit.SECONDS);
ksession.getEntryPoint("ep1").insert(new StockTick("ACME"));
assertEquals(0, ksession.fireAllRules());
clock.advanceTime(1, TimeUnit.SECONDS);
ksession.getEntryPoint("ep2").insert(new StockTick("ACME"));
assertEquals(1, ksession.fireAllRules());
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.getEntryPoint("ep2").insert(new StockTick("ACME"));
assertEquals(0, ksession.fireAllRules());
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testAfter.
@Test
public void testAfter() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + " $a : StockTick( company == \"DROO\" )\n" + " $b : 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"));
assertEquals(1, ksession.fireAllRules());
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
assertEquals(0, ksession.fireAllRules());
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testAfterWithAnd.
@Test
public void testAfterWithAnd() throws Exception {
String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R when\n" + " $a : StockTick( company == \"DROO\" )\n" + " $b : 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"));
assertEquals(1, ksession.fireAllRules());
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
assertEquals(0, ksession.fireAllRules());
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class CepTest method testBeforeOnLongFieldsBindingFirst.
@Test
public void testBeforeOnLongFieldsBindingFirst() 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\", $a.timeFieldAsLong before[5,8] timeFieldAsLong )\n" + "then\n" + " System.out.println(\"fired\");\n" + "end\n";
KieSession ksession = getKieSession(getCepKieModuleModel(), str);
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());
}
Aggregations