use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class CepEspTest method testEventAssertionWithDuration.
@Test(timeout = 10000)
public void testEventAssertionWithDuration() {
final String drl = "package org.drools.compiler\n" + "\n" + "import " + StockTick.class.getCanonicalName() + ";\n" + "\n" + "global java.util.List results;\n" + "\n" + "declare StockTick \n" + " @role( event )\n" + " @duration( duration )\n" + " @timestamp( time )\n" + "end\n" + "\n" + "rule \"Check event\"\n" + "when\n" + " $st : StockTick( company == \"ACME\" )\n" + "then\n" + " results.add( $st );\n" + "end";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("cep-esp-test", kieBaseTestConfiguration, drl);
final KieSession session = kbase.newKieSession(KieSessionTestConfiguration.STATEFUL_PSEUDO.getKieSessionConfiguration(), null);
try {
final List results = new ArrayList();
session.setGlobal("results", results);
final StockTick tick1 = new StockTick(1, "DROO", 50, 10000, 5);
final StockTick tick2 = new StockTick(2, "ACME", 10, 11000, 10);
final StockTick tick3 = new StockTick(3, "ACME", 10, 12000, 8);
final StockTick tick4 = new StockTick(4, "DROO", 50, 13000, 7);
final InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
final InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
final InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
final InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
assertNotNull(handle1);
assertNotNull(handle2);
assertNotNull(handle3);
assertNotNull(handle4);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
assertTrue(handle3.isEvent());
assertTrue(handle4.isEvent());
final EventFactHandle eh1 = (EventFactHandle) handle1;
final EventFactHandle eh2 = (EventFactHandle) handle2;
final EventFactHandle eh3 = (EventFactHandle) handle3;
final EventFactHandle eh4 = (EventFactHandle) handle4;
assertEquals(tick1.getTime(), eh1.getStartTimestamp());
assertEquals(tick2.getTime(), eh2.getStartTimestamp());
assertEquals(tick3.getTime(), eh3.getStartTimestamp());
assertEquals(tick4.getTime(), eh4.getStartTimestamp());
assertEquals(tick1.getDuration(), eh1.getDuration());
assertEquals(tick2.getDuration(), eh2.getDuration());
assertEquals(tick3.getDuration(), eh3.getDuration());
assertEquals(tick4.getDuration(), eh4.getDuration());
session.fireAllRules();
assertEquals(2, results.size());
} finally {
session.dispose();
}
}
Aggregations