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 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));
}
use of org.drools.mvel.compiler.StockTick in project drools by kiegroup.
the class LengthSlidingWindowTest method testCompilationFailureWithUnknownWindow.
@Test
public void testCompilationFailureWithUnknownWindow() {
// DROOLS-841
String drl = "import " + StockTick.class.getCanonicalName() + "\n" + "global java.util.List list;\n" + "declare StockTick @role( event ) end\n" + "declare window RhtStocksWindow\n" + " StockTick() over window:length( 3 )\n" + "end\n" + "rule R\n" + "when \n" + " accumulate( StockTick( company == \"RHT\", $price : price ) from window AbcStocksWindow; $total : sum($price) )\n" + "then \n" + " list.add($total);\n" + "end \n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
final KieBuilder kieBuilder = KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
assertEquals(1, kieBuilder.getResults().getMessages().size());
}
use of org.drools.mvel.compiler.StockTick in project drools by kiegroup.
the class LengthSlidingWindowTest method checkPrice.
private void checkPrice(String drl, double expectedPrice) {
KieSessionConfiguration sessionConfig = RuleBaseFactory.newKnowledgeSessionConfiguration();
sessionConfig.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession(sessionConfig, null);
List<Double> list = new ArrayList<Double>();
ksession.setGlobal("list", list);
ksession.insert("RHT");
ksession.insert(new StockTick(1L, "RHT", 10.0));
ksession.insert(new StockTick(2L, "RHT", 10.0));
ksession.insert(new StockTick(3L, "ABC", 20.0));
ksession.insert(new StockTick(4L, "RHT", 10.0));
ksession.insert(new StockTick(5L, "XYZ", 20.0));
ksession.insert(new StockTick(6L, "XYZ", 20.0));
ksession.insert(new StockTick(7L, "RHT", 10.0));
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals(expectedPrice, (double) list.get(0), 0.01);
}
use of org.drools.mvel.compiler.StockTick in project drools by kiegroup.
the class DescrBuilderTest method testRuleRHSOptional.
@Test
public void testRuleRHSOptional() throws InstantiationException, IllegalAccessException {
PackageDescr pkg = DescrFactory.newPackage().name("org.drools.mvel.compiler").newRule().name("r1").lhs().pattern("StockTick").constraint("company == \"RHT\"").end().end().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);
}
Aggregations