use of org.drools.mvel.compiler.StockTick in project drools by kiegroup.
the class DeserializationWithCompositeTriggerTest method testSerializationAndDeserialization.
/**
* Verifies that serialization of a rule with composite trigger does not fail on
* org.drools.core.time.impl.CompositeMaxDurationTrigger class serialization.
*/
@Test
public void testSerializationAndDeserialization() throws Exception {
this.ksession.insert(new StockTick(2, "AAA", 1.0, 0));
this.ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true, false);
Assertions.assertThat(this.ksession).isNotNull();
}
use of org.drools.mvel.compiler.StockTick in project drools by kiegroup.
the class DescrBuilderTest method testTopLevelAccumulate.
@Test
public void testTopLevelAccumulate() throws InstantiationException, IllegalAccessException {
PackageDescr pkg = DescrFactory.newPackage().name("org.drools.mvel.compiler").newRule().name("r1").lhs().accumulate().source().pattern("StockTick").constraint("company == \"RHT\"").bind("$p", "price", false).end().end().function("sum", "$sum", false, "$p").function("count", "$cnt", false, "$p").end().end().rhs("// some comment").end().getDescr();
KiePackage kpkg = compilePkgDescr(pkg, "org.drools.mvel.compiler");
assertEquals("org.drools.mvel.compiler", kpkg.getName());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Collections.singletonList(kpkg));
KieSession ksession = kbase.newKieSession();
AgendaEventListener ael = mock(AgendaEventListener.class);
ksession.addEventListener(ael);
ksession.insert(new StockTick(1, "RHT", 80, 1));
ksession.insert(new StockTick(2, "RHT", 100, 10));
int rules = ksession.fireAllRules();
assertEquals(1, rules);
ArgumentCaptor<AfterMatchFiredEvent> cap = ArgumentCaptor.forClass(AfterMatchFiredEvent.class);
verify(ael).afterMatchFired(cap.capture());
assertThat(((Number) cap.getValue().getMatch().getDeclarationValue("$sum")).intValue(), is(180));
assertThat(((Number) cap.getValue().getMatch().getDeclarationValue("$cnt")).intValue(), is(2));
}
use of org.drools.mvel.compiler.StockTick in project drools by kiegroup.
the class DescrBuilderTest method testRule.
@Test
public void testRule() throws InstantiationException, IllegalAccessException {
PackageDescrBuilder packBuilder = DescrFactory.newPackage().name("org.drools.mvel.compiler").newRule().name("r1").lhs().and().or().pattern("StockTick").constraint("price > 100").end().pattern("StockTick").constraint("price < 10").end().end().pattern("StockTick").constraint("company == \"RHT\"").end().end().end().rhs(" System.out.println(\"foo\");\n").end();
PackageDescr pkg = packBuilder.getDescr();
String drl = new DrlDumper().dump(packBuilder.getDescr());
System.out.println(drl);
KiePackage kpkg = compilePkgDescr(pkg);
assertEquals("org.drools.mvel.compiler", kpkg.getName());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Collections.singletonList(kpkg));
KieSession ksession = kbase.newKieSession();
ksession.insert(new StockTick(1, "RHT", 80, 1));
int rules = ksession.fireAllRules();
assertEquals(0, rules);
ksession = kbase.newKieSession();
ksession.insert(new StockTick(2, "RHT", 150, 1));
rules = ksession.fireAllRules();
assertEquals(1, rules);
}
use of org.drools.mvel.compiler.StockTick in project drools by kiegroup.
the class DescrBuilderTest method testRuleRHSComment.
@Test
public void testRuleRHSComment() throws InstantiationException, IllegalAccessException {
PackageDescr pkg = DescrFactory.newPackage().name("org.drools.mvel.compiler").newRule().name("r1").lhs().pattern("StockTick").constraint("company == \"RHT\"").end().end().rhs("// some comment").end().getDescr();
KiePackage kpkg = compilePkgDescr(pkg);
assertEquals("org.drools.mvel.compiler", kpkg.getName());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(Collections.singletonList(kpkg));
KieSession ksession = kbase.newKieSession();
ksession.insert(new StockTick(1, "RHT", 80, 1));
int rules = ksession.fireAllRules();
assertEquals(1, rules);
}
use of org.drools.mvel.compiler.StockTick in project drools by kiegroup.
the class LifecycleTest method testExpires.
@Test
public void testExpires() throws Exception {
EntryPoint entryPoint = kieSession.getEntryPoint("EventStream");
StockTick event = new StockTick();
FactHandle handle = entryPoint.insert(event);
assertTrue(entryPoint.getFactHandles().contains(handle));
kieSession.fireAllRules();
assertTrue(entryPoint.getFactHandles().contains(handle));
advanceTime(5, TimeUnit.SECONDS);
kieSession.fireAllRules();
assertFalse(entryPoint.getFactHandles().contains(handle));
}
Aggregations