use of org.drools.compiler.StockTickEvent in project drools by kiegroup.
the class CepEspTest method testAnnotatedEventAssertion.
@Test(timeout = 10000)
public void testAnnotatedEventAssertion() throws Exception {
KieBase kbase = loadKnowledgeBase("test_CEP_SimpleAnnotatedEventAssertion.drl");
KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
conf.setOption(ClockTypeOption.get("pseudo"));
KieSession session = createKnowledgeSession(kbase, conf);
SessionPseudoClock clock = (SessionPseudoClock) session.<SessionClock>getSessionClock();
final List results = new ArrayList();
session.setGlobal("results", results);
StockTickInterface tick1 = new StockTickEvent(1, "DROO", 50, 10000);
StockTickInterface tick2 = new StockTickEvent(2, "ACME", 10, 10010);
StockTickInterface tick3 = new StockTickEvent(3, "ACME", 10, 10100);
StockTickInterface tick4 = new StockTickEvent(4, "DROO", 50, 11000);
InternalFactHandle handle1 = (InternalFactHandle) session.insert(tick1);
clock.advanceTime(10, TimeUnit.SECONDS);
InternalFactHandle handle2 = (InternalFactHandle) session.insert(tick2);
clock.advanceTime(30, TimeUnit.SECONDS);
InternalFactHandle handle3 = (InternalFactHandle) session.insert(tick3);
clock.advanceTime(20, TimeUnit.SECONDS);
InternalFactHandle handle4 = (InternalFactHandle) session.insert(tick4);
clock.advanceTime(10, TimeUnit.SECONDS);
assertNotNull(handle1);
assertNotNull(handle2);
assertNotNull(handle3);
assertNotNull(handle4);
assertTrue(handle1.isEvent());
assertTrue(handle2.isEvent());
assertTrue(handle3.isEvent());
assertTrue(handle4.isEvent());
session.fireAllRules();
assertEquals(2, ((List) session.getGlobal("results")).size());
}
Aggregations