use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class AccumulateTest method testAccumulateWithMaxCalendar.
@Test
public void testAccumulateWithMaxCalendar() {
String str = "import " + StockTick.class.getCanonicalName() + ";\n" + "rule AccumulateMaxDate\n" + " dialect \"java\"\n" + " when\n" + " $max1 : Number() from accumulate(\n" + " StockTick($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());
ksession.insert(st);
Assertions.assertThat(ksession.fireAllRules()).isEqualTo(1);
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class PatternDSLTest method testAfterOnLongFields.
@Test
public void testAfterOnLongFields() throws Exception {
Variable<StockTick> var_$a = declarationOf(StockTick.class, "$a");
Variable<StockTick> var_$b = declarationOf(StockTick.class, "$b");
Rule rule = rule("R").build(pattern(var_$a).expr("$expr$1$", (_this) -> org.drools.modelcompiler.util.EvaluationUtil.areNullSafeEquals(_this.getCompany(), "DROO"), alphaIndexedBy(String.class, Index.ConstraintType.EQUAL, 0, _this -> _this.getCompany(), "DROO"), reactOn("company")), pattern(var_$b).expr("$expr$2$", (_this) -> org.drools.modelcompiler.util.EvaluationUtil.areNullSafeEquals(_this.getCompany(), "ACME"), alphaIndexedBy(String.class, Index.ConstraintType.EQUAL, 0, _this -> _this.getCompany(), "ACME"), reactOn("company")).expr("$expr$3$", _this -> _this.getTimeFieldAsLong(), var_$a, $a -> $a.getTimeFieldAsLong(), after(5, java.util.concurrent.TimeUnit.MILLISECONDS, 8, java.util.concurrent.TimeUnit.MILLISECONDS)), execute(() -> {
System.out.println("fired");
}));
Model model = new ModelImpl().addRule(rule);
KieBase kieBase = KieBaseBuilder.createKieBaseFromModel(model, EventProcessingOption.STREAM);
KieSessionConfiguration conf = KieServices.get().newKieSessionConfiguration();
conf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
KieSession ksession = kieBase.newKieSession(conf, null);
SessionPseudoClock clock = ksession.getSessionClock();
ksession.insert(new StockTick("DROO").setTimeField(0));
clock.advanceTime(6, TimeUnit.MILLISECONDS);
ksession.insert(new StockTick("ACME").setTimeField(6));
assertEquals(1, ksession.fireAllRules());
clock.advanceTime(4, TimeUnit.MILLISECONDS);
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 PatternDSLTest method testNegatedAfter.
@Test
public void testNegatedAfter() throws Exception {
Variable<StockTick> var_$a = declarationOf(StockTick.class, "$a");
Variable<StockTick> var_$b = declarationOf(StockTick.class, "$b");
Rule rule = rule("R").build(pattern(var_$a).expr("$expr$1$", (_this) -> org.drools.modelcompiler.util.EvaluationUtil.areNullSafeEquals(_this.getCompany(), "DROO"), alphaIndexedBy(String.class, Index.ConstraintType.EQUAL, 0, _this -> _this.getCompany(), "DROO"), reactOn("company")), pattern(var_$b).expr("$expr$2$", (_this) -> org.drools.modelcompiler.util.EvaluationUtil.areNullSafeEquals(_this.getCompany(), "ACME"), alphaIndexedBy(String.class, Index.ConstraintType.EQUAL, 0, _this -> _this.getCompany(), "ACME"), reactOn("company")).expr("$expr$3$", var_$a, not(after(5, java.util.concurrent.TimeUnit.SECONDS, 8, java.util.concurrent.TimeUnit.SECONDS))), execute(() -> {
System.out.println("fired");
}));
Model model = new ModelImpl().addRule(rule);
KieBase kieBase = KieBaseBuilder.createKieBaseFromModel(model, EventProcessingOption.STREAM);
KieSessionConfiguration conf = KieServices.get().newKieSessionConfiguration();
conf.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
KieSession ksession = kieBase.newKieSession(conf, null);
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 NodeSharingTest method testShareCombinedConstraintOr.
@Test
public void testShareCombinedConstraintOr() throws Exception {
// DROOLS-6330
String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R1 when\n" + " $a : StockTick( company == \"DROO\" )\n" + " $b : StockTick( company == \"XXXX\" || this after[5s,8s] $a )\n" + "then\n" + " System.out.println(\"fired\");\n" + "end\n" + "rule R2 when\n" + " $a : StockTick( company == \"DROO\" )\n" + " $b : StockTick( company == \"XXXX\" || this after[5s,8s] $a )\n" + "then\n" + " System.out.println(\"fired\");\n" + "end\n";
KieSession ksession = getKieSession(CepTest.getCepKieModuleModel(), str);
SessionPseudoClock clock = ksession.getSessionClock();
ksession.insert(new StockTick("DROO"));
clock.advanceTime(6, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
assertEquals(2, ksession.fireAllRules());
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
assertEquals(0, ksession.fireAllRules());
assertEquals(1, ReteDumper.collectNodes(ksession).stream().filter(JoinNode.class::isInstance).count());
}
use of org.drools.modelcompiler.domain.StockTick in project drools by kiegroup.
the class NodeSharingTest method testShareCombinedConstraintAnd.
@Test
public void testShareCombinedConstraintAnd() throws Exception {
// DROOLS-6330
// Note: if DROOLS-6329 is resolved, this test may not produce CombinedConstraint
String str = "import " + StockTick.class.getCanonicalName() + ";" + "rule R1 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" + "rule R2 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(CepTest.getCepKieModuleModel(), str);
SessionPseudoClock clock = ksession.getSessionClock();
ksession.insert(new StockTick("DROO"));
clock.advanceTime(6, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
assertEquals(2, ksession.fireAllRules());
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.insert(new StockTick("ACME"));
assertEquals(0, ksession.fireAllRules());
assertEquals(1, ReteDumper.collectNodes(ksession).stream().filter(JoinNode.class::isInstance).count());
}
Aggregations